다음을 통해 공유


How to Retrieve Errors after Running a Pipeline

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

When you run a pipeline on an OrderGroup object — a Basket object, an OrderTemplate object, or a PurchaseOrder object — the pipeline returns a PipelineExecutionResult object that indicates whether the pipeline generated errors. If it did, the OrderForm object contains two lists of error messages. The value of the _Basket_Errors property is a list of error messages that generally concern the contents of the OrderForm. The value of the _Purchase_Errors property is a list of error messages that generally concern the OrderForm as a whole.

To retrieve errors after running an Orders System pipeline

  1. Create a new project in Visual Studio.

  2. Add the Microsoft.CommerceServer.Interop.dll reference to the Web application.

  3. Add using directives for the following namespaces:

  4. Create an instance of the OrderGroup object that you will run the pipeline on — a Basket object, an OrderTemplate object, or a PurchaseOrder object.

  5. Perform any processing that is required before you run the pipeline. For example, you might add an OrderForm object and LineItem objects to a Basket.

  6. Create a PipelineInfo object to represent the pipeline.

  7. Run the pipeline and save the PipelineExecutionResult object that the pipeline returns.

  8. Check the value of the PipelineExecutionResult. If the value is PipelineExecutionResult.Warning, the pipeline generated errors. If the value is PipelineExecutionResult.Success, the pipeline did not generate errors.

  9. If the pipeline generated errors, create an object of type SimpleList that can hold the basket errors in each OrderForm, and set it to the value of the _Basket_Errors property in the OrderForm.

  10. If the pipeline generated errors, create an object of type SimpleList that can hold the purchase errors in each OrderForm, and set it to the value of the _Purchase_Errors property in the OrderForm.

    Note

    All Orders System pipelines can generate both basket errors and purchase errors.

  11. Loop through the list or lists of errors, and process each error.

Example

The code in this example creates a Basket object, an OrderForm object, and a LineItem object so that there is an object to run the pipeline on — the Basket. Because the LineItem represents a product that is not in the catalog, the pipeline will generate an error.

using System;
using System.Web;
using System.Collections;
using Microsoft.CommerceServer.Runtime;
using Microsoft.CommerceServer.Runtime.Orders;

public partial class Default_aspx : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // For this example, create a new GUID for the user's ID.  
        // If this were part of a full Commerce Server site that
        // implemented logons, you could get the ID of the current
        // user from the CommerceContext object.

        Guid userID = Guid.NewGuid();

        // Create a new Basket object named "primary".

        Basket sampleBasket = OrderContext.Current.GetBasket(userID, "primary");

        // Create a new OrderForm object.

        OrderForm orderForm = new OrderForm();

        // Create a LineItem object for a product that is not in
        // the catalog, and add the LineItem to the OrderForm.

        LineItem item1 = new LineItem("Holiday", "ABC-123", "", 1);
        orderForm.LineItems.Add(item1);

        // Add the OrderForm to the Basket.

        sampleBasket.OrderForms.Add(orderForm);

        // Run the Basket pipeline on the Basket. The pipeline
        // will generate errors.

        PipelineInfo pipeline = new PipelineInfo("Basket");
        PipelineExecutionResult result = sampleBasket.RunPipeline(pipeline);

        // Display the errors that the pipeline generated.

        if (result == PipelineExecutionResult.Warning)
        {
            foreach (OrderForm of in sampleBasket.OrderForms)
            {
                // Some pipeline components record basket errors, so
                // display these.

                foreach (String basketError in (SimpleList)of["_Basket_Errors"])
                {
                    Response.Write(basketError + "<br/>");
                }

                // Some pipeline components record purchase errors, so
                // display these.

                foreach (String purchaseError in (SimpleList)of["_Purchase_Errors"])
                {
                    Response.Write(purchaseError + "<br/>");
                }
            }
        }
    }
}

To run this sample, you must have configured the Basket pipeline for your site and configured your site to use MessageManager. For more information about how to configure the Basket pipeline, see pipelines Element. For more information about how to use MessageManager, see messageManager Element.

See Also

Other Resources

pipelines Element

Error Handling in Pipelines

How to Use MessageManager