public TabWorkflowTracker()
 {
     _tabController       = TabController.Instance;
     _workflowEngine      = WorkflowEngine.Instance;
     _workflowManager     = WorkflowManager.Instance;
     _tabWorkflowSettings = TabWorkflowSettings.Instance;
 }
Beispiel #2
0
        static void ComposeModules()
        {
            //Bootstrapping section
            //Wherein we select the modules this application will use.
            //This is referred to as the "composition root" of a modular application.
            //There are several ways of implementing it, but I'm doing the simple route of hard coding the modules.

            var defaultLogger         = new ConsoleLogger();
            var defaultItemRepository = new ItemRepository();

            _defaultWorkflowEngine = new WorkflowEngine(defaultLogger);

            _defaultWorkflowProducer = new WorkflowProducer
                                       (
                new FooWorkflowFactory
                (
                    defaultItemRepository,
                    new FooProcessor(),
                    new FooSender(defaultLogger)
                ),
                new BarWorkflowFactory
                (
                    defaultItemRepository,
                    new RecordDeleter(defaultLogger)
                )
                                       );
        }
        public void Initialize()
        {
            var options = TestDbContext.CreateDbContextOptions();

            Context = new TestDbContext(options);

            var diHelper      = new DITestHelper();
            var loggerFactory = diHelper.GetLoggerFactory();
            ILogger <WorkflowEngine <TestDbContext> > logger = loggerFactory
                                                               .CreateLogger <WorkflowEngine <TestDbContext> >();

            SimpleWorkflowDefinitionProvider.Instance
            .RegisterWorkflowDefinition(new HolidayApprovalWorkflow());
            SimpleWorkflowDefinitionProvider.Instance
            .RegisterWorkflowDefinition(new OnOffWorkflow());
            SimpleWorkflowDefinitionProvider.Instance
            .RegisterWorkflowDefinition(new EntityOnOffWorkflow());

            IUserContextService userContextService = new TestUserContextService();

            this.WorkflowEngine = new WorkflowEngine <TestDbContext>(
                Context,
                logger,
                SimpleWorkflowDefinitionProvider.Instance,
                userContextService
                );
        }
Beispiel #4
0
        static void ComposeModules()
        {
            //Bootstrapping section
            //Wherein we select the modules this application will use.
            //This is referred to as the "composition root" of a modular application.
            //There are several ways of implementing it, but I'm doing the simple route of hard coding the modules.

            var defaultLogger = new ConsoleLogger();
            var defaultItemRepository = new ItemRepository();

            _defaultWorkflowEngine = new WorkflowEngine(defaultLogger);

            _defaultWorkflowProducer = new WorkflowProducer
                (
                    new FooWorkflowFactory
                        (
                            defaultItemRepository,
                            new FooProcessor(),
                            new FooSender(defaultLogger)
                        ),
                    new BarWorkflowFactory
                        (
                            defaultItemRepository,
                            new RecordDeleter(defaultLogger)
                        )
                );
        }
Beispiel #5
0
        public WorkflowEngineTests()
        {
            _fixture         = new Fixture();
            _criteriaFactory = new FakeCriteriaFactory();

            _corralSetttings = new List <TestCorralSettings>
            {
                new TestCorralSettings
                {
                    Name           = "A",
                    MaxElements    = 50,
                    StartBIBNumber = 1
                },
                new TestCorralSettings
                {
                    Name           = "B",
                    MaxElements    = 100,
                    StartBIBNumber = 4000
                },
                new TestCorralSettings
                {
                    Name           = "C",
                    MaxElements    = 2000,
                    StartBIBNumber = 2000
                }
            };
            _runnerGeneratorMock = new Mock <IRunnerGenerator>();
            _workflowEngine      = new WorkflowEngine(_corralSetttings, _criteriaFactory, _runnerGeneratorMock.Object);
        }
 public void Run(IWorkflowEngine workflow)
 {
     foreach (ITasks tasks in workflow.GetTasks())
     {
         tasks.Execute();
     }
 }
