Added rScripting solution to the project so those who do not have the rScript engine library. Makes for easier debugging and adding Mud Designer features to script engine.
This commit is contained in:
parent
d1c0ff188a
commit
b0cfc5f487
14 changed files with 1450 additions and 8 deletions
|
@ -11,9 +11,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MudClient", "MudClient\MudC
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MudDesigner", "MudDesigner\MudDesigner.csproj", "{5B18E552-26D0-4491-8BAC-FF80046F0B0F}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MudDesigner", "MudDesigner\MudDesigner.csproj", "{5B18E552-26D0-4491-8BAC-FF80046F0B0F}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "rScripting", "rScripting\rScripting.csproj", "{BC1B32DA-7209-4B32-8171-A190EF21F5D6}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(TeamFoundationVersionControl) = preSolution
|
GlobalSection(TeamFoundationVersionControl) = preSolution
|
||||||
SccNumberOfProjects = 6
|
SccNumberOfProjects = 7
|
||||||
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
|
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
|
||||||
SccTeamFoundationServer = https://tfs.codeplex.com/tfs/tfs03
|
SccTeamFoundationServer = https://tfs.codeplex.com/tfs/tfs03
|
||||||
SccLocalPath0 = .
|
SccLocalPath0 = .
|
||||||
|
@ -32,6 +34,9 @@ Global
|
||||||
SccProjectUniqueName5 = MudDesigner\\MudDesigner.csproj
|
SccProjectUniqueName5 = MudDesigner\\MudDesigner.csproj
|
||||||
SccProjectName5 = MudDesigner
|
SccProjectName5 = MudDesigner
|
||||||
SccLocalPath5 = MudDesigner
|
SccLocalPath5 = MudDesigner
|
||||||
|
SccProjectUniqueName6 = rScripting\\rScripting.csproj
|
||||||
|
SccProjectName6 = rScripting
|
||||||
|
SccLocalPath6 = rScripting
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -92,6 +97,16 @@ Global
|
||||||
{5B18E552-26D0-4491-8BAC-FF80046F0B0F}.Release|Mixed Platforms.Build.0 = Release|x86
|
{5B18E552-26D0-4491-8BAC-FF80046F0B0F}.Release|Mixed Platforms.Build.0 = Release|x86
|
||||||
{5B18E552-26D0-4491-8BAC-FF80046F0B0F}.Release|x86.ActiveCfg = Release|x86
|
{5B18E552-26D0-4491-8BAC-FF80046F0B0F}.Release|x86.ActiveCfg = Release|x86
|
||||||
{5B18E552-26D0-4491-8BAC-FF80046F0B0F}.Release|x86.Build.0 = Release|x86
|
{5B18E552-26D0-4491-8BAC-FF80046F0B0F}.Release|x86.Build.0 = Release|x86
|
||||||
|
{BC1B32DA-7209-4B32-8171-A190EF21F5D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{BC1B32DA-7209-4B32-8171-A190EF21F5D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{BC1B32DA-7209-4B32-8171-A190EF21F5D6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
|
{BC1B32DA-7209-4B32-8171-A190EF21F5D6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||||
|
{BC1B32DA-7209-4B32-8171-A190EF21F5D6}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{BC1B32DA-7209-4B32-8171-A190EF21F5D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{BC1B32DA-7209-4B32-8171-A190EF21F5D6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{BC1B32DA-7209-4B32-8171-A190EF21F5D6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
|
{BC1B32DA-7209-4B32-8171-A190EF21F5D6}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
|
{BC1B32DA-7209-4B32-8171-A190EF21F5D6}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
@ -40,9 +40,6 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="rScripting">
|
|
||||||
<HintPath>..\..\rScripting\rScripting\bin\Release\rScripting.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core">
|
<Reference Include="System.Core">
|
||||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
@ -94,6 +91,12 @@
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Scripting\MudScriptCompiler.cs" />
|
<Compile Include="Scripting\MudScriptCompiler.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\rScripting\rScripting.csproj">
|
||||||
|
<Project>{BC1B32DA-7209-4B32-8171-A190EF21F5D6}</Project>
|
||||||
|
<Name>rScripting</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|
|
@ -38,10 +38,6 @@
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="rScripting, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
|
||||||
<SpecificVersion>False</SpecificVersion>
|
|
||||||
<HintPath>..\..\rScripting\rScripting\bin\Release\rScripting.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
@ -107,6 +103,10 @@
|
||||||
<Project>{498943A8-DF5A-4DB0-B506-0BFF44788657}</Project>
|
<Project>{498943A8-DF5A-4DB0-B506-0BFF44788657}</Project>
|
||||||
<Name>MudEngine</Name>
|
<Name>MudEngine</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\rScripting\rScripting.csproj">
|
||||||
|
<Project>{BC1B32DA-7209-4B32-8171-A190EF21F5D6}</Project>
|
||||||
|
<Name>rScripting</Name>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
|
456
rScripting/CompileEngine.cs
Normal file
456
rScripting/CompileEngine.cs
Normal file
|
@ -0,0 +1,456 @@
|
||||||
|
/*
|
||||||
|
* rScripting Engine for .NET Framework
|
||||||
|
* Website: http://rScript.Codeplex.com
|
||||||
|
*
|
||||||
|
* Current Working Version: 1.3
|
||||||
|
* - Change Log:
|
||||||
|
* * Compilers and Compile Engine only compile under the Windows Platform.
|
||||||
|
* * Late Binding Classes compile for both Windows & Windows Phone.
|
||||||
|
* Note: Windows Phone compiles the Late Binding classes, however use of the classes not tested.
|
||||||
|
* Apps using the Late Binding classes might not pass certification at this time. (Un-tested)
|
||||||
|
* * Restructed the engine class namespace paths.
|
||||||
|
*
|
||||||
|
* Future Versions:
|
||||||
|
* - TODO (Ordered by Priority)
|
||||||
|
* * Provide separate example projects for each supported language.
|
||||||
|
* * Add IronPython Compiler Wrapper
|
||||||
|
* * Validate the use of PC compiled script libraries running on Windows Phone 7.
|
||||||
|
* * Support the XNA Framework
|
||||||
|
* - Windows PC
|
||||||
|
* - Xbox 360
|
||||||
|
* - GameComponent Types
|
||||||
|
* - DrawableGameComponent Types
|
||||||
|
* * Add support for Script Styles.
|
||||||
|
* - Classless Scripts.
|
||||||
|
* - Namespace free Scripts.
|
||||||
|
* - Script Styles Interface for 3rd party extensions.
|
||||||
|
* * Add IronRuby Compiler Wrapper
|
||||||
|
* * Add F# Compiler Wrapper
|
||||||
|
* * Add client/server compiling (HTML Content sent to Server for compiling)
|
||||||
|
*
|
||||||
|
* Microsoft Public License (Ms-PL)
|
||||||
|
* This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
|
||||||
|
* 1. Definitions
|
||||||
|
* The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
|
||||||
|
* A "contribution" is the original software, or any additions or changes to the software.
|
||||||
|
* A "contributor" is any person that distributes its contribution under this license.
|
||||||
|
* "Licensed patents" are a contributor's patent claims that read directly on its contribution.
|
||||||
|
* 2. Grant of Rights
|
||||||
|
* (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
|
||||||
|
* (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
|
||||||
|
* 3. Conditions and Limitations
|
||||||
|
* (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
|
||||||
|
* (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
|
||||||
|
* (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
|
||||||
|
* (D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
|
||||||
|
* (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.CSharp;
|
||||||
|
using Microsoft.VisualBasic;
|
||||||
|
|
||||||
|
using rScripting.Compilers;
|
||||||
|
using rScripting.LateBinding;
|
||||||
|
|
||||||
|
namespace rScripting
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides Properties & Methods needed to compile script source code into .NET assemblies.
|
||||||
|
/// </summary>
|
||||||
|
public class CompileEngine
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The file extension used for the script files.
|
||||||
|
/// </summary>
|
||||||
|
public String ScriptExtension
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _ScriptExtension;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value.StartsWith("."))
|
||||||
|
_ScriptExtension = value;
|
||||||
|
else
|
||||||
|
_ScriptExtension = "." + value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private String _ScriptExtension;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a collection of Assemblies that the compiler will add to its reference list.
|
||||||
|
/// </summary>
|
||||||
|
public List<String> AssemblyReferences { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a reference to the assembly generated during script compilation.
|
||||||
|
/// </summary>
|
||||||
|
public Assembly CompiledAssembly { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The compiler that will be used when the contents of ScriptRepository are compiled.
|
||||||
|
/// </summary>
|
||||||
|
public String Compiler { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used to supply compiling options to various compilers if they support this feature.
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<String, String> CompilerOptions { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used to check if the compilation contained any errors.
|
||||||
|
/// </summary>
|
||||||
|
public Boolean HasErrors { get; internal set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// String of errors that occurred during compilation, if any.
|
||||||
|
/// </summary>
|
||||||
|
public String Errors
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_CompileMessages.Length == 0)
|
||||||
|
return "No Errors.";
|
||||||
|
else
|
||||||
|
{
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
foreach (String error in _CompileMessages)
|
||||||
|
{
|
||||||
|
builder.AppendLine(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Messages stored from the compilers CompilerResults property.
|
||||||
|
private String[] _CompileMessages;
|
||||||
|
|
||||||
|
//Returns all of the assemblies currently loaded in the current domain.
|
||||||
|
private Assembly[] _Assemblies
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return AppDomain.CurrentDomain.GetAssemblies();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompileEngine() : this(".cs")
|
||||||
|
{
|
||||||
|
//Passes defaults off to the parameterized constructor.
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompileEngine(String scriptExtensions)
|
||||||
|
{
|
||||||
|
_CompileMessages = new String[] { "No compiler messages available." };
|
||||||
|
|
||||||
|
CompilerOptions = new Dictionary<string, string>();
|
||||||
|
Compiler = "C#";
|
||||||
|
|
||||||
|
AssemblyReferences = new List<string>();
|
||||||
|
AssemblyReferences.Add("mscorlib.dll");
|
||||||
|
AssemblyReferences.Add("System.dll");
|
||||||
|
AssemblyReferences.Add("System.Core.dll");
|
||||||
|
|
||||||
|
ScriptExtension = scriptExtensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a reference to the supplied Assembly name to the compilers reference collection.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="assembly"></param>
|
||||||
|
public void AddAssemblyReference(String assembly)
|
||||||
|
{
|
||||||
|
if (!AssemblyReferences.Contains(assembly))
|
||||||
|
AssemblyReferences.Add(assembly);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a reference to the supplied Assembly to the compilers reference collection.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="assembly"></param>
|
||||||
|
public void AddAssemblyReference(Assembly assembly)
|
||||||
|
{
|
||||||
|
if (!AssemblyReferences.Contains(assembly.GetName().Name))
|
||||||
|
AssemblyReferences.Add(assembly.GetName().Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the supplied assembly from the compilers reference collection.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="assembly"></param>
|
||||||
|
public void RemoveAssemblyReference(String assembly)
|
||||||
|
{
|
||||||
|
if (AssemblyReferences.Contains(assembly))
|
||||||
|
AssemblyReferences.Remove(assembly);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clears the compilers reference collection, leaving it empty.
|
||||||
|
/// </summary>
|
||||||
|
public void ClearAssemblyReference()
|
||||||
|
{
|
||||||
|
AssemblyReferences.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles the scripts found within the CompileEngine.ScriptRepository directory that match the CompileEngine.ScriptExtension file extension.
|
||||||
|
/// The compiler will compile the scripts using the compiler specified with the CompileEngine.Compiler Property.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Returns true if compilation was completed without any errors.</returns>
|
||||||
|
public Boolean Compile(String scriptRepository)
|
||||||
|
{
|
||||||
|
//Get the compiler that the developer has selected.
|
||||||
|
//If the developer chooses a compiler that is not part of the engine, the GetCompiler() method
|
||||||
|
//will check all the currently loaded assemblies in memory for a custom compiler implementing
|
||||||
|
//the ICompiler interface.
|
||||||
|
Type compiler = GetCompiler();
|
||||||
|
|
||||||
|
//Incase a non-default compiler was specified and we could not find it in memory, fail.
|
||||||
|
if (compiler.Name == "ICompiler")
|
||||||
|
{
|
||||||
|
this._CompileMessages = new string[] { "Compilation Failed.", "Unable to locate the specified compiler of Type '" + Compiler + "'." };
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the compiler parameters.
|
||||||
|
CompilerParameters param = GetParameters();
|
||||||
|
|
||||||
|
//Create a Instance of the compiler, either custom or internal.
|
||||||
|
ICompiler com = (ICompiler)Activator.CreateInstance(compiler);
|
||||||
|
|
||||||
|
//Setup it's properties to match that of our CompileEngine.
|
||||||
|
com.AssemblyReferences = AssemblyReferences;
|
||||||
|
com.ScriptExtension = ScriptExtension;
|
||||||
|
com.CompilerOptions = this.CompilerOptions;
|
||||||
|
|
||||||
|
//Compile the scripts.
|
||||||
|
Boolean isSuccess = com.Compile(param, scriptRepository);
|
||||||
|
HasErrors = !isSuccess;
|
||||||
|
|
||||||
|
//If the compilation failed, store all of the compiler errors
|
||||||
|
//into our _CompileMessages string.
|
||||||
|
if (!isSuccess)
|
||||||
|
{
|
||||||
|
List<String> compilerMessages = new List<string>();
|
||||||
|
foreach (String message in com.Results.Output)
|
||||||
|
{
|
||||||
|
compilerMessages.Add(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
_CompileMessages = compilerMessages.ToArray();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Compiling completed without error, so we need to save
|
||||||
|
//a reference to the compiled assembly.
|
||||||
|
CompiledAssembly = com.Results.CompiledAssembly;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles the script supplied.
|
||||||
|
/// The compiler will compile the script using the compiler specified with the CompileEngine.Compiler Property.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Returns true if compilation was completed without any errors.</returns>
|
||||||
|
public Boolean Compile(FileInfo sourceFile)
|
||||||
|
{
|
||||||
|
if (!sourceFile.Exists)
|
||||||
|
{
|
||||||
|
this._CompileMessages = new String[] { "Error: File " + sourceFile.FullName + " does not exists." };
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the compiler that the developer has selected.
|
||||||
|
//If the developer chooses a compiler that is not part of the engine, the GetCompiler() method
|
||||||
|
//will check all the currently loaded assemblies in memory for a custom compiler implementing
|
||||||
|
//the ICompiler interface.
|
||||||
|
Type compiler = GetCompiler();
|
||||||
|
|
||||||
|
//Incase a non-default compiler was specified and we could not find it in memory, fail.
|
||||||
|
if (compiler.Name == "ICompiler")
|
||||||
|
{
|
||||||
|
this._CompileMessages = new string[] { "Compilation Failed.", "Unable to locate the specified compiler of Type '" + Compiler + "'." };
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the compiler parameters.
|
||||||
|
CompilerParameters param = GetParameters();
|
||||||
|
|
||||||
|
//Create a Instance of the compiler, either custom or internal.
|
||||||
|
ICompiler com = (ICompiler)Activator.CreateInstance(compiler);
|
||||||
|
|
||||||
|
//Setup it's properties to match that of our CompileEngine.
|
||||||
|
com.AssemblyReferences = AssemblyReferences;
|
||||||
|
com.ScriptExtension = ScriptExtension;
|
||||||
|
com.CompilerOptions = this.CompilerOptions;
|
||||||
|
|
||||||
|
//Compile the script.
|
||||||
|
Boolean isSuccess = com.Compile(param, sourceFile);
|
||||||
|
HasErrors = !isSuccess;
|
||||||
|
|
||||||
|
//If the compilation failed, store all of the compiler errors
|
||||||
|
//into our _CompileMessages string.
|
||||||
|
if (!isSuccess)
|
||||||
|
{
|
||||||
|
List<String> compilerMessages = new List<string>();
|
||||||
|
foreach (String message in com.Results.Output)
|
||||||
|
{
|
||||||
|
compilerMessages.Add(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
_CompileMessages = compilerMessages.ToArray();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Compiling completed without error, so we need to save
|
||||||
|
//a reference to the compiled assembly.
|
||||||
|
CompiledAssembly = com.Results.CompiledAssembly;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles the source code provided.
|
||||||
|
/// The compiler will compile the scripts using the compiler specified with the CompileEngine.Compiler Property.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Returns true if compilation was completed without any errors.</returns>
|
||||||
|
public Boolean Compile(String[] sourceCode)
|
||||||
|
{
|
||||||
|
//Get the compiler that the developer has selected.
|
||||||
|
//If the developer chooses a compiler that is not part of the engine, the GetCompiler() method
|
||||||
|
//will check all the currently loaded assemblies in memory for a custom compiler implementing
|
||||||
|
//the ICompiler interface.
|
||||||
|
Type compiler = GetCompiler();
|
||||||
|
|
||||||
|
//Incase a non-default compiler was specified and we could not find it in memory, fail.
|
||||||
|
if (compiler.Name == "ICompiler")
|
||||||
|
{
|
||||||
|
this._CompileMessages = new string[] { "Compilation Failed.", "Unable to locate the specified compiler of Type '" + Compiler + "'." };
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the compiler parameters.
|
||||||
|
CompilerParameters param = GetParameters();
|
||||||
|
|
||||||
|
//Create a Instance of the compiler, either custom or internal.
|
||||||
|
ICompiler com = (ICompiler)Activator.CreateInstance(compiler);
|
||||||
|
|
||||||
|
//Setup it's properties to match that of our CompileEngine.
|
||||||
|
com.AssemblyReferences = AssemblyReferences;
|
||||||
|
com.ScriptExtension = ScriptExtension;
|
||||||
|
com.CompilerOptions = this.CompilerOptions;
|
||||||
|
|
||||||
|
//Compile the scripts.
|
||||||
|
Boolean isSuccess = com.Compile(param, sourceCode);
|
||||||
|
HasErrors = !isSuccess;
|
||||||
|
|
||||||
|
//If the compilation failed, store all of the compiler errors
|
||||||
|
//into our _CompileMessages string.
|
||||||
|
if (!isSuccess)
|
||||||
|
{
|
||||||
|
List<String> compilerMessages = new List<string>();
|
||||||
|
foreach (String message in com.Results.Output)
|
||||||
|
{
|
||||||
|
compilerMessages.Add(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
_CompileMessages = compilerMessages.ToArray();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Compiling completed without error, so we need to save
|
||||||
|
//a reference to the compiled assembly.
|
||||||
|
CompiledAssembly = com.Results.CompiledAssembly;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets compiler parameters that the compiler will be supplied with.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
private CompilerParameters GetParameters()
|
||||||
|
{
|
||||||
|
//Setup some default parameters that will be used by the compilers.
|
||||||
|
CompilerParameters param = new CompilerParameters(this.AssemblyReferences.ToArray());
|
||||||
|
param.GenerateExecutable = false;
|
||||||
|
param.GenerateInMemory = true;
|
||||||
|
|
||||||
|
//Left out, Add as CompileEngine properties in the future.
|
||||||
|
//param.TreatWarningsAsErrors = true;
|
||||||
|
//param.WarningLevel = 0;
|
||||||
|
//param.IncludeDebugInformation = true;
|
||||||
|
return param;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the compiler that will be used during the compilation of the scripts.
|
||||||
|
/// If a custom compiler is used, then the method will check every assembly in memory
|
||||||
|
/// and find the custom one requested. If none are found, then it will return a new
|
||||||
|
/// Object of type ICompiler.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
private Type GetCompiler()
|
||||||
|
{
|
||||||
|
Type compiler = typeof(ICompiler);
|
||||||
|
|
||||||
|
//Internal CSharpRaw compiler Type specified, so we'll use that.
|
||||||
|
if ((this.Compiler.ToLower() == "c#") || (this.Compiler.ToLower() == "csharp"))
|
||||||
|
{
|
||||||
|
compiler = typeof(Compilers.CSharp);
|
||||||
|
return compiler;
|
||||||
|
}
|
||||||
|
else if ((this.Compiler.ToLower() == "vb") || (this.Compiler.Replace(" ", "").ToLower() == "visualbasic"))
|
||||||
|
{
|
||||||
|
compiler = typeof(Compilers.VisualBasic);
|
||||||
|
}
|
||||||
|
//Build a collection of available compilers by scanning all the assemblies loaded in memory.
|
||||||
|
//If any of the assemblies contain a Type that uses the ICompiler interface, we will assume that the
|
||||||
|
//assembly is a add-on assembly for rScript, adding a new compiler to the CompileEngine.
|
||||||
|
//Only used if a non-internal compiler is specified
|
||||||
|
else
|
||||||
|
{ //Non-internal compiler supplied, so loop through every assembly loaded in memory
|
||||||
|
foreach (Assembly a in _Assemblies)
|
||||||
|
{
|
||||||
|
Boolean isCompiler = false;
|
||||||
|
|
||||||
|
//Create an array of all Types within this assembly
|
||||||
|
Type[] types = a.GetTypes();
|
||||||
|
|
||||||
|
//Itterate through each Type; See if any implement the ICompiler interface.
|
||||||
|
foreach (Type t in a.GetTypes())
|
||||||
|
{
|
||||||
|
//If this Type implements ICompiler, then our compiler field needs to reference the Type.
|
||||||
|
if ((t.GetInterface("ICompiler") != null) && (t.Name.ToLower() == Compiler.ToLower()))
|
||||||
|
{
|
||||||
|
//compiler needs to reference this custom compiler Type.
|
||||||
|
compiler = t;
|
||||||
|
isCompiler = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//If we found a matching compiler, then exit this loop.
|
||||||
|
if (isCompiler)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return compiler;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
140
rScripting/Compilers/CSharp.cs
Normal file
140
rScripting/Compilers/CSharp.cs
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
/*
|
||||||
|
* Microsoft Public License (Ms-PL)
|
||||||
|
* This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
|
||||||
|
* 1. Definitions
|
||||||
|
* The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
|
||||||
|
* A "contribution" is the original software, or any additions or changes to the software.
|
||||||
|
* A "contributor" is any person that distributes its contribution under this license.
|
||||||
|
* "Licensed patents" are a contributor's patent claims that read directly on its contribution.
|
||||||
|
* 2. Grant of Rights
|
||||||
|
* (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
|
||||||
|
* (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
|
||||||
|
* 3. Conditions and Limitations
|
||||||
|
* (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
|
||||||
|
* (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
|
||||||
|
* (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
|
||||||
|
* (D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
|
||||||
|
* (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.CSharp;
|
||||||
|
|
||||||
|
namespace rScripting.Compilers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Standard C# source code compiler.
|
||||||
|
/// </summary>
|
||||||
|
internal class CSharp : ICompiler
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The file extension used for the script files.
|
||||||
|
/// </summary>
|
||||||
|
public String ScriptExtension { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a collection of Assemblies that the compiler will add to its reference list.
|
||||||
|
/// </summary>
|
||||||
|
public List<String> AssemblyReferences { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The results of the compilation
|
||||||
|
/// </summary>
|
||||||
|
public CompilerResults Results { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides compiling options to various compilers, if they support this feature.
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<String, String> CompilerOptions { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles the source files found within the scriptRepository directory matching the ICompiler.ScriptExtension
|
||||||
|
/// The Compiler defaults to the C# 4.0 compiler if none other is supplied via the ICompiler.CompilerOptions argument.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="param">Compiler Parameters that can be supplied to customize the compilation of the source.</param>
|
||||||
|
/// <returns>Returns true if the compilation was completed without error.</returns>
|
||||||
|
public Boolean Compile(CompilerParameters param, String scriptRepository)
|
||||||
|
{
|
||||||
|
//Make sure we have a compiler version supplied.
|
||||||
|
if (!CompilerOptions.ContainsKey("CompilerVersion"))
|
||||||
|
CompilerOptions.Add("CompilerVersion", "v4.0");
|
||||||
|
|
||||||
|
//Instance a reference to the C# code provider, this is what will perform the compiling.
|
||||||
|
CSharpCodeProvider provider = new CSharpCodeProvider(CompilerOptions);
|
||||||
|
//Create an array of script files found within the ScriptRepository matching the ScriptExtension properties.
|
||||||
|
String[] scripts = Directory.GetFiles(scriptRepository, "*" + this.ScriptExtension, SearchOption.AllDirectories);
|
||||||
|
|
||||||
|
//Compile the scripts and provide the Results property with a reference to the compilation results.
|
||||||
|
Results = provider.CompileAssemblyFromFile(param, scripts);
|
||||||
|
|
||||||
|
//if the compiler has errors, return false.
|
||||||
|
if (Results.Errors.HasErrors)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles the source files found within the scriptFile argument.
|
||||||
|
/// The Compiler defaults to the C# 4.0 compiler if none other is supplied via the ICompiler.CompilerOptions argument.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="param"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Boolean Compile(CompilerParameters param, FileInfo scriptFile)
|
||||||
|
{
|
||||||
|
//Make sure we have a compiler version supplied.
|
||||||
|
if (!CompilerOptions.ContainsKey("CompilerVersion"))
|
||||||
|
CompilerOptions.Add("CompilerVersion", "v4.0");
|
||||||
|
|
||||||
|
CSharpCodeProvider provider = new CSharpCodeProvider(CompilerOptions);
|
||||||
|
|
||||||
|
//Make sure the file exists prior to attempting to compile it.
|
||||||
|
if (scriptFile.Exists)
|
||||||
|
{
|
||||||
|
//Compile the script and provide the Results property with a referece to the compilation results.
|
||||||
|
Results = provider.CompileAssemblyFromFile(param, scriptFile.FullName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Results.Errors.Add(new CompilerError(scriptFile.FullName, 0, 0, "rS01", "The supplied filename does not exist."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Results.Errors.HasErrors)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles the source code found within the scriptSourceCode argument
|
||||||
|
/// The Compiler defaults to the C# 4.0 compiler if none other is supplied via the ICompiler.CompilerOptions argument.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="param"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Boolean Compile(CompilerParameters param, String[] scriptSourceCode)
|
||||||
|
{
|
||||||
|
if (!CompilerOptions.ContainsKey("CompilerVersion"))
|
||||||
|
CompilerOptions.Add("CompilerVersion", "v4.0");
|
||||||
|
|
||||||
|
CSharpCodeProvider provider = new CSharpCodeProvider(CompilerOptions);
|
||||||
|
|
||||||
|
if (scriptSourceCode.Length == 0)
|
||||||
|
{
|
||||||
|
Results.Errors.Add(new CompilerError("None", 0, 0, "rS02", "No Source provided."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Results = provider.CompileAssemblyFromSource(param, scriptSourceCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Results.Errors.HasErrors)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
rScripting/Compilers/ICompiler.cs
Normal file
60
rScripting/Compilers/ICompiler.cs
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* Microsoft Public License (Ms-PL)
|
||||||
|
* This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
|
||||||
|
* 1. Definitions
|
||||||
|
* The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
|
||||||
|
* A "contribution" is the original software, or any additions or changes to the software.
|
||||||
|
* A "contributor" is any person that distributes its contribution under this license.
|
||||||
|
* "Licensed patents" are a contributor's patent claims that read directly on its contribution.
|
||||||
|
* 2. Grant of Rights
|
||||||
|
* (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
|
||||||
|
* (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
|
||||||
|
* 3. Conditions and Limitations
|
||||||
|
* (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
|
||||||
|
* (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
|
||||||
|
* (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
|
||||||
|
* (D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
|
||||||
|
* (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
|
||||||
|
*/
|
||||||
|
#if WINDOWS_PC
|
||||||
|
using System;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace rScripting.Compilers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Used to implement a wrapper for an existing compiler.
|
||||||
|
/// </summary>
|
||||||
|
public interface ICompiler
|
||||||
|
{
|
||||||
|
CompilerResults Results { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// The file extension used for the script files.
|
||||||
|
/// </summary>
|
||||||
|
String ScriptExtension { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a collection of Assemblies that the compiler will add to its reference list.
|
||||||
|
/// </summary>
|
||||||
|
List<String> AssemblyReferences { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides compiling options to various compilers, if they support this feature.
|
||||||
|
/// </summary>
|
||||||
|
Dictionary<String, String> CompilerOptions { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles the source files found within the scriptRepository directory matching the ICompiler.ScriptExtension
|
||||||
|
/// The Compiler defaults to the C# 4.0 compiler if none other is supplied via the ICompiler.CompilerOptions argument.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="param">Compiler Parameters that can be supplied to customize the compilation of the source.</param>
|
||||||
|
/// <returns>Returns true if the compilation was completed without error.</returns>
|
||||||
|
Boolean Compile(CompilerParameters param, String scriptRepository);
|
||||||
|
|
||||||
|
Boolean Compile(CompilerParameters param, System.IO.FileInfo scriptFile);
|
||||||
|
|
||||||
|
Boolean Compile(CompilerParameters param, String[] scriptSource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
129
rScripting/Compilers/JScript.cs
Normal file
129
rScripting/Compilers/JScript.cs
Normal file
|
@ -0,0 +1,129 @@
|
||||||
|
/*
|
||||||
|
* Microsoft Public License (Ms-PL)
|
||||||
|
* This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
|
||||||
|
* 1. Definitions
|
||||||
|
* The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
|
||||||
|
* A "contribution" is the original software, or any additions or changes to the software.
|
||||||
|
* A "contributor" is any person that distributes its contribution under this license.
|
||||||
|
* "Licensed patents" are a contributor's patent claims that read directly on its contribution.
|
||||||
|
* 2. Grant of Rights
|
||||||
|
* (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
|
||||||
|
* (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
|
||||||
|
* 3. Conditions and Limitations
|
||||||
|
* (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
|
||||||
|
* (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
|
||||||
|
* (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
|
||||||
|
* (D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
|
||||||
|
* (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
|
||||||
|
*/
|
||||||
|
#if WINDOWS_PC
|
||||||
|
using System;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.JScript;
|
||||||
|
|
||||||
|
namespace rScripting.Compilers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// JScript source code compiler.
|
||||||
|
/// </summary>
|
||||||
|
internal class JScript : ICompiler
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The file extension used for the script files.
|
||||||
|
/// </summary>
|
||||||
|
public String ScriptExtension { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a collection of Assemblies that the compiler will add to its reference list.
|
||||||
|
/// </summary>
|
||||||
|
public List<String> AssemblyReferences { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The results of the compilation
|
||||||
|
/// </summary>
|
||||||
|
public CompilerResults Results { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides compiling options to various compilers, if they support this feature.
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<String, String> CompilerOptions { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles the source files found within the scriptRepository directory matching the ICompiler.ScriptExtension
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="param">Compiler Parameters that can be supplied to customize the compilation of the source.</param>
|
||||||
|
/// <returns>Returns true if the compilation was completed without error.</returns>
|
||||||
|
public Boolean Compile(CompilerParameters param, String scriptRepository)
|
||||||
|
{
|
||||||
|
//Instance a reference to the C# code provider, this is what will perform the compiling.
|
||||||
|
JScriptCodeProvider provider = new JScriptCodeProvider();
|
||||||
|
|
||||||
|
//Create an array of script files found within the ScriptRepository matching the ScriptExtension properties.
|
||||||
|
String[] scripts = Directory.GetFiles(scriptRepository, "*" + this.ScriptExtension, SearchOption.AllDirectories);
|
||||||
|
|
||||||
|
//Compile the scripts and provide the Results property with a reference to the compilation results.
|
||||||
|
Results = provider.CompileAssemblyFromFile(param, scripts);
|
||||||
|
|
||||||
|
//if the compiler has errors, return false.
|
||||||
|
if (Results.Errors.HasErrors)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles the source files found within the scriptFile argument.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="param"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Boolean Compile(CompilerParameters param, FileInfo scriptFile)
|
||||||
|
{
|
||||||
|
JScriptCodeProvider provider = new JScriptCodeProvider();
|
||||||
|
|
||||||
|
//Make sure the file exists prior to attempting to compile it.
|
||||||
|
if (scriptFile.Exists)
|
||||||
|
{
|
||||||
|
//Compile the script and provide the Results property with a referece to the compilation results.
|
||||||
|
Results = provider.CompileAssemblyFromFile(param, scriptFile.FullName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Results.Errors.Add(new CompilerError(scriptFile.FullName, 0, 0, "rS01", "The supplied filename does not exist."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Results.Errors.HasErrors)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles the source code found within the scriptSourceCode argument
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="param"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Boolean Compile(CompilerParameters param, String[] scriptSourceCode)
|
||||||
|
{
|
||||||
|
JScriptCodeProvider provider = new JScriptCodeProvider();
|
||||||
|
|
||||||
|
if (scriptSourceCode.Length == 0)
|
||||||
|
{
|
||||||
|
Results.Errors.Add(new CompilerError("None", 0, 0, "rS02", "No Source provided."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Results = provider.CompileAssemblyFromSource(param, scriptSourceCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Results.Errors.HasErrors)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
123
rScripting/Compilers/Python.cs
Normal file
123
rScripting/Compilers/Python.cs
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
/*
|
||||||
|
* Microsoft Public License (Ms-PL)
|
||||||
|
* This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
|
||||||
|
* 1. Definitions
|
||||||
|
* The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
|
||||||
|
* A "contribution" is the original software, or any additions or changes to the software.
|
||||||
|
* A "contributor" is any person that distributes its contribution under this license.
|
||||||
|
* "Licensed patents" are a contributor's patent claims that read directly on its contribution.
|
||||||
|
* 2. Grant of Rights
|
||||||
|
* (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
|
||||||
|
* (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
|
||||||
|
* 3. Conditions and Limitations
|
||||||
|
* (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
|
||||||
|
* (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
|
||||||
|
* (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
|
||||||
|
* (D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
|
||||||
|
* (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
|
||||||
|
*/
|
||||||
|
#if PYTHON_EDITION //Temporary symbol that is not used. Allows me to continue working on the engine without this compiler being compiled at the moment.
|
||||||
|
using System;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using IronPython.Hosting;
|
||||||
|
using IronPython.Runtime;
|
||||||
|
using Microsoft.Scripting;
|
||||||
|
using Microsoft.Scripting.Hosting;
|
||||||
|
|
||||||
|
namespace rScripting.Compilers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Python source code compiler.
|
||||||
|
/// </summary>
|
||||||
|
internal class Python : ICompiler
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The file extension used for the script files.
|
||||||
|
/// </summary>
|
||||||
|
public String ScriptExtension { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a collection of Assemblies that the compiler will add to its reference list.
|
||||||
|
/// </summary>
|
||||||
|
public List<String> AssemblyReferences { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The results of the compilation
|
||||||
|
/// </summary>
|
||||||
|
public CompilerResults Results { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides compiling options to various compilers, if they support this feature.
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<String, String> CompilerOptions { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles the source files found within the scriptRepository directory matching the ICompiler.ScriptExtension
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="param">Compiler Parameters that can be supplied to customize the compilation of the source.</param>
|
||||||
|
/// <returns>Returns true if the compilation was completed without error.</returns>
|
||||||
|
public Boolean Compile(CompilerParameters param, String scriptRepository)
|
||||||
|
{
|
||||||
|
ScriptEngine pyEngine = null;
|
||||||
|
pyEngine = IronPython.Hosting.Python.CreateEngine(); //TODO: Add Domain argument
|
||||||
|
|
||||||
|
ScriptSource source = pyEngine.CreateScriptSourceFromFile(
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles the source files found within the scriptFile argument.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="param"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Boolean Compile(CompilerParameters param, FileInfo scriptFile)
|
||||||
|
{
|
||||||
|
JScriptCodeProvider provider = new JScriptCodeProvider();
|
||||||
|
|
||||||
|
//Make sure the file exists prior to attempting to compile it.
|
||||||
|
if (scriptFile.Exists)
|
||||||
|
{
|
||||||
|
//Compile the script and provide the Results property with a referece to the compilation results.
|
||||||
|
Results = provider.CompileAssemblyFromFile(param, scriptFile.FullName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Results.Errors.Add(new CompilerError(scriptFile.FullName, 0, 0, "rS01", "The supplied filename does not exist."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Results.Errors.HasErrors)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles the source code found within the scriptSourceCode argument
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="param"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Boolean Compile(CompilerParameters param, String[] scriptSourceCode)
|
||||||
|
{
|
||||||
|
JScriptCodeProvider provider = new JScriptCodeProvider();
|
||||||
|
|
||||||
|
if (scriptSourceCode.Length == 0)
|
||||||
|
{
|
||||||
|
Results.Errors.Add(new CompilerError("None", 0, 0, "rS02", "No Source provided."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Results = provider.CompileAssemblyFromSource(param, scriptSourceCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Results.Errors.HasErrors)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
143
rScripting/Compilers/VisualBasic.cs
Normal file
143
rScripting/Compilers/VisualBasic.cs
Normal file
|
@ -0,0 +1,143 @@
|
||||||
|
/*
|
||||||
|
* Microsoft Public License (Ms-PL)
|
||||||
|
* This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
|
||||||
|
* 1. Definitions
|
||||||
|
* The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
|
||||||
|
* A "contribution" is the original software, or any additions or changes to the software.
|
||||||
|
* A "contributor" is any person that distributes its contribution under this license.
|
||||||
|
* "Licensed patents" are a contributor's patent claims that read directly on its contribution.
|
||||||
|
* 2. Grant of Rights
|
||||||
|
* (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
|
||||||
|
* (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
|
||||||
|
* 3. Conditions and Limitations
|
||||||
|
* (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
|
||||||
|
* (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
|
||||||
|
* (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
|
||||||
|
* (D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
|
||||||
|
* (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
|
||||||
|
*/
|
||||||
|
#if WINDOWS_PC
|
||||||
|
using System;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.VisualBasic;
|
||||||
|
|
||||||
|
namespace rScripting.Compilers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Standard VB source code compiler.
|
||||||
|
/// </summary>
|
||||||
|
internal class VisualBasic : ICompiler
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The file extension used for the script files.
|
||||||
|
/// </summary>
|
||||||
|
public String ScriptExtension { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a collection of Assemblies that the compiler will add to its reference list.
|
||||||
|
/// </summary>
|
||||||
|
public List<String> AssemblyReferences { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The results of the compilation
|
||||||
|
/// </summary>
|
||||||
|
public CompilerResults Results { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides compiling options to various compilers, if they support this feature.
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<String, String> CompilerOptions { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles the source files found within the scriptRepository directory matching the ICompiler.ScriptExtension
|
||||||
|
/// The Compiler defaults to the VB 3.5 compiler if none other is supplied via the ICompiler.CompilerOptions argument.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="param">Compiler Parameters that can be supplied to customize the compilation of the source.</param>
|
||||||
|
/// <returns>Returns true if the compilation was completed without error.</returns>
|
||||||
|
public Boolean Compile(CompilerParameters param, String scriptRepository)
|
||||||
|
{
|
||||||
|
//Make sure we have a compiler version supplied.
|
||||||
|
if (!CompilerOptions.ContainsKey("CompilerVersion"))
|
||||||
|
CompilerOptions.Add("CompilerVersion", "v3.5");
|
||||||
|
|
||||||
|
//Instance a reference to the VB code provider, this is what will perform the compiling.
|
||||||
|
VBCodeProvider provider = new VBCodeProvider(CompilerOptions);
|
||||||
|
|
||||||
|
//Create an array of script files found within the ScriptRepository matching the ScriptExtension properties.
|
||||||
|
String[] scripts = Directory.GetFiles(scriptRepository, "*" + this.ScriptExtension, SearchOption.AllDirectories);
|
||||||
|
|
||||||
|
//Compile the scripts and provide the Results property with a reference to the compilation results.
|
||||||
|
Results = provider.CompileAssemblyFromFile(param, scripts);
|
||||||
|
|
||||||
|
//if the compiler has errors, return false.
|
||||||
|
if (Results.Errors.HasErrors)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles the source files found within the scriptFile argument.
|
||||||
|
/// The Compiler defaults to the VB 3.5 compiler if none other is supplied via the ICompiler.CompilerOptions property.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="param"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Boolean Compile(CompilerParameters param, FileInfo scriptFile)
|
||||||
|
{
|
||||||
|
//Make sure we have a compiler version supplied.
|
||||||
|
if (!CompilerOptions.ContainsKey("CompilerVersion"))
|
||||||
|
CompilerOptions.Add("CompilerVersion", "v3.5");
|
||||||
|
|
||||||
|
VBCodeProvider provider = new VBCodeProvider(CompilerOptions);
|
||||||
|
|
||||||
|
//Make sure the file exists prior to attempting to compile it.
|
||||||
|
if (scriptFile.Exists)
|
||||||
|
{
|
||||||
|
//Compile the script and provide the Results property with a referece to the compilation results.
|
||||||
|
Results = provider.CompileAssemblyFromFile(param, scriptFile.FullName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Results.Errors.Add(new CompilerError(scriptFile.FullName, 0, 0, "rS01", "The supplied filename does not exist."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Results.Errors.HasErrors)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compiles the source code found within the scriptSourceCode argument
|
||||||
|
/// The Compiler defaults to the VB 3.5 compiler if none other is supplied via the ICompiler.CompilerOptions property.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="param"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Boolean Compile(CompilerParameters param, String[] scriptSourceCode)
|
||||||
|
{
|
||||||
|
if (!CompilerOptions.ContainsKey("CompilerVersion"))
|
||||||
|
CompilerOptions.Add("CompilerVersion", "v3.5");
|
||||||
|
|
||||||
|
VBCodeProvider provider = new VBCodeProvider(CompilerOptions);
|
||||||
|
|
||||||
|
if (scriptSourceCode.Length == 0)
|
||||||
|
{
|
||||||
|
Results.Errors.Add(new CompilerError("None", 0, 0, "rS02", "No Source provided."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Results = provider.CompileAssemblyFromSource(param, scriptSourceCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Results.Errors.HasErrors)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
154
rScripting/LateBinding/ScriptFactory.cs
Normal file
154
rScripting/LateBinding/ScriptFactory.cs
Normal file
|
@ -0,0 +1,154 @@
|
||||||
|
/*
|
||||||
|
* Microsoft Public License (Ms-PL)
|
||||||
|
* This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
|
||||||
|
* 1. Definitions
|
||||||
|
* The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
|
||||||
|
* A "contribution" is the original software, or any additions or changes to the software.
|
||||||
|
* A "contributor" is any person that distributes its contribution under this license.
|
||||||
|
* "Licensed patents" are a contributor's patent claims that read directly on its contribution.
|
||||||
|
* 2. Grant of Rights
|
||||||
|
* (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
|
||||||
|
* (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
|
||||||
|
* 3. Conditions and Limitations
|
||||||
|
* (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
|
||||||
|
* (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
|
||||||
|
* (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
|
||||||
|
* (D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
|
||||||
|
* (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace rScripting.LateBinding
|
||||||
|
{
|
||||||
|
public class ScriptFactory
|
||||||
|
{
|
||||||
|
//The assembly loaded that will be used.
|
||||||
|
private List<Assembly> _AssemblyCollection;
|
||||||
|
|
||||||
|
#if WINDOWS_PC
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor for a Windows PC Script Factory
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="assembly"></param>
|
||||||
|
public ScriptFactory(String assembly)
|
||||||
|
{
|
||||||
|
Assembly a;
|
||||||
|
_AssemblyCollection = new List<Assembly>();
|
||||||
|
|
||||||
|
//See if a file exists first with this assembly name.
|
||||||
|
if (File.Exists(assembly))
|
||||||
|
{
|
||||||
|
a = Assembly.Load(new AssemblyName(assembly));
|
||||||
|
}
|
||||||
|
//If not, then try and load it differently
|
||||||
|
else
|
||||||
|
{
|
||||||
|
a = Assembly.Load(assembly);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
//Add the assembly to our assembly collection.
|
||||||
|
_AssemblyCollection.Add(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Alternate Constructor for a Windows PC ScriptFactory
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="assembly"></param>
|
||||||
|
public ScriptFactory(Assembly assembly)
|
||||||
|
{
|
||||||
|
_AssemblyCollection = new List<Assembly>();
|
||||||
|
//Add the supplied assembly to our AssemblyCollection
|
||||||
|
_AssemblyCollection.Add(assembly);
|
||||||
|
}
|
||||||
|
#elif WINDOWS_PHONE
|
||||||
|
public ScriptFactory()
|
||||||
|
{
|
||||||
|
_AssemblyCollection = new List<Assembly>();
|
||||||
|
foreach(System.Windows.AssemblyPart part in System.Windows.Deployment.Current.Parts)
|
||||||
|
{
|
||||||
|
String assemName = part.Source.Replace(".dll", String.Empty);
|
||||||
|
Assembly a = Assembly.Load(assemName);
|
||||||
|
_AssemblyCollection.Add(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/// <summary>
|
||||||
|
/// Adds another assembly to the factories assembly collection.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="assembly">provides the name of the assembly, or file name that needs to be loaded.</param>
|
||||||
|
public void AddAssembly(String assembly)
|
||||||
|
{
|
||||||
|
Assembly a;
|
||||||
|
|
||||||
|
//See if a file exists first with this assembly name.
|
||||||
|
if (File.Exists(assembly))
|
||||||
|
{
|
||||||
|
a = Assembly.Load(new AssemblyName(assembly));
|
||||||
|
}
|
||||||
|
//If not, then try and load it differently
|
||||||
|
else
|
||||||
|
{
|
||||||
|
a = Assembly.Load(assembly);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Add the assembly to our assembly collection.
|
||||||
|
_AssemblyCollection.Add(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds another assembly to the factories assembly collection.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="assembly">Provides a reference to the assembly that will be added to the collection.</param>
|
||||||
|
public void AddAssembly (Assembly assembly)
|
||||||
|
{
|
||||||
|
//Add the supplied assembly to our AssemblyCollection
|
||||||
|
_AssemblyCollection.Add(assembly);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScriptObject GetScript(String scriptName)
|
||||||
|
{
|
||||||
|
Type script = typeof(Object);
|
||||||
|
Boolean foundScript = false;
|
||||||
|
|
||||||
|
if (_AssemblyCollection.Count == 0)
|
||||||
|
return new ScriptObject(null);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (Assembly a in _AssemblyCollection)
|
||||||
|
{
|
||||||
|
//The assembly can be null if accessing after a failed compilation.
|
||||||
|
if (a == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (Type t in a.GetTypes())
|
||||||
|
{
|
||||||
|
if (t.Name == scriptName)
|
||||||
|
{
|
||||||
|
script = t;
|
||||||
|
foundScript = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foundScript)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw new Exception("Error encounted during factory instancing of script " + scriptName + ".");
|
||||||
|
}
|
||||||
|
|
||||||
|
ScriptObject obj = new ScriptObject(Activator.CreateInstance(script));
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
111
rScripting/LateBinding/ScriptObject.cs
Normal file
111
rScripting/LateBinding/ScriptObject.cs
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
/*
|
||||||
|
* Microsoft Public License (Ms-PL)
|
||||||
|
* This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
|
||||||
|
* 1. Definitions
|
||||||
|
* The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
|
||||||
|
* A "contribution" is the original software, or any additions or changes to the software.
|
||||||
|
* A "contributor" is any person that distributes its contribution under this license.
|
||||||
|
* "Licensed patents" are a contributor's patent claims that read directly on its contribution.
|
||||||
|
* 2. Grant of Rights
|
||||||
|
* (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
|
||||||
|
* (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
|
||||||
|
* 3. Conditions and Limitations
|
||||||
|
* (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
|
||||||
|
* (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
|
||||||
|
* (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
|
||||||
|
* (D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
|
||||||
|
* (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace rScripting.LateBinding
|
||||||
|
{
|
||||||
|
public class ScriptObject
|
||||||
|
{
|
||||||
|
public Object Instance { get; set; }
|
||||||
|
|
||||||
|
public ScriptObject(Object instance)
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
Instance = new Object();
|
||||||
|
else
|
||||||
|
Instance = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
~ScriptObject()
|
||||||
|
{
|
||||||
|
//TODO: Add ability to call a Shutdown() method within this Instance.
|
||||||
|
Instance = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetProperty(String propertyName, object propertyValue)
|
||||||
|
{
|
||||||
|
PropertyInfo propertyInfo = Instance.GetType().GetProperty(propertyName);
|
||||||
|
|
||||||
|
if (propertyValue is String)
|
||||||
|
{
|
||||||
|
if (propertyInfo.PropertyType.Name is String)
|
||||||
|
{
|
||||||
|
propertyInfo.SetValue(Instance, propertyValue, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public object GetProperty(String propertyName)
|
||||||
|
{
|
||||||
|
String[] tokens = propertyName.Split('.');
|
||||||
|
PropertyInfo previousProperty = Instance.GetType().GetProperty(tokens[0]);
|
||||||
|
|
||||||
|
return previousProperty.GetValue(Instance, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if WINDOWS_PC
|
||||||
|
public dynamic GetProperty()
|
||||||
|
{
|
||||||
|
return Instance;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public object GetField(String propertyName)
|
||||||
|
{
|
||||||
|
String[] tokens = propertyName.Split('.');
|
||||||
|
FieldInfo previousField = Instance.GetType().GetField(tokens[0]);
|
||||||
|
|
||||||
|
return previousField.GetValue(Instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if WINDOWS_PC
|
||||||
|
public dynamic GetField()
|
||||||
|
{
|
||||||
|
return Instance;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public Object InvokeMethod(String methodName)
|
||||||
|
{
|
||||||
|
return InvokeMethod(methodName, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object InvokeMethod(String methodName, params Object[] parameters)
|
||||||
|
{
|
||||||
|
MethodInfo method = Instance.GetType().GetMethod(methodName);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (parameters == null || parameters.Length == 0)
|
||||||
|
return method.Invoke(Instance, null);
|
||||||
|
else
|
||||||
|
return method.Invoke(Instance, parameters);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.Append("Error invoking method. Does the method exist?");
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
rScripting/Properties/AssemblyInfo.cs
Normal file
36
rScripting/Properties/AssemblyInfo.cs
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyTitle("rScripting")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("rScripting")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2010")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
[assembly: Guid("3d017b1e-afaa-4067-8809-35258b2d164a")]
|
||||||
|
|
||||||
|
// Version information for an assembly consists of the following four values:
|
||||||
|
//
|
||||||
|
// Major Version
|
||||||
|
// Minor Version
|
||||||
|
// Build Number
|
||||||
|
// Revision
|
||||||
|
//
|
||||||
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
|
// by using the '*' as shown below:
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
62
rScripting/rScripting.csproj
Normal file
62
rScripting/rScripting.csproj
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProductVersion>8.0.30703</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{BC1B32DA-7209-4B32-8171-A190EF21F5D6}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>rScripting</RootNamespace>
|
||||||
|
<AssemblyName>rScripting</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<SccProjectName>SAK</SccProjectName>
|
||||||
|
<SccLocalPath>SAK</SccLocalPath>
|
||||||
|
<SccAuxPath>SAK</SccAuxPath>
|
||||||
|
<SccProvider>SAK</SccProvider>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>TRACE;DEBUG;WINDOWS_PC</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE;WINDOWS_PC</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.JScript" />
|
||||||
|
<Reference Include="Microsoft.VisualBasic" />
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Compilers\Python.cs" />
|
||||||
|
<Compile Include="Compilers\JScript.cs" />
|
||||||
|
<Compile Include="Compilers\VisualBasic.cs" />
|
||||||
|
<Compile Include="Compilers\CSharp.cs" />
|
||||||
|
<Compile Include="Compilers\ICompiler.cs" />
|
||||||
|
<Compile Include="CompileEngine.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="LateBinding\ScriptFactory.cs" />
|
||||||
|
<Compile Include="LateBinding\ScriptObject.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
10
rScripting/rScripting.csproj.vspscc
Normal file
10
rScripting/rScripting.csproj.vspscc
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
""
|
||||||
|
{
|
||||||
|
"FILE_VERSION" = "9237"
|
||||||
|
"ENLISTMENT_CHOICE" = "NEVER"
|
||||||
|
"PROJECT_FILE_RELATIVE_PATH" = ""
|
||||||
|
"NUMBER_OF_EXCLUDED_FILES" = "0"
|
||||||
|
"ORIGINAL_PROJECT_FILE_PATH" = ""
|
||||||
|
"NUMBER_OF_NESTED_PROJECTS" = "0"
|
||||||
|
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue