Exemple #1
0
        public override void Run()
        {
            try
            {
                var runner = GetRunner();

                var task = runner.Prepare(ProcessInfo.FromStartInfo(StartInfo), ProcessOptions, server.Configuration.AccessToken);

                task.Wait(cts.Token);

                remoteProcess = task.Result;

                OnProcessPrepared?.Invoke(this, remoteProcess);

                runner.Run(remoteProcess, server.Configuration.AccessToken).Wait(cts.Token);

                cts.Token.WaitHandle.WaitOne();
            }
            catch (Exception ex)
            {
                thrownException = new ProcessException(-99, ex.Message, ex);
            }

            HasExited = true;

            if (thrownException != null || errors.Count > 0)
            {
                RaiseOnError(thrownException, string.Join(Environment.NewLine, errors.ToArray()));
            }

            RaiseOnEnd();
        }
        internal void RaiseProcessRestart(RpcProcess process, ProcessRestartReason reason)
        {
            if (!wrappers.TryGetValue(process.Id, out var list) ||
                !schedulers.TryGetValue(process.Id, out var scheduler))
            {
                throw new InvalidOperationException(
                          $"OnRestart for process {process.Id} was called but there's no record of it in the process list.");
            }

            foreach (var wrapper in list)
            {
                scheduler.Schedule(s => OnProcessRestart?.Invoke(this, (RpcProcessRestartEventArgs)s),
                                   new RpcProcessRestartEventArgs(process, reason), cts.Token);
            }
        }
        private string SetupProcess(IRequestContext client, RpcProcess process,
                                    IProcessTask <string, List <string> > task = null, RaiseUntilDetachOutputProcess outputProcessor = null)
        {
            var         id   = process.Id;
            ContextData data = default;

            var processExists = processes.TryGetValue(process.Id, out data);

            if (task == null && (!processExists || data.Task.IsCompleted))
            {
                outputProcessor = new RaiseUntilDetachOutputProcess();
                task            = new ProcessTaskWithListOutput <string>(taskManager, processEnvironment,
                                                                         outputProcessor: outputProcessor, token: cts.Token);
                processManager.Configure(task, process.StartInfo.ToStartInfo());
            }
            else if (task != null)
            {
                task.Dispose();
                task = null;
            }

            data = processes.GetOrAdd(id, data);

            data.Process = process;
            data.Client  = client;
            if (task != null)
            {
                data.Task            = task;
                data.OutputProcessor = outputProcessor;
            }

            if (data.Notifications == null)
            {
                data.Notifications =
                    new SynchronizationContextTaskScheduler(new ThreadSynchronizationContext(cts.Token));
            }

            processes[id] = data;

            HookupProcessHandlers(data);

            return(id);
        }
Exemple #4
0
 private void RpcServerTask_OnProcessPrepared(RemoteProcessWrapper wrapper, RpcProcess process)
 {
     configuration.RemoteProcessId = process.Id;
     wrapper.OnProcessPrepared    -= RpcServerTask_OnProcessPrepared;
 }
 public Task Detach(RpcProcess process, string accessToken)
 {
     owner.Detach(process.Id, accessToken);
     return(Task.CompletedTask);
 }
 public Task Stop(RpcProcess process, string accessToken)
 {
     owner.StopProcess(process.Id, accessToken);
     return(Task.CompletedTask);
 }
Exemple #7
0
 public Task ProcessRestarting(RpcProcess process, ProcessRestartReason reason)
 {
     server.ProcessRestarting(process, reason);
     return(Task.CompletedTask);
 }
Exemple #8
0
 private void ProcessRestarting(RpcProcess process, ProcessRestartReason reason) => processManager.RaiseProcessRestart(process, reason);