[IronPython] Embedding IronPython in ASP.NET/SharePoint2010/Commerce Server

Dody Gunawinata empirebuilder at gmail.com
Sun Oct 10 22:01:20 CEST 2010


I am using similar approach in our business license software that runs the
city of Alexandria, Egypt. We have to deal with 350 different type of
business licenses with multiple factor for calculating the fees (minimum 5).
So we just construct the fees calculation formula in Python script that a
business admin can change at any time and import all the necessary variables
for the formula to work.


On Sun, Oct 3, 2010 at 1:45 PM, Jeff Hardy <jdhardy at gmail.com> wrote:

> Hi Charles,
> The approach I've used for web applications in the past is to have the
> runtime and engine be application-wide and create a new scope for each
> script on every request. Scopes are very cheap to create and will keep the
> scripts isolated so that they don't affect each other.  The engine and
> runtime are thread-safe, so you can safely get away with only having one per
> application. I also use a cache of CompiledCode objects for each script to
> avoid recompiling them each time.
>
> - Jeff
>
> On Sun, Oct 3, 2010 at 6:15 AM, Medcoff, Charles <charles.medcoff at rcmt.com
> > wrote:
>
>> Hello,
>>
>>
>>
>> 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.
>>
>>
>>
>> My approach is to launch an Iron Python script from within an Operation
>> Sequence Component (
>> http://msdn.microsoft.com/en-us/library/dd464335(CS.90).aspx) 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.
>>
>>
>>
>> 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:
>>
>>
>>
>> namespace IPythonOperationalSequenceComponent
>> {
>>     public class IronPythonOperationSequenceComponent
>>  : Microsoft.Commerce.Providers.Components.OperationSequenceComponent
>>     {
>>         public override void ExecuteQuery(
>>             Microsoft.Commerce.Contracts.Messages.CommerceQueryOperation
>>  queryOperation,
>>             Microsoft.Commerce.Broker.OperationCacheDictionary
>>  operationCache,
>>             Microsoft.Commerce.Contracts.Messages.
>> CommerceQueryOperationResponse response)
>>         {
>>             try
>>             {
>>                 ScriptEngine pyEngine = Python.CreateEngine();
>>                 ScriptScope pyScope = pyEngine.CreateScope();
>>                 pyScope.SetVariable("request", queryOperation);
>>                 pyScope.SetVariable("cache", operationCache);
>>                 pyScope.SetVariable("response", response);
>>                 ScriptSource
>>  source = pyEngine.CreateScriptSourceFromFile(@"rules.py");
>>                 CompiledCode compiled = source.Compile();
>>                 compiled.Execute(pyScope);
>>             }
>>             catch (Exception ex)
>>             {
>>                 // error handling elided
>>             }
>>         }
>>     }
>> }
>>
>>
>>
>>
>>
>> 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.
>>
>>
>>
>> --chuck
>>
>>
>>
>>
>>
>> Best Regards,
>>
>> Chuck
>>
>>
>>
>>
>>
>> Charles Medcoff
>>
>> Principal Consultant* *|* *Enterprise Integration Solutions* *
>>
>>  [image: Description: Description: mailsiglogo]
>>
>> Tel:  (248) 687-5623
>>
>> Cell: (248) 884-2854
>>
>> www.rcmt.com/eis<https://mail.nusoftsolutions.com/owa/redir.aspx?C=0fb759b134e24832b79fe8f920b40e0c&URL=http%3a%2f%2fwww.rcmt.com%2feis>
>>
>>
>>
>> _______________________________________________
>> Users mailing list
>> Users at lists.ironpython.com
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>
>>
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>


-- 
nomadlife.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20101010/f8d0030c/attachment.html>


More information about the Ironpython-users mailing list