Beispiel #7
0
 public WorkerClient(IClientService clientService, IConfiguration configuration, IServerStatusService serverStatusService,
                     IWorkflowEngine workflowEngine, ILog log, IWorkerLockManager workerLockManager, IWorkerServiceHost workerServiceHost)
     : base(clientService, configuration, serverStatusService, log)
 {
     _workflowEngine = workflowEngine;
     _workerLockManager = workerLockManager;
     _workerServiceHost = workerServiceHost;
 }
        private static void ExecuteBenchmark()
        {
            // Get number of transitions
            Console.Write("Executed transitions: ");
            var transCount = int.Parse(Console.ReadLine());

            // Generate Workplan
            Console.WriteLine();
            Console.Write("Generating workplan...");
            var workplan = GenerateWorkplan(transCount);

            Console.WriteLine("done!");

            // Prepare benchmarks
            IWorkflowEngine engine     = null;
            var             benchmarks = new[]
            {
                new
                {
                    message   = "Creating engine",
                    operation = new Action(() => engine = CreateEngine(workplan))
                },
                new
                {
                    message   = "Running on default path",
                    operation = new Action(() =>
                    {
                        engine.TransitionTriggered += (sender, transition) => { };
                        engine.Start();
                    })
                },
                new
                {
                    message   = "Creating engine",
                    operation = new Action(() => engine = CreateEngine(workplan))
                },
                new
                {
                    message   = "Running on random path",
                    operation = new Action(() =>
                    {
                        engine.TransitionTriggered += FindPath;
                        engine.Start();
                    })
                }
            };

            // Run benchmarks
            foreach (var benchmark in benchmarks)
            {
                Console.Write(benchmark.message + "...");
                StopWatch.Restart();
                benchmark.operation();
                StopWatch.Stop();
                Console.WriteLine("done! Elapsed time: {0}ms", StopWatch.ElapsedMilliseconds);
            }
        }
Beispiel #9
0
        public async Task <OpenApiResult> HandleTrigger(string tenantId, string workflowInstanceId, IWorkflowTrigger body)
        {
            ITenant tenant = await this.marainServicesTenancy.GetRequestingTenantAsync(tenantId).ConfigureAwait(false);

            IWorkflowEngine workflowEngine = await this.workflowEngineFactory.GetWorkflowEngineAsync(tenant).ConfigureAwait(false);

            await workflowEngine.ProcessTriggerAsync(body, workflowInstanceId).ConfigureAwait(false);

            return(this.OkResult());
        }
Beispiel #10
0
        public async Task <OpenApiResult> StartWorkflowInstance(string tenantId, StartWorkflowInstanceRequest body)
        {
            ITenant tenant = await this.marainServicesTenancy.GetRequestingTenantAsync(tenantId).ConfigureAwait(false);

            IWorkflowEngine workflowEngine = await this.workflowEngineFactory.GetWorkflowEngineAsync(tenant).ConfigureAwait(false);

            await workflowEngine.StartWorkflowInstanceAsync(body).ConfigureAwait(false);

            return(this.CreatedResult());
        }
Beispiel #11
0
 public HolidayService(
     DomainContext context,
     IWorkflowEngine workflowEngine,
     IUserContextService userContext
     )
 {
     this._context        = context;
     this._workflowEngine = workflowEngine;
     this._userContext    = userContext;
 }
Beispiel #12
0
 public StepperService(
     DomainContext context,
     IWorkflowEngine workflowEngine,
     IUserContextService userContext,
     IMessageBus messageBus
     )
 {
     this.context        = context;
     this.workflowEngine = workflowEngine;
     this.userContext    = userContext;
     this.messageBus     = messageBus;
 }
Beispiel #13
0
 public IssueService(
     DomainContext context,
     IWorkflowEngine workflowEngine,
     IUserContextService userContext,
     IMessageBus messageBus
     )
 {
     this._context        = context;
     this._workflowEngine = workflowEngine;
     this._userContext    = userContext;
     this._messageBus     = messageBus;
 }
Beispiel #14
0
        public void Monitor(IWorkflowEngine instance)
        {
            lock (_monitoredEngines)
            {
                var monitoredEngine = (IMonitoredEngine)instance;
                _monitoredEngines.Add(monitoredEngine);

                monitoredEngine.TransitionTriggered += OnTransitionTriggered;
                monitoredEngine.PlaceReached        += OnPlaceReached;
                monitoredEngine.Completed           += EngineCompleted;
            }
        }
