Beispiel #1
0
        public bool Start(HostControl hostControl)
        {
            try
            {
                Log.Info("Start command received.");

                // load from config
                _serviceConfig.Load();

                foreach (var item in _serviceConfig.Items)
                {
                    Log.Info($"Scheduling {item.Name}, Delay {item.Delay}, Interval {item.Interval}, Active {item.Active}");

                    // initiate schedules
                    _threadScheduler.LoadSchedule(() =>
                    {
                        try
                        {
                            Log.Info($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}: Starting process {item.Name}");

                            (new ProcessController {
                                CreateNoWindow = true, UseShellExecute = false
                            })
                            .Start(item.File, item.Options);
                        }
                        catch (Exception ex)
                        {
                            Trace.TraceError($"Process {item.Name} failed!", ex);
                        }
                    },
                                                  item.Delay,
                                                  item.Interval,
                                                  item.Active);
                }

                // Start SHMHLA (if specified and found)
                if (File.Exists(_settings.HlaCorePath))
                {
                    _processController.Start(_settings.HlaCorePath);
                }
                else
                {
                    Log.Warn($"SHMHLA not found at {_settings.HlaCorePath}");
                }

                _threadScheduler.StartAll();
            }
            catch (Exception ex)
            {
                Log.Error($"Error.", ex);
            }
            return(true);
        }