コード例 #1
0
		protected override HostedService CreateRemoteHost(AppDomain appDomain)
		{
			appDomain.SetData("ConnectionString",_connectionString);
			appDomain.DoCallBack(SetConnectionStringInAppDomain);
			var service = base.CreateRemoteHost(appDomain);
			return service;
		}
コード例 #2
0
        public static void Main(string[] args)
        {
            var obj = new ComObject();

            obj.Report("Object created.");

            System.AppDomain domain = System.AppDomain.CreateDomain("New domain");

            // via GCHandle
            var gcHandle = GCHandle.Alloc(obj);

            domain.SetData("gcCookie", GCHandle.ToIntPtr(gcHandle));

            // via COM GIT
            var git       = (ComExt.IGlobalInterfaceTable)(Activator.CreateInstance(Type.GetTypeFromCLSID(ComExt.CLSID_StdGlobalInterfaceTable)));
            var comCookie = git.RegisterInterfaceInGlobal(obj, ComExt.IID_IUnknown);

            domain.SetData("comCookie", comCookie);

            // via COM CCW
            var unkCookie = Marshal.GetIUnknownForObject(obj);

            domain.SetData("unkCookie", unkCookie);

            // invoke in another domain
            domain.DoCallBack(() =>
            {
                Program.Report("Another domain");

                // trying GCHandle - fails
                var gcCookie2 = (IntPtr)(System.AppDomain.CurrentDomain.GetData("gcCookie"));
                var gcHandle2 = GCHandle.FromIntPtr(gcCookie2);
                try
                {
                    var gcObj2 = (ComObject)(gcHandle2.Target);
                    gcObj2.Report("via GCHandle");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                // trying COM GIT - works
                var comCookie2 = (uint)(System.AppDomain.CurrentDomain.GetData("comCookie"));
                var git2       = (ComExt.IGlobalInterfaceTable)(Activator.CreateInstance(Type.GetTypeFromCLSID(ComExt.CLSID_StdGlobalInterfaceTable)));
                var obj2       = (ITest)git2.GetInterfaceFromGlobal(comCookie2, ComExt.IID_IUnknown);
                obj2.Report("via GIT");

                // trying COM CCW
                var unkCookie2 = (IntPtr)(System.AppDomain.CurrentDomain.GetData("unkCookie"));
                // this casting works because we derived from MarshalByRefObject
                var unkObj2 = (ComObject)Marshal.GetObjectForIUnknown(unkCookie2);
                obj2.Report("via CCW");
            });

            Console.ReadLine();
        }
コード例 #3
0
ファイル: AppDomainCreator.cs プロジェクト: zhangz/Toolbox
		public void ConfigureNewDomain(AppDomain domain)
		{
			if (!string.IsNullOrWhiteSpace(AssemblyFolder))
				domain.SetData("Folder", AssemblyFolder);

			if (domain == AppDomain.CurrentDomain)
				ResolveCustomAssemblies();
			else
				domain.DoCallBack(new CrossAppDomainDelegate(ResolveCustomAssemblies));
		}
コード例 #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Start Main {0}", Thread.CurrentThread.ManagedThreadId);

            var bigObject = new BigClass();

            System.AppDomain otherDomain = System.AppDomain.CreateDomain("otherDomain");
            otherDomain.DoCallBack(new CrossAppDomainDelegate(bigObject.LongMethod));

            Console.WriteLine("End Main");
        }
コード例 #5
0
ファイル: Asm.cs プロジェクト: mind0n/hive
		public static void Load(AppDomain domain, string file, Action<Assembly> callback)
		{
			Asm asm = new Asm() { asmfile = file, handler = callback };
			try
			{
				domain.DoCallBack(new CrossAppDomainDelegate(asm.loadAsmFile));
			}
			catch (Exception ex)
			{
				Console.WriteLine($"Failed to load one of the assembly into domain {domain.FriendlyName}: {ex.Message}");
			}
		}
