static async void Run() { List<HubReference> hubs = new List<HubReference>(); while (true) { Console.WriteLine("Receive messages\n"); string watcherTableConnectionString = ConfigurationManager.ConnectionStrings["WatcherTableStorage"].ToString(); CloudStorageAccount storageAccount = CloudStorageAccount.Parse(watcherTableConnectionString); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable table = tableClient.GetTableReference("watcher"); TableQuery<WatcherRecordModel> rangeQuery = new TableQuery<WatcherRecordModel>().Take(10000); IEnumerable<WatcherRecordModel> records = table.ExecuteQuery(rangeQuery); foreach (WatcherRecordModel record in records) { if (record.Timeout < DateTime.Now) { TableOperation deleteOperation = TableOperation.Delete(record); table.Execute(deleteOperation); } else if (!IsHubInList(record, hubs)) { HubReference hub = new HubReference(record.IoTHubConnectionString, record.IotHubEndpoint); hub.GetMessagesFromHub(); } } Thread.Sleep(60 * 1000); } }
static async void Run() { List <HubReference> hubs = new List <HubReference>(); while (true) { Console.WriteLine("Receive messages\n"); string watcherTableConnectionString = ConfigurationManager.ConnectionStrings["WatcherTableStorage"].ToString(); CloudStorageAccount storageAccount = CloudStorageAccount.Parse(watcherTableConnectionString); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable table = tableClient.GetTableReference("watcher"); TableQuery <WatcherRecordModel> rangeQuery = new TableQuery <WatcherRecordModel>().Take(10000); IEnumerable <WatcherRecordModel> records = table.ExecuteQuery(rangeQuery); foreach (WatcherRecordModel record in records) { if (record.Timeout < DateTime.Now) { TableOperation deleteOperation = TableOperation.Delete(record); table.Execute(deleteOperation); } else if (!IsHubInList(record, hubs)) { HubReference hub = new HubReference(record.IoTHubConnectionString, record.IotHubEndpoint); hub.GetMessagesFromHub(); } } Thread.Sleep(60 * 1000); } }