示例#1
0
            public async Task SignalAsync(WorkflowExecution execution, string signalName, params object[] args)
            {
                await SyncContext.Clear;

                var dataConverter = Activity.Client.DataConverter;

                await Activity.Client.SignalWorkflowAsync(execution, signalName, TemporalHelper.ArgsToBytes(dataConverter, args));
            }
示例#2
0
        /// <summary>
        /// Used to construct an untyped workflow stub that can manage an existing external workflow.
        /// </summary>
        /// <param name="client">The associated client.</param>
        /// <param name="execution">The workflow execution.</param>
        /// <param name="withinWorkflow">
        /// Optionally indicates that the stub was created from within a workflow and that
        /// operations such as get result, query, signal, and cancel must be performed
        /// within local activities such that that can be replayed from history correctly.
        /// </param>
        internal WorkflowStub(TemporalClient client, WorkflowExecution execution, bool withinWorkflow = false)
        {
            Covenant.Requires <ArgumentNullException>(client != null, nameof(client));
            Covenant.Requires <ArgumentNullException>(execution != null, nameof(execution));

            this.client         = client;
            this.Execution      = execution;
            this.withinWorkflow = withinWorkflow;
        }
示例#3
0
        /// <summary>
        /// Internal constructor for use outside of a workflow.
        /// </summary>
        /// <param name="client">Specifies the associated client.</param>
        /// <param name="execution">Specifies the target workflow execution.</param>
        /// <param name="namespace">Optionally specifies the target namespace (defaults to the client's default namespace).</param>
        internal ExternalWorkflowStub(TemporalClient client, WorkflowExecution execution, string @namespace = null)
        {
            Covenant.Requires <ArgumentNullException>(client != null, nameof(client));
            Covenant.Requires <ArgumentNullException>(execution != null, nameof(execution));

            this.client     = client;
            this.@namespace = client.ResolveNamespace(@namespace);
            this.Execution  = execution;
        }
示例#4
0
        /// <summary>
        /// Internal constructor for use within a workflow.
        /// </summary>
        /// <param name="parentWorkflow">Specifies the parent workflow.</param>
        /// <param name="execution">Specifies the target workflow execution.</param>
        /// <param name="namespace">Optionally specifies the target namespace (defaults to the client's default namespace).</param>
        internal ExternalWorkflowStub(Workflow parentWorkflow, WorkflowExecution execution, string @namespace = null)
        {
            Covenant.Requires <ArgumentNullException>(parentWorkflow != null, nameof(parentWorkflow));
            Covenant.Requires <ArgumentNullException>(execution != null, nameof(execution));

            this.parentWorkflow = parentWorkflow;
            this.client         = parentWorkflow.Client;
            this.@namespace     = client.ResolveNamespace(@namespace);
            this.Execution      = execution;
        }
示例#5
0
        /// <summary>
        /// Used to construct an untyped workflow stub that can be used to start an external workflow.
        /// </summary>
        /// <param name="client">The associated client.</param>
        /// <param name="workflowTypeName">The workflow type name.</param>
        /// <param name="execution">The workflow execution.</param>
        /// <param name="options">The workflow options.</param>
        internal WorkflowStub(TemporalClient client, string workflowTypeName, WorkflowExecution execution, StartWorkflowOptions options)
        {
            Covenant.Requires <ArgumentNullException>(client != null, nameof(client));
            Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(workflowTypeName), nameof(workflowTypeName));
            Covenant.Requires <ArgumentNullException>(execution != null, nameof(execution));
            Covenant.Requires <ArgumentNullException>(options != null, nameof(options));

            this.client           = client;
            this.WorkflowTypeName = workflowTypeName;
            this.Execution        = execution;
            this.Options          = options;
            this.withinWorkflow   = false;
        }