Beispiel #15
0
 public StepperService(
   DomainContext context,
   IWorkflowEngine workflowEngine,
   IUserContextService userContext,
   IMessageBus messageBus
 )
 {
   _context = context;
   _workflowEngine = workflowEngine;
   _userContext = userContext;
   _messageBus = messageBus;
 }
Beispiel #16
0
        public async Task WhenICreateANewInstanceCalledOfTheWorkflowWithId(
            string instanceId,
            string workflowId,
            Table table)
        {
            var context = table.Rows.ToDictionary(x => x["Key"], x => x["Value"]);

            ITenantedWorkflowEngineFactory engineFactory = ContainerBindings.GetServiceProvider(this.featureContext).GetService <ITenantedWorkflowEngineFactory>();
            ITenantProvider tenantProvider = ContainerBindings.GetServiceProvider(this.featureContext).GetService <ITenantProvider>();
            IWorkflowEngine engine         = await engineFactory.GetWorkflowEngineAsync(tenantProvider.Root).ConfigureAwait(false);

            await engine.StartWorkflowInstanceAsync(new StartWorkflowInstanceRequest { Context = context, WorkflowId = workflowId, WorkflowInstanceId = instanceId }).ConfigureAwait(false);
        }
Beispiel #17
0
        public BaseController()
        {
            // DI ready
            IServiceLocator locator = ServiceLocator.Current;

            _host             = locator.GetService <IApplicationHost>();
            _dbContext        = locator.GetService <IDbContext>();
            _renderer         = locator.GetServiceOrNull <IRenderer>();
            _workflowEngine   = locator.GetServiceOrNull <IWorkflowEngine>();
            _localizer        = locator.GetService <ILocalizer>();
            _scripter         = locator.GetService <IDataScripter>();
            _messageService   = locator.GetServiceOrNull <IMessageService>();
            _userStateManager = locator.GetServiceOrNull <IUserStateManager>();
        }
Beispiel #18
0
        /// <summary>
        /// The Process method is invoked asynchronously when <see cref="StartProcessing" /> is
        /// called. It will run on a background thread until <see cref="FinishProcessing" />
        /// is called.
        /// </summary>
        /// <returns>
        /// A <see cref="Task" /> that will complete after <see cref="FinishProcessing" /> is called.
        /// </returns>
        private async Task Process()
        {
            while (true)
            {
                if (this.queue.IsEmpty)
                {
                    if (this.shouldComplete)
                    {
                        break;
                    }

                    await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);

                    continue;
                }

                this.queue.TryPeek(out WorkflowMessageEnvelope item);

                IWorkflowInstanceStore instanceStore =
                    await this.workflowInstanceStoreFactory.GetWorkflowInstanceStoreForTenantAsync(this.tenantProvider.Root).ConfigureAwait(false);

                IWorkflowEngine engine =
                    await this.workflowEngineFactory.GetWorkflowEngineAsync(this.tenantProvider.Root).ConfigureAwait(false);

                if (item.IsTrigger)
                {
                    this.logger.LogInformation("Processing trigger with content type {ContentType}", item.ContentType);

                    IWorkflowTrigger trigger = item.Trigger;

                    IEnumerable <string> instanceIds = await instanceStore.GetMatchingWorkflowInstanceIdsForSubjectsAsync(
                        item.Trigger.GetSubjects(),
                        int.MaxValue,
                        0).ConfigureAwait(false);

                    foreach (string current in instanceIds)
                    {
                        await engine.ProcessTriggerAsync(trigger, current).ConfigureAwait(false);
                    }
                }
                else
                {
                    this.logger.LogInformation("Processing start workflow instance request");
                    await engine.StartWorkflowInstanceAsync(item.StartWorkflowInstanceRequest)
                    .ConfigureAwait(false);
                }

                this.queue.TryDequeue(out _);
            }
        }
