Exemplo n.º 1
0
        public Task StartAsync(CancellationToken token)
        {
            BasePath    = ServiceContext.Instance().Get("BasePath");
            ServiceName = ServiceContext.Instance().Get("ServiceName");
            ServiceExe  = ServiceContext.Instance().GetService(ServiceName, "Exe");
            ServiceArg  = ServiceContext.Instance().GetService(ServiceName, "Arg");
            IsPolling   = ServiceContext.Instance().GetService(ServiceName, "Type") == "Polling";

            ServiceArg = ServiceArg.Replace(@"%EXEDIR%", BasePath);

            IsElapsing = false;

            if (IsPolling)
            {
                var interval = int.Parse(ServiceContext.Instance().GetService(ServiceName, "Interval"));
                Timer          = new System.Timers.Timer(interval);
                Timer.Elapsed += Pooling;
                Timer.Start();
            }
            else
            {
                RunningProcess = Setup();
                RunningProcess.Start();

                var interval = 1000;
                Timer          = new System.Timers.Timer(interval);
                Timer.Elapsed += HealthCheck;
                Timer.Start();
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
 private void HealthCheck(object sender, System.Timers.ElapsedEventArgs e)
 {
     if (RunningProcess.HasExited && !IsElapsing)
     {
         IsElapsing     = true;
         RunningProcess = Setup();
         RunningProcess.Start();
         IsElapsing = false;
     }
 }