Beispiel #1
0
        void ProcessExited(IAsyncOperation oper)
        {
            lock (this) {
                Counters.ExternalHostProcesses--;

                // Remove all callbacks from existing objects
                foreach (object ob in remoteObjects)
                {
                    RemotingService.UnregisterMethodCallback(ob, "Dispose");
                }

                remoteObjects.Clear();

                exitedEvent.Set();

                // If the remote process crashes, a thread may be left hung in WaitForExit. This will awaken it.
                exitRequestEvent.Set();

                if (oper != process)
                {
                    return;
                }

                // The process suddently died
                runningEvent.Reset();
                processHost = null;
                process     = null;
                references  = 0;
            }
        }
Beispiel #2
0
        private async Task AcceptConnection(Connection connection)
        {
            try
            {
                DisableTimer();
                var request = await ReadElevationRequest(connection.ControlStream).ConfigureAwait(false);

                if (request.KillCache)
                {
                    throw new OperationCanceledException();
                }

                IProcessHost applicationHost = CreateProcessHost(request);

                if (!string.IsNullOrEmpty(request.Prompt))
                {
                    Environment.SetEnvironmentVariable("PROMPT",
                                                       Environment.ExpandEnvironmentVariables(request.Prompt));
                }

                await applicationHost.Start(connection, request).ConfigureAwait(false);
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception e)
            {
                Logger.Instance.Log(e.ToString(), LogLevel.Error);
                await connection.FlushAndCloseAll().ConfigureAwait(false);
            }
        }
Beispiel #3
0
        void ProcessExited(IAsyncOperation oper)
        {
            lock (this) {
                Counters.ExternalHostProcesses--;

                // Remove all callbacks from existing objects
                foreach (object ob in remoteObjects)
                {
                    RemotingService.UnregisterMethodCallback(ob, "Dispose");
                }

                remoteObjects.Clear();

                exitedEvent.Set();
                if (oper != process)
                {
                    return;
                }

                // The process suddently died
                runningEvent.Reset();
                processHost = null;
                process     = null;
                references  = 0;
            }
        }
Beispiel #4
0
 public void RegisterHost(IProcessHost processHost)
 {
     lock (this)
     {
         this.processHost = processHost;
         runningEvent.Set();
         starting = false;
     }
 }
        public IPluginPoweredProcessHost GetPluginPoweredInterface(IProcessHost host)
        {
            if (host == null) throw Ex.ArgNull(() => host);

            if (!IsPluginPowered(host))
            {
                throw Ex.Arg(() => host, "Host isn't plugin powered");
            }

            return (IPluginPoweredProcessHost)host;
        }
        public ITypePoweredProcessHost GetTypePoweredInterface(IProcessHost host)
        {
            if (host == null) throw Ex.ArgNull(() => host);

            if (!IsTypePowered(host))
            {
                throw Ex.Arg(() => host, "Host isn't type powered");
            }

            return (ITypePoweredProcessHost)host;
        }
Beispiel #7
0
        protected override ResultSignal DoAccept(IProcessHost host, Signal signal)
        {
            if (signal is WorkPartDoneSignal)
            {
                var workPartDone = signal as WorkPartDoneSignal;
                Messages[workPartDone.Part] = "{0} - '{1}' - {2}".Args(workPartDone.Part, workPartDone.Message, App.TimeSource.UTCNow);
                host.Update(this);
                return(OkSignal.Make(this));
            }

            return(null);
        }
        public SystemPowerType GetPowerType(IProcessHost host)
        {
            if (host == null) throw Ex.ArgNull(() => host);

            if (IsPluginPowered(host))
            {
                return SystemPowerType.Plugin;
            }
            else if (IsTypePowered(host))
            {
                return SystemPowerType.Type;
            }
            else
            {
                throw Ex.Arg(() => host, "Host is of unknown power type");
            }
        }
