Exemple #1
0
 private void RegisterWorkflows()
 {
     _host.RegisterWorkflow <GeostationaryWorkflow, GeostationaryWorkflowData>();
     _host.RegisterWorkflow <GeostationaryReprojectedWorkflow, EquirectangularStitchWorkflowData>();
     _host.RegisterWorkflow <EquirectangularStitchWorkflow, EquirectangularStitchWorkflowData>();
     _host.RegisterWorkflow <EquirectangularTimelapseWorkflow, EquirectangularTimelapseWorkflowData>();
     _host.RegisterWorkflow <EquirectangularWorkflow, EquirectangularWorkflowData>();
 }
        static void Main(string[] args)
        {
            //Configuration
            IServiceCollection services = new ServiceCollection();

            services.AddLogging();
            services.AddWorkflow();

            //Service
            IServiceProvider provider = services.BuildServiceProvider();

            //Workflow get and trigger
            IWorkflowHost host = provider.GetService <IWorkflowHost>();

            host.RegisterWorkflow <HelloWorldWorkflow, MyData>();
            host.Start();

            //Start flow which by flowId
            host.StartWorkflow("HelloWorld", new MyData {
                Value1 = 1, Value2 = 99
            });

            Console.ReadKey();

            host.Stop();
        }
Exemple #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            // Start the workflow host
            host = app.ApplicationServices.GetService <IWorkflowHost>();
            host.RegisterWorkflow <ContactFormWorkflow, ContactForm>();
            host.Start();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Exemple #4
0
        public static void DIWorkflow(IWorkflowHost host)
        {
            host.RegisterWorkflow <DIWorkflow>();
            host.Start();

            host.StartWorkflow("DIWorkflow", 1, null, null);
        }
Exemple #5
0
        public static void LoopingWorkflow(IWorkflowHost host)
        {
            host.RegisterWorkflow <LoopingWorkflow>();
            host.Start();

            host.StartWorkflow("LoopingWorkflow");
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            // Start the workflow host
            host = app.ApplicationServices.GetService <IWorkflowHost>();
            host.RegisterWorkflow <ContactFormWorkflow, ContactForm>();
            host.Start();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Exemple #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var serviceProvider = ConfigureServices();

            PersistenceProvider = serviceProvider.GetRequiredService <IPersistenceProvider>();

            IWorkflowHost host = serviceProvider.GetService <IWorkflowHost>();

            host.RegisterWorkflow <MySagaWorkflow, MySagaData>();
            //host.RegisterWorkflow<MySagaWorkflow>(); // To do withput the MySagaData class

            host.Start();

            var data = new MySagaData {
                boo          = "boo",
                SpanishGreet = "¡Hola, mundo!",
                EnglishGreet = "Hello, World!",
                FrenchGreet  = "Salut, monde!",
                GermanGreet  = "Hallo, Welt!",
                RussianGreet = ".____.",
            };

            var workflowId = host.StartWorkflow <MySagaData>("PablosSagaPattern", data).Result;

            // Console.ReadKey(); // This wait the user to press enter.
            var remainingTime = TimeSpan.FromSeconds(5);

            WaitForWorkflowToComplete(workflowId, remainingTime);

            host.Stop();
        }
        protected virtual void Setup(bool registerClassMap = false)
        {
            //setup dependency injection
            IServiceCollection services = new ServiceCollection();

            services.AddLogging();
            ConfigureServices(services);

            var serviceProvider = services.BuildServiceProvider();

            //config logging
            var loggerFactory = serviceProvider.GetService <ILoggerFactory>();

            //loggerFactory.AddConsole(LogLevel.Debug);

            if (registerClassMap && !BsonClassMap.IsClassMapRegistered(typeof(TData)))
            {
                BsonClassMap.RegisterClassMap <TData>(map => map.AutoMap());
            }

            PersistenceProvider = serviceProvider.GetService <IPersistenceProvider>();
            Host = serviceProvider.GetService <IWorkflowHost>();
            Host.RegisterWorkflow <TWorkflow, TData>();
            Host.OnStepError += Host_OnStepError;
            Host.Start();
        }
Exemple #9
0
        public static void CheckStatement(IWorkflowHost host)
        {
            host.RegisterWorkflow <CheckWorkflow, CheckData>();
            host.Start();

            Console.WriteLine("Starting Check...");
            string workflowId = host.StartWorkflow("check").Result;
        }
        /// <summary>
        /// 啟動 ExeWorkflow 與 檔案產生監測,請注意只能執行一次,建議在 Startup 中執行
        /// </summary>
        /// <param name="folder">執行檔產生檔案的目錄</param>
        /// <param name="eventName">呼叫的 ExeWorkflow.Waitfor 的 Event Name </param>
        public void Start()
        {
            _fileWatcher = new FileWatcher(_fileConfig.OutputFolder, _fileConfig.EventName, _fileConfig.BackupFolder);
            _fileWatcher.FileDetectHandler += FileWatcher_FileDetectHandler;

            _host.RegisterWorkflow <ExeWorkflow, ExeWorkItem>();
            _host.OnLifeCycleEvent += Host_OnLifeCycleEvent;
            _host.Start();
            _fileWatcher.Start();
        }
