(ats3-dev02) scripting with .net assemblies in symyx notebook

19
(ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook Mark Benzel Principal Software Engineer, R&D [email protected]

Post on 18-Oct-2014

631 views

Category:

Technology


5 download

DESCRIPTION

Scripting in Notebook provides a powerful mechanism for extending the out-of-the-box capabilities of the ELN, and the Python script editor embedded within Symyx Notebook works great for quickly creating small scripts that are certain never to change. But the embedded script editor doesn’t provide the rich editing capabilities of popular, modern Integrated Development Environments (IDEs) such as Microsoft Visual Studio, which are needed for larger scripts. Maintaining, enhancing and redeploying large, sophisticated Python scripts is also a challenge in Symyx Notebook. Fortunately, the Symyx Notebook Vault server comes with a built-in capability to publish .NET assemblies to the server, and then to deliver them to the client computers without any manual intervention, making distribution of assembly-based code changes easy.In this session we will explain and demonstrate how to use the assembly deployment capabilities of Symyx Notebook in conjunction with its Python scripting features to extend the Notebook in ways that enable re-deployment of the extensions after they have been deployed into production. We will also talk about how to avoid some of the potential pitfalls of doing so.

TRANSCRIPT

Page 1: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

(ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

Mark BenzelPrincipal Software Engineer, R&D

[email protected]

Page 2: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

The information on the roadmap and future software development efforts are intended to outline general product direction and should not be relied on in making a purchasing decision.

Page 3: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

Scripting with .NET Assemblies

The problem: how to update scripts after they have been deployed to production

Page 4: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

Demo• The problem

Page 5: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

Scripting with .NET Assemblies

A solution: using Vault’s assembly deployment capabilities to deploy changes to script extensions.

Page 6: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

Demo• A potential solution

Page 7: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

Other Reasons to use Assemblies versus Scripting

• Convert a potentially complex script into a simple script– Just enough script to call into the assembly

• Deploy custom code more efficiently• Ability to use the rich editing and debugging capabilities

of Integrated Development Environments (IDEs) such as Microsoft Visual Studio– No IntelliSense or debug capability in the Notebook scripting

environment

Page 8: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

How it works

from Symyx.Framework.Extensibility import AssemblyCache

speaker = AssemblyCache.CreateInstanceFromLatestAssembly(“MegaCorp.Greeter.Speaker, MegaCorp.Greeter")speaker.SayIt()

Page 9: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

Assembly Deployment

• New assemblies deployable into an existing system– Similar to Click-Once– Stored in Vault– Downloaded automatically into a “Symyx assembly cache”

Notebook

Experiment

Vault

Template

ScientistTemplate author

Notebook

• Sets up experiment templates.• Assemblies downloaded on demand

TemplateAssemblies

Assemblies

Assembliespublished viaconsole app

Assemblies

• Assemblies and templates downloaded automatically, on-demand

Script author• Creates and publishes assemblies

Page 10: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

How it works

from Symyx.Framework.Extensibility import AssemblyCache

speaker = AssemblyCache.CreateInstanceFromLatestAssembly(“MegaCorp.Greeter.Speaker, MegaCorp.Greeter")speaker.SayIt()

• AssemblyCache.CreateInstanceFromLatestAssembly

– Retrieves your custom .NET assembly by the following algorithm:• Is an assembly of the given name already loaded in memory? Then use it.• Otherwise, find the latest version of the assembly in Vault.

– If offline, find the latest version of the assembly in the local machine’s assembly cache

• If online, then download the latest assembly if necessary• Load the latest assembly into memory• Create the indicated object from it

Page 11: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

Setting up your .NET project

• Select an IDE– Microsoft Visual Studio is recommended

• Version 2008 or 2010• Not the Express (free) versions

– Doesn’t support debugging

– For a free IDE, see #develop• Pronounced “SharpDevelop”• Supports debugging but not edit-and-continue

• Create the project– Remember to target .NET Framework 3.5

• Select a language– C# and VB.NET are most common– Can’t use IronPython

Page 12: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

Demo• Setting up your .NET project

Page 13: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

Writing Your Class

• Use “CompanyName.ProjectName” as the assembly name, and as the namespace

• CreateInstanceFromLatestAssembly uses a “partially-qualified type name”– i.e., an assembly and class name pair

• Pass script variables into your method

Page 14: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

Demo• Writing your class

Page 15: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

Publishing your assembly to Vault Demo Notes

• Create a console app– Set target version to .NET 3.5– Set Target CPU to x86– Reference Symyx.Framework.dll, Symyx.Framework.STS.dll, Symys.Framework.STS.Provider.dll, Accelrys.DependencyInjection.dll, Ninject.dll– Add the code:

Imports Symyx.Framework.VaultImports Symyx.Framework.Extensibility Module Module1  Sub Main()  LogIn() Publish()  End Sub  Sub Publish()  Dim assembly = System.Reflection.Assembly.LoadFile("D:\Projects\Visual Studio\CompanyName.ProjectName\CompanyName.ProjectName\bin\Debug\CompanyName.ProjectName.dll")  If (AssemblyCache.IsPublished(assembly)) Then Throw New ApplicationException("Assembly has already been published. Increment the assembly version number and try again.") Else AssemblyCache.Publish(assembly) End If  End Sub  Sub LogIn()  Dim workspace = New VaultWorkspace("servername") Dim loginState = workspace.Login("domain\username", "password")  If (loginState = AuthenticationState.Yes) Then workspace.MakeCurrentWorkspace() Else Throw New ApplicationException("Login failed.") End If  End Sub End Module

Page 16: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

Demo• Publishing your assembly to Vault

Page 17: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

Publishing a new version of your assembly to Vault

• Assemblies are stored in Vault by “fully-qualified assembly name”

– Meaning it includes version information

– Need to change the assembly version numbers before publishing the new assembly

• Can’t un-publish an assembly

– To “undo” a publish, you need to advance the version number and publish again

– Use a source control system to maintain old source code versions

Page 18: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

• Presented a potential problem with using scripts– How to update scripts after they have been deployed

• Presented a possible solution in the use of .NET assemblies– Discussed how to create, publish and update assemblies

• Resource– Symyx Notebook Developer’s Guide

• Section entitled “Custom Development with Symyx Notebook”

Summary

Page 19: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook

The information on the roadmap and future software development efforts are intended to outline general product direction and should not be relied on in making a purchasing decision.

For more information on the Accelrys Tech Summits and other IT & Developer information, please visit:https://community.accelrys.com/groups/it-dev