Moustafa Refaat
Login   Search
Skip Navigation Links
Home
Publications
Service Offerings
Downloads and Samples
My Resume
Endorsements
Contact Me
Books
Technical Articles
Software Packages
Scroll up
Scroll down
BizTalk The Practical Course
Mastering The BizTalk Technical Interview
Soduku:Challenging Puzzels
Scroll up
Scroll down
Design Patterns Review
Software Architecture Basics Review
Simplified BizTalk Content Based Routing for a Pass_Throu data
An Extensible Light Xml Rules Engine Component
Secure Messaging Solution
Create a SQL Database Programmatically
BizTalk Unzip Adapter
Implementing Singleton pattern with BizTalk Orchestrations
Developing BizTalk Custom Adapters
The BizTalk ESB Toolkit 2.0 experience Series
Scroll up
Scroll down
Setting the ESB Toolkit on the 64 Bit Machines
How The ESB Works
Sample Custom Resolver
Scroll up
Scroll down
Recent Training
Scroll up
Scroll down

News List

  • iBTSInterview (BizTalk Technical Interview) is available on iPhone and iPad
  • Toronto Code Camp Presentation is uploaded
  • BizTalk: The Practical Course is recommended by Micorsoft
  • Canadian Gigs Network (www.CanadianGigs.Net) a job web site focusing on Canadian Jobs
  • BizTalk Technical Interview Preparation
  • GT-DataSafe© Online Backup for Amazon Storage Services 3.0 is released
  • Soduku Challenging Puzzles
  • BizTalk: The Practical Course
  • Mastering The BizTalk Technical Interview is Published Now Avaliable on iPhone an iPad

Technical Articles

  • JavaScript, and SharePoint Calculated Field Trick
  • Scrum Pitfalls
  • Customizing the XSLTListView Web Part
  • SharePoint List Simplified Configuration Store
  • WCF and xsd:choice how to implement!
Skip Navigation Links>Home

 Welcome to my website, in the following pages you will find information about my experience, publications, software products I developed, and synopsis of the services I provide in the areas of software development, design, and architecture. As a software consultant, I worked on different roles, such as BizTalk Developer, SharePoint Developer, BizTalk Architect, Enterprise Architect, Technical Lead, and Instructor. I mainly provide services in the  GTA (Toronto, ON) , though I have provided services in Calgary AB, St Johns NFLD, Chicago IL, and Denver CL in the past. I work with many technologies but I am mainly focused on Microsoft .Net platform. Some of the technologies that I specialize in are:

  • BizTalk
  • SharePoint
  • ASP.Net
  • .Net 3.5
  • Amazon Web Services
  • Oracle
  • MS Dynamics CRM and GP
  • and lately iPhone and iPad

 

Lately I have been focusing on the cloud with Azure and Amazon web services.  Feel free to contact me at Moustafa@MoustafaRefaat.com if you have any questions regarding any of my posts, books, services, or products.

DateNews
16/12/2010iBTSInterview (BizTalk Technical Interview) is available on iPhone and iPad
07/05/2010Toronto Code Camp Presentation is uploaded
11/12/2009BizTalk: The Practical Course is recommended by Micorsoft
10/09/2009Canadian Gigs Network (www.CanadianGigs.Net) a job web site focusing on Canadian Jobs
07/08/2009BizTalk Technical Interview Preparation
11/07/2009GT-DataSafe© Online Backup for Amazon Storage Services 3.0 is released
06/04/2009Soduku Challenging Puzzles
06/04/2009BizTalk: The Practical Course
17/03/2008Mastering The BizTalk Technical Interview is Published Now Avaliable on iPhone an iPad

Rss
<January 2012>
SuMoTuWeThFrSa
25262728293031
1234567
891011121314
15161718192021
22232425262728
2930311234
JavaScript, and SharePoint Calculated Field Trick

I had a client who wanted to display and indicator showing the task list status as of today, for example: if  there is more than 15 days for the task due date display a green light image, less than 15 days display yellow light image, the task is already late display a red light image.

 

 

Simple, however, this client is hosting the SharePoint out of site and we can not deploy custom code at all. I can use an calculate field to select the image to display however that image would not get updated unless a user updates the task, I can write a timer that would run daily and update the filed but that is not possible as I can not deploy custom code, or I can write a custom code that runs a client machine using SharePoint APIs iterates through the task list and updates the items causing all calculated fields to be re-evaluated. The problem with this solution is that it is kind of dependent on having a client machine that would run this code periodically and frankly kind of a messy solution. After researching many of the info on the internet, and a friend’s brains, we devised the following solution.

 

