/// <summary>
        /// Handles the receipt of a response message coming from a remote platform by resuming the workflow run and handing the
        /// messages to the relevant CAST activity implementation.
        /// </summary>
        /// <param name="request">The original request message.</param>
        /// <param name="response">The response message to process.</param>
        public async void Process(TRequest request, TResponse response)
        {
            using (new DeferredChannelMessageContext())
                using (CastService.GetCastContext())
                {
                    try
                    {
                        var run = EntityRepository.Get <WorkflowRun>(request.RunId, WorkflowRunPreload);
                        if (run == null)
                        {
                            throw new Exception(string.Format("CAST workflow activity could not resume. Workflow run ({0}) not found.", request.RunId));
                        }

                        // let the workflow or caching or whatever, catch up before officially responding to RabbitMQ
                        if (run.RunStepCounter <= request.RunStep)
                        {
                            var state = await WaitForRunStep(run.Id, request.RunStep);

                            if (state < request.RunStep)
                            {
                                throw new Exception(string.Format("CAST workflow activity could not resume. Workflow run ({0}) wasn't in step.", request.RunId));
                            }
                        }

                        var castEvent = new CastActivityResponseEvent <TRequest, TResponse>(request, response);

                        WorkflowRunner.ResumeWorkflowAsync(run, castEvent);
                    }
                    catch (Exception err)
                    {
                        EventLog.Application.WriteError("Failed to process CAST response. {0}", err);
                    }
                }
        }
Beispiel #2
0
        public async Task RunWorkflowAsyncShouldReturnExpectedOutput([Frozen] object expectedOutput, FinishWorkflow sut)
        {
            var workflowInstance = await WorkflowRunner.BuildAndStartWorkflowAsync(sut);

            var actualOutput = (workflowInstance.Output as FinishOutput)?.Output;

            Assert.Same(expectedOutput, actualOutput);
        }
        public async Task RunWorkflowAsyncShouldSetWorkflowStatusToFinished(FinishWorkflow sut)
        {
            var runWorkflowResult = await WorkflowRunner.BuildAndStartWorkflowAsync(sut);

            var workflowInstance = runWorkflowResult.WorkflowInstance !;

            Assert.Equal(WorkflowStatus.Finished, workflowInstance.WorkflowStatus);
        }
Beispiel #4
0
        private static void TestWorkflowEngine()
        {
            var workflowRunner = new WorkflowRunner();

            workflowRunner.Add(new UploadVideoToCloudStorageActivity());
            workflowRunner.Add(new PostToYoutubeActivity());
            workflowRunner.Run();
        }
Beispiel #5
0
        public async Task Test01()
        {
            var items            = Enumerable.Range(1, 10).Select(x => $"Item {x}").ToList();
            var workflow         = new ForEachWorkflow(items);
            var workflowInstance = await WorkflowRunner.BuildAndStartWorkflowAsync(workflow);

            Assert.Equal(WorkflowStatus.Suspended, workflowInstance.WorkflowStatus);
        }
Beispiel #6
0
        public async Task Test01()
        {
            var runWorkflowResult = await WorkflowRunner.BuildAndStartWorkflowAsync <BasicWorkflow>();

            var workflowInstance = runWorkflowResult.WorkflowInstance !;

            Assert.Equal(WorkflowStatus.Finished, workflowInstance.WorkflowStatus);
        }
Beispiel #7
0
        public MainWindow()
        {
            InitializeComponent();

            var eventBroker       = new EventBroker();
            var messageRepository = new FileMessageProvider();

            Type[] events =
            {
                typeof(MessageNofiticationEvent),
                typeof(VisualNotificationEvent)
            };
            var eventAgent = new EventAgent();

            foreach (var eventType in events)
            {
                eventAgent.Register(eventType);
            }

            var debugTracking = new DebugTrackingParticipant();
            var agent         = new MessageAgent();

            IPrototype[] messages =
            {
                new MessageInfo(messageRepository),
                new PowerSupplayVisualComponent(eventBroker,agent,         eventAgent),
                new MessageError(messageRepository,         eventBroker),
            };

            foreach (var message in messages)
            {
                agent.RegisterPrototype(message);
            }

            RegisterComponentTemplate(messages);

            var workflowProvide = new WorkflowProvider(SynchronizationContext.Current, eventBroker, debugTracking, agent, eventAgent);

            var model = new WorkflowRunner(workflowProvide, eventBroker);

            var componentViewCollection = new ComponentViewCollection();
            var userNotificationView    = new UserNotificationView();

            var view = new EnableViewModel(model, componentViewCollection, userNotificationView, eventBroker);

            eventBroker.Register(componentViewCollection);
            eventBroker.Register(userNotificationView);
            eventBroker.Register(view);
            eventBroker.Register(model);

            // ioc for each IStartable.Start()

            //this.Closing += view.ViewClosing;
            //this.Closed += view.ViewClosed;

            DataContext = view;
        }
        public void IWorkflowRunner_Instance()
        {
            IWorkflowRunner instance = Factory.Current.Resolve <IWorkflowRunner>();

            Assert.That(instance, Is.TypeOf <WorkflowRunner>());

            WorkflowRunner runner = (WorkflowRunner)instance;

            Assert.That(runner.MetadataFactory, Is.Not.Null);
        }
Beispiel #9
0
 public Worker(
     IWorkflowRepository workflowRepository,
     WorkflowRunner workflowRunner,
     IOptionsMonitor <CoreOptions> coreOptions,
     ILogger <Worker> logger)
 {
     _workflowRepository = workflowRepository;
     _workflowRunner     = workflowRunner;
     _coreOptions        = coreOptions;
     _logger             = logger;
 }
