This repository has been archived by the owner on Nov 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from brianb12321/Scripting
Scripting
- Loading branch information
Showing
76 changed files
with
2,295 additions
and
368 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace RemotePlusLibrary.Scripting | ||
{ | ||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Method)] | ||
public class IndexScriptObjectAttribute : Attribute | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("RemotePlusLibrary.Scripting")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("RemotePlusLibrary.Scripting")] | ||
[assembly: AssemblyCopyright("Copyright © 2018")] | ||
[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("5c399f78-c133-4f9b-9758-c36a4b7fae98")] | ||
|
||
// 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")] |
95 changes: 95 additions & 0 deletions
95
RemotePlusLibrary.Scripting/RemotePlusLibrary.Scripting.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{5C399F78-C133-4F9B-9758-C36A4B7FAE98}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>RemotePlusLibrary.Scripting</RootNamespace> | ||
<AssemblyName>RemotePlusLibrary.Scripting</AssemblyName> | ||
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<TargetFrameworkProfile /> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</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</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Ionic.Zip.1.9.1.8\lib\Ionic.Zip.dll</HintPath> | ||
</Reference> | ||
<Reference Include="IronPython, Version=2.7.8.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\IronPython.2.7.8.1\lib\net45\IronPython.dll</HintPath> | ||
</Reference> | ||
<Reference Include="IronPython.Modules, Version=2.7.8.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\IronPython.2.7.8.1\lib\net45\IronPython.Modules.dll</HintPath> | ||
</Reference> | ||
<Reference Include="IronPython.SQLite, Version=2.7.8.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\IronPython.2.7.8.1\lib\net45\IronPython.SQLite.dll</HintPath> | ||
</Reference> | ||
<Reference Include="IronPython.Wpf, Version=2.7.8.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\IronPython.2.7.8.1\lib\net45\IronPython.Wpf.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Microsoft.Dynamic, Version=1.2.0.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\DynamicLanguageRuntime.1.2.1\lib\net45\Microsoft.Dynamic.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Microsoft.Scripting, Version=1.2.0.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\DynamicLanguageRuntime.1.2.1\lib\net45\Microsoft.Scripting.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Microsoft.Scripting.Metadata, Version=1.2.0.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\DynamicLanguageRuntime.1.2.1\lib\net45\Microsoft.Scripting.Metadata.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Microsoft.VisualStudio.CodeCoverage.Shim, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\DynamicLanguageRuntime.1.2.1\lib\net45\Microsoft.VisualStudio.CodeCoverage.Shim.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.IO.Compression.FileSystem"> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System.Runtime.Serialization" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="IndexScriptObjectAttribute.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="ScriptBuilder.cs" /> | ||
<Compile Include="ScriptGlobal.cs" /> | ||
<Compile Include="ScriptGlobalInformation.cs" /> | ||
<Compile Include="ScriptGlobalTypecs.cs" /> | ||
<Compile Include="ScriptPackageEngine\ScriptPackage.cs" /> | ||
<Compile Include="ScriptPackageEngine\ScriptPackageManifest.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\src\RemotePlusLibrary.Configuration\RemotePlusLibrary.Configuration.csproj"> | ||
<Project>{8a8a5888-1ce7-46ed-b8de-1ac7671f3426}</Project> | ||
<Name>RemotePlusLibrary.Configuration</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using IronPython.Hosting; | ||
using Microsoft.Scripting; | ||
using Microsoft.Scripting.Hosting; | ||
using RemotePlusLibrary; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace RemotePlusLibrary.Scripting | ||
{ | ||
public class ScriptBuilder | ||
{ | ||
private Dictionary<string, ScriptGlobal> globals = new Dictionary<string, ScriptGlobal>(); | ||
public const string SCRIPT_LOG_CONSTANT = "Script Engine"; | ||
public ScriptEngine ScriptingEngine { get; private set; } | ||
void InitializeGlobals() | ||
{ | ||
foreach (KeyValuePair<string, ScriptGlobal> global in globals) | ||
{ | ||
ScriptingEngine.GetBuiltinModule().SetVariable(global.Key, global.Value.Global); | ||
} | ||
} | ||
public void AddScriptObject<T>(string objectName, T scriptObject, string description, ScriptGlobalType objectType) where T : class | ||
{ | ||
var newGlobal = new ScriptGlobal(scriptObject) { Information = new ScriptGlobalInformation() { Name = objectName, Description = description, Type = objectType } }; | ||
FillMembersRecurs(newGlobal); | ||
globals.Add(objectName, newGlobal); | ||
} | ||
|
||
private void FillMembersRecurs(ScriptGlobal newGlobal) | ||
{ | ||
FillData(newGlobal.Global.GetType(), newGlobal.Information); | ||
} | ||
void FillData(Type t, ScriptGlobalInformation i) | ||
{ | ||
foreach (MethodInfo method in t.GetMethods().Where(type => type.GetCustomAttribute<IndexScriptObjectAttribute>() != null)) | ||
{ | ||
ScriptGlobalInformation info = new ScriptGlobalInformation(); | ||
var g = new ScriptGlobalInformation(); | ||
g.Name = method.Name; | ||
g.Type = ScriptGlobalType.Function; | ||
i.Members.Add(g); | ||
} | ||
foreach (var property in t.GetProperties().Where(type => type.GetCustomAttribute<IndexScriptObjectAttribute>() != null)) | ||
{ | ||
ScriptGlobalInformation info = new ScriptGlobalInformation(); | ||
info.Name = property.Name; | ||
info.Type = ScriptGlobalType.Variable; | ||
FillDataProperty(property.PropertyType, info); | ||
i.Members.Add(info); | ||
} | ||
} | ||
void FillDataProperty(Type t, ScriptGlobalInformation i) | ||
{ | ||
ScriptGlobalInformation info = new ScriptGlobalInformation(); | ||
foreach (var property in t.GetProperties().Where(type => type.GetCustomAttribute<IndexScriptObjectAttribute>() != null)) | ||
{ | ||
info.Name = property.Name; | ||
info.Type = ScriptGlobalType.Variable; | ||
i.Members.Add(info); | ||
FillDataProperty(property.PropertyType, info); | ||
} | ||
} | ||
public bool FunctionExists(string functionName) | ||
{ | ||
return globals.ContainsKey(functionName); | ||
} | ||
public List<ScriptGlobal> GetGlobals() | ||
{ | ||
return globals.Values.ToList(); | ||
} | ||
|
||
public void InitializeEngine() | ||
{ | ||
ScriptingEngine = Python.CreateEngine(); | ||
InitializeGlobals(); | ||
} | ||
public bool ExecuteString(string script) | ||
{ | ||
var source = ScriptingEngine.CreateScriptSourceFromString(script); | ||
return source.Execute(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using RemotePlusLibrary; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace RemotePlusLibrary.Scripting | ||
{ | ||
public class ScriptGlobal | ||
{ | ||
public ScriptGlobalInformation Information { get; set; } | ||
public object Global { get; set; } | ||
public ScriptGlobal(object g) | ||
{ | ||
Global = g; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.Serialization; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace RemotePlusLibrary.Scripting | ||
{ | ||
[DataContract] | ||
public class ScriptGlobalInformation | ||
{ | ||
[DataMember] | ||
public string Name { get; set; } | ||
[DataMember] | ||
public string Description { get; set; } | ||
[DataMember] | ||
public ScriptGlobalType Type { get; set; } | ||
[DataMember] | ||
public List<ScriptGlobalInformation> Members { get; set; } = new List<ScriptGlobalInformation>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.Serialization; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace RemotePlusLibrary.Scripting | ||
{ | ||
[DataContract] | ||
public enum ScriptGlobalType | ||
{ | ||
[EnumMember] | ||
Variable, | ||
[EnumMember] | ||
Function | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
RemotePlusLibrary.Scripting/ScriptPackageEngine/ScriptPackage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Ionic.Zip; | ||
using System.IO; | ||
using System.Runtime.Serialization; | ||
using System.Xml; | ||
|
||
namespace RemotePlusLibrary.Scripting.ScriptPackageEngine | ||
{ | ||
public class ScriptPackage | ||
{ | ||
public ZipFile PackageContents { get; private set; } | ||
public ScriptPackageManifest PackageManifest { get; private set; } | ||
public string PackageFileName { get; set; } | ||
private ScriptPackage(ZipFile contents, ScriptPackageManifest manifest, string packageFileName) | ||
{ | ||
PackageContents = contents; | ||
PackageManifest = manifest; | ||
PackageFileName = packageFileName; | ||
} | ||
public static ScriptPackage Open(string packageName) | ||
{ | ||
if(!File.Exists(packageName)) | ||
{ | ||
throw new FileNotFoundException($"{packageName} does not exist."); | ||
} | ||
ZipFile package = ZipFile.Read(packageName); | ||
var manifest = ReadPackageManifest(package[$"{Path.GetFileNameWithoutExtension(packageName)}/{Path.GetFileNameWithoutExtension(packageName)}.manifest"]); | ||
return new ScriptPackage(package, manifest, Path.GetFileNameWithoutExtension(packageName)); | ||
} | ||
|
||
private static ScriptPackageManifest ReadPackageManifest(ZipEntry zipArchiveEntry) | ||
{ | ||
DataContractSerializer ser = new DataContractSerializer(typeof(ScriptPackageManifest)); | ||
XmlReader reader = XmlReader.Create(zipArchiveEntry.OpenReader()); | ||
var ss = (ScriptPackageManifest)ser.ReadObject(reader); | ||
reader.Close(); | ||
return ss; | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
RemotePlusLibrary.Scripting/ScriptPackageEngine/ScriptPackageExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace RemotePlusLibrary.Scripting.ScriptPackageEngine | ||
{ | ||
public static class ScriptPackageExtensions | ||
{ | ||
public static bool ExecuteScript(this ScriptPackage package) | ||
{ | ||
Stream s = package.PackageContents.GetEntry(package.PackageManifest.ScriptEntryPoint).Open(); | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.