├── .gitignore
├── BuildAll.csproj
├── README.md
├── dist.cmd
├── install
├── build.cmd
├── dotNetFx40_Full_setup.exe
├── install.iss
├── setlocals.cmd
└── vcredist_x86.exe
├── src
├── 1Script.sln
├── 1Script_Mono.sln
├── GlobalAssemblyInfo.cs
├── ScriptEngine.HostedScript
│ ├── HostedScriptEngine.cs
│ ├── IHostApplication.cs
│ ├── Library
│ │ ├── ArrayImpl.cs
│ │ ├── BinaryDataContext.cs
│ │ ├── CLREnumValueWrapper.cs
│ │ ├── CommandLineArguments.cs
│ │ ├── ConsoleContext.cs
│ │ ├── FileContext.cs
│ │ ├── FileOperations.cs
│ │ ├── GuidWrapper.cs
│ │ ├── Http
│ │ │ ├── HttpConnectionContext.cs
│ │ │ ├── HttpRequestBody.cs
│ │ │ ├── HttpRequestBodyBinary.cs
│ │ │ ├── HttpRequestBodyFile.cs
│ │ │ ├── HttpRequestBodyString.cs
│ │ │ ├── HttpRequestBodyUnknown.cs
│ │ │ ├── HttpRequestContext.cs
│ │ │ ├── HttpResponseBody.cs
│ │ │ ├── HttpResponseContext.cs
│ │ │ └── InternetProxyContext.cs
│ │ ├── KeyAndValueImpl.cs
│ │ ├── MapImpl.cs
│ │ ├── MiscGlobalFunctions.cs
│ │ ├── Net
│ │ │ ├── TCPClient.cs
│ │ │ └── TCPServer.cs
│ │ ├── ProcessContext.cs
│ │ ├── RandomNumberGenerator.cs
│ │ ├── Reflector.cs
│ │ ├── StdTextReadStream.cs
│ │ ├── StdTextWriteStream.cs
│ │ ├── StructureImpl.cs
│ │ ├── SymbolsEnum.cs
│ │ ├── SystemEnvironmentContext.cs
│ │ ├── SystemGlobalContext.cs
│ │ ├── TextEncodingEnum.cs
│ │ ├── TextReadImpl.cs
│ │ ├── TextWriteImpl.cs
│ │ ├── ValueTable
│ │ │ ├── CollectionIndexes.cs
│ │ │ ├── ValueTable.cs
│ │ │ ├── ValueTableColumn.cs
│ │ │ ├── ValueTableColumnCollection.cs
│ │ │ ├── ValueTableIndex.cs
│ │ │ └── ValueTableRow.cs
│ │ ├── Xml
│ │ │ ├── XmlGlobalFunctions.cs
│ │ │ ├── XmlNodeTypeEnum.cs
│ │ │ ├── XmlReaderImpl.cs
│ │ │ └── XmlWriterImpl.cs
│ │ └── Zip
│ │ │ ├── ZIPSubDirProcessingModeEnum.cs
│ │ │ ├── ZipCompressionLevelEnum.cs
│ │ │ ├── ZipCompressionMethodEnum.cs
│ │ │ ├── ZipEncryptionMethodEnum.cs
│ │ │ ├── ZipFileEntriesCollection.cs
│ │ │ ├── ZipFileEntryContext.cs
│ │ │ ├── ZipReader.cs
│ │ │ ├── ZipRestoreFilePathsModeEnum.cs
│ │ │ ├── ZipStorePathModeEnum.cs
│ │ │ └── ZipWriter.cs
│ ├── Process.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── ScriptEngine.HostedScript.csproj
│ └── packages.config
├── ScriptEngine.Snegopat
│ ├── AssemblyInfo.cpp
│ ├── CriticalResourceLoader.cpp
│ ├── CriticalResourceLoader.h
│ ├── DispatchHelpers.cpp
│ ├── DispatchHelpers.h
│ ├── EventCallableSDO.cpp
│ ├── EventCallableSDO.h
│ ├── IAddinImpl.cpp
│ ├── IAddinImpl.h
│ ├── IAddinLoaderImpl.cpp
│ ├── IAddinLoaderImpl.h
│ ├── LibraryAttachedContext.cpp
│ ├── LibraryAttachedContext.h
│ ├── MarshalingHelpers.cpp
│ ├── MarshalingHelpers.h
│ ├── ReadMe.txt
│ ├── RefCountable.cpp
│ ├── RefCountable.h
│ ├── ScriptDrivenAddin.cpp
│ ├── ScriptDrivenAddin.h
│ ├── ScriptEngine.Snegopat.vcxproj
│ ├── ScriptEngine.Snegopat.vcxproj.filters
│ ├── SnegAPIDefinitions.h
│ ├── Snegopat.idl
│ ├── SnegopatAttachedContext.cpp
│ ├── SnegopatAttachedContext.h
│ ├── Stdafx.cpp
│ ├── Stdafx.h
│ ├── app.ico
│ ├── app.rc
│ ├── clrfactory.cpp
│ ├── resource.h
│ └── snegopat.cpp
├── ScriptEngine
│ ├── CodePositionInfo.cs
│ ├── Compiler
│ │ ├── Compiler.cs
│ │ ├── CompilerContext.cs
│ │ ├── CompilerExceptions.cs
│ │ ├── ExpressionBuilder.cs
│ │ ├── ICompilerContext.cs
│ │ ├── ModuleCompilerContext.cs
│ │ ├── ModulePersistor.cs
│ │ ├── ModuleWriter.cs
│ │ ├── ParseIterator.cs
│ │ ├── Parser.cs
│ │ ├── ParserException.cs
│ │ ├── SourceCodeIndexer.cs
│ │ ├── SymbolScope.cs
│ │ └── Tokens.cs
│ ├── CompilerService.cs
│ ├── Environment
│ │ ├── CodeSources.cs
│ │ ├── FileOpener.cs
│ │ ├── ICodeSource.cs
│ │ ├── ICodeSourceFactory.cs
│ │ ├── ModuleInformation.cs
│ │ ├── ScriptModuleHandle.cs
│ │ └── ScriptSourceFactory.cs
│ ├── Machine
│ │ ├── BuiltinFunctions.cs
│ │ ├── Contexts
│ │ │ ├── AttachedScriptsFactory.cs
│ │ │ ├── AutoContext.cs
│ │ │ ├── COMWrapperContext.cs
│ │ │ ├── CollectionEnumerator.cs
│ │ │ ├── ContextClassAttribute.cs
│ │ │ ├── ContextDiscoverer.cs
│ │ │ ├── ContextIValueImpl.cs
│ │ │ ├── ContextMethodMapper.cs
│ │ │ ├── ContextPropertyMapper.cs
│ │ │ ├── ContextValuesMarshaller.cs
│ │ │ ├── DispatchUtility.cs
│ │ │ ├── DynamicPropertiesAccessor.cs
│ │ │ ├── DynamicPropertiesHolder.cs
│ │ │ ├── EnumContextHelper.cs
│ │ │ ├── EnumValueAttribute.cs
│ │ │ ├── EnumerationContext.cs
│ │ │ ├── EnumerationValue.cs
│ │ │ ├── ExceptionInfoContext.cs
│ │ │ ├── GlobalContextAttribute.cs
│ │ │ ├── GlobalContextBase.cs
│ │ │ ├── ICollectionContext.cs
│ │ │ ├── IObjectWrapper.cs
│ │ │ ├── LibraryContextBase.cs
│ │ │ ├── PropertyNameIndexAccessor.cs
│ │ │ ├── ReflectableSDO.cs
│ │ │ ├── ReflectedMethodInfo.cs
│ │ │ ├── ReflectedParamInfo.cs
│ │ │ ├── ReflectedPropertyInfo.cs
│ │ │ ├── SafeArrayWrapper.cs
│ │ │ ├── ScriptDrivenObject.cs
│ │ │ ├── ScriptInformationContext.cs
│ │ │ ├── SelfAwareEnumValue.cs
│ │ │ ├── SystemEnumAttribute.cs
│ │ │ └── UserScriptContextInstance.cs
│ │ ├── Core.cs
│ │ ├── ExecutionFrame.cs
│ │ ├── GenericIValueComparer.cs
│ │ ├── GenericValue.cs
│ │ ├── GlobalInstancesManager.cs
│ │ ├── IAttachableContext.cs
│ │ ├── IReflectableContext.cs
│ │ ├── IRuntimeContextInstance.cs
│ │ ├── IValue.cs
│ │ ├── LoadedModule.cs
│ │ ├── MachineInstance.cs
│ │ ├── NullValueImpl.cs
│ │ ├── PropertyBag.cs
│ │ ├── RuntimeExceptions.cs
│ │ ├── Scope.cs
│ │ ├── TypeManager.cs
│ │ ├── TypeTypeValue.cs
│ │ ├── ValueFactory.cs
│ │ ├── ValueFormatter.cs
│ │ └── Variables.cs
│ ├── ModuleImage.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── RuntimeEnvironment.cs
│ ├── ScriptEngine.csproj
│ ├── ScriptException.cs
│ ├── ScriptingEngine.cs
│ └── Utils.cs
├── StandaloneRunner
│ ├── Program.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── StandaloneProcess.cs
│ └── StandaloneRunner.csproj
├── TestApp
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── Controls
│ │ ├── 1CV8Syntax.xshd
│ │ ├── CodeControl.xaml
│ │ ├── CodeControl.xaml.cs
│ │ ├── ImageArray.cs
│ │ ├── MDConstants.cs
│ │ ├── ProcedureListWnd.xaml
│ │ └── ProcedureListWnd.xaml.cs
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ ├── Resources
│ │ └── module_icons.png
│ ├── TestApp.csproj
│ ├── packages.config
│ └── script_badge.ico
├── oscript
│ ├── AppBehavior.cs
│ ├── BehaviorSelector.cs
│ ├── CgiBehavior.cs
│ ├── ExecuteScriptBehavior.cs
│ ├── MakeAppBehavior.cs
│ ├── MeasureBehavior.cs
│ ├── Program.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── ShowCompiledBehavior.cs
│ ├── ShowUsageBehavior.cs
│ ├── WebRequestContext.cs
│ └── oscript.csproj
└── packages
│ ├── AvalonEdit.4.4.2.9744
│ ├── AvalonEdit.4.4.2.9744.nupkg
│ ├── AvalonEdit.4.4.2.9744.nuspec
│ └── lib
│ │ ├── Net35
│ │ ├── ICSharpCode.AvalonEdit.dll
│ │ └── ICSharpCode.AvalonEdit.xml
│ │ └── Net40
│ │ ├── ICSharpCode.AvalonEdit.dll
│ │ └── ICSharpCode.AvalonEdit.xml
│ ├── DotNetZip.1.9.3
│ ├── DotNetZip.1.9.3.nupkg
│ └── lib
│ │ └── net20
│ │ └── Ionic.Zip.dll
│ └── repositories.config
└── tests
├── binarydata.os
├── engine-behaviors.os
├── example-test.os
├── file-object.os
├── formatting.os
├── global-funcs.os
├── global-new.os
├── http.os
├── process.os
├── random.os
├── readme.md
├── reflector.os
├── socket.os
├── start-all.cmd
├── start.cmd
├── sysinfo.os
├── testrunner.os
├── tests-cmd-line.os
├── text-write.os
├── types.os
├── values-test.os
├── valuetable.os
├── xmlread.os
├── xmlwrite.os
└── zip.os
/.gitignore:
--------------------------------------------------------------------------------
1 | /*.vssscc
2 | *.vspscc
3 |
4 | /src/*.vssscc
5 | /src/*.suo
6 | /src/oscript/oscript.csproj.user
7 |
8 | /src/ScriptEngine/bin/x86/Debug
9 |
10 | /src/ScriptEngine/bin/x86/Release
11 |
12 | /src/ScriptEngine/obj/Release/*.cache
13 | /src/ScriptEngine/obj/x86/Debug/*.cache
14 | /src/ScriptEngine/obj/x86/Debug
15 |
16 | /src/TestApp/bin/x86/Debug
17 |
18 | /src/ScriptEngine/obj/x86/Release
19 |
20 | /src/TestApp/bin/x86/Release
21 | /src/TestApp/obj/Release
22 |
23 | /src/TestApp/obj/x86/Debug
24 |
25 | /src/TestApp/obj/x86/Release
26 |
27 | /src/oscript/obj/Release
28 |
29 | /src/oscript/obj/Debug
30 |
31 | /src/oscript/obj/x86/Release
32 |
33 | /src/oscript/bin/x86/Release
34 |
35 | /src/oscript/obj/x86/Debug
36 |
37 | /src/ScriptEngine.StdLib/bin/x86/Release
38 |
39 | /src/ScriptEngine.StdLib/obj/Release
40 |
41 | /src/ScriptEngine.StdLib/obj/x86/Release
42 |
43 | /src/ScriptEngine.StdLib/obj/Debug/*.cache
44 | /src/*.sdf
45 | /src/Debug
46 | /src/ScriptEngine.HostedScript/bin/x86/Debug
47 | /src/ScriptEngine.HostedScript/obj/x86/Debug
48 | Debug
49 | /src/*.opensdf
50 | /src/ipch/scriptengine.snegopat-bbe5b63/scriptengine.ipch
51 | /src/ScriptEngine.Snegopat/Release/ScriptEngine.Snegopat.tlb
52 | /src/ScriptEngine.Snegopat/ScriptEngine.Snegopat.tlb
53 | /src/ScriptEngine.Snegopat/Release
54 | /src/Release
55 | /src/StandaloneRunner/obj/x86/Release
56 | /src/ScriptEngine.HostedScript/obj/x86/Release
57 | /src/ScriptEngine.HostedScript/bin/x86/Release
58 | /src/StandaloneRunner/*.dll
59 | /src/StandaloneRunner/bin/x86/Release
60 | /src/ipch/scriptengine.snegopat-724401f6/*.ipch
61 | /src/oscript/*.exe
62 | /src/ScriptEngine.Snegopat/dlldata.c
63 | /src/ScriptEngine.Snegopat/Snegopat_p.c
64 | install/build/ICSharpCode.AvalonEdit.dll
65 | install/build/ScriptEngine.HostedScript.dll
66 | install/build/ScriptEngine.Snegopat.dll
67 | install/build/ScriptEngine.dll
68 | install/build/TestApp.exe
69 | install/build/oscript.exe
70 |
71 | #Snegopat autogenerated interfaces
72 | src/ScriptEngine.Snegopat/Snegopat_h.h
73 | src/ScriptEngine.Snegopat/Snegopat_i.c
74 |
75 | #CI and full build|deploy
76 | /dist
77 | /install/build
78 | *.os.xml
79 | /src/packages/DotNetZip.1.9.3/lib/net20
80 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # README #
2 |
3 | ### Зачем нужен этот репозиторий? ###
4 |
5 | * Данное приложение является исполняющей средой для скриптов на языке 1С:Предприятие.
6 | * Позволяет писать скрипты WSH на языке 1С без наличия самой платформы.
7 | * Подробнее см. [WIKI проекта](/EvilBeaver/1script/wiki/Home/)
8 |
9 | ### Как установить и собрать? ###
10 |
11 | * Установите Visual Studio 2010-2013
12 | * Откройте файл 1Script.sln
13 | * Выполните сборку проекта
14 |
15 | ### Как поучаствовать в проекте? ###
16 |
17 | * Клонируйте репозиторий
18 | * Меняйте что хотите
19 | * Присылайте pull-request
20 |
21 | ### С кем я говорю? ###
22 |
23 | * http://habrahabr.ru/users/evilbeaver/
--------------------------------------------------------------------------------
/dist.cmd:
--------------------------------------------------------------------------------
1 | @echo Full distr and tests
2 | @echo add MSBuild 12 to your path
3 |
4 | MSBuild.exe ./BuildAll.csproj
5 | MSBuild.exe ./BuildAll.csproj /t:CreateZipForUpdateDll
6 | MSBuild.exe ./BuildAll.csproj /t:xUnitTest
--------------------------------------------------------------------------------
/install/build.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | :build
4 | echo Build started. This CMD file will be deprecated. Use MSBUILD.exe BuildAll.csproj instead
5 |
6 | call setlocals.cmd
7 |
8 | pushd %SolutionPath%
9 | %git% pull origin master
10 | popd
11 |
12 | if NOT ERRORLEVEL == 0 GOTO bad_exit
13 |
14 | call "%vsvars%vsvars32.bat"
15 | devenv "%SolutionFilename%" /Clean
16 | devenv "%SolutionFilename%" /build Release
17 |
18 | if NOT ERRORLEVEL == 0 GOTO bad_exit
19 |
20 | if exist build (
21 | erase /Q /S build\*
22 | rmdir /Q /S build)
23 | md build
24 |
25 | copy "%SolutionPath%\TestApp\bin\x86\Release\ScriptEngine.dll" build\ScriptEngine.dll
26 | copy "%SolutionPath%\TestApp\bin\x86\Release\ScriptEngine.HostedScript.dll" build\ScriptEngine.HostedScript.dll
27 | copy "%SolutionPath%\Release\ScriptEngine.Snegopat.dll" build\ScriptEngine.Snegopat.dll
28 | copy "%SolutionPath%\TestApp\bin\x86\Release\TestApp.exe" build\TestApp.exe
29 | copy "%SolutionPath%\TestApp\bin\x86\Release\ICSharpCode.AvalonEdit.dll" build\ICSharpCode.AvalonEdit.dll
30 | copy "%SolutionPath%\oscript\bin\x86\Release\oscript.exe" build\oscript.exe
31 |
32 | "%installer%" install.iss /o./dist
33 | if NOT ERRORLEVEL == 0 GOTO bad_exit
34 | echo Done
35 |
36 | exit /B 0
37 |
38 | :bad_exit
39 | echo Fail
40 |
41 | exit /B 1
--------------------------------------------------------------------------------
/install/dotNetFx40_Full_setup.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xDrivenDevelopment/1script/25f62879a041dce674b09a7b1e6d57f20633f21e/install/dotNetFx40_Full_setup.exe
--------------------------------------------------------------------------------
/install/setlocals.cmd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xDrivenDevelopment/1script/25f62879a041dce674b09a7b1e6d57f20633f21e/install/setlocals.cmd
--------------------------------------------------------------------------------
/install/vcredist_x86.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xDrivenDevelopment/1script/25f62879a041dce674b09a7b1e6d57f20633f21e/install/vcredist_x86.exe
--------------------------------------------------------------------------------
/src/GlobalAssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // Этот код создан программой.
4 | // Исполняемая версия:4.0.30319.34014
5 | //
6 | // Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
7 | // повторной генерации кода.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | [assembly: System.Reflection.AssemblyCompany("BeaverSoft")]
12 | [assembly: System.Reflection.AssemblyCopyright("Copyright (c) 2014 BeaverSoft")]
13 | [assembly: System.Reflection.AssemblyConfiguration("Commit 2a614c0")]
14 | [assembly: System.Reflection.AssemblyVersion("1.0.9.0")]
15 | [assembly: System.Reflection.AssemblyFileVersion("1.0.9.0")]
16 | [assembly: System.Reflection.AssemblyInformationalVersion("1.0.9.0")]
17 |
18 |
19 |
20 | internal sealed partial class ThisAssembly {
21 |
22 | internal const string AssemblyCompany = "BeaverSoft";
23 |
24 | internal const string AssemblyCopyright = "Copyright (c) 2014 BeaverSoft";
25 |
26 | internal const string AssemblyConfiguration = "Commit 2a614c0";
27 |
28 | internal const string AssemblyVersion = "1.0.9.0";
29 |
30 | internal const string AssemblyFileVersion = "1.0.9.0";
31 |
32 | internal const string AssemblyInformationalVersion = "1.0.9.0";
33 |
34 | private ThisAssembly() {
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/IHostApplication.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace ScriptEngine.HostedScript
7 | {
8 | public interface IHostApplication
9 | {
10 | void Echo(string str);
11 | void ShowExceptionInfo(Exception exc);
12 | bool InputString(out string result, int maxLen);
13 | string[] GetCommandLineArguments();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/BinaryDataContext.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine;
2 | using ScriptEngine.Machine.Contexts;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Text;
8 |
9 | namespace ScriptEngine.HostedScript.Library
10 | {
11 | [ContextClass("ДвоичныеДанные", "BinaryData")]
12 | public class BinaryDataContext : AutoContext, IDisposable
13 | {
14 | byte[] _buffer;
15 |
16 | public BinaryDataContext(string filename)
17 | {
18 | using(var fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
19 | {
20 | _buffer = new byte[fs.Length];
21 | fs.Read(_buffer, 0, _buffer.Length);
22 | }
23 | }
24 |
25 | public BinaryDataContext(byte[] buffer)
26 | {
27 | _buffer = buffer;
28 | }
29 |
30 | public void Dispose()
31 | {
32 | _buffer = null;
33 | }
34 |
35 | [ContextMethod("Размер","Size")]
36 | public int Size()
37 | {
38 | return _buffer.Length;
39 | }
40 |
41 | [ContextMethod("Записать","Write")]
42 | public void Write(string filename)
43 | {
44 | using(var fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
45 | {
46 | fs.Write(_buffer, 0, _buffer.Length);
47 | }
48 | }
49 |
50 | public byte[] Buffer
51 | {
52 | get
53 | {
54 | return _buffer;
55 | }
56 | }
57 |
58 | [ScriptConstructor(Name="На основании файла")]
59 | public static BinaryDataContext Constructor(IValue filename)
60 | {
61 | return new BinaryDataContext(filename.AsString());
62 | }
63 |
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/CLREnumValueWrapper.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine.Contexts;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace ScriptEngine.HostedScript.Library
8 | {
9 | class CLREnumValueWrapper : EnumerationValue
10 | {
11 | T _realValue;
12 |
13 | public CLREnumValueWrapper(EnumerationContext owner, T realValue):base(owner)
14 | {
15 | _realValue = realValue;
16 | }
17 |
18 | public T UnderlyingObject
19 | {
20 | get
21 | {
22 | return _realValue;
23 | }
24 | }
25 |
26 | public override bool Equals(Machine.IValue other)
27 | {
28 | var otherWrapper = other.GetRawValue() as CLREnumValueWrapper;
29 | if (otherWrapper == null)
30 | return false;
31 |
32 | return this.UnderlyingObject.Equals(otherWrapper.UnderlyingObject);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/GuidWrapper.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine;
2 | using ScriptEngine.Machine.Contexts;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | namespace ScriptEngine.HostedScript.Library
9 | {
10 | [ContextClass("УникальныйИдентификатор","UUID")]
11 | public class GuidWrapper : IValue
12 | {
13 | Guid _value;
14 |
15 | public GuidWrapper()
16 | {
17 | _value = Guid.NewGuid();
18 | }
19 |
20 | public GuidWrapper(string uuidString)
21 | {
22 | _value = Guid.Parse(uuidString);
23 | }
24 |
25 | [ScriptConstructor]
26 | public static GuidWrapper Create()
27 | {
28 | return new GuidWrapper();
29 | }
30 |
31 | [ScriptConstructor]
32 | public static GuidWrapper Create(IValue uuidString)
33 | {
34 | return new GuidWrapper(uuidString.AsString());
35 | }
36 |
37 | public DataType DataType
38 | {
39 | get { return Machine.DataType.GenericValue; }
40 | }
41 |
42 | public TypeDescriptor SystemType
43 | {
44 | get
45 | {
46 | return TypeManager.GetTypeByFrameworkType(typeof(GuidWrapper));
47 | }
48 | }
49 |
50 | public decimal AsNumber()
51 | {
52 | throw RuntimeException.ConvertToNumberException();
53 | }
54 |
55 | public DateTime AsDate()
56 | {
57 | throw RuntimeException.ConvertToDateException();
58 | }
59 |
60 | public bool AsBoolean()
61 | {
62 | throw RuntimeException.ConvertToBooleanException();
63 | }
64 |
65 | public string AsString()
66 | {
67 | return _value.ToString();
68 | }
69 |
70 | public IRuntimeContextInstance AsObject()
71 | {
72 | throw RuntimeException.ValueIsNotObjectException();
73 | }
74 |
75 | public IValue GetRawValue()
76 | {
77 | return this;
78 | }
79 |
80 | public int CompareTo(IValue other)
81 | {
82 | GuidWrapper otherUuid = other.GetRawValue() as GuidWrapper;
83 | if (otherUuid == null)
84 | throw RuntimeException.ComparisonNotSupportedException();
85 |
86 | return _value.CompareTo(otherUuid._value);
87 | }
88 |
89 | public bool Equals(IValue other)
90 | {
91 | GuidWrapper otherUuid = other.GetRawValue() as GuidWrapper;
92 | if (otherUuid == null)
93 | return false;
94 | else
95 | return _value.Equals(otherUuid._value);
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/Http/HttpRequestBody.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | namespace ScriptEngine.HostedScript.Library.Http
9 | {
10 | interface IHttpRequestBody : IDisposable
11 | {
12 | IValue GetAsString();
13 | IValue GetAsBinary();
14 | IValue GetAsFilename();
15 |
16 | Stream GetDataStream();
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/Http/HttpRequestBodyBinary.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine;
2 | using System;
3 |
4 | namespace ScriptEngine.HostedScript.Library.Http
5 | {
6 | class HttpRequestBodyBinary : IHttpRequestBody
7 | {
8 | BinaryDataContext _data;
9 |
10 | public HttpRequestBodyBinary(BinaryDataContext data)
11 | {
12 | _data = data;
13 | }
14 |
15 | public IValue GetAsString()
16 | {
17 | return ValueFactory.Create();
18 | }
19 |
20 | public IValue GetAsBinary()
21 | {
22 | return _data;
23 | }
24 |
25 | public IValue GetAsFilename()
26 | {
27 | return ValueFactory.Create();
28 | }
29 |
30 | public System.IO.Stream GetDataStream()
31 | {
32 | var bytes = _data.Buffer;
33 | return new System.IO.MemoryStream(bytes);
34 | }
35 |
36 | public void Dispose()
37 | {
38 | _data = null;
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/Http/HttpRequestBodyFile.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine;
2 | using System;
3 | using System.IO;
4 |
5 | namespace ScriptEngine.HostedScript.Library.Http
6 | {
7 | class HttpRequestBodyFile : IHttpRequestBody
8 | {
9 | private FileStream _bodyOpenedFile;
10 |
11 | public HttpRequestBodyFile(string filename)
12 | {
13 | _bodyOpenedFile = new FileStream(filename, FileMode.Open);
14 | }
15 |
16 | public IValue GetAsString()
17 | {
18 | return ValueFactory.Create();
19 | }
20 |
21 | public IValue GetAsBinary()
22 | {
23 | return ValueFactory.Create();
24 | }
25 |
26 | public IValue GetAsFilename()
27 | {
28 | return ValueFactory.Create(_bodyOpenedFile.Name);
29 | }
30 |
31 | public Stream GetDataStream()
32 | {
33 | return _bodyOpenedFile;
34 | }
35 |
36 | public void Dispose()
37 | {
38 | _bodyOpenedFile.Dispose();
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/Http/HttpRequestBodyString.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine;
2 | using System;
3 | using System.Text;
4 |
5 | namespace ScriptEngine.HostedScript.Library.Http
6 | {
7 | class HttpRequestBodyString : IHttpRequestBody
8 | {
9 | string _data;
10 | Encoding _encoding;
11 |
12 | public HttpRequestBodyString(string body, IValue encoding = null)
13 | {
14 | _data = body;
15 | if (encoding == null)
16 | _encoding = new UTF8Encoding(true);
17 | else
18 | _encoding = TextEncodingEnum.GetEncoding(encoding);
19 | }
20 |
21 | public IValue GetAsString()
22 | {
23 | return ValueFactory.Create(_data);
24 | }
25 |
26 | public IValue GetAsBinary()
27 | {
28 | return ValueFactory.Create();
29 | }
30 |
31 | public IValue GetAsFilename()
32 | {
33 | return ValueFactory.Create();
34 | }
35 |
36 | public System.IO.Stream GetDataStream()
37 | {
38 | var bytes = _encoding.GetBytes(_data);
39 | return new System.IO.MemoryStream(bytes);
40 | }
41 |
42 | public void Dispose()
43 | {
44 | _data = null;
45 | _encoding = null;
46 | }
47 | }
48 | }
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/Http/HttpRequestBodyUnknown.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine;
2 |
3 | namespace ScriptEngine.HostedScript.Library.Http
4 | {
5 | class HttpRequestBodyUnknown : IHttpRequestBody
6 | {
7 |
8 | public IValue GetAsString()
9 | {
10 | return ValueFactory.Create();
11 | }
12 |
13 | public IValue GetAsBinary()
14 | {
15 | return ValueFactory.Create();
16 | }
17 |
18 | public IValue GetAsFilename()
19 | {
20 | return ValueFactory.Create();
21 | }
22 |
23 | public void Dispose()
24 | {
25 | ;
26 | }
27 |
28 | public System.IO.Stream GetDataStream()
29 | {
30 | return null;
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/KeyAndValueImpl.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine;
2 | using ScriptEngine.Machine.Contexts;
3 |
4 | namespace ScriptEngine.HostedScript.Library
5 | {
6 | [ContextClass("КлючИЗначение", "KeyAndValue")]
7 | public class KeyAndValueImpl : AutoContext
8 | {
9 | private IValue _key;
10 | private IValue _value;
11 |
12 | public KeyAndValueImpl(IValue key, IValue value)
13 | {
14 | _key = key;
15 | _value = value;
16 | }
17 |
18 | [ContextProperty("Ключ", "Key")]
19 | public IValue Key
20 | {
21 | get
22 | {
23 | return _key;
24 | }
25 | }
26 |
27 | [ContextProperty("Значение", "Value")]
28 | public IValue Value
29 | {
30 | get
31 | {
32 | return _value;
33 | }
34 | }
35 |
36 | public override IValue GetPropValue(int propNum)
37 | {
38 | return propNum == 0 ? _key : _value;
39 | }
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/MapImpl.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using ScriptEngine.Machine;
3 | using ScriptEngine.Machine.Contexts;
4 |
5 | namespace ScriptEngine.HostedScript.Library
6 | {
7 | [ContextClass("Соответствие", "Map")]
8 | public class MapImpl : AutoContext, ICollectionContext
9 | {
10 | private Dictionary _content = new Dictionary(new GenericIValueComparer());
11 |
12 | public override bool IsIndexed
13 | {
14 | get
15 | {
16 | return true;
17 | }
18 | }
19 |
20 | public override IValue GetIndexedValue(IValue index)
21 | {
22 | IValue result;
23 | if (!_content.TryGetValue(index, out result))
24 | {
25 | result = ValueFactory.Create();
26 | _content.Add(index, result);
27 | }
28 |
29 | return result;
30 | }
31 |
32 | public override void SetIndexedValue(IValue index, IValue val)
33 | {
34 | _content[index] = val;
35 | }
36 |
37 | public override bool IsPropReadable(int propNum)
38 | {
39 | return false;
40 | }
41 |
42 | public override bool IsPropWritable(int propNum)
43 | {
44 | return false;
45 | }
46 |
47 | #region ICollectionContext Members
48 |
49 | [ContextMethod("Вставить", "Insert")]
50 | public void Insert(IValue key, IValue val)
51 | {
52 | SetIndexedValue(key, val);
53 | }
54 |
55 | [ContextMethod("Получить", "Get")]
56 | public IValue Retrieve(IValue key)
57 | {
58 | return GetIndexedValue(key);
59 | }
60 |
61 | [ContextMethod("Количество", "Count")]
62 | public int Count()
63 | {
64 | return _content.Count;
65 | }
66 |
67 | [ContextMethod("Очистить", "Clear")]
68 | public void Clear()
69 | {
70 | _content.Clear();
71 | }
72 |
73 | [ContextMethod("Удалить", "Delete")]
74 | public void Delete(IValue key)
75 | {
76 | _content.Remove(key);
77 | }
78 |
79 | public CollectionEnumerator GetManagedIterator()
80 | {
81 | return new CollectionEnumerator(GetEnumerator());
82 | }
83 |
84 | #endregion
85 |
86 | #region IEnumerable Members
87 |
88 | public IEnumerator GetEnumerator()
89 | {
90 | foreach (var item in _content)
91 | {
92 | yield return new KeyAndValueImpl(item.Key, item.Value);
93 | }
94 | }
95 |
96 | #endregion
97 |
98 | #region IEnumerable Members
99 |
100 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
101 | {
102 | return GetEnumerator();
103 | }
104 |
105 | #endregion
106 |
107 | [ScriptConstructor]
108 | public static MapImpl Constructor()
109 | {
110 | return new MapImpl();
111 | }
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/MiscGlobalFunctions.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine.Contexts;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace ScriptEngine.HostedScript.Library
8 | {
9 | [GlobalContext(Category="Прочие функции")]
10 | public class MiscGlobalFunctions : GlobalContextBase
11 | {
12 | [ContextMethod("Base64Строка", "Base64String")]
13 | public string Base64String(BinaryDataContext data)
14 | {
15 | return Convert.ToBase64String(data.Buffer);
16 | }
17 |
18 | [ContextMethod("Base64Значение", "Base64Value")]
19 | public BinaryDataContext Base64String(string data)
20 | {
21 | byte[] bytes = Convert.FromBase64String(data);
22 | return new BinaryDataContext(bytes);
23 | }
24 |
25 | public static MiscGlobalFunctions CreateInstance()
26 | {
27 | return new MiscGlobalFunctions();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/Net/TCPServer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Net;
5 | using System.Net.Sockets;
6 | using System.Text;
7 | using ScriptEngine.Machine;
8 | using ScriptEngine.Machine.Contexts;
9 |
10 | namespace ScriptEngine.HostedScript.Library.Net
11 | {
12 | [ContextClass("TCPСервер", "TCPServer")]
13 | public class TCPServer : AutoContext
14 | {
15 | private TcpListener _listener;
16 |
17 | public TCPServer(int port)
18 | {
19 | _listener = new TcpListener(IPAddress.Any, port);
20 | }
21 |
22 | [ContextMethod("Запустить", "Start")]
23 | public void Start()
24 | {
25 | _listener.Start();
26 | }
27 |
28 | [ContextMethod("Остановить", "Stop")]
29 | public void Stop()
30 | {
31 | _listener.Stop();
32 | }
33 |
34 | [ContextMethod("ОжидатьСоединения","WaitForConnection")]
35 | public TCPClient WaitForConnection()
36 | {
37 | var client = _listener.AcceptTcpClient();
38 | return new TCPClient(client);
39 | }
40 |
41 | [ScriptConstructor]
42 | public static TCPServer ConstructByPort(IValue port)
43 | {
44 | return new TCPServer((int)port.AsNumber());
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/RandomNumberGenerator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using ScriptEngine.Machine;
3 | using ScriptEngine.Machine.Contexts;
4 |
5 | namespace ScriptEngine.HostedScript.Library
6 | {
7 | [ContextClass("ГенераторСлучайныхЧисел", "RandomNumberGenerator")]
8 | class RandomNumberGenerator : AutoContext
9 | {
10 | private Random _random;
11 |
12 | public RandomNumberGenerator(int seed = 0)
13 | {
14 | if (seed == 0)
15 | _random = new Random();
16 | else
17 | _random = new Random(seed);
18 | }
19 |
20 | [ContextMethod("СлучайноеЧисло", "RandomNumber")]
21 | public IValue RandomNumber(IValue low = null, IValue high = null)
22 | {
23 | long lo64 = 0, hi64 = UInt32.MaxValue;
24 |
25 | if (low != null)
26 | lo64 = decimal.ToInt64(low.AsNumber());
27 |
28 | if (high != null)
29 | hi64 = decimal.ToInt64(high.AsNumber());
30 |
31 | if (lo64 < 0 || lo64 > 4294967295)
32 | throw RuntimeException.InvalidArgumentValue();
33 |
34 | if (hi64 < 0 || hi64 > 4294967295)
35 | throw RuntimeException.InvalidArgumentValue();
36 |
37 | if (hi64 < lo64)
38 | throw RuntimeException.InvalidArgumentValue();
39 |
40 | // Приводим к рабочему диапазону
41 | lo64 += Int32.MinValue;
42 | hi64 += Int32.MinValue;
43 |
44 | int lo = (int)lo64, hi = (int)hi64;
45 |
46 | int v = _random.Next(lo, hi);
47 | long v64 = v;
48 | v64 -= Int32.MinValue;
49 |
50 | return ValueFactory.Create( v64 );
51 | }
52 |
53 | ///
54 | /// Формирует ГСЧ с возможностью указания начального числа.
55 | ///
56 | /// Начальное число. Последовательность случайных чисел для одного и того же начального числа будет одинакова
57 | ///
58 | [ScriptConstructor]
59 | public static IRuntimeContextInstance Constructor(IValue seed)
60 | {
61 | seed = seed.GetRawValue();
62 | if (seed.DataType == DataType.Number)
63 | return new RandomNumberGenerator(decimal.ToInt32(seed.AsNumber()));
64 |
65 | return new RandomNumberGenerator();
66 | }
67 |
68 | [ScriptConstructor(Name="Формирование неинициализированного объекта")]
69 | public static IRuntimeContextInstance Constructor()
70 | {
71 | return new RandomNumberGenerator();
72 | }
73 |
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/Reflector.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using ScriptEngine.Machine;
3 | using ScriptEngine.Machine.Contexts;
4 |
5 | namespace ScriptEngine.HostedScript.Library
6 | {
7 | ///
8 | /// Рефлектор предназначен для получения метаданных объектов во время выполнения.
9 | /// Как правило, рефлексия используется для проверки наличия у объекта определенных свойств/методов.
10 | /// В OneScript рефлексию можно применять для вызова методов объектов по именам методов.
11 | ///
12 | [ContextClass("Рефлектор","Reflector")]
13 | public class ReflectorContext : AutoContext
14 | {
15 | public ReflectorContext()
16 | {
17 |
18 | }
19 |
20 | ///
21 | /// Вызывает метод по его имени.
22 | ///
23 | /// Объект, метод которого нужно вызвать.
24 | /// Имя метода для вызова
25 | /// Массив аргументов, передаваемых методу
26 | /// Если вызывается функция, то возвращается ее результат. В противном случае возвращается Неопределено.
27 | [ContextMethod("ВызватьМетод", "CallMethod")]
28 | public IValue CallMethod(IRuntimeContextInstance target, string methodName, IRuntimeContextInstance arguments = null)
29 | {
30 | ArrayImpl argArray;
31 | if (arguments != null)
32 | {
33 | argArray = arguments as ArrayImpl;
34 | if (argArray == null)
35 | throw RuntimeException.InvalidArgumentType();
36 | }
37 | else
38 | {
39 | argArray = new ArrayImpl();
40 | }
41 |
42 | var methodIdx = target.FindMethod(methodName);
43 |
44 | var methInfo = target.GetMethodInfo(methodIdx);
45 | IValue retValue = ValueFactory.Create();
46 | if (methInfo.IsFunction)
47 | {
48 | target.CallAsFunction(methodIdx, argArray.ToArray(), out retValue);
49 | }
50 | else
51 | {
52 | target.CallAsProcedure(methodIdx, argArray.ToArray());
53 | }
54 |
55 | return retValue;
56 | }
57 |
58 | [ScriptConstructor]
59 | public static IRuntimeContextInstance CreateNew()
60 | {
61 | return new ReflectorContext();
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/StdTextReadStream.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine;
2 | using ScriptEngine.Machine.Contexts;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Text;
8 |
9 | namespace ScriptEngine.HostedScript.Library
10 | {
11 | [ContextClass("ПотокВыводаТекста","TextOutputStream")]
12 | public class StdTextReadStream : AutoContext, IDisposable
13 | {
14 | private StreamReader _reader;
15 |
16 | public StdTextReadStream(StreamReader source)
17 | {
18 | _reader = source;
19 | }
20 |
21 | [ContextProperty("ЕстьДанные", "HasData")]
22 | public bool HasData
23 | {
24 | get
25 | {
26 | return !_reader.EndOfStream;
27 | }
28 | }
29 |
30 | [ContextMethod("Прочитать", "Read")]
31 | public string Read()
32 | {
33 | return _reader.ReadToEnd();
34 | }
35 |
36 | [ContextMethod("ПрочитатьСтроку", "ReadLine")]
37 | public string ReadLine()
38 | {
39 | return _reader.ReadLine();
40 | }
41 |
42 | [ContextMethod("Закрыть", "Close")]
43 | public void Close()
44 | {
45 | _reader.Close();
46 | }
47 |
48 | public void Dispose()
49 | {
50 | _reader.Dispose();
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/StdTextWriteStream.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine;
2 | using ScriptEngine.Machine.Contexts;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Text;
8 |
9 | namespace ScriptEngine.HostedScript.Library
10 | {
11 | [ContextClass("ПотокВводаТекста", "TextInputStream")]
12 | public class StdTextWriteStream : AutoContext, IDisposable
13 | {
14 | private StreamWriter _writer;
15 |
16 | public StdTextWriteStream(StreamWriter writer)
17 | {
18 | _writer = writer;
19 | }
20 |
21 | [ContextMethod("Записать","Write")]
22 | public void Write(string data)
23 | {
24 | _writer.Write(data);
25 | }
26 |
27 | [ContextMethod("ЗаписатьСтроку", "WriteLine")]
28 | public void WriteLine(string data)
29 | {
30 | _writer.WriteLine(data);
31 | }
32 |
33 | [ContextMethod("Закрыть", "Close")]
34 | public void Close()
35 | {
36 | _writer.Close();
37 | }
38 |
39 | public void Dispose()
40 | {
41 | _writer.Dispose();
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/SymbolsEnum.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine;
2 | using ScriptEngine.Machine.Contexts;
3 |
4 | namespace ScriptEngine.HostedScript.Library
5 | {
6 |
7 | [SystemEnum("Символы", "Symbols")]
8 | public class SymbolsEnum : EnumerationContext
9 | {
10 | private SymbolsEnum(TypeDescriptor typeRepresentation, TypeDescriptor valuesType)
11 | :base(typeRepresentation, valuesType)
12 | {
13 |
14 | }
15 |
16 | class SymbolsEnumValue : EnumerationValue
17 | {
18 | string _val;
19 |
20 | public SymbolsEnumValue(EnumerationContext owner, string val)
21 | : base(owner)
22 | {
23 | _val = val;
24 | }
25 |
26 | public override string AsString()
27 | {
28 | return _val;
29 | }
30 |
31 | public override DataType DataType
32 | {
33 | get
34 | {
35 | return DataType.String;
36 | }
37 | }
38 |
39 | public override TypeDescriptor SystemType
40 | {
41 | get
42 | {
43 | return TypeDescriptor.FromDataType(DataType);
44 | }
45 | }
46 |
47 | public override int CompareTo(IValue other)
48 | {
49 | return _val.CompareTo(other.AsString());
50 | }
51 |
52 | public override bool Equals(IValue other)
53 | {
54 | return _val == other.AsString();
55 | }
56 | }
57 |
58 | public static SymbolsEnum CreateInstance()
59 | {
60 |
61 | var type = TypeManager.RegisterType("Символы", typeof(SymbolsEnum));
62 | var stringType = TypeDescriptor.FromDataType(DataType.String);
63 | var instance = new SymbolsEnum(type, stringType);
64 |
65 | instance.AddValue("ПС", new SymbolsEnumValue(instance, "\n"));
66 | instance.AddValue("ВК", new SymbolsEnumValue(instance, "\r"));
67 | instance.AddValue("ВТаб", new SymbolsEnumValue(instance, "\v"));
68 | instance.AddValue("Таб", new SymbolsEnumValue(instance, "\t"));
69 | instance.AddValue("ПФ", new SymbolsEnumValue(instance, "\f"));
70 | instance.AddValue("НПП", new SymbolsEnumValue(instance, "\u00A0"));
71 |
72 | return instance;
73 | }
74 |
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/TextReadImpl.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Text;
4 | using ScriptEngine.Machine;
5 | using ScriptEngine.Machine.Contexts;
6 |
7 | namespace ScriptEngine.HostedScript.Library
8 | {
9 | [ContextClass("ЧтениеТекста", "TextReader")]
10 | class TextReadImpl : AutoContext, IDisposable
11 | {
12 | StreamReader _reader;
13 |
14 | [ContextMethod("Открыть", "Open")]
15 | public void Open(string path, IValue encoding = null)
16 | {
17 | if (encoding == null)
18 | {
19 | _reader = Environment.FileOpener.OpenReader(path);
20 | }
21 | else
22 | {
23 | var enc = TextEncodingEnum.GetEncoding(encoding);
24 | _reader = Environment.FileOpener.OpenReader(path, enc);
25 | }
26 | }
27 |
28 | [ContextMethod("Прочитать", "Read")]
29 | public IValue ReadAll()
30 | {
31 | RequireOpen();
32 | if (_reader.EndOfStream)
33 | return ValueFactory.Create();
34 |
35 | return ValueFactory.Create(_reader.ReadToEnd());
36 | }
37 |
38 | [ContextMethod("ПрочитатьСтроку", "ReadLine")]
39 | public IValue ReadLine()
40 | {
41 | RequireOpen();
42 | if (_reader.EndOfStream)
43 | return ValueFactory.Create();
44 |
45 | return ValueFactory.Create(_reader.ReadLine());
46 | }
47 |
48 | [ContextMethod("Закрыть", "Close")]
49 | public void Close()
50 | {
51 | Dispose();
52 | }
53 |
54 | private void RequireOpen()
55 | {
56 | if (_reader == null)
57 | {
58 | throw new RuntimeException("Файл не открыт");
59 | }
60 | }
61 |
62 | [ScriptConstructor(Name="По имени файла и кодировке")]
63 | public static IRuntimeContextInstance Constructor(IValue path, IValue encoding)
64 | {
65 | var reader = new TextReadImpl();
66 | reader.Open(path.AsString(), encoding);
67 | return reader;
68 | }
69 |
70 | [ScriptConstructor(Name = "По имени файла")]
71 | public static IRuntimeContextInstance Constructor(IValue path)
72 | {
73 | var reader = new TextReadImpl();
74 | reader.Open(path.AsString(), null);
75 | return reader;
76 | }
77 |
78 | [ScriptConstructor]
79 | public static IRuntimeContextInstance Constructor()
80 | {
81 | var reader = new TextReadImpl();
82 | return reader;
83 | }
84 |
85 | #region IDisposable Members
86 |
87 | public void Dispose()
88 | {
89 | if (_reader != null)
90 | {
91 | _reader.Dispose();
92 | _reader = null;
93 | }
94 | }
95 |
96 | #endregion
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/ValueTable/CollectionIndexes.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using ScriptEngine.Machine.Contexts;
6 | using ScriptEngine.Machine;
7 |
8 | namespace ScriptEngine.HostedScript.Library.ValueTable
9 | {
10 | [ContextClass("ИндексыКоллекции", "CollectionIndexes")]
11 | class CollectionIndexes : AutoContext, ICollectionContext
12 | {
13 |
14 | List _indexes = new List();
15 |
16 | [ContextMethod("Добавить", "Add")]
17 | public CollectionIndex Add(string columns)
18 | {
19 | CollectionIndex newIndex = new CollectionIndex();
20 | _indexes.Add(newIndex);
21 | return newIndex;
22 | }
23 |
24 | [ContextMethod("Количество", "Count")]
25 | public int Count()
26 | {
27 | return _indexes.Count();
28 | }
29 |
30 | [ContextMethod("Удалить", "Delete")]
31 | public void Delete(IValue Index)
32 | {
33 | Index = Index.GetRawValue();
34 | if (Index is CollectionIndex)
35 | _indexes.Remove(Index as CollectionIndex);
36 | else
37 | _indexes.RemoveAt(Decimal.ToInt32(Index.AsNumber()));
38 | }
39 |
40 | [ContextMethod("Очистить", "Clear")]
41 | public void Clear()
42 | {
43 | _indexes.Clear();
44 | }
45 |
46 | public IEnumerator GetEnumerator()
47 | {
48 | foreach (var item in _indexes)
49 | {
50 | yield return item;
51 | }
52 | }
53 |
54 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
55 | {
56 | return GetEnumerator();
57 | }
58 |
59 | public CollectionEnumerator GetManagedIterator()
60 | {
61 | return new CollectionEnumerator(GetEnumerator());
62 | }
63 |
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/ValueTable/ValueTableColumn.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using ScriptEngine.Machine.Contexts;
6 | using ScriptEngine.Machine;
7 |
8 |
9 | namespace ScriptEngine.HostedScript.Library.ValueTable
10 | {
11 | [ContextClass("КолонкаТаблицыЗначений", "ValueTableColumn")]
12 | class ValueTableColumn : AutoContext
13 | {
14 | private string _title;
15 | private string _name;
16 | private IValue _valueType;
17 | private int _width;
18 | private WeakReference _owner;
19 |
20 | // id нужен для правильной работы функции FindProperty.
21 | // Порядковый номер колонки не может быть использовать из-за своей изменчивости.
22 | private int _id;
23 |
24 | public ValueTableColumn(ValueTableColumnCollection Owner, int id, string Name, string Title, IValue Type, int Width)
25 | {
26 | _name = Name;
27 | _title = Title;
28 | _valueType = Type;
29 | _width = Width;
30 |
31 | _owner = new WeakReference(Owner);
32 | _id = id;
33 |
34 | }
35 |
36 | public int ID
37 | {
38 | get { return _id; }
39 | }
40 |
41 | [ContextProperty("Заголовок", "Title")]
42 | public string Title
43 | {
44 | get { return _title == null ? _name : _title; }
45 | set { _title = value; }
46 | }
47 |
48 | [ContextProperty("Имя", "Name")]
49 | public string Name
50 | {
51 | get { return _name; }
52 | set
53 | {
54 | ValueTableColumnCollection Owner = _owner.Target as ValueTableColumnCollection;
55 | if (Owner.FindColumnByName(value) != null)
56 | throw new RuntimeException("Неверное имя колонки!");
57 |
58 | if (_title == _name)
59 | _title = value;
60 |
61 | _name = value;
62 |
63 | }
64 | }
65 | [ContextProperty("ТипЗначения", "ValueType")]
66 | public IValue ValueType
67 | {
68 | get { return _valueType; }
69 | set { _valueType = value; } // TODO: Проверить тип
70 | }
71 | [ContextProperty("Ширина", "Width")]
72 | public int Width
73 | {
74 | get { return Width; }
75 | set { _width = value; } // TOOD: Проверить неотрицательность значения
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/ValueTable/ValueTableIndex.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using ScriptEngine.Machine.Contexts;
6 | using ScriptEngine.Machine;
7 |
8 | namespace ScriptEngine.HostedScript.Library.ValueTable
9 | {
10 | [ContextClass("ИндексКоллекции", "CollectionIndex")]
11 | class CollectionIndex : AutoContext
12 | {
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/Xml/XmlGlobalFunctions.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine;
2 | using ScriptEngine.Machine.Contexts;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Xml;
8 |
9 | namespace ScriptEngine.HostedScript.Library.Xml
10 | {
11 | [GlobalContext(Category="Функции работы с XML")]
12 | public class XmlGlobalFunctions : GlobalContextBase
13 | {
14 | [ContextMethod("XMLСтрока", "XMLString")]
15 | public string XMLString(IValue value)
16 | {
17 | switch(value.DataType)
18 | {
19 | case DataType.Undefined:
20 | return "";
21 | case DataType.Boolean:
22 | return XmlConvert.ToString(value.AsBoolean());
23 | case DataType.Date:
24 | return XmlConvert.ToString(value.AsDate(), XmlDateTimeSerializationMode.Unspecified);
25 | case DataType.Number:
26 | return XmlConvert.ToString(value.AsNumber());
27 | default:
28 |
29 | if(value.SystemType.Equals(TypeManager.GetTypeByFrameworkType(typeof(BinaryDataContext))))
30 | {
31 | var bdc = value.GetRawValue() as BinaryDataContext;
32 | System.Diagnostics.Debug.Assert(bdc != null);
33 |
34 | return Convert.ToBase64String(bdc.Buffer, Base64FormattingOptions.InsertLineBreaks);
35 | }
36 | else
37 | {
38 | return value.GetRawValue().AsString();
39 | }
40 |
41 | }
42 | }
43 |
44 | [ContextMethod("XMLЗначение", "XMLValue")]
45 | public IValue XMLValue(IValue givenType, string presentation)
46 | {
47 | var typeValue = TypeManager.GetTypeDescriptorFor(givenType.GetRawValue());
48 |
49 | if(typeValue.Equals(TypeDescriptor.FromDataType(DataType.Boolean)))
50 | {
51 | return ValueFactory.Create(XmlConvert.ToBoolean(presentation));
52 | }
53 | else if (typeValue.Equals(TypeDescriptor.FromDataType(DataType.Date)))
54 | {
55 | return ValueFactory.Create(XmlConvert.ToDateTime(presentation, XmlDateTimeSerializationMode.Unspecified));
56 | }
57 | else if (typeValue.Equals(TypeDescriptor.FromDataType(DataType.Number)))
58 | {
59 | return ValueFactory.Create(XmlConvert.ToDecimal(presentation));
60 | }
61 | else if (typeValue.Equals(TypeDescriptor.FromDataType(DataType.String)))
62 | {
63 | return ValueFactory.Create(presentation);
64 | }
65 | else if (typeValue.Equals(TypeDescriptor.FromDataType(DataType.Undefined)) && presentation == "")
66 | {
67 | return ValueFactory.Create();
68 | }
69 | else
70 | {
71 | throw RuntimeException.InvalidArgumentValue();
72 | }
73 |
74 | }
75 |
76 | public static IAttachableContext CreateInstance()
77 | {
78 | return new XmlGlobalFunctions();
79 | }
80 |
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/Zip/ZIPSubDirProcessingModeEnum.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine;
2 | using ScriptEngine.Machine.Contexts;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | namespace ScriptEngine.HostedScript.Library.Zip
9 | {
10 | [SystemEnum("РежимОбработкиПодкаталоговZIP", "ZIPSubDirProcessingMode")]
11 | public class ZIPSubDirProcessingModeEnum : EnumerationContext
12 | {
13 | private const string EV_DONT_RECURSE = "НеОбрабатывать";
14 | private const string EV_RECURSE = "ОбрабатыватьРекурсивно";
15 |
16 | private ZIPSubDirProcessingModeEnum(TypeDescriptor typeRepresentation, TypeDescriptor valuesType)
17 | : base(typeRepresentation, valuesType)
18 | {
19 | }
20 |
21 | [EnumValue(EV_DONT_RECURSE)]
22 | public EnumerationValue DontRecurse
23 | {
24 | get
25 | {
26 | return this[EV_DONT_RECURSE];
27 | }
28 | }
29 |
30 | [EnumValue(EV_RECURSE)]
31 | public EnumerationValue Recurse
32 | {
33 | get
34 | {
35 | return this[EV_RECURSE];
36 | }
37 | }
38 |
39 | public static ZIPSubDirProcessingModeEnum CreateInstance()
40 | {
41 | ZIPSubDirProcessingModeEnum instance;
42 |
43 | TypeDescriptor enumType;
44 | TypeDescriptor enumValType;
45 |
46 | EnumContextHelper.RegisterEnumType(out enumType, out enumValType);
47 |
48 | instance = new ZIPSubDirProcessingModeEnum(enumType, enumValType);
49 |
50 | EnumContextHelper.RegisterValues(instance);
51 |
52 | return instance;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/Zip/ZipCompressionLevelEnum.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine;
2 | using ScriptEngine.Machine.Contexts;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | namespace ScriptEngine.HostedScript.Library.Zip
9 | {
10 | [SystemEnum("УровеньСжатияZIP", "ZIPCompressionLevel")]
11 | public class ZipCompressionLevelEnum : EnumerationContext
12 | {
13 | private const string EV_MINIMAL_NAME = "Минимальный";
14 | private const string EV_OPTIMAL_NAME = "Оптимальный";
15 | private const string EV_MAXIMAL_NAME = "Максимальный";
16 |
17 | private ZipCompressionLevelEnum(TypeDescriptor typeRepresentation, TypeDescriptor valuesType)
18 | : base(typeRepresentation, valuesType)
19 | {
20 | }
21 |
22 | [EnumValue(EV_MINIMAL_NAME)]
23 | public EnumerationValue Minimal
24 | {
25 | get
26 | {
27 | return this[EV_MINIMAL_NAME];
28 | }
29 | }
30 |
31 | [EnumValue(EV_OPTIMAL_NAME)]
32 | public EnumerationValue Optimal
33 | {
34 | get
35 | {
36 | return this[EV_OPTIMAL_NAME];
37 | }
38 | }
39 |
40 | [EnumValue(EV_MAXIMAL_NAME)]
41 | public EnumerationValue Maximal
42 | {
43 | get
44 | {
45 | return this[EV_MAXIMAL_NAME];
46 | }
47 | }
48 |
49 | public static ZipCompressionLevelEnum CreateInstance()
50 | {
51 | ZipCompressionLevelEnum instance;
52 |
53 | TypeDescriptor enumType;
54 | TypeDescriptor enumValType;
55 |
56 | EnumContextHelper.RegisterEnumType(out enumType, out enumValType);
57 |
58 | instance = new ZipCompressionLevelEnum(enumType, enumValType);
59 |
60 | EnumContextHelper.RegisterValues(instance);
61 |
62 | return instance;
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/Zip/ZipCompressionMethodEnum.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine;
2 | using ScriptEngine.Machine.Contexts;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | namespace ScriptEngine.HostedScript.Library.Zip
9 | {
10 | [SystemEnum("МетодСжатияZIP", "ZIPCompressionMethod")]
11 | public class ZipCompressionMethodEnum : EnumerationContext
12 | {
13 | private const string EV_COPY_NAME = "Копирование";
14 | private const string EV_DEFLATE_NAME = "Сжатие";
15 |
16 | private ZipCompressionMethodEnum(TypeDescriptor typeRepresentation, TypeDescriptor valuesType)
17 | : base(typeRepresentation, valuesType)
18 | {
19 | }
20 |
21 | [EnumValue(EV_COPY_NAME)]
22 | public EnumerationValue Copy
23 | {
24 | get
25 | {
26 | return this[EV_COPY_NAME];
27 | }
28 | }
29 |
30 | [EnumValue(EV_DEFLATE_NAME)]
31 | public EnumerationValue Deflate
32 | {
33 | get
34 | {
35 | return this[EV_DEFLATE_NAME];
36 | }
37 | }
38 |
39 | public static ZipCompressionMethodEnum CreateInstance()
40 | {
41 | ZipCompressionMethodEnum instance;
42 |
43 | TypeDescriptor enumType;
44 | TypeDescriptor enumValType;
45 |
46 | EnumContextHelper.RegisterEnumType(out enumType, out enumValType);
47 |
48 | instance = new ZipCompressionMethodEnum(enumType, enumValType);
49 |
50 | EnumContextHelper.RegisterValues(instance);
51 |
52 | return instance;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/Zip/ZipEncryptionMethodEnum.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine;
2 | using ScriptEngine.Machine.Contexts;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | namespace ScriptEngine.HostedScript.Library.Zip
9 | {
10 | [SystemEnum("МетодШифрованияZIP", "ZIPEncryptionMethod")]
11 | public class ZipEncryptionMethodEnum : EnumerationContext
12 | {
13 | private const string EV_AES128 = "AES128";
14 | private const string EV_AES192 = "AES192";
15 | private const string EV_AES256 = "AES256";
16 | private const string EV_ZIP20 = "Zip20";
17 |
18 | private ZipEncryptionMethodEnum(TypeDescriptor typeRepresentation, TypeDescriptor valuesType)
19 | : base(typeRepresentation, valuesType)
20 | {
21 | }
22 |
23 | [EnumValue(EV_AES128)]
24 | public EnumerationValue Aes128
25 | {
26 | get
27 | {
28 | return this[EV_AES128];
29 | }
30 | }
31 |
32 | [EnumValue(EV_AES192)]
33 | public EnumerationValue Aes192
34 | {
35 | get
36 | {
37 | return this[EV_AES192];
38 | }
39 | }
40 |
41 | [EnumValue(EV_AES256)]
42 | public EnumerationValue Aes256
43 | {
44 | get
45 | {
46 | return this[EV_AES256];
47 | }
48 | }
49 |
50 | [EnumValue(EV_ZIP20)]
51 | public EnumerationValue Zip20
52 | {
53 | get
54 | {
55 | return this[EV_ZIP20];
56 | }
57 | }
58 |
59 | public static ZipEncryptionMethodEnum CreateInstance()
60 | {
61 | ZipEncryptionMethodEnum instance;
62 |
63 | TypeDescriptor enumType;
64 | TypeDescriptor enumValType;
65 |
66 | EnumContextHelper.RegisterEnumType(out enumType, out enumValType);
67 |
68 | instance = new ZipEncryptionMethodEnum(enumType, enumValType);
69 |
70 | EnumContextHelper.RegisterValues(instance);
71 |
72 | return instance;
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/Zip/ZipFileEntriesCollection.cs:
--------------------------------------------------------------------------------
1 | using Ionic.Zip;
2 | using ScriptEngine.Machine;
3 | using ScriptEngine.Machine.Contexts;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 |
9 | namespace ScriptEngine.HostedScript.Library.Zip
10 | {
11 | [ContextClass("ЭлементыZipФайла", "ZipFileEntries")]
12 | public class ZipFileEntriesCollection : AutoContext, ICollectionContext
13 | {
14 | List _entries;
15 |
16 | public ZipFileEntriesCollection(IEnumerable entries)
17 | {
18 | _entries = entries.Select(x => new ZipFileEntryContext(x)).ToList();
19 | }
20 |
21 | [ContextMethod("Количество", "Count")]
22 | public int Count()
23 | {
24 | return _entries.Count;
25 | }
26 |
27 | [ContextMethod("Получить", "Get")]
28 | public IValue Get(IValue index)
29 | {
30 | return GetIndexedValue(index);
31 | }
32 |
33 | [ContextMethod("Найти", "Find")]
34 | public IValue Find(string name)
35 | {
36 | var entry = _entries.FirstOrDefault(x => System.IO.Path.GetFileName(x.GetZipEntry().FileName) == name);
37 |
38 | if (entry == null)
39 | return ValueFactory.Create();
40 |
41 | return entry;
42 | }
43 |
44 | public override bool IsIndexed
45 | {
46 | get
47 | {
48 | return true;
49 | }
50 | }
51 |
52 | public override IValue GetIndexedValue(IValue index)
53 | {
54 | int idx = (int)index.AsNumber();
55 | return _entries[idx];
56 | }
57 |
58 | public CollectionEnumerator GetManagedIterator()
59 | {
60 | return new CollectionEnumerator(GetEnumerator());
61 | }
62 |
63 | public IEnumerator GetEnumerator()
64 | {
65 | return _entries.GetEnumerator();
66 | }
67 |
68 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
69 | {
70 | return GetEnumerator();
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/Zip/ZipRestoreFilePathsModeEnum.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine;
2 | using ScriptEngine.Machine.Contexts;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | namespace ScriptEngine.HostedScript.Library.Zip
9 | {
10 | [SystemEnum("РежимВосстановленияПутейФайловZIP", "ZIPRestoreFilePathsMode")]
11 | public class ZipRestoreFilePathsModeEnum : EnumerationContext
12 | {
13 | private const string RESTORE_PATHS_NAME = "Восстанавливать";
14 | private const string DONT_RESTORE_PATHS_NAME = "НеВосстанавливать";
15 |
16 | private ZipRestoreFilePathsModeEnum(TypeDescriptor typeRepresentation, TypeDescriptor valuesType)
17 | : base(typeRepresentation, valuesType)
18 | {
19 | }
20 |
21 | [EnumValue(RESTORE_PATHS_NAME)]
22 | public EnumerationValue Restore
23 | {
24 | get
25 | {
26 | return this[RESTORE_PATHS_NAME];
27 | }
28 | }
29 |
30 | [EnumValue(DONT_RESTORE_PATHS_NAME)]
31 | public EnumerationValue DoNotRestore
32 | {
33 | get
34 | {
35 | return this[DONT_RESTORE_PATHS_NAME];
36 | }
37 | }
38 |
39 | public static ZipRestoreFilePathsModeEnum CreateInstance()
40 | {
41 | ZipRestoreFilePathsModeEnum instance;
42 |
43 | TypeDescriptor enumType;
44 | TypeDescriptor enumValType;
45 |
46 | EnumContextHelper.RegisterEnumType(out enumType, out enumValType);
47 |
48 | instance = new ZipRestoreFilePathsModeEnum(enumType, enumValType);
49 |
50 | EnumContextHelper.RegisterValues(instance);
51 |
52 | return instance;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Library/Zip/ZipStorePathModeEnum.cs:
--------------------------------------------------------------------------------
1 | using ScriptEngine.Machine;
2 | using ScriptEngine.Machine.Contexts;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | namespace ScriptEngine.HostedScript.Library.Zip
9 | {
10 | [SystemEnum("РежимСохраненияПутейZIP", "ZIPStorePathsMode")]
11 | public class ZipStorePathModeEnum : EnumerationContext
12 | {
13 | const string DONT_SAVE = "НеСохранятьПути";
14 | const string SAVE_RELATIVE = "СохранятьОтносительныеПути";
15 | const string SAVE_FULL = "СохранятьПолныеПути";
16 |
17 | public ZipStorePathModeEnum(TypeDescriptor typeRepresentation, TypeDescriptor valuesType)
18 | : base(typeRepresentation, valuesType)
19 | {
20 |
21 | }
22 |
23 | [EnumValue(DONT_SAVE)]
24 | public EnumerationValue DontStorePath
25 | {
26 | get
27 | {
28 | return this[DONT_SAVE];
29 | }
30 | }
31 |
32 | [EnumValue(SAVE_RELATIVE)]
33 | public EnumerationValue StoreRelativePath
34 | {
35 | get
36 | {
37 | return this[SAVE_RELATIVE];
38 | }
39 | }
40 |
41 | [EnumValue(SAVE_FULL)]
42 | public EnumerationValue StoreFullPath
43 | {
44 | get
45 | {
46 | return this[SAVE_FULL];
47 | }
48 | }
49 |
50 | public static ZipStorePathModeEnum CreateInstance()
51 | {
52 | ZipStorePathModeEnum instance;
53 |
54 | TypeDescriptor enumType;
55 | TypeDescriptor enumValType;
56 |
57 | EnumContextHelper.RegisterEnumType(out enumType, out enumValType);
58 |
59 | instance = new ZipStorePathModeEnum(enumType, enumValType);
60 |
61 | EnumContextHelper.RegisterValues(instance);
62 |
63 | return instance;
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Process.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using ScriptEngine.Environment;
6 | using ScriptEngine.Machine;
7 |
8 | namespace ScriptEngine.HostedScript
9 | {
10 | public class Process
11 | {
12 | ScriptingEngine _engine;
13 | IHostApplication _host;
14 | LoadedModuleHandle _module;
15 |
16 | internal Process(IHostApplication host, LoadedModuleHandle src, ScriptingEngine runtime)
17 | {
18 | _host = host;
19 | _engine = runtime;
20 | _module = src;
21 | }
22 |
23 | public int Start()
24 | {
25 | try
26 | {
27 | _engine.NewObject(_module);
28 | return 0;
29 | }
30 | catch (ScriptInterruptionException e)
31 | {
32 | return e.ExitCode;
33 | }
34 | catch (Exception e)
35 | {
36 | _host.ShowExceptionInfo(e);
37 | return 1;
38 | }
39 | finally
40 | {
41 | //AttachedScriptsFactory.Dispose();
42 | _engine = null;
43 | }
44 | }
45 |
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ScriptEngine.HostedScript")]
9 | [assembly: AssemblyProduct("ScriptEngine.HostedScript")]
10 |
11 | // Setting ComVisible to false makes the types in this assembly not visible
12 | // to COM components. If you need to access a type in this assembly from
13 | // COM, set the ComVisible attribute to true on that type.
14 | [assembly: ComVisible(false)]
15 |
16 | // The following GUID is for the ID of the typelib if this project is exposed to COM
17 | [assembly: Guid("1b057f7e-4a28-4c51-8620-3c90a75408bf")]
18 |
19 | // Version information for an assembly consists of the following four values:
20 | //
21 | // Major Version
22 | // Minor Version
23 | // Build Number
24 | // Revision
25 | //
26 | // You can specify all the values or you can default the Build and Revision Numbers
27 | // by using the '*' as shown below:
28 | // [assembly: AssemblyVersion("1.0.*")]
29 |
--------------------------------------------------------------------------------
/src/ScriptEngine.HostedScript/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/ScriptEngine.Snegopat/AssemblyInfo.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 |
3 | using namespace System;
4 | using namespace System::Reflection;
5 | using namespace System::Runtime::CompilerServices;
6 | using namespace System::Runtime::InteropServices;
7 | using namespace System::Security::Permissions;
8 |
9 | //
10 | // General Information about an assembly is controlled through the following
11 | // set of attributes. Change these attribute values to modify the information
12 | // associated with an assembly.
13 | //
14 | [assembly:AssemblyTitleAttribute("ScriptEngineSnegopat")];
15 | [assembly:AssemblyDescriptionAttribute("")];
16 | [assembly:AssemblyConfigurationAttribute("")];
17 | [assembly:AssemblyCompanyAttribute("")];
18 | [assembly:AssemblyProductAttribute("ScriptEngineSnegopat")];
19 | [assembly:AssemblyCopyrightAttribute("Copyright BeaverSoft(c) 2014")];
20 | [assembly:AssemblyTrademarkAttribute("")];
21 | [assembly:AssemblyCultureAttribute("")];
22 |
23 | //
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the value or you can default the Revision and Build Numbers
32 | // by using the '*' as shown below:
33 |
34 | [assembly:AssemblyVersionAttribute("1.0.9.0")];
35 |
36 | [assembly:ComVisible(false)];
37 |
38 | [assembly:CLSCompliantAttribute(true)];
39 |
40 | [assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];
41 |
--------------------------------------------------------------------------------
/src/ScriptEngine.Snegopat/CriticalResourceLoader.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "CriticalResourceLoader.h"
3 |
4 | CriticalResourceLoader::CriticalResourceLoader(HMODULE mod)
5 | {
6 | m_module = mod;
7 | m_modulePath = new WCHAR[MAX_PATH+1];
8 | memset(m_modulePath, 0, (MAX_PATH+1) * sizeof(WCHAR));
9 | GetModuleFileName(mod, m_modulePath, MAX_PATH);
10 |
11 | System::AppDomain::CurrentDomain->AssemblyResolve +=
12 | gcnew System::ResolveEventHandler(this, &CriticalResourceLoader::DependencyHandler);
13 |
14 | }
15 |
16 | Reflection::Assembly^ CriticalResourceLoader::DependencyHandler(Object^ sender, ResolveEventArgs^ args)
17 | {
18 | System::String^ str = args->Name;
19 | if(str->IndexOf(L"ScriptEngine",0) >= 0)
20 | {
21 |
22 | System::IntPtr^ ptr = gcnew System::IntPtr(m_modulePath);
23 | System::String^ pathBuild = System::Runtime::InteropServices::Marshal::PtrToStringUni(*ptr, MAX_PATH);
24 |
25 | int idx = pathBuild->LastIndexOf('\\');
26 | System::String^ dir = pathBuild->Substring(0, idx + 1);
27 |
28 | idx = str->IndexOf(',');
29 | System::String^ dll = str->Substring(0, idx) + ".dll";
30 | pathBuild = System::IO::Path::Combine(dir, dll);
31 |
32 | return System::Reflection::Assembly::LoadFrom(pathBuild);
33 |
34 | }
35 | else
36 | {
37 | return nullptr;
38 | }
39 | }
40 |
41 | CriticalResourceLoader::~CriticalResourceLoader(void)
42 | {
43 | delete[] m_modulePath;
44 | }
45 |
46 | bool CriticalResourceLoader::PrepareTypeInfo()
47 | {
48 | return true;
49 | }
50 |
51 | IUnknown* CriticalResourceLoader::GetLoader(IDispatch* pDesigner)
52 | {
53 | IAddinLoader* loader = new IAddinLoaderImpl(pDesigner);
54 | return loader;
55 | }
--------------------------------------------------------------------------------
/src/ScriptEngine.Snegopat/CriticalResourceLoader.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "StdAfx.h"
3 | #include
4 | #include "IAddinImpl.h"
5 | #include "IAddinLoaderImpl.h"
6 |
7 | using namespace System;
8 |
9 | ref class CriticalResourceLoader
10 | {
11 | private:
12 | HMODULE m_module;
13 | WCHAR* m_modulePath;
14 |
15 | Reflection::Assembly^ DependencyHandler(Object^ sender, ResolveEventArgs^ args);
16 |
17 | public:
18 | CriticalResourceLoader(HMODULE);
19 | bool PrepareTypeInfo();
20 | IUnknown* GetLoader(IDispatch* pDesigner);
21 | ~CriticalResourceLoader(void);
22 | };
23 |
24 |
--------------------------------------------------------------------------------
/src/ScriptEngine.Snegopat/DispatchHelpers.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | HRESULT invoke(LPDISPATCH pdisp,
6 | WORD wFlags,
7 | LPVARIANT pvRet,
8 | ::EXCEPINFO FAR* pexcepinfo,
9 | UINT FAR* pnArgErr,
10 | LPOLESTR pszName,
11 | LPCTSTR pszFmt,
12 | ...);
13 |
14 | LPCTSTR getNextVarType(LPCTSTR pszFmt, VARTYPE FAR* pvt);
15 |
16 | HRESULT countArgsInFormat(LPCTSTR pszFmt, UINT FAR *pn);
--------------------------------------------------------------------------------
/src/ScriptEngine.Snegopat/EventCallableSDO.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "EventCallableSDO.h"
3 |
4 | EventCallableSDO::EventCallableSDO(ScriptDrivenObject^ instance, LoadedModuleHandle module)
5 | : ReflectableSDO(instance, module)
6 | {
7 | }
8 |
9 | Object^ EventCallableSDO::InvokeInternal(String^ name,
10 | System::Reflection::BindingFlags invokeAttr,
11 | Binder^ binder,
12 | Object^ target,
13 | array