Exemple #11
0
        public static void WhileLoop(IWorkflowHost host)
        {
            host.RegisterWorkflow <WhileWorkflow, WhileLoop.MyData>();
            host.Start();

            Console.WriteLine("Starting workflow...");
            string workflowId = host.StartWorkflow("While", new WhileLoop.MyData()
            {
                Counter = 0
            }).Result;
        }
Exemple #12
0
        public static void ParallelTask(IWorkflowHost host)
        {
            host.RegisterWorkflow <ParallelWorkflow, ParallelTask.MyData>();
            host.Start();

            Console.WriteLine("Starting workflow...");
            string workflowId = host.StartWorkflow("parallel-sample", new ParallelTask.MyData()
            {
                Counter = 4
            }).Result;
        }
Exemple #13
0
        public static void MutipleOutcome(IWorkflowHost host)
        {
            host.RegisterWorkflow <OutcomeWorkflow, MutipleOutcomes.MyData>();
            host.Start();

            Console.WriteLine("Starting workflow...");
            host.StartWorkflow("outcome-sample", new MutipleOutcomes.MyData()
            {
                Value = 2
            });
        }
Exemple #14
0
        public static void HelloWorld(IWorkflowHost host, IServiceProvider provider)
        {
            var workflowController = provider.GetService <IWorkflowController>();
            var persist            = provider.GetService <IPersistenceProvider>();

            host.RegisterWorkflow <UserWorkflow1, MyData>();
            host.RegisterWorkflow <OutcomeWorkflow, MutipleOutcomes.MyData>();
            host.Start();

            //persist.GetWorkflowInstance
            // Demo1:Hello World
            var id = host.StartWorkflow("workflow1", new MyData()
            {
                Message = "message"
            }).Result;

            //host.s()
            // Console.ReadKey();
            // var wid = host.StartWorkflow("outcome-sample", new MutipleOutcomes.MyData() { Value = 2, id = id}).Result;
            //Console.ReadKey();
            //var a = workflowController.ResumeWorkflow(result1).Result;
            Console.WriteLine($"{Thread.CurrentThread.ManagedThreadId}");
        }
Exemple #15
0
        public Worker(ILogger <Worker> logger, IWorkflowHost workflowHost, IOptions <Models.ASNNumbers> options)
        {
            _logger = logger
                      ?? throw new ArgumentNullException(nameof(logger));

            _workflowHost = workflowHost
                            ?? throw new ArgumentNullException(nameof(workflowHost));
            _workflowHost.OnStepError += WorkflowHost_OnStepError;

            _workflowHost.RegisterWorkflow <Workflows.Workflow, Models.PersistenceData>();

            _asnNumbers = Guard.Argument(options).NotNull().Wrap(o => o.Value)
                          .NotNull().NotEmpty().Value;
        }
Exemple #16
0
        public static void PassingData(IWorkflowHost host)
        {
            host.RegisterWorkflow <PassingDataWorkflow, MyDataClass>();
            host.RegisterWorkflow <PassingDataWorkflow2, Dictionary <string, int> >();
            host.Start();

            var initialData = new MyDataClass
            {
                Value1 = 2,
                Value2 = 3
            };

            //host.StartWorkflow("PassingDataWorkflow", 1, initialData);


            var initialData2 = new Dictionary <string, int>
            {
                ["Value1"] = 7,
                ["Value2"] = 2
            };

            host.StartWorkflow("PassingDataWorkflow", 1, initialData);
        }
Exemple #17
0
        protected void Setup()
        {
            //setup dependency injection
            IServiceCollection services = new ServiceCollection();

            services.AddLogging(x => x.AddConsole());
            Configure(services);

            var serviceProvider = services.BuildServiceProvider();

            PersistenceProvider = serviceProvider.GetService <IPersistenceProvider>();
            Host = serviceProvider.GetService <IWorkflowHost>();
            Host.RegisterWorkflow <TWorkflow, TData>();
            Host.Start();
        }
Exemple #18
0
        public static void RoleWorkflow(IWorkflowHost host, IServiceProvider provider)
        {
            host.RegisterWorkflow <RoleSwitchWorkflow, RoleData>();
            var roleService = provider.GetService <IRoleSrvice>();

            roleService.SetStudentRole();
            host.Start();

            RoleData roleData = new RoleData()
            {
                branchId = 1, Role = Role.Student
            };

            host.StartWorkflow("role workflow", roleData);
        }
Exemple #19
0
        public bool RegisterScheduleWorkflow <TWorkflow>(string workflowId) where TWorkflow : IWorkflow, new()
        {
            if (_scheduler == null)
            {
                return(false);
            }

            _workflowHost.RegisterWorkflow <TWorkflow>();

            var job = JobBuilder.Create <ScheduleWorkflowJob>()
                      .WithIdentity(new JobKey(workflowId, "ScheduleWorkflowGroup"))
                      .Build();

            return(_jobs.TryAdd(workflowId, job));
        }
