Beispiel #1
0
        public void SaveAndLoadConfigData()
        {
            try {
                var config = new BuildStatusConfig();
                config.Settings.Add("PollFrequency", "15");

                var monitor1 = config.Monitors.Add("Monitor1", "Assembly1", "Class1");
                monitor1.Settings.Add("Setting1", "Value1");
                var monitor2 = config.Monitors.Add("Monitor2", "Assembly2", "Class2");
                monitor2.Settings.Add("Setting2", "Value2");
                monitor2.Settings.Add("Setting3", "Value3");

                var visualiser1 = config.Visualisers.Add("Visualiser1", "Assembly1", "Class1");
                visualiser1.Settings.Add("Setting1", "Value1");
                var visualiser2 = config.Visualisers.Add("Visualiser2", "Assembly2", "Class2");
                visualiser2.Settings.Add("Setting2", "Value2");
                visualiser2.Settings.Add("Setting3", "Value3");

                config.Save("C:\\Test.xml");

                BuildStatusConfig newConfig = BuildStatusConfig.Load("C:\\Test.xml");

                Assert.AreEqual(config.Settings["PollFrequency"], newConfig.Settings["PollFrequency"]);
            }
            catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
        }
        /// <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;
            }
        }
Beispiel #3
0
        public void SaveAndLoadConfigData()
        {
            try {
                var config = new BuildStatusConfig();
                config.Settings.Add("PollFrequency", "15");

                var setting = new Settings();
                setting.Add("Host", "nzakledci01:8080");
                setting.Add("ProjectID", "project8");

                var monitor1 = config.Monitors.Add("Monitor1", "Assembly1", "Class1", setting);
                var monitor2 = config.Monitors.Add("Monitor2", "Assembly2", "Class2", setting);

                var visualiser1 = config.Visualisers.Add("Visualiser1", "Assembly1", "Class1", setting);
                var visualiser2 = config.Visualisers.Add("Visualiser2", "Assembly2", "Class2", setting);

                config.Schedules.Add(new Schedule("6:00AM", "8:00PM", "ON", "Week"));
                config.Schedules.DefaultState = "OFF";

                config.Save("C:\\Test.xml");

                BuildStatusConfig newConfig = BuildStatusConfig.Load("C:\\Test.xml");

                Assert.AreEqual(config.Settings["PollFrequency"], newConfig.Settings["PollFrequency"]);
            }
            catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #4
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        private static void Main(string[] args)
        {
            InitialiseLogFile();
            FileLogger.Logger.LogInformation("BuildStatusMonitor Application Starting.");
            FileLogger.Logger.LogInformation("Current Directory is '{0}'", Directory.GetCurrentDirectory());
            FileLogger.Logger.LogInformation("Assembly Directory is '{0}'", Assembly.GetExecutingAssembly().Location);
            FileLogger.Logger.LogInformation("Logging the attached Delcom Lights.");
            foreach (var light in DelcomManager.GetDevices())
            {
                FileLogger.Logger.LogInformation(light);
            }

            AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
            if (Environment.UserInteractive)
            {
                var parameter = string.Concat(args);
                try {
                    switch (parameter)
                    {
                    case "--install":
                        FileLogger.Logger.LogInformation("Installing Service.");
                        ManagedInstallerClass.InstallHelper(new[] { Assembly.GetExecutingAssembly().Location });
                        break;

                    case "--uninstall":
                        FileLogger.Logger.LogInformation("UnInstalling Service.");
                        ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location });
                        break;

                    case "--run":
                        FileLogger.Logger.LogInformation("Running in Test Mode.");
                        var controller = new BuildStatusController();
                        controller.Initialise();
                        controller.PollMonitors();
                        controller.Finalise();
                        break;

                    case "--default":
                        FileLogger.Logger.LogInformation("Creating DEFAULT settings file.");
                        BuildStatusConfig.CreateDefaultConfigFile();
                        break;

                    default:
                        Console.WriteLine("BuildStatusMonitor");
                        Console.WriteLine("--install     To install as a service.");
                        Console.WriteLine("--uninstall   To uninstall the service.");
                        Console.WriteLine("--run         To execute a single poll/execution.");
                        Console.WriteLine("--default     To create a sample default config file.");
                        Console.WriteLine("");
                        Console.WriteLine("Attached Lights are:");
                        foreach (var light in DelcomManager.GetDevices())
                        {
                            Console.WriteLine(light);
                        }
                        break;
                    }
                }
                catch (Exception ex) {
                    FileLogger.Logger.LogError("Error starting the Application", ex);
                }
            }
            else
            {
                Run(new Program());
            }
            FileLogger.Logger.LogInformation("BuildStatusMonitor Application Finished.");
            FileLogger.Logger.Terminate();
        }