Beispiel #9
0
        protected internal virtual ResultSignal Accept(IProcessHost host, Signal signal)
        {
            if (signal is FinalizeSignal)
            {
                host.Finalize(this);
                return(OkSignal.Make(this));
            }
            if (signal is TerminateSignal)
            {
                var finish = signal as TerminateSignal;
                UpdateStatus(host, ProcessStatus.Terminated, "Terminated!!!!", App.TimeSource.UTCNow, finish.SysAbout);
                host.Update(this, true);
                return(OkSignal.Make(this));
            }
            // a pochemy net try/cath i ERROR signal???? ili eto v drugom meste
            var result = DoAccept(host, signal);  //Do Accept razve ne doljen byt POSLE systemnix signalov??

            if (result != null)
            {
                return(result);
            }

            // a gde ostalnie signali? Terminate etc...?

            if (signal is FinishSignal)
            {
                var finish = signal as FinishSignal;
                UpdateStatus(host, ProcessStatus.Finished, finish.Description, App.TimeSource.UTCNow, finish.SysAbout);
                host.Update(this, true);
                return(OkSignal.Make(this));
            }

            if (signal is CancelSignal)
            {
                var finish = signal as CancelSignal;
                UpdateStatus(host, ProcessStatus.Canceled, "Canceled!!!", App.TimeSource.UTCNow, finish.SysAbout);
                host.Update(this, true);
                return(OkSignal.Make(this));
            }

            return(UnknownSignal.Make(this, signal));
        }
Beispiel #10
0
        void WaitTimeout(object sender, System.Timers.ElapsedEventArgs args)
        {
            try {
                IProcessAsyncOperation oldProcess;

                lock (this) {
                    if (references > 0)
                    {
                        stopping = false;
                        return;
                    }

                    uint waited = (uint)(DateTime.Now - lastReleaseTime).TotalMilliseconds;
                    if (waited < stopDelay)
                    {
                        timer.Interval = stopDelay - waited;
                        timer.Enabled  = true;
                        return;
                    }

                    runningEvent.Reset();
                    exitedEvent.Reset();
                    exitRequestEvent.Set();
                    oldProcess  = process;
                    processHost = null;
                    process     = null;
                    stopping    = false;
                }

                if (!exitedEvent.WaitOne(shutdownTimeout, false))
                {
                    try {
                        oldProcess.Cancel();
                    } catch {
                    }
                }
            } catch (Exception ex) {
                LoggingService.LogError(ex.ToString());
            }
        }
Beispiel #11
0
 protected void UpdateStatus(IProcessHost host, ProcessStatus status, string description, DateTime timestamp, string about)
 {
     m_SysDescriptor = new ProcessDescriptor(SysDescriptor, status, description, timestamp, about);
 }
Beispiel #12
0
 protected abstract ResultSignal DoAccept(IProcessHost host, Signal signal);
Beispiel #13
0
 /// <summary>
 /// Executes merge operation on the existing process and another instance which tries to get spawned.
 /// This method MUST execute be VERY FAST and only contain merge logic, do not make external IO calls -
 /// all business data must already be contained in the original and another instance
 /// </summary>
 protected internal abstract void Merge(IProcessHost host, DateTime utcNow, Process another);
