Ejemplo n.º 1
0
            public async Task RunAsync(TimeSpan delay)
            {
                var delayStub = Workflow.NewLocalActivityStub <ISignalBlastDelayActivity, SignalBlastDelayActivity>();

                signalQueue = await Workflow.NewQueueAsync <SignalRequest <string> >(int.MaxValue);

                // Process messages until we get one that passes NULL.

                while (true)
                {
                    var signalRequest = await signalQueue.DequeueAsync();

                    var name  = signalRequest.Arg <string>("name");
                    var reply = (string)null;

                    if (name != null)
                    {
                        reply = $"Hello {name}!";

                        if (delay > TimeSpan.Zero)
                        {
                            await delayStub.DelayAsync(delay);
                        }
                    }

                    await signalRequest.ReplyAsync(reply);

                    if (name == null)
                    {
                        break;
                    }
                }
            }
Ejemplo n.º 2
0
        public async Task <string> HelloAsync()
        {
            signalQueue = await Workflow.NewQueueAsync <string>();

            var name = await signalQueue.DequeueAsync();

            return($"Hello {name}!");
        }
Ejemplo n.º 3
0
            public async Task RunResultAsync()
            {
                resultQueue = await Workflow.NewQueueAsync <SignalRequest <string> >();

                var signalRequest = await resultQueue.DequeueAsync();

                SignalProcessed = true;
                Name            = signalRequest.Arg <string>("name");

                await signalRequest.ReplyAsync($"Hello {Name}!");
            }
Ejemplo n.º 4
0
            public async Task RunVoidAsync()
            {
                voidQueue = await Workflow.NewQueueAsync <SignalRequest>();

                var signalRequest = await voidQueue.DequeueAsync();

                SignalProcessed = true;
                Name            = signalRequest.Arg <string>("name");

                await signalRequest.ReplyAsync();
            }
Ejemplo n.º 5
0
        public async Task DoItAsync()
        {
            signalQueue = await Workflow.NewQueueAsync <string>();

            while (true)
            {
                state = await signalQueue.DequeueAsync();

                if (state == "done")
                {
                    break;
                }
            }
        }
Ejemplo n.º 6
0
            public async Task RunAsync(TimeSpan delay)
            {
                signalQueue = await Workflow.NewQueueAsync <SignalRequest <string> >();

                var stub = Workflow.NewActivityStub <IDelayActivity>();

                await stub.DelayAsync(delay);

                var signalRequest = await signalQueue.DequeueAsync();

                var name  = signalRequest.Arg <string>("name");
                var reply = (string)null;

                if (name != null)
                {
                    reply = $"Hello {name}!";
                }

                await signalRequest.ReplyAsync(reply);
            }
Ejemplo n.º 7
0
        public async Task ProcessOrderAsync()
        {
            // Create queue to receive signal requests from the
            // [CancelOrderAsync()] synchronous signal method.

            queue = await Workflow.NewQueueAsync <SignalRequest <string> >();

            // Wait for a signal request to be dequeued, and obtain the
            // "reason" argument.  This will be the "reason" parameter
            // value passed to [CancelOrderAsync()] below.

            var signal = await queue.DequeueAsync();

            var reason = signal.Arg <string>("reason");

            // This line actually specifies the result to be returned
            // back to the external code that sent the synchronous signal.

            await signal.ReplyAsync($"Order cancelled due to: {reason}");
        }
Ejemplo n.º 8
0
        public async Task <bool> ProcessAsync()
        {
            status      = OrderStatus.Pending;
            cancelQueue = await Workflow.NewQueueAsync <SignalRequest <bool> >();

            //---------------------------------------------
            // STEP-1: Collect the order items from inventory.

            status = OrderStatus.Picking;

            // This is where you'd execute one or more activities telling
            // your inventory team (or robots) what they need to gather
            // for this order.  In real life, this would also probably
            // wait for a signal from an external system indicating that
            // the items have been collected and that the workflow can
            // proceed to the next step.
            //
            // We're going to leave this to your imagination to keep the
            // example simple.

            await Workflow.SleepAsync(TimeSpan.FromSeconds(5));

            // Abort order processing if an cancellation signal has been
            // received.

            try
            {
                var signalRequest = await cancelQueue.DequeueAsync(timeout : TimeSpan.FromSeconds(1));

                // This call indicates that the signal method that enqueued
                // the signal should return TRUE.

                await signalRequest.ReplyAsync(true);

                // This terminates the workflow.

                return(false);
            }
            catch (CadenceTimeoutException)
            {
                // There was no signal pending.
            }

            //---------------------------------------------
            // STEP-2: Pack the order.

            status = OrderStatus.Packing;

            // This is where you'd execute one or more activities telling
            // your packers what to do as well as printing labels and ordering
            // a pickup from your shipper.

            await Workflow.SleepAsync(TimeSpan.FromSeconds(5));

            // Abort order processing if an cancellation signal has been
            // received.

            try
            {
                var signalRequest = await cancelQueue.DequeueAsync(timeout : TimeSpan.FromSeconds(1));

                // This call indicates that the signal method that enqueued
                // the signal should return TRUE.

                await signalRequest.ReplyAsync(true);

                // This terminates the workflow.

                return(false);
            }
            catch (CadenceTimeoutException)
            {
                // There was no signal pending.
            }

            //---------------------------------------------
            // STEP-3: The order is considered to have shipped at this point
            //         and cancellation is no longer an option.

            status = OrderStatus.Shipped;

            // This is where the delivery would be tracked and potential
            // return logic would live.

            await Workflow.SleepAsync(TimeSpan.FromSeconds(5));

            return(status != OrderStatus.Cancelled);
        }