The calculated field would contain a simplified date and a javascript would run in the browser updating the field with HTML with the proper image info and executing that HTML.

 

 

 

<script type="text/javascript">

//<!-- This script searches for calculated fields that are "marked" vith "Due:" and         -->

//<!-- Create a calculated field in the list with the following formula:                    -->

//<!-- =IF(DueDate="","N/A","Due: "&MONTH(DueDate)&"/"&DAY(DueDate)&"/"&YEAR(DueDate))      -->

//<!-- The data type returned from this formula is: Date and Time                           -->

// call script

findDatefields();

function findDatefields() {

    var d = new Date();

    var today = new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();

 

    var arr = document.getElementsByTagName('td');

    for (var i = 0; i < arr.length; i++) {

        // Check if it is "our field"

        if ((arr[i].className == "ms-vb2") && (arr[i].innerHTML.indexOf("Due:") == 0)) {

            var sepDate = arr[i].innerHTML.substring(5).split("/", 3);

            var m = sepDate[0];

            var d = sepDate[1];

            var y = sepDate[2];

 

            // build the datestring

            var fieldDate = new Date(y, m - 1, d, 00, 00, 00).getTime();

            if (fieldDate > today) {

                arr[i].innerHTML = "<IMG src='_layouts/images/KPIDefault-0.gif' Title='On track' />";

            }

            else if (fieldDate == today) {

                arr[i].innerHTML = "<IMG src='_layouts/images/KPIDefault-1.gif' Title='Due today' />";

            }

            else {

                arr[i].innerHTML = "<IMG src='_layouts/images/KPIDefault-2.gif' Title='Overdue' />";

            }

        }

    }

}

// For it to work in collapsed views

function ExpGroupRenderData(htmlToRender, groupName, isLoaded) {

    var tbody = document.getElementById("tbod" + groupName + "_");

    var wrapDiv = document.createElement("DIV");

    wrapDiv.innerHTML = "<TABLE><TBODY id=\"tbod" + groupName + "_\" isLoaded=\"" + isLoaded + "\">" + htmlToRender + "</TBODY></TABLE>";

    tbody.parentNode.replaceChild(wrapDiv.firstChild.firstChild, tbody);

    findDatefields();

}

</script>

 

You can check the following links for information on this subject  

  •  Dynamically Updating A SharePoint Calculated Column Containing A "Today" Reference http://vspug.com/dez/2008/07/31/dynamically-updating-a-sharepoint-calculated-column-containing-a-quot-today-quot-reference/
  • Date Functions in Calculated Fields http://blogs.msdn.com/b/sharepointdesigner/archive/2008/08/01/date-functions-in-calculated-fields.aspx
{28/02/2011 9:17 AM} {0 Comments}  {Tags: SharePoint, JavaScript}
Scrum Pitfalls

I was working with a team on a SharePoint implementation in NYC. The team was adopting Scrum as a methodology to run the project. This is my first Scrum project. Things seemed crazy to me. I read and acquainted myself with Scrum, well things still seemed crazy to me till I took a high level look and saw why things was crazy. The team was implementing Scrum literary without understanding of software engineering principles. Scrum in short advocates iterative development with emphasis on short cycles, and each iteration delivering a working (or kind of working) software, it encourages “daily stand ups” or review of the activities the team is going to do this day and has done the day before { now here comes my first beef, early in the morning is the most productive period of my day and I believe it is for most people I hate to waste this in a meeting discussing stuff} this should be a short meeting 15 min or so (hum well with any modest team of 5-7 people, this takes more than 45 min, and people tend to go into details and waste time and there is the micromanagement which creeps in , and those who love to hear their voice does not matter they are talking nonsense and I can go on and on).   But the most missing and important ingredient is the design and architecture, Scrum does not address that and assumes everyone in the team can play any role and advocates learning on the job, that is fine for graduation project but to deliver a project on time and within budget you need a good architecture, a good design and assigns tasks to each member of the team that suite his skill set. Learning is very important but that is a specific task to be assigned separately. To be continued..

{28/09/2010 7:56 AM} {0 Comments}  {Tags: Project Management}
Customizing the XSLTListView Web Part

