public async void ListenForActivity() { List <Task> taskList = new List <Task>(); await foreach (ActivityRequest activityRequest in activityReader.ReadAllAsync()) { if (activityRequest.Played) { communication.SendDebugMessage($"Replaying Notification {activityRequest.Id}: {activityRequest}"); } else { activityRequest.Played = true; communication.SendDebugMessage($"Playing Notification {activityRequest.Id}: {activityRequest}"); } await activityRequest.Execute().WithCancellation(cancellationTokenSource.Token); lastFinishedRequest = activityRequest; taskList.Clear(); //2 second delay between notifications await Task.Delay(2000, cancellationTokenSource.Token); } }
public void QueueActivity(ActivityRequest activity, bool approved) { activity.Id = nextActivityID++; if (!approved) { //Submit as request instead pendingActivityRequests.Add(activity.Id, activity); communication.NotifyPendingNotification(activity.Id, activity.ToString()); return; } activityDict.Add(activity.Id, activity); communication.NotifyNotification(activity.Id, activity.ToString()); activityWriter.TryWrite(activity); }
public bool UpdatePendingRequest(int index, bool approve) { if (!pendingActivityRequests.ContainsKey(index)) { return(false); } ActivityRequest activity = pendingActivityRequests[index]; pendingActivityRequests.Remove(index); if (approve) { //Queue approved activity activityDict.Add(activity.Id, activity); communication.NotifyNotification(activity.Id, activity.ToString()); activityWriter.TryWrite(activity); } return(true); }