Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Monitor Devices From {0}", AzureIoTHubDevices.HostName);
            var ctsForDataMonitoring = new CancellationTokenSource();
            Cls();
            var azureIoTHubMonitor = new AzureIoTHubMonitor(ctsForDataMonitoring, AzureIoTHubDevices.AllDevices);
            while (true)
            {
                var result = azureIoTHubMonitor.Monitor("");
                if (result != null)
                {
                    foreach (var r in result)
                        Console.WriteLine(r.ToString());
                }

                if (Console.KeyAvailable)
                {
                    var k = Console.ReadKey().Key;
                    if (k == ConsoleKey.Q)
                    {
                        azureIoTHubMonitor.Stop();
                        break;
                    }
                    if (k == ConsoleKey.C) Cls();
                }
            }
        }
Пример #2
0
        public HttpResponseMessage Get()
        {
            var deviceId       = string.Empty;
            var action         = string.Empty;
            DateTime startTime = DateTime.Now;
            var lastMaxSample  = 32;
            var r              = new EditorApiResult();
            var nameValues     = base.Request.RequestUri.ParseQueryString();
            r.Url              = base.Request.RequestUri.ToString();

            if (nameValues.AllKeys.Contains("deviceId"))
            {
                deviceId = nameValues["deviceId"];
            }
            if (nameValues.AllKeys.Contains("action"))
            {
                action = nameValues["action"];
            }
            if (nameValues.AllKeys.Contains("startTime"))
            {
                var s = nameValues["startTime"];
                startTime = DateTime.Parse(s);
            }
            if (nameValues.AllKeys.Contains("lastMaxSample"))
            {
                var s = nameValues["lastMaxSample"];
                lastMaxSample = int.Parse(s);
            }
            if (string.IsNullOrEmpty(deviceId))
            {
                r.SetStatus(false);
            }
            else
            {
                //if(action.ToLowerInvariant() =="cleardata")
                  //  _azureIoTHubMonitor.ClearData();

                if (_azureIoTHubMonitor == null || startTime != _azureIoTHubMonitor.StartTime)
                {
                    if (_azureIoTHubMonitor != null)
                        _azureIoTHubMonitor.Clean();
                    _azureIoTHubMonitor = new AzureIoTHubMonitor(null, AzureIoTHubDevices.AllDevices, startTime);
                }
                r.Data = _azureIoTHubMonitor.Monitor(deviceId, lastMaxSample);
                r.SetStatus(r.Data != null);
            }

            return new HttpResponseMessage()
            {
                Content = new StringContent(r.ToJson(), Encoding.UTF8, "text/json")
            };
        }