Beispiel #1
0
        protected virtual OutOfProcessServerOptions ParseOptions(string[] args, out Mono.Options.OptionSet Options)
        {
            var ret = new OutOfProcessServerOptions();

            ret.Parse(args, out Options);

            return(ret);
        }
Beispiel #2
0
        public static IpcServer Create(OutOfProcessServerOptions Options, OutOfProcessFactory?Factory = default)
        {
            var EP = Options.ToEndpoint();

            var Server  = new IpcServer(EP);
            var Handler = new OutOfProcessController(Server, Options, Factory);

            Server.Handler = Handler;

            return(Server);
        }
        protected virtual OutOfProcessServerOptions DefaultServerOptions()
        {
            var ret = new OutOfProcessServerOptions()
            {
                ListenOn_Provider             = ProtocolProvider.Default,
                ListenOn_Host                 = $@"{Guid.NewGuid()}",
                ListenOn_Port                 = $@"{Guid.NewGuid()}",
                ListenOn_Key                  = $@"{Guid.NewGuid()}",
                ParentProcess_ID              = System.Diagnostics.Process.GetCurrentProcess().Id,
                Terminate_OnParentProcessExit = true,
                Terminate_OnStop              = true,
            };

            return(ret);
        }
        protected virtual System.Diagnostics.Process StartProcess(OutOfProcessServerOptions Options)
        {
            var FN = FileNameToLaunch();

            var PSI = new System.Diagnostics.ProcessStartInfo()
            {
                FileName        = FN,
                UseShellExecute = true,
                Arguments       = Options.ToString(),
            };

            var Proc = System.Diagnostics.Process.Start(PSI);

            return(Proc);
        }
Beispiel #5
0
        protected virtual async Task <int> MainAsync(OutOfProcessServerOptions ProcessOptions)
        {
            var ret  = -1;
            var Host = default(IpcServerBase);

            try {
                Host = OutOfProcessIpcServer.Create(ProcessOptions);

                await Host.StartHostingAsync()
                .DefaultAwait()
                ;


                ret = 0;
            } catch (Exception ex) {
                ex.Equals(ex);
            }

            try {
                if (Host != null)
                {
                    var Delays = new LinkedList <Task>();

                    var AddAll = !(ProcessOptions.Terminate_OnStop || ProcessOptions.Terminate_OnParentProcessExit);

                    if (AddAll || ProcessOptions.Terminate_OnStop)
                    {
                        Delays.AddLast(DelayTask_StopAsync(Host));
                    }

                    if ((AddAll || ProcessOptions.Terminate_OnParentProcessExit) && ProcessOptions.ParentProcess_ID is int ProcessID)
                    {
                        Delays.AddLast(DelayTask_ParentProcessAsync(ProcessID));
                    }

                    await Task.WhenAny(Delays)
                    .DefaultAwait()
                    ;
                }
            } catch (Exception ex) {
                ex.Equals(ex);
            }



            return(ret);
        }
        public virtual OutOfProcessServerOptions Clone()
        {
            var ret = new OutOfProcessServerOptions()
            {
                ListenOn_Provider = ListenOn_Provider,
                ListenOn_Host     = ListenOn_Host,
                ListenOn_Port     = ListenOn_Port,
                ListenOn_Key      = ListenOn_Key,

                ParentProcess_ID = ParentProcess_ID,

                Terminate_OnParentProcessExit = Terminate_OnParentProcessExit,
                Terminate_OnStop = Terminate_OnStop,
            };

            return(ret);
        }
Beispiel #7
0
 public OutOfProcessController(IpcServerBase Server, OutOfProcessServerOptions Options, OutOfProcessFactory?Factory = default)
 {
     V3 = new StoppableIpcServer(Server);
     V1 = new MultiIpcServer(Options.ToEndpoint());
     V2 = new OutOfProcessCloneableIpcServer(Options, Factory);
 }
 public OutOfProcessCloneableIpcServer(OutOfProcessServerOptions ProcessOptions, OutOfProcessFactory?Factory = default)
 {
     this.ProcessOptions = ProcessOptions;
     this.Factory        = Factory ?? CurrentProcessProcessHost.Instance;
 }