コード例 #1
0
        public void PackageUpgradeCompatibilityDeserializationTest()
        {
            var dataConverter = new JsonDataConverter();

            string serialized = File.ReadAllText(@"TestData\v1.0\SerializedTaskMessage.json");
            var    message    = dataConverter.Deserialize <TaskMessage>(serialized);

            Assert.IsNotNull(message);

            serialized = File.ReadAllText(@"TestData\v1.0\SerializedOrchestrationStateNoTags.json");
            var state = dataConverter.Deserialize <OrchestrationState>(serialized);

            Assert.IsNotNull(state);

            serialized = File.ReadAllText(@"TestData\v1.0\SerializedRuntimeState.json");
            var runtimeState = dataConverter.Deserialize <OrchestrationRuntimeState>(serialized);

            Assert.IsNotNull(runtimeState);

            serialized = File.ReadAllText(@"TestData\vnext\SerializedExecutionStartedEvent.json");
            var executionStarted = dataConverter.Deserialize <ExecutionStartedEvent>(serialized);

            Assert.IsNotNull(executionStarted);

            serialized = File.ReadAllText(@"TestData\vnext\SerializedStateWithTags.json");
            state      = dataConverter.Deserialize <OrchestrationState>(serialized);
            Assert.IsNotNull(state);
        }
コード例 #2
0
        /// <summary>
        /// Gets the input of the current orchestrator function as a deserialized value.
        /// </summary>
        /// <typeparam name="T">Any data contract type that matches the JSON input.</typeparam>
        /// <returns>The deserialized input value.</returns>
        public T GetInput <T>()
        {
            this.ThrowIfInvalidAccess();

            // Nulls need special handling because the JSON converter will throw
            // if you try to convert a JSON null into a CLR value type.
            if (this.serializedInput == null || this.serializedInput == "null")
            {
                return(default(T));
            }

            return(SharedJsonConverter.Deserialize <T>(this.serializedInput));
        }
コード例 #3
0
        internal static T ParseActivityInput <T>(string rawInput)
        {
            // Copied from DTFx Framework\TaskActivity.cs
            T      parameter = default(T);
            JArray array     = JArray.Parse(rawInput);

            if (array != null)
            {
                int parameterCount = array.Count;
                if (parameterCount > 1)
                {
                    throw new ArgumentException(
                              "Activity implementation cannot be invoked due to more than expected input parameters.  Signature mismatch.");
                }

                if (parameterCount == 1)
                {
                    JToken token = array[0];
                    var    value = token as JValue;
                    if (value != null)
                    {
                        parameter = value.ToObject <T>();
                    }
                    else
                    {
                        string serializedValue = token.ToString();
                        parameter = SharedJsonConverter.Deserialize <T>(serializedValue);
                    }
                }
            }

            return(parameter);
        }
コード例 #4
0
        public async Task <TResult> ExecuteTask <TResult>(string name, string version, params object[] parameters)
        {
            string       serializedInput = dataConverter.Serialize(parameters);
            TaskActivity activity        = objectManager.GetObject(name, version);

            Interlocked.Increment(ref pendingExecutions);

            string serializedResult = await Task.Factory.StartNew(() =>
            {
                try
                {
                    string result = activity.RunAsync(null, serializedInput).Result;
                    return(result);
                }
                catch (AggregateException e)
                {
                    e = e.Flatten();
                    if (e.InnerException is TaskFailureException)
                    {
                        var taskFailureException = e.InnerException as TaskFailureException;
                        Exception cause          = Utils.RetrieveCause(taskFailureException.Details, dataConverter);
                        throw new TaskFailedException(0, 0, name, version, taskFailureException.Message, cause);
                    }
                    throw new TaskFailedException(0, 0, name, version, e.Message, e);
                }
                finally
                {
                    Interlocked.Decrement(ref pendingExecutions);
                }
            });

            var r = dataConverter.Deserialize <TResult>(serializedResult);

            return(r);
        }
コード例 #5
0
        public void DataConverterDeserializationTest()
        {
            var dataConverter = new JsonDataConverter();

            string serializedState = File.ReadAllText(@"TestData\SerializedExecutionStartedEvent.json");
            var    startedEvent    = dataConverter.Deserialize <ExecutionStartedEvent>(serializedState);

            Assert.IsNotNull(startedEvent);

            serializedState = File.ReadAllText(@"TestData\SerializedOrchestrationState.json");
            var runtimeState = dataConverter.Deserialize <OrchestrationRuntimeState>(serializedState);

            Assert.IsNotNull(runtimeState);

            serializedState = File.ReadAllText(@"TestData\SerializedOrchestrationStateWithTags.json");
            runtimeState    = dataConverter.Deserialize <OrchestrationRuntimeState>(serializedState);
            Assert.IsNotNull(runtimeState);
        }
コード例 #6
0
        public T GetStatus <T>(OrchestrationInstance instance)
        {
            if (instance == null || string.IsNullOrWhiteSpace(instance.InstanceId))
            {
                throw new ArgumentException("instance");
            }

            TaskOrchestration execution = null;

            if (!(currentExecutions.TryGetValue(instance.InstanceId, out execution) ||
                  completedExecutions.TryGetValue(instance, out execution)))
            {
                throw new OrchestrationFrameworkException("Unknown orchestration instance.  Id: " + instance.InstanceId);
            }

            string status = execution.GetStatus();

            return(dataConverter.Deserialize <T>(status));
        }
コード例 #7
0
        /// <summary>
        /// Gets the input of the current activity function as a deserialized value.
        /// </summary>
        /// <typeparam name="T">Any data contract type that matches the JSON input.</typeparam>
        /// <returns>The deserialized input value.</returns>
        public T GetInput <T>()
        {
            if (this.serializedInput == null)
            {
                return(default(T));
            }

            JToken jToken = this.GetInputAsJson();
            var    value  = jToken as JValue;

            if (value != null)
            {
                return(value.ToObject <T>());
            }

            string serializedValue = jToken.ToString(Formatting.None);

            return(SharedJsonConverter.Deserialize <T>(serializedValue));
        }