Beispiel #19
0
        public bool Remove(IWorkflowEngine instance)
        {
            lock (_monitoredEngines)
            {
                var monitoredEngine = (IMonitoredEngine)instance;

                var wasMonitored = _monitoredEngines.Remove(monitoredEngine);
                if (wasMonitored)
                {
                    UnregisterEvents(monitoredEngine);
                }

                return(wasMonitored);
            }
        }
Beispiel #20
0
 public BaseController(IServiceLocator currentLocator = null)
 {
     // DI ready
     _locator              = currentLocator ?? ServiceLocator.Current;
     _host                 = _locator.GetService <IApplicationHost>();
     _dbContext            = _locator.GetService <IDbContext>();
     _renderer             = _locator.GetServiceOrNull <IRenderer>();
     _workflowEngine       = _locator.GetServiceOrNull <IWorkflowEngine>();
     _localizer            = _locator.GetService <ILocalizer>();
     _scripter             = _locator.GetService <IDataScripter>();
     _messageService       = _locator.GetServiceOrNull <IMessageService>();
     _userStateManager     = _locator.GetServiceOrNull <IUserStateManager>();
     _externalDataProvider = _locator.GetServiceOrNull <IExternalDataProvider>();
     _tokenProvider        = _locator.GetService <ITokenProvider>();
     _userLocale           = _locator.GetService <IUserLocale>();
 }
    static void Main()
    {
        // 0. First define workflow types and implementation classes. Register these with
        // the batch workflow factory.
        // As an example, a workflow 'type' could constitute a sequence of tasks to deploy
        // an application.  For example, the sample type 'K8S_DETAILS' below retrieves and
        // prints info. on the kubernetes cluster deployed on Azure Batch.

        // 1. Register workflow type(s) with the workflow factory
        IBatchWorkflowFactory factory = BatchWorkflowFactory.GetInstance();

        factory.RegisterWorkflowType(WorkflowTypes.K8S_DETAILS, "core.Flows.K8sClusterInfo");
        factory.RegisterWorkflowType(WorkflowTypes.TESK_DEPLOY, "core.Flows.DeployTesk");

        // Add a couple more tasks to test TESK deployment
        // factory.RegisterWorkflowType("test-tesk-deployment","core.Flows.VerifyTeskDeployment");

        // 2. Instantiate the workflow engine (Kubernetes on Azure Batch)
        IWorkflowEngine engine =
            BatchEngineFactory.GetEngine(
                BatchEngineFactory.ENGINE_TYPE_K8S, // Batch workflow engine of type "Kubernetes"
                "k8s-pool");                        // Name of the Azure Batch pool

        // Add batch pool metadata
        Dictionary <string, string> poolMetaData = new Dictionary <string, string>();

        poolMetaData.Add("Env", "Test");
        poolMetaData.Add("OS", "Ubuntu Server 18.04 LTS");
        poolMetaData.Add("ImageType", "Custom image with docker");

        // Add batch job metadata
        Dictionary <string, string> jobMetaData = new Dictionary <string, string>();

        jobMetaData.Add("Type", "Run tasks on K8s on Azure Batch");

        // 3. Add workflow type(s) to be executed by the workflow engine
        // Sample workflow types can be found in './core/Flows' directory
        engine.AddWorkflow(WorkflowTypes.K8S_DETAILS);
        engine.AddWorkflow(WorkflowTypes.TESK_DEPLOY);
        // engine.AddWorkflow("test-tesk-deployment"); // verify Tesk deployment

        // 4. Execute workflows in the context of a batch job on the engine
        engine.ExecuteWorkflow(
            "k8s-job1",   // name of Azure Batch job
            poolMetaData, // metadata to be assigned to the batch pool
            jobMetaData); // metadata to be assigned to the job
    }
        public static IWorkflowEngine GetEngine(
            string name,
            string poolName)
        {
            IWorkflowEngine engine = null;

            if (name.Equals(BatchEngineFactory.ENGINE_TYPE_K8S))
            {
                engine = new K8sWorkflowEngine(poolName);
            }
            else
            {
                throw new ArgumentOutOfRangeException($"Engine type: {name} not supported!");
            }

            return(engine);
        }
