Welcome to MSDN Blogs Sign in | Join | Help
Creating a Custom Mojave OperationalSequence Component

Background

In many enterprises product/catalog information is stored across many disparate systems.  One of the big challenges was finding an effective way to aggregate that information on the web to facilitate the customers buying experience.  This caused many Commerce Server engagements to be heavy on the integration side as you worked to get all the necessary information into the Commerce Server Catalog.  For this example lets assume our enterprise stored custom product description information in an ERP system.

Mojave Solution

Mojave is implemented using  Operational Sequences to service requests.  An operational pipeline is implemented using a pipeline style pattern similar to ASP.NET.  The pipeline represents a sequence of operations.  Each component in the Operational Sequence is a discrete unit of work.  Mojave gives you the ability to extend its pipelines through configuration files and custom component development. 

For querying product information we would use the QueryOperation_Product (pipeline).  In our scenario, we will create a custom OperationalSequence, ProductDescriptionQuery, which is a  component to call out to our ERP system to grab additional product description information.

The following example assumes you have installed the Mojave October CTP and have downloaded the SampleSite.pup available on the Connect site.  Also, this code could change based on the next release of Mojave.

1. Unpup the SampleSite. I typically do a custom unpup and set all the properties myself.

2. Using Commerce Server Catalog Schema Manager, extend the Commerce Server catalog schema and add the “AdditionalDescription” property definition.

a. Property Type : Text

b. Property Name: AdditionalDescription

c. Display On Site: Checked

d. Assign To All Product Types: Checked

3. Open SampleSite web site in Visual Studio.

4. Set a reference to the following libraries Mojave libraries located at \Program Files\Microsoft Commerce\Assemblies:

a. Microsoft.Commerce.Broker.dll

b. Microsoft.Commerce.Contracts.dll

c. Microsoft.Commerce.Providers.dll

6. Add a new Class Library project to the solution. I called mine Commerce.Providers.Components to match the naming structure provided by Mojave.

7. Add a class file called ProductDescriptionQuery

8. Add the following using statements:

a. Microsoft.Commerce.Providers

b. Microsoft.Commerce.Providers.Components

c. Microsoft.Commerce.Providers.Exceptions

d. Microsoft.Commerce.Providers.Utility

e. Microsoft.Commerce.Providers.Broker

f. Microsoft.Commerce.Contracts

g. Microsoft.Commerce.Contracts.Messages

h. Microsoft.Commerce.Contracts.CommerceEntities

9. Set the ProductDescriptionQuery class to inherit from PipelineComponent (Microsoft.Commerce.Providers.Components.PipelineComponent)

10. Override the ExecuteQuery Method:

Public class ProductDescriptionQuery : PipelineComponent

{

Public override void ExecuteQuery(QueryOperation queryOperation,

OperationCacheDictionary operationCache,

QueryOperationResponse response)

{

// The queryOperation provides the inputs to the method

CommerceEntity searchModel = queryOperation.GetSearchModel(“Product”);

If(!searchModel.Properties.ContainsProperty(“Id”))

Throw new OperationNotSupportedException(“This is invalid”);

// response is used to return values through the process

Response.CommerceEntities[0].Properties[“AdditionalDescription”]

= GetAdditionalDescription(searchModel.Id);

}

// Simulate a call to ERP

Private string GetAdditionalDescription(string productId)

{

Return “More Content….”);

}

}

11. Strong name the assembly and register in the GAC. All PipelineComponents need to be in the GAC because the Mojave assemblies are in the GAC.

12. Set a reference to the new assembly in the web project.

13. Open the ChannelConfiguration.config located in the web project. The ChannelConfiguration is responsible for maintaining the OperationalSequences and the mappings between Commece Server and Mojave Types. We need to make a couple additions here:

a. Search for the “QueryOperation_Product” MessageHandler. Add a child node at the end of the “Product Query Processor” component node which looks like this:

<Component name=”Addional Product Query” type=”Components.Providers.Components.ProductDescriptionQuery, Components.Providers.Components, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxx”>

b. In the “ToExternalEntities” node add the following child node:

<Translator sourceModelName=”Product” destinationType=”Microsoft.CommerceServer.Catalog.Product, Microsoft.CommerceServer.Catalog, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf385ad364e35” type=”Microsoft.Commerce.Products.Translators.ProductTranslator, Microsoft.Commerce.Providers, Version=1.0.0.0, Culture=neutral,PublicKeyToken=31bf385ad364e35” />

The publictokenkey can be found on the Component in the GAC

14. The MetadataDefinitions.xml file manages the relationships between the Commerce Server types and Mojave types. We need to add a couple lines so the AdditionalDescription will be available to us.

a. Under the CommerceEntity[“product”]/EntityMappings/EntityMapping/PropertyMappings node add the following:

<PropertyMapping property=”AdditionalDescription” csProperty=”AdditionalDescription” />

15. The sample web solution has types similar to what would be created for a real project, just not deployed in the same manner. Open Product.cs in the App_Code folder of the web application. Create a new property to hold the AdditionalDescription.

Public string AdditionalDescription

{

Get{ return this._commerceEntity.GetPropertyValue(“AdditionalDescription”) as String; }

Set{ this._commerceEntity.SetPropertyValue(“AdditionalDescription”, value); }

}

16. Product.cs also contains a class called PropertyName which holds a list of properties exposed by the Product Class. The class already has a property name for InventoryCondition. Add the following life to the PropertyName class:

Public const string AdditionalDescription= “AdditionalDescription”;

17. Now we need to add the property to the queryBuilder.model so we will have access to it inside of our ExecuteQuery method.

queryBuilder.Model.Properties.Add(Product.PropertyName.AdditionalDescription);

18. Add the following line at the Page_Load method for Default.aspx.cs

Response.Write(product.AdditionalDescription);

19. Build the solution.

20. In the web application set a break point at:

Response response = _operationService.ProcessRequest(Utility………

This is the call which processes the QueryOperation_Product OperationalSequence (OpSec).

21. In the ProductDescriptionQuery class set a breakpoint at the top of the ExecuteQuery method.

22. Debug the Default.aspx page. At this point you should be able to step into the ProductDescriptionQuery.ExecuteQuery method.

Posted: Wednesday, October 29, 2008 11:48 AM by Brad Bont

Comments

No Comments

Anonymous comments are disabled
Page view tracker