blfoley.com - all things development
Creating Your First Commerce Server Sequence Component

Commerce Server Sequence Component

3/6/2009

Let's say for instance that each time a user profile was created, you need to create an external record of the account and their initial registration for audit purposes or to alert another system such as CRM or another LOB system that an account has been created.

First we will need to create a new Class Project to house our Operation Sequence Component.

In that project add references to the following (you can do this by unloading the project, opening the .csproj file, and adding the following xml block with the default references)

<Reference Include="Microsoft.Commerce.Application.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<
Reference Include="Microsoft.Commerce.Broker, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"
/>
<
Reference Include="Microsoft.Commerce.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"
/>
<
Reference Include="Microsoft.Commerce.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"
/>
<
Reference Include="Microsoft.Commerce.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"
/>
<
Reference Include="Microsoft.CommerceServer.Catalog, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"
/>
<
Reference Include="Microsoft.CommerceServer.Runtime, Version=6.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

Create your class, for my example i will be using:

class NotifyUserCreate : OperationSequenceComponent

Make sure your class inherits from OperationSequenceComponent.

Add the following using statements:

using Microsoft.Commerce.Providers.Components;
using
Microsoft.Commerce.Contracts.Messages;
using
Microsoft.Commerce.Broker;
using
Microsoft.CommerceServer.Catalog;
using Microsoft.Commerce.Providers.ContextProviders;

Now for our method we only need to override one of the methods.

public override void ExecuteCreate(CommerceCreateOperation createOperation, OperationCacheDictionary operationCache, CommerceCreateOperationResponse response)
{
}

We will skip the meat of this method for now. Now we will need to modify our ChannelConfiguration.config file.

You will need to find the <MessageHandler> block with the sequence that we are looking to update, which is CommerceCreateOperation_UserProfile. You can search on that string.

In the existing <OperationSequence> block you need to add the following at the end of the sequence.

<Component name="User Account Creation Notification" type="Your Full Class Type, Your Assembly, Version=1.0.0.0, Culture=neutral,PublicKeyToken=Your Public Key"/>

Now back to your project, you will need to sign your assembly and deploy it to the GAC.

You can run your new sequence now. It won't do anything, but you'll be able to verify your deployment and check your configuraiton files.

Now lets add some goodies to the method you created above (add the following to your method, or something similar)

string firstName = createOperation.Model.Properties["FirstName"] as string;
string lastName = createOperation.Model.Properties["LastName"] as string
;
string email = createOperation.Model.Properties["Email"] as string
;
{
// Do your logic here to export to an external system;
}

Now you have completed your operation sequence. Keep in mind you can respond to any of the four operation types (Update/Create/Delete/Query). You can put these sequences in any order, add and remove them from the channel configuraion. There is a great deal of extensibility here and an infinite amount of possibility for expansion.

Related Postings