Exemple #20
0
        protected virtual void Setup()
        {
            //setup dependency injection
            IServiceCollection services = new ServiceCollection();

            services.AddLogging();
            ConfigureServices(services);

            var serviceProvider = services.BuildServiceProvider();

            PersistenceProvider = serviceProvider.GetService <IPersistenceProvider>();
            Host = serviceProvider.GetService <IWorkflowHost>();
            Host.RegisterWorkflow <TWorkflow, TData>();
            Host.OnStepError += Host_OnStepError;
            Host.Start();
        }
Exemple #21
0
        public WorkflowCoreTests(Fixtures.TracerFixture fixture)
        {
            _provider = new ServiceCollection()
                        .AddLogging()
                        .AddWorkflow()
                        .AddOpenTracing()
                        .AddSingleton(fixture.Tracer)
                        .AddTransient <TestStep>()
                        .BuildServiceProvider();

            _tracer       = _provider.GetRequiredService <ITracer>();
            _workflowHost = _provider.GetRequiredService <IWorkflowHost>();

            _workflowHost.RegisterWorkflow <TestWorkflow, Data>();

            _workflowHost.Start();
        }
Exemple #22
0
    public Worker(
        IWorkflowHost workflowHost,
        IOptions <Config.Settings> options,
        ILogger <Worker> logger)
    {
        _workflowHost = Guard.Argument(workflowHost).NotNull().Value;

        Guard.Argument(options).NotNull();
        Guard.Argument(options.Value).NotNull();
        _intervalMilliseconds = Guard.Argument(options.Value.IntervalMilliseconds).Positive().Value !.Value;
        _logger = logger;

        _workflowHost.OnStepError += WorkflowHost_OnStepError;

        _workflowHost.RegisterWorkflow <Workflows.Workflow, Models.PersistenceData>();

        _workflowHost.Start();
    }
Exemple #23
0
        public static void EventWorkflow(IWorkflowHost host, IServiceProvider provider)
        {
            var workflowController = provider.GetService <IWorkflowController>();
            var persist            = provider.GetService <IPersistenceProvider>();

            host.RegisterWorkflow <EventSampleWorkflow, EventFlowData>();
            host.Start();

            var initialData = new EventFlowData();
            var workflowId  = host.StartWorkflow("EventSampleWorkflow", 1, initialData).Result;

            var id = "EventSampleWorkflow";

            //var workflow = workflowController.SuspendWorkflow(workflowId).Result;
            Console.WriteLine("Enter value to publish");
            string value = Console.ReadLine();

            host.PublishEvent("MyEvent", workflowId, value);
        }
Exemple #24
0
        protected void Setup()
        {
            //setup dependency injection
            IServiceCollection services = new ServiceCollection();

            services.AddLogging();
            Configure(services);

            var serviceProvider = services.BuildServiceProvider();

            //config logging
            var loggerFactory = serviceProvider.GetService <ILoggerFactory>();

            loggerFactory.AddConsole(LogLevel.Debug);

            PersistenceProvider = serviceProvider.GetService <IPersistenceProvider>();
            Host = serviceProvider.GetService <IWorkflowHost>();
            Host.RegisterWorkflow <TWorkflow, TData>();
            Host.Start();
        }
Exemple #25
0
        private void RegisterWorkflows()
        {
            if (isRegistered)
            {
                return;
            }
            //var savedWorkflows = _host.PersistenceStore.GetWorkflowInstances(null, null, null, null, 0, 100);
            foreach (var workflow in workflows.Where(w => !w.IsGeneric))
            {
                _host.RegisterWorkflow(workflow as IWorkflow);
            }

            foreach (var workflow in workflows.Where(w => w.IsGeneric))
            {
                _host.RegisterGenericWorkflow(workflow);
            }

            _host.OnStepError += _host_OnStepError;
            isRegistered       = true;
        }
Exemple #26
0
        private void RegisterWorkflows(WorkflowMode mode)
        {
            if (isRegistered)
            {
                return;
            }

            foreach (var workflow in workflows.Where(w => !w.IsGeneric))
            {
                workflow.SetMode(mode);
                _host.RegisterWorkflow(workflow as IWorkflow);
            }

            foreach (var workflow in workflows.Where(w => w.IsGeneric))
            {
                workflow.SetMode(mode);
                _host.RegisterGenericWorkflow(workflow);
            }

            _host.OnStepError += _host_OnStepError;
            isRegistered       = true;
        }
Exemple #27
0
 public override void OnPostApplicationInitialization(ApplicationInitializationContext context)
 {
     workflowHost = context.ServiceProvider.GetService <IWorkflowHost>();
     workflowHost.RegisterWorkflow <CompensatingWorkflow>();
     workflowHost.Start();
 }