Ejemplo n.º 1
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            var db = new TelegramsDb();

            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    const int inputPinNumber = 18;
                    var infinite             = new TimeSpan(0, 0, 0, 0, Timeout.Infinite);
                    var telegram             = TelegramRecorder.Read(
                        inputPinNumber,
                        infinite,
                        TimeSpan.FromMilliseconds(100),
                        CancellationToken.None);
                    db.Add(DoConvert.ToDo(telegram));
                }
            });

            _deferral = taskInstance.GetDeferral();
            var restRouteHandler = new RestRouteHandler();

            restRouteHandler.RegisterController <SprinklerController>();

            var telegramHandler = new RestRouteHandler();

            telegramHandler.RegisterController <TelegramsController>(db);

            var httpServer = new HttpServer(1390);

            httpServer.RegisterRoute("sprinkler", restRouteHandler);
            httpServer.RegisterRoute("inbox", telegramHandler);

            httpServer.StartServerAsync().Wait();
        }
Ejemplo n.º 2
0
 public TelegramsController(TelegramsDb db)
 {
     _db = db;
 }