In a project I was working in I wanted to customize how the blog post was displayed. The Post.aspx in the Post list uses the new WebPartPages:XsltListViewWebPart, which is a new web part in SharePoint 2010. I would not bore you with a lot of background and stuff that You can read in the MSDN. I will just describe the solution that I implemented.  I had to change the XSL Link  it uses in Miscellaneous  options of the web part and implement  the template as follows

<!-- BaseViewID='7' and TemplateType='301' is Posts.aspx view for Blog's posts list -->

  <xsl:template match="View[@BaseViewID='7' and List/@TemplateType='301']" mode="full">

    <xsl:apply-templates select="." mode="AdeccoRenderView" />

   

  </xsl:template>

 

  <xsl:template match="View" mode="AdeccoRenderView">

    <xsl:variable name="ViewStyleID">

      <xsl:value-of select="ViewStyle/@ID"/>

    </xsl:variable>

  

    <!-- total first -->

 

    <xsl:variable name="HasExtraColumn" select="$TabularView='1' and $MasterVersion=4 and ($ViewStyleID = '' or $ViewStyleID = '17')"/>

    <xsl:variable name="Fields" select="ViewFields/FieldRef[not(@Explicit='TRUE')]"/>

    <xsl:variable name="Groups" select="Query/GroupBy/FieldRef"/>

    <xsl:variable name="Collapse" select="Query/GroupBy[@Collapse='TRUE']"/>

    <xsl:variable name="GroupCount" select="count($Groups)"/>

    <xsl:if test="Aggregations[not(@Value='Off')]/FieldRef">

      <tr>

        <xsl:if test="$HasExtraColumn">

          <td/>

        </xsl:if>

        <xsl:if test="$InlineEdit">

          <td width="1%"/>

        </xsl:if >

        <xsl:apply-templates mode="aggregate" select="ViewFields/FieldRef[not(@Explicit='TRUE')]">

          <xsl:with-param name="Rows" select="$AllRows"/>

          <xsl:with-param name="GroupLevel" select="0"/>

        </xsl:apply-templates>

      </tr>

    </xsl:if>

    <xsl:for-each select="$AllRows">

      <xsl:variable name="thisNode" select="."/>

      <xsl:for-each select="//Row">

        <tr>

          <td colspan="2">

 

 

            <div class="TopTitle">

              <div  class="PostTitle">

                <strong>

                  <xsl:value-of select="@Title" disable-output-escaping="yes" />

                </strong>

              </div>

              <xsl:if test="../../@BaseViewID='7'">

                <!-- Handle _edit only their own_ property on list -->

                <xsl:if test="($thisNode/../@value.listpermission.EditListItems = '1' and (($thisNode/../@value.listpermission.ManageLists  = '1') or ($XmlDefinition/List/@WriteSecurity = '2' and $thisNode/@Author.id = $Userid) or ($XmlDefinition/List/@WriteSecurity != '2')))">

                  <div  class="ms-blogedit">

                    <a href="javascript:" onclick="javascript:STSNavigate('{$HttpVDir}/{$thisNode/../@resource.wss.lists_Folder}/{$thisNode/../@resource.wss.blogpost_Folder}/EditPost.aspx?ID={$thisNode/@ID}&amp;Source={$HttpVDir}%2Fdefault.aspx');">

                      <xsl:value-of select="$thisNode/../@resource.wss.blog_edit" />

                    </a>

                  </div>

                </xsl:if>

              </xsl:if>

            </div>

        

            <div class="PostSubtitle" >

              <div class="PostAuther" >

                By: <xsl:value-of select="@Author" disable-output-escaping="yes" />

              </div>

              <div class="PostPublishDate">

                Posted <xsl:value-of select="@PublishedDate" />

              </div>

            </div>

            <div class="PostTable">

              <div class="PostDateBox" >

                <div class="PostSmallDate">

                  <xsl:value-of select="ddwrt:FormatDateTime(string(@PublishedDate), 1033, 'MMM. d yyyy')" />

                </div>

              </div>

              <div class="PostBody" >

                <xsl:value-of select="@Body" disable-output-escaping="yes"/>

              </div>

              <div class="PostComments">

                <img src="_layouts/images/AdeccoPortal2010/icon_comment.png" alt="comment"/><xsl:value-of select="@NumComments" /> Comment(s)

              </div>

            </div>

 

            <hr />

         

       

          </td>

        </tr>

 

       

 

      </xsl:for-each>

 

    </xsl:for-each>

    <xsl:if test="$InlineEdit and not($IsDocLib) and $ListRight_AddListItems = '1'">

      <xsl:call-template name="rowinsert">

        <xsl:with-param name="Fields" select="$Fields"/>

      </xsl:call-template>

    </xsl:if>

  </xsl:template>

 

