public async void Execute() { while (true) { IEnumerable <StillInterestedEntity> messages = null; do { var day = DateTimeOffset.UtcNow.AddDays(-configurationProvider.GetConfiguration <int>("stillInterestedTimeoutDays")); TableQuery <StillInterestedEntity> tableQuery = new TableQuery <StillInterestedEntity>().Where(TableQuery.CombineFilters( TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.LessThanOrEqual, day), TableOperators.And, TableQuery.GenerateFilterConditionForBool("ReceivedAnswer", QueryComparisons.Equal, false))); messages = await tableStorageProvider.RetrieveFromTableAsync("stillInterested", tableQuery); if (messages.Any(x => !x.ReceivedAnswer)) { foreach (var message in messages.Where(x => !x.ReceivedAnswer)) { var conversationReference = JsonConvert.DeserializeObject <ConversationReference>(message.ConversationReference).GetPostToBotMessage(); var client = new ConnectorClient(new Uri(conversationReference.ServiceUrl)); using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, conversationReference)) { var botData = scope.Resolve <IBotData>(); await botData.LoadAsync(CancellationToken.None); var task = scope.Resolve <IDialogTask>(); //interrupt the stack var dialog = new StillInterestedDialog(message); task.Call(dialog.Void <object, IMessageActivity>(), null); await task.PollAsync(CancellationToken.None); //flush dialog stack await botData.FlushAsync(CancellationToken.None); } } await tableStorageProvider.DeleteFromTableAsync("stillInterested", messages); } } while (messages.Any()); Thread.Sleep(TimeSpan.FromHours(configurationProvider.GetConfiguration <int>("stillInterestedPollIntervalHours"))); } }
private async Task UpdateUserTableEntity(Activity activity) { var entity = new UserEntity() { ChannelId = activity.ChannelId, UserId = activity.From.Id, ConversationReference = JsonConvert.SerializeObject(activity.AsMessageActivity().ToConversationReference()), Notifications = true, LastActiveTime = DateTime.UtcNow }; var existingEntity = await tableStorageProvider.RetrieveFromTableAsync <UserEntity>("users", entity.PartitionKey, entity.RowKey); if (existingEntity != null) { entity.Notifications = existingEntity.Notifications; } await tableStorageProvider.SendToTableAsync("users", entity); }