Пример #1
0
        internal async static Task Initialize(string url = "http://localhost:9003/webapi/")
        {
            Logger.Log("Initializing to serial service at {0}", url);
            Instance = new ThermostatDaemon(url);

            await Instance.InitializeInstance();
        }
Пример #2
0
        public async Task Run(string[] args)
        {
            string assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            int    lastPoint       = assemblyVersion.LastIndexOf('.');

            assemblyVersion = assemblyVersion.Substring(0, lastPoint);
            Logger.Log("HippotronicsThermoDaemon version {0} started", assemblyVersion);

            // Set up REST services in OWIN web server
            var url    = String.Format("http://*:{0}/", Config.Port);
            var webapp = WebApp.Start(url, new Action <IAppBuilder>(Configuration));

            // Start the Thermostat Daemon. This will throw if there is a problem and the app will exit
            await ThermostatDaemon.Initialize(Config.SerialService);

            // See if we need to use some averaging
            ThermostatDaemon.Instance.SetMedianBehavior(Config.UseMedian, Config.MedianSamples);

            Console.CancelKeyPress += (sender, e) =>
            {
                Logger.Log("HippotronicsThermoDaemon stopped");
                webapp.Dispose();
            };

            Logger.Log("HippotronicsThermoDaemon running");

            // Schedule purge of records that have not been updated
            await ScheduleNextUpdate();


            // Run until Ctrl+C
            Console.CancelKeyPress += (sender, e) =>
            {
                _endEvent.Set();
            };

            // Start watchdog
            Watchdog.Dog.ScheduleDog();

            // Wait for normal termination
            _endEvent.WaitOne();

            Logger.Log("HippotronicsThermoDaemon ending");
            Environment.Exit(0);        // Normal exit
        }