Now the blog post looks like the following

 

Not bad eh

Hope this helps you in your SharePoint 2010 implementation

{15/09/2010 12:17 PM} {0 Comments}  {Tags: SharePoint}
SharePoint List Simplified Configuration Store

This is a sample configuration store that I wrote for a SharePoint implementation that I was working on. The configuration manager has a simple interface that takes two keys (siteID, and Key)  and returns the string associated with these keys here is the interface definition

 

public interface IConfigurationManager

    {

        string GetConfiguration(string siteID, string key);

    }

 

The implementation for the IConfiguration manager expects to find the list URL and the site URL where the list exists(the list can exist in any site) in the application settings of the web.config. The implementation caches the retrieved values which has its own draw backs as changes to the list are not reflected till the cash expires but for this implementation the requirement did not expect lots of changes.

/// <summary>

    ///  Reads the configuration information from the Configuration list

    ///  the URL for the list is stored in application settings in key

    ///   <add key="ConfigListURL" value="/Configuration/Lists/ConfigurationStore" />

    ////  <add key="configWebSiteURLKey"  value="http://localhost/Configuration"/>

    /// 

    /// </summary>

    public class ConfigurationManager: IConfigurationManager

    {

        private const string configListNameKey = "ConfigListURL";

        private const string configWebSiteURLKey = "configWebSiteURLKey";

       

        public ConfigurationManager()

        {

        }

        public string GetConfiguration(string siteID, string key)

        {

            string entry = null;

            bool dirty = false;

            Dictionary<string, Dictionary<string, string>> globalMap = GetMap();

            Dictionary<string, string> siteMap = null;

            if(globalMap.ContainsKey(siteID))

            {

                siteMap = globalMap[siteID];

                if(siteMap.ContainsKey(key))

                {

                entry = siteMap[key];

                }

                if(null == entry)

                {

                    dirty = true;

                    entry = GetConfigEnrtyFromSharePoint(siteID, key);

                    if (entry != null)

                    {

                        siteMap[key] = entry;

                    }

                }

            }

            else

            {

                dirty = true;

                entry = GetConfigEnrtyFromSharePoint(siteID, key);

                siteMap = new Dictionary<string, string>();

                if (entry != null)

                {

                    siteMap[key] = entry;

                }

                globalMap[siteID] = siteMap;

            }

            // update map if need be

            if (dirty)

            {

                HttpContext.Current.Cache[globalMapCacheKey] = globalMap;

            }

            return entry;

        }

        private string GetValue(SPListItem item)

        {

            string value = string.Empty;

            try

            {

                value = item["Value"].ToString();

            

            }

            catch

            {

                Debug.WriteLine("NoValue");

            }

            return value;

        }

 

        const string queryformatstr = "<Where> <And><Eq><FieldRef Name='Title'/><Value Type='Text'>{0}</Value></Eq><Eq><FieldRef Name='SiteID'/><Value Type='Text'>{1}</Value></Eq> </And></Where>";

        private string GetConfigEnrtyFromSharePoint(string siteID, string key)

        {

            string result = null;

            string SiteUrl = WebConfigurationManager.AppSettings[configWebSiteURLKey];

            SPSecurity.RunWithElevatedPrivileges(delegate()

            {

                using (SPSite siteCollection = new SPSite(SiteUrl))

                {

 

                    using (SPWeb rootweb = siteCollection.OpenWeb())

                    {

 

                        string configlistUrl = WebConfigurationManager.AppSettings[configListNameKey];

                        SPList list = null;

                        try

                        {

                            list = rootweb.GetList(configlistUrl);

                            SPQuery oQuery = new SPQuery();

                            oQuery.Query = string.Format(queryformatstr, key, siteID);

                            SPListItemCollection collListItems = list.GetItems(oQuery);

                            if ((null != collListItems) && (collListItems.Count >= 1))

                            {

                                result = GetValue(collListItems[0]);

                            }

                        }

                        catch (Exception ex)

                        {

                            Debug.WriteLine(ex.ToString());

                        }

                    }

                }

            }

            );

            return result;

        }

        const string globalMapCacheKey = "globalConfigurationMapCacheKey";

 

        private Dictionary<string, Dictionary<string, string>> GetMap()

        {

            Dictionary<string, Dictionary<string, string>> map = HttpContext.Current.Cache[globalMapCacheKey] as Dictionary<string, Dictionary<string, string>>;

            if (null == map)

            {

                map = new Dictionary<string, Dictionary<string, string>>();

                HttpContext.Current.Cache[globalMapCacheKey] = map;

            }

            return map;

        }

    }

}

 

