Exemple #1
0
        //public static object createObject()

        public static object loadTypeAndExecuteMethodInAppDomain(AppDomain appDomain, string dllWithType,
                                                                 string typeToCreateAndUnwrap, string methodToExecute,
                                                                 object[] methodParameters)
        {
            var    appDomainHelper = new O2AppDomainFactory(appDomain);
            object proxyObject     = appDomainHelper.appDomain().createAndUnWrap(dllWithType, typeToCreateAndUnwrap);

            if (proxyObject == null)
            {
                PublicDI.log.error("in loadTypeAndExecuteMethodInAppDomain, proxy == null");
            }
            else
            {
                MethodInfo methodInfo = PublicDI.reflection.getMethod(proxyObject.GetType(), methodToExecute, methodParameters);
                if (methodInfo == null)
                {
                    PublicDI.log.error("in loadTypeAndExecuteMethodInAppDomain, methodInfo == null");
                }
                else
                {
                    return(PublicDI.reflection.invoke(proxyObject, methodInfo, methodParameters));
                }
            }
            return(null);
        }
        /*static Assembly assemblyResolve(object sender, ResolveEventArgs args)
         * {
         *
         *  //return Assembly.LoadFile(GetAssemblyFileName());
         *  return null;
         * } */


        /// <summary>
        /// This will generate an anonymous appDomain proxy (good for tests but _note that the AppDomain will not be terminated
        /// </summary>
        /// <param name="assemblyName"></param>
        /// <param name="typeToCreateSimpleName"></param>
        /// <returns></returns>
        public static object getProxy(string assemblyName, string typeToCreateSimpleName)
        {
            string appDomainName        = Path.GetFileNameWithoutExtension(PublicDI.config.TempFileNameInTempDirectory) + "_" + typeToCreateSimpleName; // make sure each appDomainName is unique
            var    tempAppDomainFactory = new O2AppDomainFactory(appDomainName);

            return(tempAppDomainFactory.appDomain().getProxyObject(typeToCreateSimpleName));
        }
Exemple #3
0
 //public static object createObject()
 public static object loadTypeAndExecuteMethodInAppDomain(AppDomain appDomain, string dllWithType,
     string typeToCreateAndUnwrap, string methodToExecute,
     object[] methodParameters)
 {
     var appDomainHelper = new O2AppDomainFactory(appDomain);
     object proxyObject = appDomainHelper.appDomain().createAndUnWrap(dllWithType, typeToCreateAndUnwrap);
     if (proxyObject == null)
         PublicDI.log.error("in loadTypeAndExecuteMethodInAppDomain, proxy == null");
     else
     {
         MethodInfo methodInfo = PublicDI.reflection.getMethod(proxyObject.GetType(), methodToExecute, methodParameters);
         if (methodInfo == null)
             PublicDI.log.error("in loadTypeAndExecuteMethodInAppDomain, methodInfo == null");
         else
             return PublicDI.reflection.invoke(proxyObject, methodInfo, methodParameters);
     }
     return null;
 }
        public static string codeStreams_CreateInAppDomain(this Saved_MethodStream savedMethodStream)
        {
            //var script = @"C:\O2\_XRules_Local\Ast_Test.cs";
            var script = "Saved_MethodStream.cs".local();
            "Creating new AppDomain".info();
            var appDomainName = 4.randomString();
            var o2AppDomain =  new O2AppDomainFactory(appDomainName);
            o2AppDomain.appDomain().load("FluentSharp.CoreLib.dll");
            var o2Proxy =  (O2Proxy)(o2AppDomain.appDomain().getProxyObject("O2Proxy"));
            var parameters = new object[]
                    {
                        savedMethodStream.Serialized_Saved_MethodStream_FileCache
            //						sourceFolder,
            //						resultsFolder,
            //						methodFilter,
            //						useCachedData,
            //						references,
            //						numberOfItemsToProcess
                    };

            var result =(string)o2Proxy.staticInvocation("O2_External_SharpDevelop","FastCompiler_ExtensionMethods","executeFirstMethod",new object[]{script, parameters});
            "Result: {0}".info(result);
            o2AppDomain.sleep(2000);
            o2AppDomain.appDomain().unLoadAppDomain();
            "AppDomain execution completed, Runing GCCollect".info();
            PublicDI.config.gcCollect();
            "GCCollect completed, returning result data: {0}".info(result);
            return result;
        }
 public static O2AppDomainFactory createAppDomain(this string appDomainName)
 {
     var o2AppDomainFactory = new O2AppDomainFactory(appDomainName);
     o2AppDomainFactory.appDomain().loadMainO2Dlls();
     return o2AppDomainFactory;
 }
        public static string executeEngineOnSeparateAppDomain(string sourceFolder, string resultsFolder, string methodFilter, bool useCachedData, List<string> references, int numberOfItemsToProcess)
        {
            //var script = @"C:\O2\_XRules_Local\Ast_Test.cs";
            var script = "MethodMappings_Engine.cs".local();
            "Creating new AppDomain".info();
             			var appDomainName = 4.randomString();
            var o2AppDomain =  new O2AppDomainFactory(appDomainName);
            //o2AppDomain.load("O2_XRules_Database");
            //o2AppDomain.load("O2_Kernel");
            //o2AppDomain.load("O2_DotNetWrappers");

            o2AppDomain.appDomain().load("FluentSharp.CoreLib",
                                         "FluentSharp.WinForms",
                                         "FluentSharp.REPL",
                                         "FluentSharp.SharpDevelopEditor.dll");

            var o2Proxy =  (O2Proxy)(o2AppDomain.appDomain().getProxyObject("O2Proxy"));
            var parameters = new object[]
                    {
                        sourceFolder,
                        resultsFolder,
                        methodFilter,
                        useCachedData,
                        references,
                        numberOfItemsToProcess
                    };

            var result =(string)o2Proxy.staticInvocation("O2_External_SharpDevelop","FastCompiler_ExtensionMethods","executeFirstMethod",new object[]{script, parameters});
            o2AppDomain.appDomain().unLoadAppDomain();
            "AppDomain execution completed, Runing GCCollect".info();
            PublicDI.config.gcCollect();
            "GCCollect completed, returning result data: {0}".info(result);
            return result;
        }
        /*static Assembly assemblyResolve(object sender, ResolveEventArgs args)
        {

            //return Assembly.LoadFile(GetAssemblyFileName());
            return null;
        } */
        /// <summary>
        /// This will generate an anonymous appDomain proxy (good for tests but _note that the AppDomain will not be terminated
        /// </summary>
        /// <param name="assemblyName"></param>
        /// <param name="typeToCreateSimpleName"></param>
        /// <returns></returns>
        public static object getProxy(string assemblyName, string typeToCreateSimpleName)
        {
            string appDomainName = Path.GetFileNameWithoutExtension(PublicDI.config.TempFileNameInTempDirectory) + "_" + typeToCreateSimpleName;        // make sure each appDomainName is unique
            var tempAppDomainFactory = new O2AppDomainFactory(appDomainName);
            return tempAppDomainFactory.appDomain().getProxyObject(typeToCreateSimpleName);
        }