Welcome to MSDN Blogs Sign in | Join | Help

Data Tools and Software Testing

Old model-based testers never die; they just transition to a higher state.

Syndication

News

    These postings are provided "AS IS" with no warranties, and confer no rights.
    Use of included script and code samples are subject to the terms specified here.

CS 2007: Running Pipelines in a Console Application

One of things you might need to do occasionally is to run pipelines from code which is not running in a web context (i.e. the code is not part of a web site or web service). This could be a console app, a WinForm app or even a Windows service. The reason this is a non-trivial task is firstly because this is not a core scenario targeted by the Commerce Server platform and secondly because when you run a web app, a lot of the work required to run pipelines is done behind the scenes when the various Commerce related sections are parsed in the web.config at app startup time. The good news though is that it is possible to run pipelines in a console (or WinForm or Windows service etc. etc. you get the idea) app, thus making it easier for you to test your components or target a niche scenario important for your business.

I have attached a fully functional VS 2005 solution that illustrates how you can run pipelines in a non-web environment. Hopefully this sample should help you get started – though please keep in mind that this is purely for illustrating the core scenario of configuring and running pipelines in a console app and is not meant to showcase the design. Also please keep in mind that the use of attached code samples are subject to the terms specified here. Hope you find the sample code useful.

On a related note, there’s been a lot happening on the CS 2007 front. In case you haven't heard, we have decided to give away our Developer Edition for FREE - that's right - zero cost to you to get started with developing a full-fledged Enterprise level eCommerce site on the Commerce Server platform. We also announced the General Availability (GA) of Commerce Server 2007 to the all partners and customers and on the documentation front, launched the TechNet site for Commerce Server and have also made the CS 2007 Migration Guide available as separate download, which should help you learn all about migrating from earlier versions of Commerce Server to CS 2007.

Also, we have some web casts available on-demand on the TechNet site which also contains an article by Jeff Lynch on Integrating Commerce Server Orders with BizTalk Adapters. Kudos Jeff!

Published Monday, August 07, 2006 8:00 PM by nihitk

Filed under:

Attachment(s): CS2007_PipelineConsoleApp.zip

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: CS 2007: Running Pipelines in a Console Application @ Tuesday, August 08, 2006 8:48 AM

I'm blushing (LOL)

Jeff

Jeff Lynch

# re: CS 2007: Running Pipelines in a Console Application @ Tuesday, August 08, 2006 10:38 AM

Thanks for that, Nihit.

On a similar(ish) subject, is there any way I can get a CommerceContext to initialise in a unit test project? I'm struggling to test such things because CommerceContext.Current always returns null when I'm running my unit tests.


Regards,
Paul

Paul Graham

# re: CS 2007: Running Pipelines in a Console Application @ Tuesday, August 08, 2006 3:06 PM

Hi Paul,

Unfortunately, it is not possible to create a CommerceContext in a non-web environment. The only way is to manually create the various objects hanging off of the CommerceContext, such as the Pipelines collection, the OrderContext etc. and then to use them invidually (or you could wrap them in a class which would be like CommerceContextForConsoleApps). The sample attached will get you a lot of the things hanging off of CommerceContext in a console environment.

nihitk

# Commerce Server 2007: Some Great New Posts! @ Thursday, August 17, 2006 10:17 PM

Now that the Commerce Server development team has shipped their flagship product, they've started to publish some great new posts about using Commerce Server 2007. If you don't already subscribe to these blogs, you really should!

Jeff Lynch [MVP]

# What about the TargetingSystem @ Friday, August 25, 2006 3:54 PM

Hi

Do you have an example on how I could do the same for the targetting system? I'm wrapping a lot of the Commerce systems and the TargetingSystem seems to be the last frontier.

I notice that you do add some configuration information for the marketing system, but I don't see how I can instantiate my own TargettingSystemInfo instance.

Please help

Phil

# re: CS 2007: Running Pipelines in a Console Application @ Friday, August 25, 2006 7:26 PM

Hi Phil,

I must ask as to what you are trying to do withte TargetingSystemInfo class? Is it not possible to do that from the DataManagement side?
I don't think you can directly create an instance of this class since the constructor is internal and only called by CommerceContext.

However, the class does not have anything special in it:
A reference to an Expression Evaluator
A reference to a TargetingContext profile
A reference to the ContentSelectionContexts

You can maintain these references from a class of your own and then you don’t need to use TargetingSystemInfo.

Would that work for you?

nihitk

# re: CS 2007: Running Pipelines in a Console Application @ Monday, August 28, 2006 1:45 PM

I don't mind wrapping it up.

I need to do something like

ContentSelector cso = null;
           
           cso = CommerceContext.Current.TargetingSystem.SelectionContexts["advertising"].GetSelector();
       

Would the code below work to properly instantiate cso ?