示例#6
0
        /// <summary>
        /// Starts the workflow, returning an <see cref="IAsyncFuture"/> that can be used
        /// to wait for the the workflow to complete and obtain its result.
        /// </summary>
        /// <typeparam name="TResult">The workflow result type.</typeparam>
        /// <param name="args">The workflow arguments.</param>
        /// <returns>An <see cref="ExternalWorkflowFuture{TResult}"/> that can be used to retrieve the workflow result as an <c>object</c>.</returns>
        /// <exception cref="InvalidOperationException">Thrown if the workflow has already been started.</exception>
        /// <remarks>
        /// <note>
        /// <b>IMPORTANT:</b> You need to take care to ensure that the parameters passed
        /// and the result type are compatible with the target workflow method.
        /// </note>
        /// </remarks>
        public async Task <ExternalWorkflowFuture <TResult> > StartAsync <TResult>(params object[] args)
        {
            await SyncContext.Clear;

            Covenant.Requires <ArgumentNullException>(args != null, nameof(args));

            if (execution != null)
            {
                throw new InvalidOperationException("Cannot start a future stub more than once.");
            }

            execution = await client.StartWorkflowAsync(workflowTypeName, TemporalHelper.ArgsToBytes(client.DataConverter, args), options);

            // Create and return the future.

            return(new ExternalWorkflowFuture <TResult>(client, execution, options.Namespace));
        }
示例#7
0
        /// <summary>
        /// Used to externally complete an activity identified by <see cref="WorkflowExecution"/> and activity ID.
        /// </summary>
        /// <param name="execution">The workflow execution.</param>
        /// <param name="activityId">The activity ID.</param>
        /// <param name="result">Passed as the activity result for activity success.</param>
        /// <param name="namespace">Optionally overrides the default <see cref="TemporalClient"/> namespace.</param>
        /// <returns>The tracking <see cref="Task"/>.</returns>
        /// <exception cref="EntityNotExistsException">Thrown if the activity no longer exists.</exception>
        public async Task ActivityCompleteByIdAsync(WorkflowExecution execution, string activityId, object result = null, string @namespace = null)
        {
            await SyncContext.Clear;

            Covenant.Requires <ArgumentNullException>(execution != null, nameof(execution));
            Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(activityId), nameof(activityId));
            EnsureNotDisposed();

            var reply = (ActivityCompleteReply) await CallProxyAsync(
                new ActivityCompleteRequest()
            {
                Namespace  = ResolveNamespace(@namespace),
                WorkflowId = execution.WorkflowId,
                RunId      = execution.RunId,
                ActivityId = activityId,
                Result     = GetClient(ClientId).DataConverter.ToData(result)
            });

            reply.ThrowOnError();
        }
示例#8
0
        /// <summary>
        /// Used to externally fail an activity by <see cref="WorkflowExecution"/> and activity ID.
        /// </summary>
        /// <param name="execution">The workflowm execution.</param>
        /// <param name="activityId">The activity ID.</param>
        /// <param name="error">Specifies the activity error.</param>
        /// <param name="namespace">Optionally overrides the default <see cref="TemporalClient"/> namespace.</param>
        /// <returns>The tracking <see cref="Task"/>.</returns>
        /// <exception cref="EntityNotExistsException">Thrown if the activity no longer exists.</exception>
        public async Task ActivityErrorByIdAsync(WorkflowExecution execution, string activityId, Exception error, string @namespace = null)
        {
            await SyncContext.Clear;

            Covenant.Requires <ArgumentNullException>(execution != null, nameof(execution));
            Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(activityId), nameof(activityId));
            Covenant.Requires <ArgumentNullException>(error != null, nameof(error));
            EnsureNotDisposed();

            var reply = (ActivityCompleteReply) await CallProxyAsync(
                new ActivityCompleteRequest()
            {
                Namespace  = ResolveNamespace(@namespace),
                WorkflowId = execution.WorkflowId,
                RunId      = execution.RunId,
                ActivityId = activityId,
                Error      = new TemporalError(error)
            });

            reply.ThrowOnError();
        }
示例#9
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="client">The associated client.</param>
 /// <param name="execution">The workflow execution.</param>
 /// /// <param name="namespace">Optionally specifies the target namespace.  This defaults to the default client namespace.</param>
 internal ExternalWorkflowFuture(TemporalClient client, WorkflowExecution execution, string @namespace)
 {
     this.client     = client;
     this.Execution  = execution;
     this.@namespace = @namespace;
 }
示例#10
0
            public async Task <byte[]> GetResultBytesAsync(WorkflowExecution execution)
            {
                await SyncContext.Clear;

                return(await Activity.Client.GetWorkflowResultAsync(execution));
            }
示例#11
0
 public async Task GetResultAsync(WorkflowExecution execution)
 {
     await SyncContext.Clear;
     await Activity.Client.GetWorkflowResultAsync(execution);
 }
示例#12
0
 public async Task CancelAsync(WorkflowExecution execution)
 {
     await SyncContext.Clear;
     await Activity.Client.CancelWorkflowAsync(execution);
 }