How to Build Pipeline Components Using C#

You can create pipeline components in C# by using Microsoft Visual Studio. The steps to build a pipeline component can be divided into these logical procedures:

  1. Create a new Microsoft Visual Studio class library project and configure it to register with COM, include the correct references, and add the correct using directives.

  2. Provide the appropriate attributes for your new pipeline component class.

  3. Implement and build your pipeline component.

After you build your pipeline component, you must debug, register, and deploy it. See the links at the bottom of this page to locate topics about these procedures.

Note

The Commerce Server Core Systems SDK includes a complete pipeline component developed in C# that is named MinMaxShipping. It can be found in the following folder: %COMMERCE_SERVER_ROOT%\Sdk\Samples\MinMaxShipping

To create and configure a C# project for your pipeline component

  1. Start Microsoft Visual Studio.

  2. On the File menu, click New, and then click Project. The New Project dialog box opens.

  3. In the New Project dialog box, in the Project types pane, select the Windows child in the Visual C# branch of the tree, and then in the Templates pane, select the Class Library template.

  4. In the New Project dialog box, select an appropriate project name, location, and solution name, and then click OK. Your new class library project opens within Microsoft Visual Studio.

  5. If it is required, open Solution Explorer. Right-click your new project and then click Properties. The multi-tabbed project properties window opens in your workspace.

  6. In the multi-tabbed project properties window, click the Build tab. Then, in the Output section, select the Register for COM interop check box. By using this setting, Microsoft Visual Studio will automatically register your pipeline component with COM.

  7. In Solution Explorer, right-click your project and then click Add Reference. The Add Reference dialog box opens.

  8. In the Add Reference dialog box, on the .NET tab, scroll and select Microsoft Commerce Server Interop Assembly, and then click OK. Your project now includes a reference to Microsoft.CommerceServer.Interop.

    Note

    Many pipeline components must also reference the assemblies Microsoft Commerce Server .NET Application Framework and Microsoft Commerce Server Shared Types Assembly. Repeat steps 7 and 8 as required.

  9. In Solution Explorer, right-click the file Class1.cs and then click Rename.

  10. Type a more descriptive name for your C# source code file (make sure that you retain the ".cs" file name extension) and then press ENTER. When you are prompted about renaming all references to related code elements, click Yes. The name of your pipeline component class will change as specified in your renamed C# source code file.

  11. In your renamed C# source code file, add the following using directives below the default using directives:

    using System.Runtime.InteropServices;
    using Microsoft.CommerceServer.Runtime;
    using Microsoft.CommerceServer.Interop;
    using Microsoft.CommerceServer.Interop.Orders;
    

To add the appropriate attributes to your pipeline component class

  1. In Microsoft Visual Studio, on the Tools menu, click Create GUID. The Create GUID dialog box opens.

  2. In the Create GUID dialog box, select the Registry Format, click Copy to create a GUID and copy it to the clipboard, and then click Exit to dismiss the tool.

  3. Add the following two bold lines immediately above your pipeline component class declaration in your C# source code file, pasting the GUID created in step 2 from the clipboard. Make sure that you do not have braces ({}) in your GUID value.

    Dd328502.alert_caution(en-US,CS.90).gifImportant Note:

    The specific GUID shown throughout this topic is an example. You must replace it with a unique GUID of your own that you generated with the Create GUID dialog box.

                [ComVisible(true)]
    [GuidAttribute("D452305E-50C9-4031-BC94-6839BE6066EE")]
    public class MyPipelineComponentClass
    {
    }
    

To implement your pipeline component class

  1. Type the names of the interfaces from which you want your pipeline component to inherit. It must inherit the interface IPipelineComponent, and optionally it may inherit one or both of the interfaces IPipelineComponentAdmin and IPipelineComponentDescription. The following example shows, in bold font, the text you would enter for your new pipeline component class to inherit from all three of these interfaces:

    [ComVisible(true)]
    [GuidAttribute("D452305E-50C9-4031-BC94-6839BE6066EE")]
    public class MyPipelineComponentClass : IPipelineComponent, IPipelineComponentAdmin, IPipelineComponentDescription
    {
    }
    
  2. For each interface name that you typed in the previous step, right-click the interface name, click Implement Interface, and then click Implement Interface (not Implement Interface Explicitly). Implementation stubs are added to your C# source code file.

  3. Implement and build your pipeline component according to your business requirements.

    Note

    The implementation stubs for the IPipelineComponent interface are for the methods EnableDesign and Execute. The former method is obsolete and should not be used. You should implement the business logic for your pipeline component in the Execute method.

    The code for a sample pipeline component should resemble the following:

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    using System.Runtime.InteropServices;
    using Microsoft.CommerceServer.Interop;
    using Microsoft.CommerceServer.Runtime;
    using Microsoft.CommerceServer.Interop.Orders;
    
    namespace CustomPipeline
    {
        [ComVisible(true)]
        [GuidAttribute ("D452305E-50C9-4031-BC94-6839BE6066EE")]
        public class MyPipelineComponentClass : IPipelineComponent
        {
            // Status codes for pipeline components
            private const Int32 StatusSuccess = 1; // success
            private const Int32 StatusWarning = 2; // warning
            private const Int32 StatusError = 3; // error
    
            #region IPipelineComponent Members
            void IPipelineComponent.EnableDesign(int fEnable){}
    
            int IPipelineComponent.Execute(object pdispOrder, object pdispContext, int lFlags)
            {
                Int32 ReturnValue = StatusSuccess;
                // TODO: add code for the pipeline
                return ReturnValue;
            }
            #endregion
        }
    }
    

See Also

Other Resources

How to Debug Pipeline Components

How to Register Pipeline Components

How to Deploy Pipeline Components

Building Pipeline Components