public bool TryRegisterNew(object taskCompletionSource, out TriggerReference triggerReference) { if (taskCompletionSource == null) { throw new ArgumentNullException(nameof(taskCompletionSource)); } if (!TaskCompletionSourceAccessor.IsTaskCompletionSource(taskCompletionSource)) { throw new ArgumentException($"Input object must be a TaskCompletionSource`1, but got {taskCompletionSource.GetType()}", nameof(taskCompletionSource)); } var task = TaskCompletionSourceAccessor.GetTask(taskCompletionSource); triggerReference = task.AsyncState as TriggerReference; if (triggerReference != null) { return(false); } triggerReference = new TriggerReference { Id = _numericIdGenerator.NewId() }; task.SetAsyncState(triggerReference); return(true); }
public void ActivateTrigger(Task trigger, TriggerReference triggerReference) { if (Context.ScheduledActions.ActivateTriggerIntents == null) { Context.ScheduledActions.ActivateTriggerIntents = new List <ActivateTriggerIntent>(); } Context.ScheduledActions.ActivateTriggerIntents.Add( new ActivateTriggerIntent { TriggerId = triggerReference.Id, Value = trigger.ToTaskResult() }); }
public void AwaitTrigger(TriggerReference triggerReference) { Context.ScheduledActions.SaveRoutineState = true; Context.ScheduledActions.SubscribeToTriggerIntent = new SubscribeToTriggerIntent { TriggerId = triggerReference.Id, Continuation = new ContinuationDescriptor { ServiceId = Context.ServiceId, Routine = Context.RoutineDescriptor } }; CompleteTransition(); }
public void AwaitTrigger(TriggerReference triggerReference) { Context.ScheduledActions.SaveRoutineState = true; if (Context.ScheduledActions.SubscribeToTriggerIntents == null) { Context.ScheduledActions.SubscribeToTriggerIntents = new List <SubscribeToTriggerIntent>(); } Context.ScheduledActions.SubscribeToTriggerIntents.Add(new SubscribeToTriggerIntent { TriggerId = triggerReference.Id, Continuation = new ContinuationDescriptor { Service = Context.ServiceRef.Id, Method = Context.MethodId, TaskId = triggerReference.Id } }); CompleteTransition(); }