Beispiel #14
0
        private void Run()
        {
            var nboot = new NinjectBootstrapper();
            nboot.Start();

            Console.WriteLine("Starting incoming comms...");

            _incoming = new TcpIncomingCommsLink<ISimpleProcNode_Comms>(
                new TCPEndpointDetails()
                {
                    Address = IPAddress.Loopback,
                    Port = 8080,
                }, new XmlCommsMessageReaderWriter(new BinaryFormatterCommsMessageFormatter()),
                new DirectInvocationCommsMessageProcessor());

            _incoming.StartListening(this);
            Console.WriteLine("Now listening on port 8080...");

            Console.WriteLine("Initialising host...");
            _host = nboot.Get<IProcessHostFactory>()
                .CreateHostFromType(typeof(SimpleProcess));
            _host.Initialise();

            Console.WriteLine("Host initialised, process details:");
            Console.WriteLine("\t{0}", _host.Metadata.Name);
            Console.WriteLine("\t{0}", _host.Metadata.Description);
            Console.WriteLine("\t{0}", _host.Metadata.Version.ToString("#.#"));
            Console.WriteLine();

            Console.WriteLine("<ENTER> to terminate");
            Console.ReadLine();

            _incoming.StopListening();
            _incoming = null;
            _host.Unitialise();
            _host = null;
        }
        void WaitTimeout(object sender, System.Timers.ElapsedEventArgs args)
        {
            try {
                Process oldProcess;

                lock (this) {
                    if (references > 0) {
                        stopping = false;
                        return;
                    }

                    uint waited = (uint) (DateTime.Now - lastReleaseTime).TotalMilliseconds;
                    if (waited < stopDelay) {
                        timer.Interval = stopDelay - waited;
                        timer.Enabled = true;
                        return;
                    }

                    runningEvent.Reset ();
                    exitedEvent.Reset ();
                    exitRequestEvent.Set ();
                    oldProcess = process;
                    processHost = null;
                    process = null;
                    stopping = false;
                }

                if (!exitedEvent.WaitOne (2000, false)) {
                    try {
                        oldProcess.Kill ();
                    } catch {
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine (ex);
            }
        }
		public void RegisterHost (IProcessHost processHost)
		{
			lock (this)
			{
				this.processHost = processHost;
				runningEvent.Set ();
				starting = false;
			}
		}
        public bool IsTypePowered(IProcessHost host)
        {
            if (host == null) throw Ex.ArgNull(() => host);

            return (host is ITypePoweredProcessHost);
        }
Beispiel #18
0
 protected override ResultSignal DoAccept(IProcessHost host, Signal signal)
 {
     return(null);
 }
Beispiel #19
0
 public ScriptController(ISettingsProvider settingsProvider, ISessionService sessionService, IProcessHost processHost)
 {
     SettingsProvider = settingsProvider ?? throw new ArgumentNullException(nameof(settingsProvider));
     ProcessHost      = processHost ?? throw new ArgumentNullException(nameof(processHost));
     SessionService   = sessionService ?? throw new ArgumentNullException(nameof(sessionService));
 }
Beispiel #20
0
 protected internal override void Merge(IProcessHost host, DateTime utcNow, Process another)
 {
 }
		void ProcessExited (IAsyncOperation oper)
		{
			lock (this) {

				Counters.ExternalHostProcesses--;
				
				// Remove all callbacks from existing objects
				foreach (object ob in remoteObjects)
					RemotingService.UnregisterMethodCallback (ob, "Dispose");
				
				remoteObjects.Clear ();
				
				exitedEvent.Set ();
				if (oper != process) return;

				// The process suddently died
				runningEvent.Reset ();
				processHost = null;
				process = null;
				references = 0;
			}
		}
 protected ProcessMonitor(IProcessHost process)
 {
     this.Process = process;
 }
		void ProcessExited (ProcessAsyncOperation oper)
		{
			lock (this) {

				Counters.ExternalHostProcesses--;
				
				// Remove all callbacks from existing objects
				foreach (object ob in remoteObjects)
					RemotingService.UnregisterMethodCallback (ob, "Dispose");
				
				remoteObjects.Clear ();
				
				exitedEvent.Set ();
				
				// If the remote process crashes, a thread may be left hung in WaitForExit. This will awaken it.
				exitRequestEvent.Set ();
				
				if (oper != process) return;

				// The process suddently died
				runningEvent.Reset ();
				processHost = null;
				process = null;
				references = 0;
			}
		}
		void WaitTimeout (object sender, System.Timers.ElapsedEventArgs args)
		{
			try {
				ProcessAsyncOperation oldProcess;
				
				lock (this) {
					if (references > 0) {
						stopping = false;
						return;
					}
	
					uint waited = (uint) (DateTime.Now - lastReleaseTime).TotalMilliseconds;
					if (waited < stopDelay) {
						timer.Interval = stopDelay - waited;
						timer.Enabled = true;
						return;
					}
				
					runningEvent.Reset ();
					exitedEvent.Reset ();
					exitRequestEvent.Set ();
					oldProcess = process;
					processHost = null;
					process = null;
					stopping = false;
				}
	
				if (!exitedEvent.WaitOne (shutdownTimeout, false)) {
					try {
						oldProcess.Cancel ();
					} catch {
					}
				}
			} catch (Exception ex) {
				LoggingService.LogError (ex.ToString ());
			}
		}
Beispiel #25
0
 public DistribProcessHost(DistribProcess process, IProcessHost host)
 {
     _process = process;
     _host = host;
 }
Beispiel #26
0
 public void Setup()
 {
     BLHelper.InitBL(dalType: DALType.Oracle);
     _id          = Guid.NewGuid();
     _processHost = IoC.Instance.Resolve <IProcessHost>();
 }
        void ProcessExited(object sender, EventArgs args)
        {
            lock (this) {
                exitedEvent.Set ();
                Process p = (Process) sender;
                if (p != process) return;

                // The process suddently died
                runningEvent.Reset ();
                processHost = null;
                process = null;
                references = 0;
            }
        }