public void TestSchedule()
        {
            var schedules1 = new Schedules();
            schedules1.Add(new Schedule("13:00", "14:00"));
            Assert.IsTrue(schedules1.IsScheduleOn(new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,13,23,00)));
            Assert.IsTrue(schedules1.IsScheduleOn(new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,11,23,00)));

            var schedules2 = new Schedules();
            schedules2.Add(new Schedule("13:00", "14:00", "OFF"));
            Assert.IsFalse(schedules2.IsScheduleOn(new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,13,23,00)));
            Assert.IsTrue(schedules2.IsScheduleOn(new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,11,23,00)));

            var schedules4 = new Schedules("OFF");
            schedules4.Add(new Schedule("13:00", "14:00", "OFF"));
            Assert.IsFalse(schedules4.IsScheduleOn(new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,13,23,00)));
            Assert.IsFalse(schedules4.IsScheduleOn(new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,11,23,00)));

            var schedules5 = new Schedules("OFF");
            schedules5.Add(new Schedule("13:00", "14:00", "ON"));
            Assert.IsTrue(schedules5.IsScheduleOn(new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,13,23,00)));
            Assert.IsFalse(schedules5.IsScheduleOn(new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,11,23,00)));

            var schedules3 = new Schedules();
            schedules3.Add(new Schedule("13:00", "14:00", "OFF", DateTime.Now.DayOfWeek.ToString()));
            Assert.IsFalse(schedules3.IsScheduleOn(new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,13,23,00)));
            Assert.IsTrue(schedules3.IsScheduleOn(new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day+1,13,23,00)));
            Assert.IsTrue(schedules3.IsScheduleOn(new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,14,00,01)));
            Assert.IsTrue(schedules3.IsScheduleOn(new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day+1,14,00,01)));
        }
Example #2
0
 public BuildStatusConfig()
 {
     Settings    = new Settings();
     Schedules   = new Schedules();
     Controllers = new Controllers();
     Monitors    = new Monitors();
     Visualisers = new Visualisers();
     Transitions = new Transitions();
 }
 public BuildStatusConfig()
 {
     Settings    = new Settings();
     Schedules   = new Schedules();
     Controllers = new Controllers();
     Monitors    = new Monitors();
     Visualisers = new Visualisers();
     Transitions = new Transitions();
 }
        /// <summary>
        /// Starts this Master Controller. 
        /// </summary>
        public void Initialise()
        {
            _controllers = new List<InstanceController>();
            try {
                _config = BuildStatusConfig.Load();
            } catch (Exception ex) {
                throw new LogApplicationException("Could not load the Configuration File.",ex);
            }

            // Using the Data, Load and Instantiate each of the Visualisers and Monitors.
            // ---------------------------------------------------------------------------
            if (_config != null) {
                FileLogger.Logger.LogVerbose("Loading Controllers.");

                foreach (var controller in _config.Controllers) {

                    FileLogger.Logger.LogInformation("Controller: {0} with Monitor={1} and Visualiser={2}", controller.Name, controller.Monitor, controller.Visualiser);

                    if (_visualiser.Contains(controller.Visualiser)) throw new ApplicationException("A visualiser cannot be used more than once.");
                    if (_config.Visualisers[controller.Visualiser] == null) throw new ApplicationException("Invalid Visualiser Specified: " +controller.Visualiser);
                    if (_config.Monitors[controller.Monitor] == null) throw new ApplicationException("Invalid Monitor Specified: " +controller.Monitor);
                    if (_config.Transitions[controller.Transition] == null) throw new ApplicationException("Invalid Transition Specified: " +controller.Transition);

                    var monitorInfo     = _config.Monitors[controller.Monitor];
                    var visualiserInfo  = _config.Visualisers[controller.Visualiser];

                    if (monitorInfo != null && visualiserInfo != null) {
                        var monitor     = ComponentFactory<IMonitor>.CreateComponent(monitorInfo);
                        var visualiser  = ComponentFactory<IVisualiser>.CreateComponent(visualiserInfo);

                        if (monitor != null && visualiser != null) {
                            visualiser.Transitions = _config.Transitions[controller.Transition];
                            _controllers.Add(new InstanceController(controller.Name, monitor, visualiser));
                        }
                    }
                    else {
                        FileLogger.Logger.LogError("Invalid Monitor and/or Visualiser Data in Config file.");
                        throw new ApplicationException("Invalid Monitor and/or Visualiser Data in Config File");
                    }
                }
                _schedules = _config.Schedules;
            }
        }