コード例 #6
0
		//[ClassInitialize]
		public static void ClassInitialize(TestContext context)
		{
			_serverDomain = AppDomain.CreateDomain("ServerDomain #2", AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation);
			_serverDomain.DoCallBack(() =>
			{
				var serverChannel = new IpcServerChannel("ipc server #2", "localhost:9091", new ProtobufServerFormatterSinkProvider { FallbackToBinaryFormatter = true });
				ChannelServices.RegisterChannel(serverChannel, false);

				RemotingServices.Marshal(new TestServer(), "TestServer", typeof(ITestServer));
			});

			_clientChannel = new IpcClientChannel("ipc client #2", new BinaryClientFormatterSinkProvider());
			ChannelServices.RegisterChannel(_clientChannel, false);

			_testServer = (ITestServer)Activator.GetObject(typeof(TestServer), "ipc://localhost:9091/TestServer");
		}
コード例 #7
0
ファイル: Asm.cs プロジェクト: mind0n/hive
		public static void Load(AppDomain domain, byte[] assemblyBytes, Action<Assembly> callback)
		{
			Asm asm = new Asm() { asmbytes = assemblyBytes, handler = callback };
			try
			{
				domain.DoCallBack(new CrossAppDomainDelegate(asm.loadAsmBytes));
			}
			catch (Exception ex)
			{
				var iex = ex;
				while (iex.InnerException != null)
				{
					iex = iex.InnerException;
				}
				Console.WriteLine($"Failed to load one of the assembly into domain {domain.FriendlyName}: {iex.Message}");
			}
		}
コード例 #8
0
        public static void Main(string[] args)
        {
            Program.Report("app start");
            System.AppDomain domain = System.AppDomain.CreateDomain("New domain");

            var ctxOb = new CtxObject();

            ctxOb.Report("ctxOb object");

            domain.SetData("ctxOb", ctxOb);
            domain.DoCallBack(() =>
            {
                Program.Report("inside another domain");
                var ctxOb2 = (CtxObject)System.AppDomain.CurrentDomain.GetData("ctxOb");
                ctxOb2.Report("ctxOb called from another domain");
            });

            Console.ReadLine();
        }
コード例 #9
0
        /// <summary>
        /// The loaded Assembly will be unloaded together with the AppDomain, when a new Assembly is loaded.
        /// Requires all used types to be Serializable.
        /// </summary>
        public void Reload()
        {
            // Requires all types to be Serializable, System.Net.Sockets.Socket is not!

            if (_appDomain != null)
            {
                AppDomain.Unload(_appDomain);
            }

            byte[] bytes = File.ReadAllBytes(_dllPath);

            _appDomain = AppDomain.CreateDomain(ASSEMBLY_NAME);
            AsmLoader asm = new AsmLoader()
            {
                Data = bytes
            };
            _appDomain.DoCallBack(asm.LoadAsm);

            AsyncSocketFactory = (IAsyncSocketFactory)asm.Assembly.CreateInstance(FULLY_QUALIFIED_TYPE_NAME);
        }
コード例 #10
0
        private static void start()
        {
            //Check if appdomain and assembly is already loaded
            if (assemblyDomain != null)
            {
                //unload appDomain and hence the assembly
                System.AppDomain.Unload(assemblyDomain);
                //Code to download new dll
            }
            string cwd            = System.AppDomain.CurrentDomain.BaseDirectory;
            string sourceFileName = @"C:\Users\deepak\Documents\visual studio 2010\Projects\ConsoleApplication1\ConsoleApplication2\bin\Debug\ConsoleApplication2.exe";
            string dllName        = "ConsoleApplication2.exe";

            // copy the file
            if (File.Exists(cwd + dllName))
            {
                File.Delete(cwd + dllName);
            }
            File.Copy(sourceFileName, cwd + dllName);
            assemblyDomain = System.AppDomain.CreateDomain("assembly1Domain", null);
            assemblyDomain.DoCallBack(() =>
            {
                var t = Task.Factory.StartNew(() =>
                {
                    try
                    {
                        string sss        = "";
                        string dllName1   = "ConsoleApplication2.exe";
                        Assembly assembly = Assembly.LoadFile(Directory.GetCurrentDirectory() + @"\" + dllName1);
                        Type type         = assembly.GetType("Lecture_1___dotNetProgramExecution.Program");
                        MethodInfo minfo  = type.GetMethod("Main", BindingFlags.Public | BindingFlags.NonPublic |
                                                           BindingFlags.Static | BindingFlags.Instance);
                        minfo.Invoke(Activator.CreateInstance(type), null);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                });
            });
        }
コード例 #11
0
        private static void MethodToBeRun(AppDomain appDomain)
        {
            appDomain.DoCallBack(() =>
            {
                AppDomain myDomain = AppDomain.CurrentDomain;

                Console.WriteLine("Im in '{0}' domain", myDomain.FriendlyName);

                for (int i = 0; i < 10000000; i++)
                {
                    Console.WriteLine("Im in domain in {0}", myDomain.GetHashCode());
                }

                //Accessing outerscope varible, not possible in AppDomain, will generate error.
                // Console.WriteLine(abc);

                //For simple hang up.
                Console.ReadLine();

            }
               );
        }
コード例 #12
0
        public FlowEnvironment(string path)
        {
            File = new FileInfo(path);
            if (!File.Exists)
                throw new FileNotFoundException("Unable to find the specified file path");

            // Create a new domain
            string domainName = string.Format("FlowEnvironment.0x{0:X8}", GetHashCode());
            domain = AppDomain.CreateDomain(domainName);

            // Preload common assemblies
            domain.DoCallBack(PreloadAssemblies);

            // Load the specified flow
            Reload();

            // Watch the specified path
            watcher = new FileSystemWatcher();
            watcher.Path = File.DirectoryName;
            watcher.Filter = File.Name;
            watcher.Changed += Watcher_Changed;
            watcher.EnableRaisingEvents = true;
        }
コード例 #13
0
        // Main
        public static void Main(string[] args)
        {
            var ob = new MyController();

            Action <string> newDomainAction = (name) =>
            {
                System.AppDomain domain = System.AppDomain.CreateDomain(name);
                domain.SetData("ob", ob);
                domain.DoCallBack(DomainCallback);
            };

            Console.WriteLine("\nPress Enter to test domains...");
            Console.ReadLine();

            var task1 = Task.Run(() => newDomainAction("domain1"));
            var task2 = Task.Run(() => newDomainAction("domain2"));

            Task.WaitAll(task1, task2);

            Console.WriteLine("\nPress Enter to test ob.Test...");
            Console.ReadLine();
            ob.Test();

            Console.WriteLine("\nPress Enter to test ob2.TestAsync...");
            Console.ReadLine();
            var ob2 = new MyController();

            ob2.TaskAsync().Wait();

            Console.WriteLine("\nPress Enter to test TestContext...");
            Console.ReadLine();
            TestContext();

            Console.WriteLine("\nPress Enter to exit...");
            Console.ReadLine();
        }
コード例 #14
0
ファイル: NancyAutoHost.cs プロジェクト: rhwy/NancyRabbit
        private void OnChange(FileSystemEventArgs args)
        {
            if (args != null)
            {
                Console.WriteLine("File Change Found:");
                Console.WriteLine("   [{0}] {1}", args.ChangeType, args.Name);
            }

            if (_ad != null)
            {
                AppDomain.Unload(_ad);
                _ad = null;
            }
            _ad = AppDomain.CreateDomain("temp");
            _ad.DoCallBack(CrossDomainRunner);
        }
コード例 #15
0
        public void Init(bool fullBind)
        {
            string name = Path.GetRandomFileName();
            tempDir = Path.Combine(Path.GetTempPath(), name);
            string robocodeShadow = Path.Combine(tempDir, Path.GetFileName(robocodeAssembly.Location));
            string hostShadow = Path.Combine(tempDir, Path.GetFileName(hostAssembly.Location));
            string controlShadow = Path.Combine(tempDir, Path.GetFileName(controlAssembly.Location));
            string jniShadow = Path.Combine(tempDir, Path.GetFileName(jniAssembly.Location));

            Directory.CreateDirectory(tempDir);
            File.Copy(robocodeAssembly.Location, robocodeShadow);
            File.Copy(controlAssembly.Location, controlShadow);
            File.Copy(hostAssembly.Location, hostShadow);
            File.Copy(jniAssembly.Location, jniShadow);

            var trustAssemblies = new[]
                                      {
                                          Reflection.GetStrongName(robocodeAssembly),
                                          Reflection.GetStrongName(controlAssembly),
                                          Reflection.GetStrongName(hostAssembly),
                                          Reflection.GetStrongName(jniAssembly),
                                      };
            var domainSetup = new AppDomainSetup();
            Evidence securityInfo = AppDomain.CurrentDomain.Evidence;
            var permissionSet = new PermissionSet(PermissionState.None);
            permissionSet.AddPermission(
                new SecurityPermission(SecurityPermissionFlag.Execution | SecurityPermissionFlag.Assertion));
            permissionSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read, tempDir));
            permissionSet.AddPermission(new UIPermission(PermissionState.None));
            //permissionSet.AddPermission(HostProtection);

            domainSetup.ApplicationBase = tempDir;

            domainSetup.ApplicationName = name;
            //domainSetup.SandboxInterop = true;
            domainSetup.DisallowBindingRedirects = true;
            domainSetup.DisallowCodeDownload = true;
            domainSetup.DisallowPublisherPolicy = true;
            domainSetup.AppDomainInitializer = AppDomainSeed.Load;
            

            domain = AppDomain.CreateDomain(name, securityInfo, domainSetup, permissionSet, trustAssemblies);
            domain.SetData("fullBind", fullBind);
            domain.SetData("JavaHome", Bridge.Setup.JavaHome);
            domain.DoCallBack(AppDomainSeed.Bind);
        }
コード例 #16
0
		private RemoteLoader CreateRemoteLoader(AppDomain appDomain)
		{
			string remoteLoaderAsmName = typeof(RemoteLoader).Assembly.FullName;
			string remoteLoaderClsName = typeof(RemoteLoader).FullName;

			try
			{
				appDomain.DoCallBack(
					delegate
						{
							Assembly.Load("Castle.Core");
							Assembly.Load("Castle.MicroKernel");
							Assembly.Load("Castle.Facilities.DynamicLoader");
						});
			}
			catch(Exception ex)
			{
				log.Fatal("Error while loading required assemblies", ex);
				throw new FacilityException("Failed to load RemoteLoader required assemblies", ex);
			}

			try
			{
				// creates the RemoteLoader
				log.Debug("Creating the RemoteLoader");
				return (RemoteLoader) appDomain.CreateInstanceAndUnwrap(remoteLoaderAsmName, remoteLoaderClsName);
			}
			catch(Exception ex)
			{
				log.Fatal("Error while creating the RemoteLoader", ex);
				throw new FacilityException("Failed to create the RemoteLoader", ex);
			}
		}
コード例 #17
0
        public static void StartServers(TestContext ctx)
        {
            #region TCP Duplex

            // Setup TCP Duplex Server AppDomain
            AppDomainSetup tcpDuplexAppDomainSetup = new AppDomainSetup() { ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) };
            _tcpDuplexServerAppDomain = AppDomain.CreateDomain("RecreateClientConnectionTests_Server", null, tcpDuplexAppDomainSetup);
            _tcpDuplexServerAppDomain.Load(typeof(ZyanConnection).Assembly.GetName());

            // Start Zyan host inside the TCP Duplex Server AppDomain
            var tcpDuplexServerWork = new CrossAppDomainDelegate(() =>
            {
                var server = TcpDuplexServerHostEnvironment.Instance;

                if (server != null)
                {
                    Console.WriteLine("TCP Duplex Server running.");
                }
            });
            _tcpDuplexServerAppDomain.DoCallBack(tcpDuplexServerWork);

            #endregion

            #region TCP Simplex

            // Setup TCP Simplex Server AppDomain
            AppDomainSetup tcpSimplexAppDomainSetup = new AppDomainSetup() { ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) };
            _tcpSimplexServerAppDomain = AppDomain.CreateDomain("RecreateClientConnectionTests_Server", null, tcpSimplexAppDomainSetup);
            _tcpSimplexServerAppDomain.Load(typeof(ZyanConnection).Assembly.GetName());

            // Start Zyan host inside the TCP Simplex Server AppDomain
            var tcpSimplexServerWork = new CrossAppDomainDelegate(() =>
            {
                var server = TcpSimplexServerHostEnvironment.Instance;

                if (server != null)
                {
                    Console.WriteLine("TCP Simplex Server running.");
                }
            });
            _tcpSimplexServerAppDomain.DoCallBack(tcpSimplexServerWork);

            #endregion
        }
コード例 #18
0
        private Silo LoadSiloInNewAppDomain(string siloName, Silo.SiloType type, ClusterConfiguration config, out AppDomain appDomain)
        {
            AppDomainSetup setup = GetAppDomainSetupInfo();

            appDomain = AppDomain.CreateDomain(siloName, null, setup);

            // Load each of the additional assemblies.
            Silo.TestHooks.CodeGeneratorOptimizer optimizer = null;
            foreach (var assembly in this.additionalAssemblies.Where(asm => asm.Value != null))
            {
                if (optimizer == null)
                {
                    optimizer =
                        (Silo.TestHooks.CodeGeneratorOptimizer)
                        appDomain.CreateInstanceFromAndUnwrap(
                            "OrleansRuntime.dll",
                            typeof(Silo.TestHooks.CodeGeneratorOptimizer).FullName,
                            false,
                            BindingFlags.Default,
                            null,
                            null,
                            CultureInfo.CurrentCulture,
                            new object[] { });
                }

                optimizer.AddCachedAssembly(assembly.Key, assembly.Value);
            }

            var args = new object[] { siloName, type, config };

            var silo = (Silo)appDomain.CreateInstanceFromAndUnwrap(
                "OrleansRuntime.dll", typeof(Silo).FullName, false,
                BindingFlags.Default, null, args, CultureInfo.CurrentCulture,
                new object[] { });

            appDomain.UnhandledException += ReportUnobservedException;
            appDomain.DoCallBack(RegisterPerfCountersTelemetryConsumer);

            return silo;
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: yallie/zyan
        public static int Main(string[] args)
        {
            AppDomainSetup setup = new AppDomainSetup();
            setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            _serverAppDomain = AppDomain.CreateDomain("Server", null, setup);
            _serverAppDomain.Load(typeof(ZyanConnection).Assembly.GetName());

            CrossAppDomainDelegate serverWork = new CrossAppDomainDelegate(() =>
            {
                var server = EventServer.Instance;
                if (server != null)
                {
                    Console.WriteLine("Event server started.");
                }
            });
            _serverAppDomain.DoCallBack(serverWork);

            // Test IPC Binary
            int ipcBinaryTestResult = IpcBinaryTest.RunTest();
            Console.WriteLine("Passed: {0}", ipcBinaryTestResult == 0);

            // Test TCP Binary
            int tcpBinaryTestResult = TcpBinaryTest.RunTest();
            Console.WriteLine("Passed: {0}", tcpBinaryTestResult == 0);

            // Test TCP Custom
            int tcpCustomTestResult = TcpCustomTest.RunTest();
            Console.WriteLine("Passed: {0}", tcpCustomTestResult == 0);

            // Test TCP Duplex
            int tcpDuplexTestResult = TcpDuplexTest.RunTest();
            Console.WriteLine("Passed: {0}", tcpDuplexTestResult == 0);

            // Test HTTP Custom
            int httpCustomTestResult = HttpCustomTest.RunTest();
            Console.WriteLine("Passed: {0}", httpCustomTestResult == 0);

            // Test NULL Channel
            const string nullChannelResultSlot = "NullChannelResult";
            _serverAppDomain.DoCallBack(new CrossAppDomainDelegate(() =>
            {
                int result = NullChannelTest.RunTest();
                AppDomain.CurrentDomain.SetData(nullChannelResultSlot, result);
            }));
            var nullChannelTestResult = Convert.ToInt32(_serverAppDomain.GetData(nullChannelResultSlot));
            Console.WriteLine("Passed: {0}", nullChannelTestResult == 0);

            // Stop the event server
            EventServerLocator locator = _serverAppDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, "IntegrationTest_DistributedEvents.EventServerLocator") as EventServerLocator;
            locator.GetEventServer().Dispose();
            Console.WriteLine("Event server stopped.");

            if (!MonoCheck.IsRunningOnMono || MonoCheck.IsUnixOS)
            {
                // Mono/Windows bug:
                // AppDomain.Unload freezes in Mono under Windows if tests for
                // System.Runtime.Remoting.Channels.Tcp.TcpChannel were executed.
                AppDomain.Unload(_serverAppDomain);
                Console.WriteLine("Server AppDomain unloaded.");
            }

            if (ipcBinaryTestResult + tcpBinaryTestResult + tcpCustomTestResult + tcpDuplexTestResult + httpCustomTestResult + nullChannelTestResult == 0)
            {
                Console.WriteLine("All tests passed.");
                return 0;
            }

            return 1;
        }
コード例 #20
0
        private void CreateAppDomain()
        {
            var appDomainSetup = new AppDomainSetup
            {
                ApplicationBase = applicationPath,
            };

            if (shadowCache)
            {
                appDomainSetup.ShadowCopyFiles = "true";
                appDomainSetup.CachePath = Path.Combine(applicationPath, CacheFolder);
            }

            // Create AppDomain
            appDomain = AppDomain.CreateDomain(appDomainName, AppDomain.CurrentDomain.Evidence, appDomainSetup);

            // Create appDomain Callback
            appDomainCallback = new AssemblyLoaderCallback(AssemblyLoaded, mainAssemblyPath);

            // Install the appDomainCallback to prepare the new app domain
            appDomain.DoCallBack(appDomainCallback.RegisterAssemblyLoad);
        }
コード例 #21
0
ファイル: NpsPlugin.cs プロジェクト: ibauersachs/OpenCymd.Nps
 private static void LoadPluginsIntoAppDomain()
 {
     lock (SyncLock)
     {
         pluginDomain = AppDomain.CreateDomain("PluginDomain");
         pluginDomain.UnhandledException += (sender, e) => Logger.Error("Plugin app-domain crashed.", (Exception)e.ExceptionObject);
         pluginDomain.DoCallBack(() => log4net.Config.XmlConfigurator.Configure(new FileInfo(Path.Combine(InstallationDirectory, "NpsPlugin.config"))));
         pluginDomain.DoCallBack(LoadPlugins);
     }
 }
コード例 #22
0
        internal static IPluginCreator GetCreator(AppDomain domain, ILoggerFactory logfactory)
        {
            if (domain == null)
            throw new ArgumentNullException("domain");

              if (logfactory == null)
            throw new ArgumentNullException("logfactory");

              IPluginCreator creator = domain.GetData(PLUGINCREATORKEY) as IPluginCreator;
              if (creator == null)
              {
            domain.SetData(LOGGERFACTORYKEY, new ProxyLoggerFactory(logfactory));
            domain.DoCallBack(() =>
            {
              Logger.Singleton.LoggerFactory = AppDomain.CurrentDomain.GetData(LOGGERFACTORYKEY) as ILoggerFactory;
              AppDomain.CurrentDomain.SetData(PLUGINCREATORKEY, new PluginCreator());
            });
            domain.SetData(LOGGERFACTORYKEY, null);
            creator = domain.GetData(PLUGINCREATORKEY) as IPluginCreator;
              }
              return creator;
        }
コード例 #23
0
ファイル: Utils.cs プロジェクト: wangjianglin/dotnet-core
 public static void LoadFrom(AppDomain appDomain,string file)
 {
     appDomain.SetData(Thread.CurrentThread.ManagedThreadId + "LoadFile", file);
     appDomain.DoCallBack(() =>
     {
         Assembly ass2 = Assembly.LoadFrom((string)AppDomain.CurrentDomain.GetData(Thread.CurrentThread.ManagedThreadId + "LoadFile"));
     });
 }
コード例 #24
0
ファイル: Program.cs プロジェクト: yallie/zyan
        public static int Main(string[] args)
        {
            AppDomainSetup setup = new AppDomainSetup();
            setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            _serverAppDomain = AppDomain.CreateDomain("Server", null, setup);
            _serverAppDomain.Load("Zyan.Communication");

            CrossAppDomainDelegate serverWork = new CrossAppDomainDelegate(() =>
            {
                EventServer server = EventServer.Instance;
            });
            _serverAppDomain.DoCallBack(serverWork);

            //TcpCustomClientProtocolSetup protocol = new TcpCustomClientProtocolSetup(true);
            MsmqClientProtocolSetup protocol = new MsmqClientProtocolSetup();
            //_connection = new ZyanConnection("tcp://*****:*****@"msmq://private$/reqchannel/EventTest", protocol);
            _proxySingleton = _connection.CreateProxy<IEventComponentSingleton>();
            _proxySingleCall = _connection.CreateProxy<IEventComponentSingleCall>();
            _proxyCallbackSingleton = _connection.CreateProxy<ICallbackComponentSingleton>();
            _proxyCallbackSingleCall = _connection.CreateProxy<ICallbackComponentSingleCall>();
            _proxyRequestResponseSingleCall = _connection.CreateProxy<IRequestResponseCallbackSingleCall>();

            int successCount = 0;

            _proxyCallbackSingleton.Out_Callback = CallBackSingleton;
            _proxyCallbackSingleCall.Out_Callback = CallBackSingleCall;

            _proxyCallbackSingleton.DoSomething();
            if (_callbackCountSingleton == 1)
            {
                successCount++;
                Console.WriteLine("Singleton Callback Test passed.");
            }
            _proxyCallbackSingleCall.DoSomething();
            if (_callbackCountSingleCall == 1)
            {
                successCount++;
                Console.WriteLine("SingleCall Callback Test passed.");
            }

            RegisterEvents();
            if (_registrationsSingleton == _proxySingleton.Registrations)
                successCount++;
            if (_registrationsSingleCall == _proxySingleCall.Registrations)
                successCount++;

            _proxySingleton.TriggerEvent();
            if (_firedCountSingleton == 1)
            {
                successCount++;
                Console.WriteLine("Singleton Event Test passed.");
            }

            _proxySingleCall.TriggerEvent();
            if (_firedCountSingleCall == 1)
            {
                successCount++;
                Console.WriteLine("SingleCall Event Test passed.");
            }

            UnregisterEvents();
            if (_registrationsSingleton == _proxySingleton.Registrations)
                successCount++;
            if (_registrationsSingleCall == _proxySingleCall.Registrations)
                successCount++;

            RequestResponseResult requestResponseResult = new RequestResponseResult();

            _proxyRequestResponseSingleCall.DoRequestResponse("Success", requestResponseResult.ReceiveResponseSingleCall);

            Thread.Sleep(1000);

            if (requestResponseResult.Count == 1)
                successCount++;

            _connection.Dispose();
            EventServerLocator locator = _serverAppDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, "IntegrationTest_DistributedEvents.EventServerLocator") as EventServerLocator;
            locator.GetEventServer().Dispose();
            AppDomain.Unload(_serverAppDomain);

            if (successCount == 9)
                return 0;
            else
                return 1;
        }
コード例 #25
0
ファイル: DomainRunner.cs プロジェクト: aries544/eXpand
        public static object RunInAppDomain(Delegate delg, AppDomain targetDomain, params object[] args) {
            var runner = new domainDomainRunner(delg, args, delg.GetHashCode());
            targetDomain.DoCallBack(runner.Invoke);

            return targetDomain.GetData("appDomainResult" + delg.GetHashCode());
        }
コード例 #26
0
 private void SetupPackageManager(AppDomain domain)
 {
     var setup = new PackageManagerSetup();
     domain.DoCallBack(setup.DoSetup);
 }
コード例 #27
0
        public static void DestroyDomain(AppDomain domain)
        {
            System.Diagnostics.Debug.WriteLine("Unloading domain: " + domain.FriendlyName);
            if (!RuntimeInfo.IsRunInMono)
            {
                domain.DoCallBack(System.Windows.Forms.Application.Exit);
            }

#if !MONO_DEV
            //appdomain unload crashes mono.exe process when running directly from 
            //Mono Develop, possibly because attached debugger. When run normally works fine.
            //use MONO_DEV compiler symbol when developing
            AppDomain.Unload(domain);
#endif
        }
コード例 #28
0
ファイル: Asm.cs プロジェクト: mind0n/hive
		public static void Unload(AppDomain domain, Action<Assembly> callback)
		{
			if (callback != null)
			{
				Asm asm = new Asm() {domain = domain, handler = callback};
				try
				{
					log.i($"Unloading {domain.FriendlyName}: {domain.BaseDirectory}");
					domain.DoCallBack(new CrossAppDomainDelegate(asm.unloadDomain));
				}
				catch (Exception ex)
				{
					log.i($"Failed to unload domain {domain.FriendlyName}: {ex.Message}");
				}
			}
		}
コード例 #29
0
        private void LoadAllRunnersIntoAppDomain()
        {
            domain = AppDomain.CreateDomain("Delta Engine Assembly Updater", null, CreateDomainSetup());
            domain.SetData("resolver", resolver);
            domain.SetData("domainInitializationCode", domainInitializationCode);
            domain.DoCallBack(InitializeInDomain);

            foreach (string assembly in AssemblyFilenames)
                LoadRunners(assembly);
        }