コード例 #1
0
ファイル: DaemonInfo.cs プロジェクト: dekkerb115/Bam.Net
        public DaemonProcess ToDaemonProcess(string workingDirectory)
        {
            DaemonProcess process = ToDaemonProcess();

            process.FileName         = Path.Combine(workingDirectory, FileName);
            process.WorkingDirectory = workingDirectory;
            return(process);
        }
コード例 #2
0
        public static DaemonProcessMonitor Start(DaemonProcess process, ILogger logger = null)
        {
            logger = logger ?? Log.Default;
            logger.AddEntry("Monitoring {0}", process.Name);
            DaemonProcessMonitor result = new DaemonProcessMonitor(process, logger);

            process.StandardOut += (o, a) => logger.Info(((DaemonProcessEventArgs)a).Message);
            process.ErrorOut    += (o, a) => logger.Warning(((DaemonProcessEventArgs)a).Message);
            process.Start(result.TryRestart);
            return(result);
        }
コード例 #3
0
 private void StartProcess(DaemonProcess process)
 {
     try
     {
         string key = process.ToString();
         Logger.AddEntry("Starting {0}", key);
         process.Subscribe(Logger);
         _monitors.Add(key, DaemonProcessMonitor.Start(process));
     }
     catch (Exception ex)
     {
         Logger.AddEntry("Error starting process {0}: {1}", ex, process?.ToString(), ex.Message);
     }
 }
コード例 #4
0
        public DaemonProcessMonitor(DaemonProcess process, ILogger logger = null)
        {
            Logger            = logger ?? Log.Default;
            MaxLogSizeInBytes = 1048576;
            Process           = process;
            FlushLineCount    = 25;
            FlushTimeout      = 5000;
            OutLogName        = Path.Combine(ServiceConfig.LogRoot, $"{Process.Name}_out.txt");
            ErrorLogName      = Path.Combine(ServiceConfig.LogRoot, $"{Process.Name}_err.txt");
            Logger.AddEntry("Outlog for {0} is {1}", Process.Name, OutLogName);
            Logger.AddEntry("ErrorLog for {0} is {1}", Process.Name, ErrorLogName);
            StandardOutLog = new FileInfo(OutLogName);
            ErrorOutLog    = new FileInfo(ErrorLogName);

            StartTimedFlush();
        }
コード例 #5
0
 public virtual CoreServiceResponse AddProcess(DaemonProcessInfo processInfo)
 {
     try
     {
         DaemonProcess        process = processInfo.CopyAs <DaemonProcess>();
         List <DaemonProcess> current = new List <DaemonProcess>(Processes)
         {
             process
         };
         Processes = current.ToArray();
         Processes.ToJsonFile(ConfigFile);
         StartProcess(process);
         return(new CoreServiceResponse {
             Success = true
         });
     }
     catch (Exception ex)
     {
         return(new CoreServiceResponse {
             Success = false, Message = ex.Message
         });
     }
 }