コード例 #1
0
        public static void Main(string[] args)
        {
            //No arguments are currently read when ran in service mode.
            if (!Environment.UserInteractive)
            {
                ServiceBase.Run(new SensorMonitoringService());
                return;
            }

            if (Parser.Default.ParseArguments(args, Options))
            {
                _output = new ProgramOutput(Options);

                if (Options.SingleRun)
                {
                    _output.Print("Initializing single run for sensor {0}", Settings.Default.SensorId);
                    var monitor = new Monitor(GetConnectionInformation(), Settings.Default.SensorId);
                    monitor.ReadAndReport();
                    _output.Print("Run finished.");
                    return;
                }

                if (Options.Install)
                {
                    _output.Print("Installing service...");
                    Install();
                    _output.Print("Service installed. Exiting...");
                    return;
                }

                if (Options.Uninstall)
                {
                    _output.Print("Installing service...");
                    Uninstall();
                    _output.Print("Service installed. Exiting...");
                    return;
                }               
            }
            else
            {
                _output = new ConsoleOutput();
            }
            _output.Print(Options.GetUsage());
        }
コード例 #2
0
 public MonitoringWorker(ConnectionInformation connectionInformation, int sensorId) : base(TimeSpan.FromSeconds(10))
 {
     _monitor = new Monitor(connectionInformation, sensorId);
 }