Click here to Skip to main content
11,494,407 members (72,338 online)
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
Add your own
alternative version

VSA Scripting in .NET

, 27 Feb 2005 102.8K 2.6K 94
Using Visual Studio for Applications to add scripting capabilities to your .NET apps.
vsascripting_demo.zip
Scripting.exe
VsaScripting.dll
vsascripting_src.zip
Scripting with Vsa
App.ico
bin
Debug
VsaScripting.dll
obj
Debug
temp
TempPE
Scripting with Vsa.csproj.user
VsaScripting
bin
Debug
obj
Debug
temp
TempPE
VsaScripting.csproj.user
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using VsaScripting;

namespace Scripting
{
	/// <summary>
	/// Summary description for Startup.
	/// </summary>
	public class Startup
	{
		private static ScriptableForm _scriptableForm;
		private static VsaScriptingHostFactory _factory;

		/// <summary>
		/// The entry point for the application
		/// </summary>
		/// <param name="args">The command line arguments passed to the application</param>
		[STAThread()]
		public static void Main(string[] args)
		{		
			// create a new form instance
			_scriptableForm = new ScriptableForm();
						
			// create a new host factory
			_factory = new VsaScriptingHostFactory();

			// create a new set of hosts
			VsaScriptingHost[] hosts = _factory.Create(@"MyScriptingHost", @"Scripting", true, Application.StartupPath);

			// wire up to the events of each host
			foreach(VsaScriptingHost host in hosts)
			{				
				host.AssemblyReferencesNeeded += new ScriptingHostEventHandler(OnAssemblyReferencesNeeded);
				host.CompilerException += new ScriptingHostCompilerExceptionEventHandler(OnCompilerException);
				host.GlobalItemsNeeded += new ScriptingHostEventHandler(OnGlobalItemsNeeded);
			}

			// execute the hosts
			foreach(VsaScriptingHost host in hosts)
				host.Execute();						

			// show the form
			_scriptableForm.ShowDialog();
		}
		
		/// <summary>
		/// Occurs when assembly references are needed
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private static void OnAssemblyReferencesNeeded(object sender, VsaScriptingHostEventArgs e)
		{
			// add the current assembly as a reference
			e.Host.CreateAssemblyReferences(Assembly.GetExecutingAssembly().Location);
		}

		/// <summary>
		/// Occurs when an error occurs during compilation or execution
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private static void OnCompilerException(object sender, VsaScriptingHostCompilerExceptionEventArgs e)
		{
			Debug.WriteLine(e.Exception);
		}

		/// <summary>
		/// Occurs when global items are needed
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private static void OnGlobalItemsNeeded(object sender, VsaScriptingHostEventArgs e)
		{
			// publish the scriptable form so that the scripts may modify it
			e.Host.CreateGlobalItem("_scriptableForm", _scriptableForm, false);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Mark Belles
Software Developer (Senior)
United States United States
Senior Application Developer specializing in Windows desktop and network development.

Professional Experience
- B.S. of Computer Science (Graduated 2001 - PSU)
- Senior Application Developer (8+ yrs)
- Microsoft Certified Professional

Primary Interests
- C#, C++, HTML, Javascript
- XML, ASP.NET, Web Services, SOAP, UDDI
- Socket programming and anything network related
- Reflection, Serialization, and Plugin Frameworks
- Owner-drawn controls and GDI+ goodness

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 27 Feb 2005
Article Copyright 2005 by Mark Belles
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid