Beispiel #1
0
        private static void Start(DebugMode debugMode, string ipcGuidString, int parentPid)
        {
            // serialization framework tries to find assembly on disk
            AppDomain.CurrentDomain.AssemblyResolve += (sender, args)
                                                       => args.Name == typeof(WorkerServerHost).Assembly.FullName ? typeof(WorkerServerHost).Assembly : null;

            if (debugMode == DebugMode.Debugger)
            {
                while (!Debugger.IsAttached)
                {
                    Debugger.Launch();
                    Console.WriteLine(string.Format(CultureInfo.InvariantCulture,
                                                    "[server:{0}] Waiting for debugger", Process.GetCurrentProcess().Id));
                    Thread.Sleep(1000);
                }
            }

            IDictionary ipcProperties = new Hashtable();

            ipcProperties["name"]            = "UnblockerServerChannel";
            ipcProperties["portName"]        = ipcGuidString;
            ipcProperties["typeFilterLevel"] = "Full";
            var ipcChannel = new IpcChannel(ipcProperties,
                                            new BinaryClientFormatterSinkProvider(ipcProperties, null),
                                            new BinaryServerFormatterSinkProvider(ipcProperties, null));

            ChannelServices.RegisterChannel(ipcChannel, false);

            // Create and expose server
            var server = new WorkerServer();

            RemotingServices.Marshal(server, server.GetType().FullName);

            // permit client to wait for this process to be ready
            var waitForProcessReadyHandle = WorkerProcess.CreateWaitForProcessReadyHandle(ipcGuidString);

            waitForProcessReadyHandle.Set();
            waitForProcessReadyHandle.Close();

            try {
                Process.GetProcessById(parentPid).WaitForExit();
            } catch {
                // exit server process anyway
            }

            Environment.Exit(0);
        }
Beispiel #2
0
        public WorkerClient(WorkerProcess process, IWorkerServer serverProxy)
        {
            this.process = process;
            this.id      = "[client:" + process.Id + "]";

            this.serverProxy = serverProxy;
            if (this.serverProxy is MarshalByRefObject)
            {
                this.proxyLifetimeSponsor.Register((MarshalByRefObject)this.serverProxy);
            }

            this.process.ProcessDeadEvent += this.OnProcessDead;

            this.serverProxy.ServerDyingEvent   += this.OnServerDying;
            this.serverProxy.ServerReadyEvent   += this.OnServerReady;
            this.serverProxy.TaskFailedEvent    += this.OnRemoteTaskFailed;
            this.serverProxy.TaskCanceledEvent  += this.OnRemoteTaskCanceled;
            this.serverProxy.TaskSucceededEvent += this.OnRemoteTaskSucceeded;
        }