Пример #1
0
            public DaemonRT(DaemonDto dto, string root, int delay)
            {
                this.delay = delay;
                this.dto   = dto.Clone();

                using (var disposer = new Disposer())
                {
                    process = new DaemonProcess(new DaemonProcess.Args
                    {
                        Executable = PathTools.Combine(root, dto.Path),
                        //id matches [a-zA_Z][a-zA_Z0-9_]*
                        Arguments = string.Format("Id={0} Daemon=True {1}", dto.Id, dto.Args),
                    });
                    disposer.Push(process);

                    status = "Starting...";

                    reader = new Runner(new Runner.Args {
                        ThreadName = string.Format("DAEMON_{0}_{1}_O", dto.Id, process.Id)
                    });
                    erroer = new Runner(new Runner.Args {
                        ThreadName = string.Format("DAEMON_{0}_{1}_E", dto.Id, process.Id)
                    });
                    disposer.Push(erroer);

                    disposer.Push(Dispose); //ensure cleanup order
                    erroer.Run(ErrorLoop);
                    reader.Run(ReadLoop);
                    reader.Run(UpdateRestart);
                    disposer.Clear();
                }
            }
Пример #2
0
        protected override void OnStart(string[] args)
        {
            base.OnStart(args);

            process = new DaemonProcess(new DaemonProcess.Args
            {
                Executable = ExecutableTools.Relative("SharpDaemon.Server.exe"),
                Arguments  = "Daemon=True",
            });
        }
Пример #3
0
        private void Process([NotNull] ITreeNode element, [NotNull] IHighlightingConsumer context)
        {
            var analyzerRunKind            = ElementProblemAnalyzerRunKind.FullDaemon;
            var interruptCheck             = DaemonProcess.GetCheckForInterrupt();
            var elementProblemAnalyzerData =
                new ElementProblemAnalyzerData(File, Settings, analyzerRunKind, interruptCheck);
            var analyzerDispatcher = Registrar.CreateDispatcher(elementProblemAnalyzerData);

            analyzerDispatcher.Run(element, context);
        }
        private void ExecuteRun(IStream io, params string[] tokens)
        {
            var exe  = tokens[1];
            var args = DaemonProcess.MakeCli(tokens, 2);

            DaemonProcess.Interactive(io, new DaemonProcess.Args
            {
                Executable = exe.Replace("{root}", downloads),
                Arguments  = args.ToString().Replace("{root}", downloads),
            });
        }
Пример #5
0
        public static void Web(Config config, Action action)
        {
            Directory.CreateDirectory(config.WebRoot);
            var zippath = PathTools.Combine(config.WebRoot, "Daemon.StaticWebServer.zip");

            if (File.Exists(zippath))
            {
                File.Delete(zippath);
            }
            Logger.Trace("Zipping to {0}", zippath);
            ZipTools.ZipFromFiles(zippath, ExecutableTools.Directory()
                                  , "Daemon.StaticWebServer.exe"
                                  , "SharpDaemon.dll"
                                  );
            var process = new DaemonProcess(new DaemonProcess.Args
            {
                Executable = ExecutableTools.Relative("Daemon.StaticWebServer.exe"),
                Arguments  = $"EndPoint={config.WebEP} Root=\"{config.WebRoot}\"",
            });

            Logger.Trace("Web process {0} {1} {2} {3}", process.Id, process.Name, process.Info.FileName, process.Info.Arguments);
            var reader = new Runner(new Runner.Args {
                ThreadName = "WEB"
            });

            reader.Run(() =>
            {
                var line = process.ReadLine();
                while (line != null)
                {
                    Logger.Trace("<w {0}", line);
                    line = process.ReadLine();
                }
            });
            using (reader)
            {
                using (process)
                {
                    action();
                }
            }
        }
        public override void Execute(Action <DaemonStageResult> committer)
        {
            Action globalHighlighter = () =>
            {
                var consumer = new DefaultHighlightingConsumer(this, mySettingsStore);
                File.ProcessThisAndDescendants(new GlobalProcessor(this, consumer));
                committer(new DaemonStageResult(consumer.Highlightings)
                {
                    Layer = 1
                });
            };

            using (var fibers = DaemonProcess.CreateFibers())
            {
                // highlight global space
                //if (DaemonProcess.FullRehighlightingRequired)
                fibers.EnqueueJob(globalHighlighter);
            }

            // remove all old highlightings
            //if (DaemonProcess.FullRehighlightingRequired)
            committer(new DaemonStageResult(EmptyArray <HighlightingInfo> .Instance));
        }
Пример #7
0
        private void ExecuteInstall(IStream io, params string[] tokens)
        {
            var id = tokens[2];

            installed.TryGetValue(id, out var dto);
            AssertTools.True(dto == null, "Daemon {0} already installed", id);
            AssertTools.True(Regex.IsMatch(id, "[a-zA_Z][a-zA_Z0-9_]*"), "Invalid id {0}", id);
            var exe = tokens[3];

            AssertTools.True(PathTools.IsChildPath(root, exe), "Invalid path {0}", exe);
            dto = new DaemonDto
            {
                Id   = id,
                Path = tokens[3],
                Args = DaemonProcess.MakeCli(tokens, 4),
            };
            var path = PathTools.Combine(root, dto.Path);

            AssertTools.True(File.Exists(path), "File {0} not found", dto.Path);
            Database.Save(database, dto);
            io.WriteLine("Daemon {0} installed as {1}", id, dto.Info("Path|Args"));
            ReloadDatabase();
        }
Пример #8
0
 public void ProcessAfterInterior(ITreeNode element) => DaemonProcess.Process(element, Consumer);
Пример #9
0
        public static void Shell(string path, string args, Action <ITestShell> action)
        {
            using (var disposer = new Disposer())
            {
                var process = new DaemonProcess(new DaemonProcess.Args
                {
                    Executable = path,
                    Arguments  = args,
                });

                Logger.Trace("Shell process {0} {1}", process.Id, process.Name, process.Info.FileName);
                Logger.Trace("Shell path {0}", process.Info.FileName);
                Logger.Trace("Shell args {0}", process.Info.Arguments);

                var shell  = new TestShell();
                var reader = new Runner(new Runner.Args {
                    ThreadName = "SDTOUT"
                });
                var erroer = new Runner(new Runner.Args {
                    ThreadName = "STDERR"
                });
                var writer = new Runner(new Runner.Args {
                    ThreadName = "STDIN"
                });
                reader.Run(() =>
                {
                    var line = process.ReadLine();
                    while (line != null)
                    {
                        Logger.Trace("<o {0}", line);
                        shell.WriteLine("<o {0}", line);
                        line = process.ReadLine();
                    }
                    shell.WriteLine(Environ.NewLines);
                });
                erroer.Run(() =>
                {
                    var line = process.ReadError();
                    while (line != null)
                    {
                        Logger.Trace("<e {0}", line);
                        shell.WriteLine("<e {0}", line);
                        line = process.ReadError();
                    }
                });
                writer.Run(() =>
                {
                    var line = shell.ReadLine();
                    while (line != null)
                    {
                        Logger.Trace("i> {0}", line);
                        process.WriteLine(line);
                        line = shell.ReadLine();
                    }
                });
                disposer.Push(erroer);
                disposer.Push(reader);
                disposer.Push(process);
                disposer.Push(writer);
                disposer.Push(shell);

                action(shell);
            }
        }
Пример #10
0
 /// <summary>
 /// The entry point of the program, where the program control starts and ends.
 /// </summary>
 /// <param name="args">The command-line arguments.</param>
 public static void Main(string[] args)
 {
     DaemonProcess.Run(args);
 }