void FreePython() { prGetNProps = null; prFindProp = null; prGetPropName = null; prGetPropVal = null; prSetPropVal = null; prIsPropReadable = null; prIsPropWritable = null; prGetNMethods = null; prFindMethod = null; prGetMethodName = null; prGetNParams = null; prGetParamDefValue = null; prHasRetVal = null; prCallAsProc = null; prCallAsFunc = null; prCleanAll = null; prAddReferences = null; prClearExcInfo = null; ops = null; conn_scope = null; interf_scope = null; interactor = null; sruntime.Shutdown(); }
void InitDLR() { try { // Возможно app.config придется упразднять // ?собрать IronPython1C #if (ONEPY45) ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration(Path.Combine(AssemblyDirectory, "OnePy45.dll.config")); #else #if (ONEPY35) ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration(Path.Combine(AssemblyDirectory, "OnePy35.dll.config")); #endif #endif //setup.Options.Add("PreferComDispatch", ScriptingRuntimeHelpers.True); sruntime = new ScriptRuntime(setup); ScriptEngine eng = sruntime.GetEngine("Python"); #region Установка путей поиска модулей var sp = eng.GetSearchPaths(); sp.Add(Environment.CurrentDirectory); sp.Add(Path.Combine(Environment.CurrentDirectory, @"Lib")); sp.Add(Path.Combine(Environment.CurrentDirectory, @"Lib\site-packages")); sp.Add(Path.Combine(Environment.CurrentDirectory, @"IronPython.lib")); sp.Add(Path.Combine(Environment.CurrentDirectory, @"IronPython")); sp.Add(Path.Combine(Environment.CurrentDirectory, @"IronPython\DLLs")); sp.Add(Path.Combine(Environment.CurrentDirectory, @"IronPython\Lib")); sp.Add(Path.Combine(Environment.CurrentDirectory, @"IronPython\Lib\site-packages")); sp.Add(Path.Combine(AssemblyDirectory, @"IronPython.lib")); sp.Add(Path.Combine(AssemblyDirectory, @"IronPython")); sp.Add(Path.Combine(AssemblyDirectory, @"IronPython\DLLs")); sp.Add(Path.Combine(AssemblyDirectory, @"IronPython\Lib")); sp.Add(Path.Combine(AssemblyDirectory, @"IronPython\Lib\site-packages")); foreach (string ap in RuntimeConfig.additional_paths) { sp.Add(ap); } sp.Add(AssemblyDirectory); eng.SetSearchPaths(sp); #endregion ScriptSource conn_src = eng.CreateScriptSource(new AssemblyStreamContentProvider("OnePy.#1"), "cm5ACF5D43F2DA488BB5414714845ACBDE.py"); ScriptSource interf_src = eng.CreateScriptSource(new AssemblyStreamContentProvider("OnePy.#2"), "interfacing.py"); var comp_options = (PythonCompilerOptions)eng.GetCompilerOptions(); comp_options.Optimized = false; comp_options.Module &= ~ModuleOptions.Optimized; interf_scope = eng.CreateScope(); interf_src.Compile(comp_options).Execute(interf_scope); conn_scope = eng.CreateScope(); conn_src.Compile(comp_options).Execute(conn_scope); ops = eng.CreateOperations(); Object calcClass = conn_scope.GetVariable("OnePyConnector"); interactor = new Interactor(); Object calcObj = ops.Invoke(calcClass, interactor); #region Получение ссылок на методы prGetNProps = ops.GetMember<Func<Object, Object>>(calcObj, "GetNProps"); prFindProp = ops.GetMember<Func<Object, Object, Object>>(calcObj, "FindProp"); prGetPropName = ops.GetMember<Func<Object, Object, Object, Object>>(calcObj, "GetPropName"); prGetPropVal = ops.GetMember<Func<Object, Object, Object>>(calcObj, "GetPropVal"); prSetPropVal = ops.GetMember<Func<Object, Object, Object>>(calcObj, "SetPropVal"); prIsPropReadable = ops.GetMember<Func<Object, Object, Object>>(calcObj, "IsPropReadable"); prIsPropWritable = ops.GetMember<Func<Object, Object, Object>>(calcObj, "IsPropWritable"); prGetNMethods = ops.GetMember<Func<Object, Object>>(calcObj, "GetNMethods"); prFindMethod = ops.GetMember<Func<Object, Object, Object>>(calcObj, "FindMethod"); prGetMethodName = ops.GetMember<Func<Object, Object, Object, Object>>(calcObj, "GetMethodName"); prGetNParams = ops.GetMember<Func<Object, Object, Object>>(calcObj, "GetNParams"); prGetParamDefValue = ops.GetMember<Func<Object, Object, Object, Object>>(calcObj, "GetParamDefValue"); prHasRetVal = ops.GetMember<Func<Object, Object, Object>>(calcObj, "HasRetVal"); prCallAsProc = ops.GetMember<Func<Object, Object, Object>>(calcObj, "CallAsProc"); prCallAsFunc = ops.GetMember<Func<Object, Object, Object, Object>>(calcObj, "CallAsFunc"); prCleanAll = ops.GetMember<Func<Object>>(calcObj, "CleanAll"); prAddReferences = ops.GetMember<Func<Object, Object>>(calcObj, "AddReferences"); prClearExcInfo = ops.GetMember<Func<Object>>(calcObj, "ClearExcInfo"); #endregion } catch (Exception e) { ProcessError(e); throw; } }