Share via


Code to Read a Pipeline Collection and Display Its Properties

Use the following code to read a pipeline collection and display the Name, Logpath, PipelineConfigPath, LoggingEnabled, and optionally the TransactionalSetting properties. The code should be used within a Commerce Server project. For more information about creating a Commerce Server project, see Creating a Commerce Project.

<%@ Page Language="C#" Debug=true%>

<%@ Import Namespace="Microsoft.CommerceServer.Runtime" %>

<%@ Import Namespace="Microsoft.CommerceServer.Runtime.Pipelines" %>

<script language="C#" >

void Page_Load(object source, EventArgs args)

{

if (!IsPostBack)

{

DisplayPipelines();

btnProperties.Text = "Display Properties";

}

}

///

/// This function gets the pipeline collection and binds it

/// to the drop-down list.

///

void DisplayPipelines()

{

try

{

PipelineCollection pipesCollection = null;

// Check that the CommerceContext object for this request

// is not null.

if (CommerceContext.Current == null)

{

throw new Exception("CommerceContext object is null.Please check settings in web.config");

}

// Get the pipeline collection.

pipesCollection = CommerceContext.Current.Pipelines;

// pipesCollection.Count contains the number of pipelines.

string[] pipeArray = new string[pipesCollection.Count];

int pipeIndex =0;

// Iterate through the pipeline collection and

// build the string array.

foreach (PipelineBase pipe in pipesCollection)

{

pipeArray[pipeIndex++] = pipe.Name;

}

// Bind the array to the drop-down list.

lbPipelines.DataSource = pipeArray;

lbPipelines.DataBind();

}

catch(Exception ex)

{

// Exception handling.

throw new Exception("An error occurred", ex);

}

}

///

/// This function displays the properties for the selected pipeline.

///

void DisplayPropertiesBtn_Click(object source, EventArgs args)

{

string pipeName;

PipelineBase pipe ;

try

{

PipelineCollection pipesCollection = null;

// Check that the CommerceContext object for this request

// is not null.

if (CommerceContext.Current == null)

{

throw new Exception("CommerceContext object is null.");

}

// Get the pipeline collection.

pipesCollection = CommerceContext.Current.Pipelines;

// Get the pipeline name whose properties are to be displayed.

pipeName = lbPipelines.SelectedItem.Text.Trim();

// Index the pipeline collection using the pipeline name to get the

// properties for this pipeline.

pipe = pipesCollection[pipeName];

// Display the Name, Logpath, PipelineConfigPath, and

// LoggingEnabled properties.

lblPipeName.Text = String.Format("Pipeline Name = {0}", pipe.Name);

lblLogPath.Text = String.Format("Log Path = {0}", pipe.LogPath);

lblConfigPath.Text = String.Format("Config Path = {0}", pipe.PipelineConfigPath);

lblLoggingEnabled.Text = String.Format("LoggingEnabled = {0}", pipe.LoggingEnabled);

// Check if this is an order pipeline.

OrderPipeline orderPipeline = pipe as OrderPipeline;

//If it is an order pipeline, display the

// TransactionalSetting property also.

if (orderPipeline != null)

{

lblTransactional.Visible = true;

lblTransactional.Text = String.Format("Transactonal = {0}", orderPipeline.TransactionalSetting);

}

else

{

lblTransactional.Visible = false;

}

}

catch(Exception ex)

{

throw new Exception("An error occurred", ex);

}

}

</script>

<html>

<head>

<title>Pipeline Collection</title>

</head>

<body>

<form >

<asp:DropDownList id="lbPipelines" />

<asp:Button id="btnProperties" OnClick="DisplayPropertiesBtn_Click" />

<asp:table width="500" Runat="server">

<asp:tablerow>

<asp:tablecell>

<asp:Label width="100%" id="lblPipeName" />

</asp:tablecell>

</asp:tablerow>

<asp:tablerow>

<asp:tablecell>

<asp:Label width="100%" id="lblLogPath" />

</asp:tablecell>

</asp:tablerow>

<asp:tablerow>

<asp:tablecell>

<asp:Label width="100%" id="lblConfigPath" />

</asp:tablecell>

</asp:tablerow>

<asp:tablerow>

<asp:tablecell>

<asp:Label width="100%" id="lblLoggingEnabled" />

</asp:tablecell>

</asp:tablerow>

<asp:tablerow>

<asp:tablecell>

<asp:Label width="100%" id="lblTransactional" />

</asp:tablecell>

</asp:tablerow>

</asp:table>

</form>

</body>

</html>

Copyright © 2005 Microsoft Corporation.
All rights reserved.