Beispiel #23
0
        public async Task GivenIHaveStartedAnInstanceOfTheWorkflowWithInstanceIdAndUsingContextObject(string workflowId, string instanceId, string contextInstanceName)
        {
            ITenantedWorkflowEngineFactory engineFactory = this.serviceProvider.GetRequiredService <ITenantedWorkflowEngineFactory>();
            IWorkflowEngine engine = await engineFactory.GetWorkflowEngineAsync(this.transientTenantManager.PrimaryTransientClient).ConfigureAwait(false);

            IDictionary <string, string> context = this.scenarioContext.Get <IDictionary <string, string> >(contextInstanceName);

            var request =
                new StartWorkflowInstanceRequest
            {
                WorkflowId         = workflowId,
                WorkflowInstanceId = instanceId,
                Context            = context,
            };

            await engine.StartWorkflowInstanceAsync(request).ConfigureAwait(false);
        }
Beispiel #24
0
 public WorkflowCommands(
     IWorkflowLoader workflowLoader,
     IWorkflowEngine workflowEngine,
     IValuesEngine valuesEngine,
     ITemplateEngineFactory templateEngineFactory,
     IYamlSerializers serializers,
     IPatternMatcherFactory patternMatcherFactory,
     ISecretTracker secretTracker,
     IBlueprintManager blueprintManager,
     IConsole console)
 {
     _workflowLoader        = workflowLoader;
     _workflowEngine        = workflowEngine;
     _valuesEngine          = valuesEngine;
     _templateEngineFactory = templateEngineFactory;
     _serializers           = serializers;
     _patternMatcherFactory = patternMatcherFactory;
     _secretTracker         = secretTracker;
     _blueprintManager      = blueprintManager;
     _console = console;
 }
        public static async Task <WorkflowTriggerInfo> ToWorkflowTriggerInfo(
            this IWorkflowEngine workflowEngine,
            IWorkflow instance,
            TriggerResult result = null)
        {
            WorkflowTriggerInfo info;

            if (result == null || !result.HasErrors)
            {
                IEnumerable <TriggerResult> triggerResults = await workflowEngine.GetTriggersAsync(instance);

                var triggers = triggerResults.Select(x => x.TriggerName);
                info = WorkflowTriggerInfo.createForSuccess(triggers);
            }
            else
            {
                info = WorkflowTriggerInfo.createForError(result.Errors);
            }

            return(info);
        }
 /// <summary>
 /// Destroy a workflow engine instance
 /// </summary>
 public static void Destroy(IWorkflowEngine engine)
 {
     engine.Dispose();
 }
Beispiel #27
0
 public WorkflowTest()
 {
     TestConfig.Start();
     _dbContext = ServiceLocator.Current.GetService <IDbContext>();
     _workflow  = ServiceLocator.Current.GetService <IWorkflowEngine>();
 }
Beispiel #28
0
 public App(IWorkflowEngine workflowEngine)
 {
     this.workflowEngine = workflowEngine;
 }
 public ContentWorkflowServiceController()
 {
     _workflowEngine = WorkflowEngine.Instance;
 }
Beispiel #30
0
 public ContentWorkflowServiceController()
 {
     _workflowEngine = WorkflowEngine.Instance;
 }
Beispiel #31
0
 public WorkflowController()
 {
     _workflowManager = WorkflowManager.Instance;
     _workflowEngine  = WorkflowEngine.Instance;
     _userController  = UserController.Instance;
 }
 public WorkflowApiController(IWorkflowEngine workflowEngine)
 {
     this.workflowEngine = workflowEngine;
 }
Beispiel #33
0
 public EngineController(IWorkflowEngine workflowEngine, IWorkContext workContext, IRepository<string> repository)
     : base(workContext, repository)
 {
     this.workflowEngine = workflowEngine;
 }
 /// <summary>
 /// Create a new instance of the subworkflow transition
 /// </summary>
 public SubworkflowTransition(IWorkflowEngine engine, IIndexResolver indexResolver)
 {
     _engine        = engine;
     _indexResolver = indexResolver;
 }
Beispiel #35
0
 public WorkflowEngineBuildResult(WorkflowEngineBuilder workflowEngineBuilder, IWorkflowEngine workflowEngine)
 {
     WorkflowEngineBuilder = workflowEngineBuilder;
     WorkflowEngine        = workflowEngine;
 }