![Page 1: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/1.jpg)
(ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook
Mark BenzelPrincipal Software Engineer, R&D
![Page 2: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/2.jpg)
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](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/3.jpg)
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](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/4.jpg)
Demo• The problem
![Page 5: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/5.jpg)
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](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/6.jpg)
Demo• A potential solution
![Page 7: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/7.jpg)
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](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/8.jpg)
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](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/9.jpg)
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](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/10.jpg)
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](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/11.jpg)
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](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/12.jpg)
Demo• Setting up your .NET project
![Page 13: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/13.jpg)
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](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/14.jpg)
Demo• Writing your class
![Page 15: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/15.jpg)
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](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/16.jpg)
Demo• Publishing your assembly to Vault
![Page 17: (ATS3-DEV02) Scripting with .NET Assemblies in Symyx Notebook](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/17.jpg)
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](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/18.jpg)
• 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](https://reader034.vdocuments.net/reader034/viewer/2022042518/544332bcafaf9fe7098b487c/html5/thumbnails/19.jpg)
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