public static MethodContinuationData Read(Message message, ISerializerProvider serializerProvider)
 {
     return(new MethodContinuationData
     {
         IntentId = (string)message.Data["IntentId"],
         Service = (ServiceId)message.Data["Service"],
         Method = (PersistedMethodId)message.Data["Method"],
         TaskId = (string)message.Data["TaskId"],
         Caller = (CallerDescriptor)message.Data["Caller"],
         State = MethodInvocationDataTransformer.TryGetMethodContinuationState(message),
         Result = new SerializedValueContainer(
             (string)message.Data["Format"],
             message.Data["Result"],
             serializerProvider)
     });
 }
Exemple #2
0
        private async Task HandleCommandOrQuery(Message message)
        {
            var invocationData       = MethodInvocationDataTransformer.Read(message, _serializerProvider);
            var communicationMessage = new CommunicationMessage(message);

            TaskCompletionSource <InvokeRoutineResult> tcs = null;

            if (message.Data.TryGetValue("Notification", out var sink))
            {
                tcs = (TaskCompletionSource <InvokeRoutineResult>)sink;
                communicationMessage.WaitForResult = true;
            }

            var result = await _localTransitionRunner.RunAsync(invocationData, communicationMessage);

            tcs?.TrySetResult(result);
        }
Exemple #3
0
        public async Task <InvokeRoutineResult> InvokeAsync(
            MethodInvocationData data,
            InvocationPreferences preferences)
        {
            var message = new Message
            {
                Type = MessageType.InvokeMethod,
            };

            MethodInvocationDataTransformer.Write(message, data, _serializer);

            var result = new InvokeRoutineResult
            {
                Outcome = InvocationOutcome.Scheduled
            };

            if (preferences.Synchronous)
            {
                var completionNotification = new TaskCompletionSource <InvokeRoutineResult>();
                message.Data["Notification"] = completionNotification;

                _messageHub.Schedule(message);

                result = await completionNotification.Task;

                if (result.Result != null)
                {
                    result.Result = TaskResult.CreateEmpty(preferences.ResultValueType);
                    _serializer.Populate(_serializer.SerializeToString(result.Result), (IValueContainer)result.Result);
                }
            }
            else if (preferences.LockMessage)
            {
                result.MessageHandle = new MessageHandle(message, _messageHub);
            }
            else
            {
                _messageHub.Schedule(message);
            }

            return(result);
        }