Subscribe


Tags

  • Commerce Server Documentation (0),
  • Architectural and Design (0),
  • Marketing System (0),
  • Orders System (0),
  • Catalog System (0),
  • CS2007 BizTalk Adapters (0),
  • Partner SDK (0),
  • Commerce Server Operations (0),
  • Profile System (0),
  • Migration (0),
  • Commerce Server Staging (0),
  • DWA and Reporting (0),
  • Deployment (0),

March 2010 (2)
February 2010 (9)
July 2010 (8)
August 2010 (8)
June 2010 (1)

Posted Date Published 8/25/2009 2:05:44 PM

Hacking Commerce Server Staging Part II

In the previous post I showed you how to create a custom UI for the Commerce Server Staging (CSS). In this post I will show you how you can create a custom handler that will fire and perform some action based on the custom UI.

Custom Handler

As noted in previous post CSS uses managed code for data import\exports. CSS engine works on using a factory object to create handlers depending on the project type name. The project type name is specified in the “BusinessDataTypes.xml” file located in “C:\Program Files\Microsoft Commerce Server 2007\Staging\Bin\” folder if Commerce Server was installed with defaults. In my sample I have a custom name called “Max's Test”. When the CSS engine identifies an export or import it reads the “BusinessDataTypes.xml” file then look at the project xml file and finds the type identified. So our project xml file should have “Max's Test” as the BusinessDataTypeName attribute. When the match is made the CSS engine will load the “HandlerAssemblyQualifiedName” attribute value. In the sample “CSSTestUI.CustomHandler” is the handler. The CustomHandler class inherits from IBusinessDataStagingHandler having two methods for implementation Import\Export.

Let’s take a look at a simple implementation:

class CustomHandler : IBusinessDataStagingHandler
{
    #region IBusinessDataStagingHandler Members

    public void Export(string projectName, BusinessData businessData, string projectLocation, string sourceSite)
    {
        if (projectName == null)
        {
            throw new ArgumentNullException("projectName");
        }
        if (businessData == null)
        {
            throw new ArgumentNullException("businessData");
        }
        if (projectLocation == null)
        {
            throw new ArgumentNullException("projectLocation");
        }
        if (sourceSite == null)
        {
            throw new ArgumentNullException("sourceSite");
        }
        string filename = Path.Combine(projectLocation, businessData.BusinessDataId + ".xml");
        StreamWriter st = File.CreateText(filename);
        st.Write("From Custom handler (Export)...");
        st.Close();
    }

    public void Import(string projectName, BusinessData businessData, string projectLocation, string destinationSite)
    {
        if (businessData == null)
        {
            throw new ArgumentNullException("businessData");
        }
        if (projectLocation == null)
        {
            throw new ArgumentNullException("projectLocation");
        }
        if (destinationSite == null)
        {
            throw new ArgumentNullException("destinationSite");
        }
        string filename = Path.Combine(projectLocation, businessData.BusinessDataId + ".xml");
        StreamWriter st = File.AppendText(filename);
        st.Write("From Custom handler (Import)...");
        st.Close();
    }

    #endregion
}

In the sample above instead of doing real work I am just writing and reading the xml project data file. Please note I am not writing xml so if you open it in a xml browser you will generate errors.

Theda theda that’s all folks

Once you create your own custom handler just make sure to sing the assembly and GAC it. Then you need to stop\start the CSS Service before the project works. To debug your code you would attach to the MMC console for the UI and the CSS Service for the handler.

Good luck creating cool custom CSS projects.

 

Once I have access to ftp I will upload the project files in these blog posts. The project was created VS2008 and tested on windows 2008\Commerce Server 2007. There should be no issues with Commerce Server 2009 if you do find issues please send me an email so I can post it for others.

by Max Akbar | Comments



Comments disabled.