The Provider just loads the implementation based on the class name and assembly name of an entry in the application settings in web.config.

// <summary>

    ///  

    /// Class, Assembly

    ///     <add key="configManagerProvider" value="ConfigurationManager, GlobalConfiguration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=22d2dcb173b01686"/>

    /// </summary>

    public class ConfigurationManagerProvider

    {

        private const string configManagerProviderKey = "configManagerProvider";

        static public  IConfigurationManager GetConfigurationManager()

        {

            string str = WebConfigurationManager.AppSettings[configManagerProviderKey];

            int isep = str.IndexOf(',');

            string assemblyName = str.Substring(isep+1);

            string typeName = str.Substring(0,isep);

            Assembly asm = Assembly.Load(assemblyName);

            IConfigurationManager mngr = asm.CreateInstance(typeName) as IConfigurationManager;

            return mngr;

        }

    }

 

The consumer would write code similar to

      IConfigurationManager cm = ConfigurationManagerProvider.GetConfigurationManager();

      lblSiteTitle.Text = cm.GetConfiguration("Site1", "Key1");

 

{26/08/2010 1:47 PM} {0 Comments}  {Tags: SharePoint}
WCF and xsd:choice how to implement!
For some reason Microsoft decided that WCF serialization is not going to support the xsd:choice. The .Net XML serialization does support xsd:choice which is important. Now, if you had a schema that used xsd:Choice and used XSD tool to generate classes for it will generate code similar to:
///<remarks/>
    [System.Xml.Serialization.XmlElementAttribute("Option1", typeof(typeOption11), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    [System.Xml.Serialization.XmlElementAttribute("Option2", typeof(typeOption2), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    [System.Xml.Serialization.XmlElementAttribute("Option3", typeof(typeOption3), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public object Item {
        get {
            return this.itemField;
        }
        set {
            this.itemField = value;
        }
Well that is look neat does not it? Now if you exposed this same generated code through WCF, the WSDL would generate item as Object on the client side and the consumer would not get any information from the WSDL about typeOption1, typeOption2, nor typeOption3. That is a real pain for the developer on the consumer side!. So one workaround that I had to device for a solution I was developing is to create another class like the following
public partial class Optionss {
 
    [System.Xml.Serialization.XmlElementAttribute("Option1", typeof(typeOption1), Form=System.Xml.Schema.XmlSchemaForm.Unqualified,IsNullable = true)]
    public typeOption1 Option1 = null;
    [System.Xml.Serialization.XmlElementAttribute("Optoin2", typeof(typeOption2), Form=System.Xml.Schema.XmlSchemaForm.Unqualified,IsNullable = true)]
    public typeOption2 Option2 = null;
    [System.Xml.Serialization.XmlElementAttribute("Option3", typeof(typeOption3), Form=System.Xml.Schema.XmlSchemaForm.Unqualified,IsNullable = true)]
    public typeOption3 Option3 = null;
 
}
And chenage the item above to be similar to
    public Optionss Item {
        get {
            return this.itemField;
        }
        set {
            this.itemField = value;
        }
 
Now the options are going to appear to the consumer, however the data you receive is going to be for a different schema so I wrote code that would serialize the received request then “fix” the XML to be corresponding to the actual schema with xsd:choice.  Not quite neat  workaround but it works.
{06/08/2010 2:21 PM} {2 Comments}  {Tags: EAI, WCF, Web Developmenet}
1 2 3 4 5 6> >>|
Rss
 
BizTalkGear.com
BizTalk components
Genetic Thought Software Inc
Genetic Thought Web Site where you can by my software products
SodukuPro.com
Play Sudoku Online or buy a PC based edition

Rss
Key Subjects
  • BizTalk
  • EMail
  • SharePoint
  • Architecture
  • EAI
  • Exception Management
  • Web Developmenet
  • Deployment
  • Security
  • Busienss Rules
  • SQL Server
  • ESB Toolkit
  • WCF
  • Project Management
  • JavaScript
Copyright © Moustafa Refaat 2004 - 2009. All Rights Reserved.