Beispiel #10
0
        private async Task <WorkflowInstance> TriggerSignalAsync(IWorkflowBlueprint workflowBlueprint, WorkflowInstance workflowInstance, string signal)
        {
            var workflowExecutionContext = new WorkflowExecutionContext(ServiceScope.ServiceProvider, workflowBlueprint, workflowInstance);
            var workflowBlueprintWrapper = new WorkflowBlueprintWrapper(workflowBlueprint, workflowExecutionContext);
            var activities              = workflowBlueprintWrapper.Activities.Where(x => x.ActivityBlueprint.Type == nameof(SignalReceived));
            var blockingActivityIds     = workflowInstance.BlockingActivities.Where(x => x.ActivityType == nameof(SignalReceived)).Select(x => x.ActivityId).ToList();
            var receiveSignalActivities = activities.Where(x => blockingActivityIds.Contains(x.ActivityBlueprint.Id)).ToList();
            var receiveSignal           = receiveSignalActivities.Single(activity => workflowBlueprintWrapper.GetActivity <SignalReceived>(activity.ActivityBlueprint.Id) !.EvaluatePropertyValueAsync(x => x.Signal).GetAwaiter().GetResult() == signal);

            var triggeredSignal = new Signal(signal);
            var result          = await WorkflowRunner.RunWorkflowAsync(workflowBlueprint, workflowInstance, receiveSignal.ActivityBlueprint.Id, new WorkflowInput(triggeredSignal));

            return(result.WorkflowInstance !);
        }
 private void Start()
 {
     _logger.Info("Service starting.");
     try
     {
         var configurator = new WorkflowConfigurator();
         var workflows    = configurator.GetWorkflows();
         var runner       = new WorkflowRunner(100);
         runner.Register(workflows);
         runner.RunAllWorkflows();
     } catch (Exception ex) {
         _logger.Error(ex);
         StopService();
         throw ex;
     }
 }
Beispiel #12
0
        internal static int LaunchWorkflowPlayer(
            string fileName,
            string layoutPath,
            PackageConfiguration packageConfiguration,
            Dictionary <string, string> propertyAssignments)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                Console.WriteLine("No workflow file was specified.");
                return(Program.NormalExitCode);
            }

            var visualizerProvider = Observable.Defer(() =>
            {
                EditorBootstrapper.EnableVisualStyles();
                return(TypeVisualizerLoader.GetVisualizerTypes(packageConfiguration));
            });

            WorkflowRunner.Run(fileName, propertyAssignments, visualizerProvider, layoutPath);
            return(Program.NormalExitCode);
        }
Beispiel #13
0
        public void Test()
        {
            if (!Factory.FeatureSwitch.Get("longRunningWorkflow"))
            {
                return;
            }

            var myRunner = new WorkflowRunner(new CachingWorkflowMetadataFactory());

            myRunner.SuspendTimeoutMs = 100;

            var mockTaskManager = new Mock <IBackgroundTaskManager>(MockBehavior.Strict);

            mockTaskManager.Setup(a => a.EnqueueTask(It.IsAny <BackgroundTask>()));          // Make sure the suspended task is put back on the queue

            using (var scope = Factory.Current.BeginLifetimeScope(builder =>
            {
                builder.Register(ctx => myRunner).As <IWorkflowRunner>();
                builder.Register(ctx => mockTaskManager.Object).As <IBackgroundTaskManager>();
            }))
                using (Factory.SetCurrentScope(scope))
                {
                    Workflow wf = null;
                    try
                    {
                        wf = CreateLoopWf();
                        wf.Save();

                        WorkflowRun run1 = null;

                        using (new WorkflowRunContext {
                            RunTriggersInCurrentThread = true
                        })
                        {
                            run1 = WorkflowRunner.Instance.RunWorkflow(new WorkflowStartEvent(wf));
                        }

                        var runStep1 = run1.RunStepCounter;
                        var runTime1 = run1.TotalTimeMs;

                        Assert.That(run1.WorkflowRunStatus_Enum, Is.EqualTo(WorkflowRunState_Enumeration.WorkflowRunSuspended));
                        Assert.That(runStep1, Is.GreaterThan(0));
                        Assert.That(runTime1, Is.GreaterThan(0));

                        WorkflowRun run2 = null;

                        using (new WorkflowRunContext {
                            RunTriggersInCurrentThread = true
                        })
                        {
                            run2 = WorkflowRunner.Instance.ResumeWorkflow(run1, new WorkflowRestoreEvent());
                        }

                        var runStep2 = run2.RunStepCounter;
                        var runTime2 = run2.TotalTimeMs;

                        Assert.That(run2.WorkflowRunStatus_Enum, Is.EqualTo(WorkflowRunState_Enumeration.WorkflowRunSuspended));
                        Assert.That(runStep2, Is.GreaterThan(runStep1));
                        Assert.That(runTime2, Is.GreaterThan(runTime1));

                        WorkflowRun run3 = null;

                        using (new WorkflowRunContext {
                            RunTriggersInCurrentThread = true
                        })
                        {
                            run3 = WorkflowRunner.Instance.ResumeWorkflow(run1, new WorkflowRestoreEvent());
                        }

                        Assert.That(run3.WorkflowRunStatus_Enum, Is.EqualTo(WorkflowRunState_Enumeration.WorkflowRunSuspended));
                        Assert.That(run3.RunStepCounter, Is.GreaterThan(runStep2));
                        Assert.That(run3.TotalTimeMs, Is.GreaterThan(runTime2));
                    }
                    finally
                    {
                        wf?.Delete();
                    }
                }

            mockTaskManager.VerifyAll();
        }