public AlarmService(EmailService emailService)
 {
     _emailService = emailService;
     _errorCounts = new Dictionary<Check, int>();
     _paused = new Dictionary<Check, bool>();
     _checks = new Check[0];
 }
 public SendEmail(XmlNode input, EmailService emailService)
 {
     _emailService = emailService;
     foreach (var childNode in input.ChildNodes.Cast<XmlNode>().Where(childNode => String.Equals(childNode.Name, "Address", StringComparison.InvariantCultureIgnoreCase)))
     {
         _address = childNode.FirstChild.Value;
     }
 }
 public XmlFile(string configFilePathRoot, IMessageService messageService, EmailService emailService, AlarmService alarmService, SoundService soundService, Func<string, int, Check> checkFactory)
 {
     _configFilePathRoot = configFilePathRoot;
     _messageService = messageService;
     _emailService = emailService;
     _alarmService = alarmService;
     _soundService = soundService;
     _checkFactory = checkFactory;
 }
        public static void Main()
        {
            Log.Logger = new LoggerConfiguration()
                .WriteTo.ColoredConsole()
                .CreateLogger();

            Log.Information("Application Start");

            try
            {
                _tempPath = AppDomain.CurrentDomain.BaseDirectory + "TEMP";
                var cleanupService = new CleanupService(_tempPath);
                var messageService = new MessageService();
                var screenshotService = new ScreenshotService();
                var emailController = new EmailService(_tempPath, screenshotService, messageService, cleanupService);
                var soundController = new SoundService(messageService);
                var alarmService = new AlarmService(emailController);

                var guiController = new GuiController();

                guiController.StartUp(() => _listOfChecks ?? new Check[0]);

                _listOfChecks = new XmlFile(_configFilePathRoot, messageService, emailController, alarmService, soundController,
                    (s, i) => new Check(i, alarmService, c => guiController.Update(c))).Load();

                alarmService.PrepareList(_listOfChecks);

                foreach (var c in _listOfChecks)
                    c.Activate();

                Thread.Sleep(Timeout.Infinite);

            }
            catch (Exception e)
            {
                Log.Error(e, "Failed to start application");
            }
        }
        private static void StartMonitoringFramework(ProductMonitorHubService hubService)
        {
            Log.Information("Initializing services");

            var tempPath = AppDomain.CurrentDomain.BaseDirectory + "TEMP";
            var cleanup = new CleanupService(tempPath);
            var messageService = new MessageService();
            var screenshotService = new ScreenshotService();
            var emailController = new EmailService(tempPath, screenshotService, messageService, cleanup);
            var soundController = new SoundService(messageService);
            var alarmService = new AlarmService(emailController);

            Log.Information("Loading configuration");

            var xmlFile = new XmlFile(_configFilePathRoot, messageService, emailController, alarmService, soundController,
                checkFactory: (s, i) => new Check(i, alarmService, hubService.UpdateCheck));

            var listOfChecks = xmlFile.Load();

            alarmService.PrepareList(listOfChecks);

            hubService.UpdateChecks(listOfChecks);

            Log.Information("Running all checks offthread");

            Task.Factory.StartNew(() => Parallel.ForEach(listOfChecks, check => check.Activate()), TaskCreationOptions.LongRunning);
        }