Everything you ever wanted to know about pipelines but were afraid to ask (Part IV)


So far you if you have followed this on going Pipeline posts, you should be very familiar with how to work with pipelines how to configure them using Pipeline Editor, how to manage your pipelines in the web.config as well as creating your own custom pipelines. I also hinted that you can use some undocumented APIs to automate some administration tasks (of course since this is undocumented its not supported :p). You should also be very familiar with creating custom UIs for your custom pipeline components and saving it's data.
As promised in this post I will show you how to debug your custom components and do how to test them and this will conclude the final post.


Before we jump into this I would like to offer you some readings, the UE team for CS2007 have done a fantastic job at documenting this version of Commerce Server so in a very nice way I would like to say please take a moment and make sure that you "Read The Fine Manual" :). Should you not agree I encourage you to take a moment and send feedback using the help docs.


There are two other great blog post that you should read David Messner's Transactional pipeline components and error handling and Nihit Kaul's  Running Pipelines in a Console Application.


Creating PropertyPages for your Pipeline Component


This is a bit off topic but if you are like me you want to know everything there is to know when developing and dealing with Pipelines. So I have been asked how do you create a property page for the pipeline components. The short answer is that you can not create a property page using .NET. You will have to develop with C++. Here is how:



  1. We are going to work with what you have created so far in the previous posts. So launch your Custom Pipeline Project.
  2. Now that you have Visual Studio up and running with our project Select File then Add and next select New Project...
  3. Form the Add New Project dialog navigate and select C++ then ATL and in the right pane select ATL Project.


     

  4. Enter a descriptive name for the project then select OK.
  5. From the ATL Project Wizard dialog select Next.
  6. From the ATL Project Wizard dialog Application Settings make sure that only Dynamic-Link Library (DLL) radio button is selected and next select Finish.
  7. The wizard will create two projects see image below.


     

  8. Now you need to implement the ISpecifyPropertyPages Interface. This interface has only one method you need to implement GetPages. This interface is implemented in your custom pipeline component class.





    using System;
    using System.Collections.Generic;
    using System.Text;

    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using Microsoft.CommerceServer.Interop;
    using Microsoft.CommerceServer.Interop.Orders;
    using Microsoft.CommerceServer.Runtime;
    using Microsoft.CommerceServer.Runtime.Orders;
    using Microsoft.CommerceServer.Internal;

    namespace CustomPipeline
    {
        [ComVisible(true)]
        [GuidAttribute ("5904C354-F1B8-485c-89DD-883D26BCE85D")]
        public class Class1 : IPipelineComponent,
                IPipelineComponentAdmin,
                IPersistDictionary,
                ISpecifyPipelineComponentUI,
                IPipelineComponentDescription,
                ISpecifyPropertyPages

    //.......
    // code commented out for clarity
    //.......

    #region ISpecifyPropertyPages Members

        public void GetPages(out tagCAUUID pPages)
        {
            throw new Exception("The method or operation is not implemented.");
        }

    #endregion

    //.......
    // code commented out for clarity
    //.......


  9. Select your ATL Project and right click then select Add and next select Class.


     

  10. From the Add Class Wizard navigate to ATL then from the right pane select ATL Property Page and select the Add button.
  11. In the ATL Page Wizard enter a descriptive name for your class then select Next.


     

  12. In the next page make sure that Apartment Threaded for Thread Modeling is selected and No for Aggregation then select Next and finally select Finish.
  13. The wizard will create a basic Property Page.
  14. In the ATL project Select the project resource file and double click. This will bring you the Resource View.
  15. FrFrom the Resource View navigate to Dialog and double click our newly created property page.


     

  16. Next drag and drop a text box and use the existing Static Text.
  17. Now we need to add some code to the GetPages method to display our property page.





     public void GetPages(out tagCAUUID pPages)
    {
        pPages = new tagCAUUID();

        pPages.cElems = 1;
        byte[] buffer1 = new Guid("{2879AC98-0A80-4F6B-AC0C-EE8A1E0391E3}").ToByteArray();
        pPages.pElems = Marshal.AllocCoTaskMem(buffer1.Length);
        for (int num1 = 0; num1 < buffer1.Length; num1++)
        {
            Marshal.WriteByte(pPages.pElems, num1, buffer1[num1]);
        }
    }

    The GUID must be of that of your property page. You can get this by opening the .rgs file of your property page.


     

  18. Now build your solution.
  19. Run the steps for registering your custom component with pipereg.exe.
  20. TeTest your new Property Page in Pipeline Editor.


     
  21. Congratulation you  have now created a new property page for you pipeline component.

How to Use MessageManager


Take a moment to read the following help topic How to Use MessageManager. This topic will help you localize your error messages.


Error Handling in Pipelines


Take a moment and read the following help topic Error Handling in Pipelines. . This will familiarize you with where to add errors so you can display it to the user.


Troubleshooting Pipelines


Debug pipelines in ASP.NET



  1. To debug your pipelines in ASP.NET unpackage the CSharp site and set the correct security permissions.
  2. Open the Custom Pipeline Solution.
  3. Right Click on your Solution and add a Existing Web Project and select CSharpSite.
  4. Modify the CSharpSite's Web.config so you can execute the basket pipeline.
  5. Modify the basket pipeline and add your custom pipeline anywhere (make sure that you had compiled your code in debug mode).
  6. Now add code to the default.aspx page to execute your basket pipeline.





     Basket basket = CommerceContext.Current.OrderSystem.GetBasket(Guid.NewGuid());
    basket.OrderForms.Add(new OrderForm());

    PipelineInfo pipeinfo = new PipelineInfo("basket");

    PipelineExecutionResult pipeResult = basket.RunPipeline(pipeinfo);
    Response.Write(pipeResult.ToString());
     
    Note: You should know how to do the above steps for a refresher please read the previous posts.
     


  7. Now add the custom pipeline dll and pdb files under the bin directory of your CSharp Site.
  8. Now go to your Custom Pipeline project and create a breakpoint anywhere under the Execute method.
  9. Check the web.config to make sure it's set for debugging:





    <application siteName="CSharpSite" debugLevel="Debug"/>

    and

    <compilation defaultLanguage="c#" debug="true">


  10. Launch Internet Explore and navigate to the CSharpSite default.aspx page (For the advanced folks you can do the next steps by adding the URL in the debug properties of your project).
  11. Now in your Visual Studio select the Debug menu then select Attach to Process...
  12. In the Attach to Process dialog find the w3wp.exe process and attach to it (your Visual Studio solution will now be in debug mode).
  13. Refresh your Internet Explorer.
  14. Notice that you now hit your breakpoint.

Using the XMLTracer Pipeline Component


David Messner originally wrote the Troubleshooting Commerce Server Pipelines and in that article he wrote the XMLTracer that has now made it's way into the product. You can read more about the XMLTracer here.


How to Debug the Scriptor Component


As a best practice never use the scriptor component for production use. You can however use the DumpOrder.vbs for debugging pruposes or only use the scriptor for proof of concept applications. Please read the documentation for How to Use the Scriptor Component. To setup the scriptor debugging please read David Messner's article Troubleshooting Commerce Server Pipelines chapter 3.


Using Pipeline Logging


This section of the help files will guide you through How to Use an Order Log.
When you set the loggingEnabled section of the pipeline make sure to create a folder under the pipeline folder called log and give ASP.NET access to write\read\modify.





<pipelines siteName="CSharpSite">

<pipeline name="basket" path="pipelines\basket.pcf" transacted="true" type="OrderPipeline" loggingEnabled="true"/>

</pipelines>
 


Using the Scriptor to dump pipeline values to a file


In my second post I mentioned the DumpOrder.vbs file, you can also find more information about it here.


Test your Pipelines


Since you have written your pipeline component in .NET testing becomes very simple all you have to do is write a test that calls the execute method. Make sure to read Nihit Kaul's  Running Pipelines in a Console Application.


Pipeline Performance


The pipeline performance counters are used for performance monitoring and tuning. The object name for the performance counters is Commerce : Pipelines. Counter instances are created per site, per a pipeline and pipeline component (.pcf file) combination. You will first need to execute your pipeline before you can collect data.


Summary


Now you know all there is to know about pipelines, good luck.

Comments (9)
  1. As previously discussed the pipeline system enables sequential workflow processing. It is a COM-based…

  2. Minah says:

    Hi Max,

    I have added a base property VAT(value added tax) using Catalog and Inventory schema manager, which I should add or subtract according to shipping address selected(country). So what should I do. I know how to add a component. But tell me where should i add the component in Total pipeline(i think i should add it here). what should be the code in execute(). And wether I can get the value of VAT in the pipeline

     I read the collin’s blog(http://rockstarguys.com/blogs/colin/archive/2007/01/30/building-an-order-pipeline-component.aspx) and have got the following doubts

     1.  "OrderForm orderForm = new OrderForm((IDictionary)pdispOrder); " Its giving me an error saying the constructor accepts only string.

     2.  "OrderAddress shippingAddress = orderForm.Addresses[lineItem.ShippingAddressId];" its not at all showing "Addresses" after typing "orderFrom."

    And how I will get the property "VAT" in similar way.

    Please help me, and thanks in advance.

  3. MSDN Archive says:

    Hi Minah,

    Take some time to read all the post I have for Pipeline Components:

    https://blogs.msdn.com/maxakbar/archive/2006/08/17/705473.aspx

    https://blogs.msdn.com/maxakbar/archive/2006/09/02/736999.aspx

    https://blogs.msdn.com/maxakbar/archive/2006/09/17/759555.aspx

    https://blogs.msdn.com/maxakbar/archive/2006/09/20/764024.aspx

    https://blogs.msdn.com/maxakbar/archive/2007/05/08/how-to-enable-pipeline-pooling.aspx

    The above links will help you get a grasp of what pipelines are, how to create them and how to edit pipeline files.

    As for where to put your custom pipeline components that really depends on your requirement, do you tax post discounts or pre. In most cases you should put your calculations before the total pipeline so create a stage Calculate Tax and add your component there before subtotaling.

    How to get the VAT? You need to add this to the Lineitem when you do add to cart.

    As to what to put in the execute method, well you need to use that VAT code in the line item and call your Tax System and find out how much you should tax that product then add that to the total of the order.

    Since I don’t have a context of the error you are running with the Orderform I can’t help you. In the future I would highly recommend posting your questionsissues on Commerce Server forum.

    http://forums.microsoft.com/msdn/default.aspx?forumgroupid=294&SiteID=1

    Good luck,

    -Max

  4. Andreas Georgsson says:

    Hi,

    Thanx for great guides.

    But I want to know how to pass temporary values between my asp.net page and my pipeline in both directions. You had a short example of using the ordercontext to pass a value from my asp.net page but but how do I pass a value back, can I use the ordercontext for this also.

    I also want to redirect the user to a new page if a value is true, but continue whit the pipeline if the value is false can this be done?

    Or do I need to create seperate pilines that execute after each other, and handels the result?

    Thanx

    – Andreas

  5. MSDN Archive says:

    Inside the pipeline you can’t redirect the user. What you can do is have a value in your OrderForm that is set inside your pipeline. You can check the value after the execution of the pipeline and redirect the user to the aspx page.

    The context is used to pass shared resources into the pipeline. It’s not meant as a bi-directional

    Good luck,

    -Max

  6. Andreas Georgsson says:

    Hi, thanx.

    Worked great.

    Have a another question. I have depolyed the project to a production server. I packed the projekt and unpacked it. I setup the server followed the installtion guide, and set all security on folders, and in the database. The business user applications and the shop works fine until I press finish in my basket. I get an access denied in pipeline execution, Checkout pipeline. The error is that the com+ can’t conntact MS DTC. The MS DTC is running I have tested to uninstall and reinstall MS DTC all checkboxes under security is selected. i think there must be a security issue but how do I trace it? Some suggestions I have seen is to use DTC tester but how can I use it to test a pipeline?

  7. MSDN Archive says:

    If you have issues with the DTC then you need to lookup DTC ping tool do a search and you will find it. If the DTC ping test fails then you have either a network issue or don’t have the ports open.

    Good luck,

    -Max

  8. Andreas Georgsson says:

    Not solved it and both DTCPING and DTCTester shows success.

    I have also installed startersite on the same machine, and I get the same error, when it is doing the transacted checkout.

    Do you have any tips where to search?

    Or should I reinstall the machine?

  9. MSDN Archive says:

    Checked out http://support.microsoft.com/kb/306843.

    Also, check and make sure that you have a recent version of MDAC on the client and which protocol being used.

    Are there any messages in the SQL Server Error Log? Do you have avirus checker if so check the settings. Try running SQL Profiler may give you an indication on what is happening when this error occurs.

    Good luck,

    -Max

Comments are closed.

Skip to main content