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); }
/// <summary> /// Sets the JSON-serializeable output of the current orchestrator function. /// </summary> /// <remarks> /// If this method is not called explicitly, the return value of the orchestrator function is used as the output. /// </remarks> /// <param name="output">The JSON-serializeable value to use as the orchestrator function output.</param> internal void SetOutput(object output) { this.ThrowIfInvalidAccess(); if (this.IsOutputSet) { throw new InvalidOperationException("The output has already been set of this orchestration instance."); } if (output != null) { JToken json = output as JToken; if (json != null) { this.serializedOutput = json.ToString(Formatting.None); } else { this.serializedOutput = SharedJsonConverter.Serialize(output); } } else { this.serializedOutput = null; } }
public void RaiseEvent(OrchestrationInstance instance, string eventName, object eventData) { if (instance == null || string.IsNullOrWhiteSpace(instance.InstanceId)) { throw new ArgumentException("instance"); } TaskOrchestration execution = null; if (!currentExecutions.TryGetValue(instance.InstanceId, out execution)) { throw new OrchestrationFrameworkException("Unknown orchestration instance. Id: " + instance.InstanceId); } string serializedInput = dataConverter.Serialize(eventData); execution.RaiseEvent(null, eventName, serializedInput); }
public async Task <string> GetOrchestrationRuntimeStateAsync(string instanceId) { var session = await this.orchestrationProvider.GetSession(instanceId); if (session == null) { throw new ArgumentException($"There is no running or pending Orchestration with the instanceId {instanceId}"); } return(FormattingConverter.Serialize(session.SessionState)); }
/// <summary> /// Sets the JSON-serializeable output of the activity function. /// </summary> /// <remarks> /// If this method is not called explicitly, the return value of the activity function is used as the output. /// </remarks> /// <param name="output"> /// The JSON-serializeable value to use as the activity function output. /// </param> public void SetOutput(object output) { if (output != null) { JToken json = output as JToken; if (json != null) { this.serializedOutput = json.ToString(Formatting.None); } else { this.serializedOutput = SharedJsonConverter.Serialize(output); } } else { this.serializedOutput = null; } }