ContentSelectionPipeline advertisingPipeline = new ContentSelectionPipeline("advertising", GetPipelinePath("advertising.pcf"), true, "advertising.log");
ContentSelectionPipeline discountsPipeline = new ContentSelectionPipeline("discounts", GetPipelinePath("discounts.pcf"), true, "discount.log");
           ContentSelectionPipeline eventPipeline = new ContentSelectionPipeline("recordevent", GetPipelinePath("RecordEvent.pcf"), true, "recordEvent.log");
           string redirectUrl = "AdRedirect.aspx";
           DebugContext debugContext = new ConsoleDebugContext(DebugMode.Debug);

           CommerceResourceCollection resources = new CommerceResourceCollection(siteName);
           CommerceResource marketingResource = resources["Marketing"];

           string marketingConnStr = marketingResource["connstr_db_marketing"].ToString();

           string cleanedMarketingConnStr;
           CleanSqlClientConnectionString(marketingConnStr, out cleanedMarketingConnStr);

           Microsoft.CommerceServer.Runtime.Targeting.ExpressionEvaluator evaluator = new Microsoft.CommerceServer.Runtime.Targeting.ExpressionEvaluator(cleanedMarketingConnStr, debugContext);

           ContentSelectionContext advertising_context = new ContentSelectionContext("advertising", advertisingPipeline, eventPipeline, "Advertising", redirectUrl, evaluator, debugContext);
           ContentSelectionContext discounts_context = new ContentSelectionContext("discounts", discountsPipeline, eventPipeline, "Discounts", redirectUrl, evaluator, debugContext);

           ContentSelectionContextCollection selections = new ContentSelectionContextCollection();
           selections.Add("advertising", advertising_context);
           selections.Add("discounts", discounts_context);

           Microsoft.CommerceServer.Runtime.Targeting.ContentSelector cso = selections["advertising"].GetSelector();
           
       }

Phil

# re: CS 2007: Running Pipelines in a Console Application @ Tuesday, August 29, 2006 10:09 AM

Yes, I could use that option to properly wrap the information.

I think I can do all the instantiations correctly except for the evaluator. I'm not sure I should be using the Marketing SQL string (as per your code) and I'm not sure which DebugContext to feed it. I could use a simple ConsoleDebugContext, but I'm not sure if it's ok.

Do you have an example that shows how to instantiate the Evaluator?

Thanks

Phil

# re: CS 2007: Running Pipelines in a Console Application @ Wednesday, August 30, 2006 1:26 PM

Hi Phil,

The ConsoleDebugContext should be fine to use in this scenario. As for the SQL connection string - are you getting an error when using that? I would suggest trying some different formats to see if the Evaluator is expecting it in a particular format.

Thanks,
Nihit

nihitk

# Everything you ever wanted to know about pipelines but were afraid to ask (Part IV) @ Sunday, September 24, 2006 6:26 PM

So far you if you have followed this on going Pipeline posts, you should be very familiar with how to...

Max Akbar

# How to modify Order limits for non-web based Commerce Server applications? @ Friday, November 10, 2006 5:18 PM

So you probably know all about how to change the various limits (such as the maximum Baskets per user

Commerce Team Blog

# Developing Your First Order Pipeline Component @ Saturday, November 11, 2006 7:58 PM

As previously discussed the pipeline system enables sequential workflow processing. It is a COM-based...

using Colin.Bowern;

# Building an Order Pipeline Component @ Tuesday, January 30, 2007 10:50 PM

As I spoke about in an earlier post, Commerce Server 2007 leverages a COM-based pipeline system...

using Colin.Bowern;

# re: CS 2007: Running Pipelines in a Console Application @ Thursday, August 02, 2007 4:59 AM

I successfully run your example, but after

PurchaseOrder order = cart.SaveAsOrder();

, the application stops (without exception), whith code 2131666259 (0x7f0ea553). Anyway, the purchaseOrder is successfully created.

Any idea ?

Thanks,

Olivier

olywyer

# re: CS 2007: Running Pipelines in a Console Application @ Friday, August 29, 2008 3:58 AM

Hi,

I am using the code provided above for some testing.  

Now, I am having some problems with the payment system, since when running the code the payment  is not being affected.  Most probably it is due to the fact that the CreditCardPayment object being created is not being used.  In fact no new entry is being added in the table transactions.dbo.CreditCardPayments.

Now, I tried to modify the code by adding the following code:

basket.OrderForms[0].Payments.Add(ccPmt);

When I execute the application, the following error is being given:

"Execution of pipeline 'CHECKOUT' failed."

And the inner exception being:

{"Component Execution failed for component[0x0]  hr: 0x80070057\r\nProgID: Commerce.PaymentMethodRouter\r\nPipelineCollection in the context dictionary does not contain 'creditcard' pipeline. Make sure creditcard pipeline is configured in the configuration file."}

It must be noted that the creditcard pipeline is available in the pipelines folder.

What should the problem be?  If there is the need of a configuration file, how should this configuration be configured for a console application?

Thanks in Advance

PBen

# re: CS 2007: Running Pipelines in a Console Application @ Friday, August 29, 2008 12:56 PM

Hi PBen,

I am sorry but I will be unable to help you with your issue since I am not working on the Commerce Server product anymore. I would suggest posting this question to either the Commerce Server MSDN newsgroup or the Commerce Server Blog (http://blogs.msdn.com/commerce/).

Thanks,

Nihit

nihitk

Leave a Comment

(required) 
required 
(required) 
Page view tracker