<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:"Calisto MT";
        panose-1:2 4 6 3 5 5 5 3 3 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>Hello,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I have a client for which I am developing a SharePoint 2010/Microsoft Commerce Server 2009 applications. The client has a fairly complex set of business rules for their ordering process which may change frequently. Rules engines are pretty expensive so I’m considering the approach of embedding Iron Python into the app as an alternative to making it a bit easier to make rules updates via scripting.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>My approach is to launch an Iron Python script from within an Operation Sequence Component (<a href="http://msdn.microsoft.com/en-us/library/dd464335(CS.90).aspx)">http://msdn.microsoft.com/en-us/library/dd464335(CS.90).aspx)</a> which is a standard extensibility point within Commerce Server. In nutshell an Operation Sequence Component is a .NET assembly containing a class which implements a particular interface, and is loaded via reflection by the Commerce Server runtime. The class is then loaded/executed when the relevant Commerce Server API is used. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal> I’ve successfully written a simple Operation Sequence Component which executes a script. The only catch to getting it to work is to register all of the related Iron Python DLL in the GAC. Here is an example of what I’m doing:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:Consolas;color:blue'>namespace</span><span style='font-size:10.0pt;font-family:Consolas'> IPythonOperationalSequenceComponent<br>{<br> <span style='color:blue'>public</span> <span style='color:blue'>class</span> <span style='color:#2B91AF'>IronPythonOperationSequenceComponent</span> : Microsoft.Commerce.Providers.Components.<span style='color:#2B91AF'>OperationSequenceComponent</span><br> {<br> <span style='color:blue'>public</span> <span style='color:blue'>override</span> <span style='color:blue'>void</span> ExecuteQuery(<br> Microsoft.Commerce.Contracts.Messages.<span style='color:#2B91AF'>CommerceQueryOperation</span> queryOperation, <br> Microsoft.Commerce.Broker.<span style='color:#2B91AF'>OperationCacheDictionary</span> operationCache, <br> Microsoft.Commerce.Contracts.Messages.<span style='color:#2B91AF'>CommerceQueryOperationResponse</span> response)<br> {<br> <span style='color:blue'>try</span><br> {<br> <span style='color:#2B91AF'>ScriptEngine</span> pyEngine = <span style='color:#2B91AF'>Python</span>.CreateEngine();<br> <span style='color:#2B91AF'>ScriptScope</span> pyScope = pyEngine.CreateScope();<br> pyScope.SetVariable(<span style='color:#A31515'>"request"</span>, queryOperation);<br> pyScope.SetVariable(<span style='color:#A31515'>"cache"</span>, operationCache);<br> pyScope.SetVariable(<span style='color:#A31515'>"response"</span>, response);<br> <span style='color:#2B91AF'>ScriptSource</span> source = pyEngine.CreateScriptSourceFromFile(<span style='color:#A31515'>@"rules.py"</span>);<br> <span style='color:#2B91AF'>CompiledCode</span> compiled = source.Compile();<br> compiled.Execute(pyScope);<br> }<br> <span style='color:blue'>catch</span> (<span style='color:#2B91AF'>Exception</span> ex)<br> {<br> <span style='color:green'>// error handling elided</span><br> }<br> }<br> }<br>}<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Now this is a “toy” approach as I shouldn’t need to create an engine, scope, compile the script, etc. for every post back. I’m thinking a better approach is to have the script engine, scope and compiled script live at the HttpWebApplication level and be shared across all threads, requests, users. My concern is that will this approach work. What are the threading, concurrency, and performance issues involved? Has anyone done anything like this in ASP, let alone SharePoint and can share their experiences with regards to what works, what does not work, best approach, etc.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>--chuck<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='color:#1F497D'>Best Regards,<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>Chuck<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Calisto MT","serif";color:#0037A4'>Charles Medcoff</span><span style='color:#1F497D'><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Calisto MT","serif";color:#0037A4'>Principal Consultant<b> </b>|</span><b><span style='font-size:14.0pt;font-family:"Calisto MT","serif";color:#0037A4'> </span></b><span style='font-size:10.0pt;font-family:"Calisto MT","serif";color:#0037A4'>Enterprise Integration Solutions<b><i> </i></b></span><span style='color:#1F497D'><o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> <img border=0 width=192 height=56 id="Picture_x0020_1" src="cid:image001.jpg@01CB62D1.7C4366B0" alt="Description: Description: mailsiglogo"><o:p></o:p></span></p><p class=MsoNormal style='line-height:9.7pt'><span style='font-size:9.0pt;font-family:"Calisto MT","serif";color:#404040'>Tel: (248) 687-5623</span><span style='color:#1F497D'><o:p></o:p></span></p><p class=MsoNormal style='line-height:9.7pt'><span style='font-size:9.0pt;font-family:"Calisto MT","serif";color:#404040'>Cell: (248) 884-2854</span><span style='color:#1F497D'><o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><a href="https://mail.nusoftsolutions.com/owa/redir.aspx?C=0fb759b134e24832b79fe8f920b40e0c&URL=http%3a%2f%2fwww.rcmt.com%2feis" target="_blank"><span style='font-size:9.0pt;font-family:"Calisto MT","serif";color:blue'>www.rcmt.com/eis</span></a><o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>