Example #1
1
        static void Main()
        {
            CreateRoles();

            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                workflowRuntime.StartRuntime();

                // Load the workflow type.
                Type type = typeof(PurchaseOrderWorkflow);

                ExternalDataExchangeService dataService = new ExternalDataExchangeService();
                workflowRuntime.AddService(dataService);

                poImpl = new StartPurchaseOrder();
                dataService.AddService(poImpl);

                workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                WorkflowInstance instance = workflowRuntime.CreateWorkflow(type);
                workflowInstanceId = instance.InstanceId;
                instance.Start();

                SendPORequestMessage();

                waitHandle.WaitOne();

                workflowRuntime.StopRuntime();
            }
        }
Example #2
0
        static void Main()
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {

                try
                {
                    // Start the engine.
                    workflowRuntime.StartRuntime();

                    // Load the workflow type.
                    Type type = typeof(Microsoft.Samples.Workflow.Synchronized.SynchronizedActivityWorkflow);

                    workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                    workflowRuntime.ServicesExceptionNotHandled += OnExceptionNotHandled;

                    workflowRuntime.CreateWorkflow(type).Start();

                    waitHandle.WaitOne();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception \n\t Source: {0} \n\t Message: {1}", e.Source, e.Message);
                }
                finally
                {
                    workflowRuntime.StopRuntime();
                    Console.WriteLine("\nWorkflow runtime stopped, program exiting... \n");
                }
            }
        }
Example #3
0
        static void Main()
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                try
                {
                    const string connectString = "Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;";

                    workflowRuntime.AddService(new SqlWorkflowPersistenceService(connectString));

                    workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                    workflowRuntime.WorkflowAborted += OnWorkflowAborted;

                    workflowRuntime.StartRuntime();
                    Type type = typeof(Compensation.PurchaseOrder);
                    workflowRuntime.CreateWorkflow(type).Start();

                    waitHandle.WaitOne();
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null)
                        Console.WriteLine(ex.InnerException.Message);
                    else
                        Console.WriteLine(ex.Message);
                }
                finally
                {
                    workflowRuntime.StopRuntime();
                }
            }
        }
        public void Pipeline_CC_Workflow_Should_Send_Acknowledgment_Email_To_Customer() {
            
            Order order = GetTestOrder();

            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime()) {
                AutoResetEvent waitHandle = new AutoResetEvent(false);
                workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { waitHandle.Set(); };
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) {
                    Debug.WriteLine(e.Exception.Message);
                    waitHandle.Set();
                };

                WorkflowInstance instance = workflowRuntime.CreateWorkflow(
                    typeof(Commerce.Pipelines.SubmitOrderWorkflow), GetParams(order));

                instance.Start();

                waitHandle.WaitOne();

                //execution should be finished
                //check the mailers
                TestMailerService mailer = _mailerService as TestMailerService;
                Assert.IsTrue(mailer.SentMail.Count > 0);

                //the first email should be to the customer
                Assert.AreEqual(MailerType.CustomerOrderReceived, mailer.SentMail[0].MailType);

            }
        }
Example #5
0
        static void Main(string[] args)
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                // Add ChannelManager
                ChannelManagerService channelmgr = new ChannelManagerService();
                workflowRuntime.AddService(channelmgr);
                
                AutoResetEvent waitHandle = new AutoResetEvent(false);
                workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { Console.WriteLine("WorkflowCompleted: " + e.WorkflowInstance.InstanceId.ToString()); waitHandle.Set(); };
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { Console.WriteLine("WorkflowTerminated: " + e.Exception.Message); waitHandle.Set(); };

                while (true)
                {
                    WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(Microsoft.WorkflowServices.Samples.SequentialCalculatorClient));
                    Console.WriteLine("Start SequentialCalculatorClient.");
                    instance.Start();
                    waitHandle.WaitOne();
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Do another calculation? (Y)");
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Press <enter> to exit.");
                    Console.ResetColor();
                    string input = Console.ReadLine();
                    if (input.Length == 0 || input[0] != 'Y')
                        break;
                    waitHandle.Reset();
                }
            }
        }
Example #6
0
        static void Main()
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                try
                {
                    // engine will unload workflow instance when it is idle
                    workflowRuntime.AddService(new FilePersistenceService(true));

                    workflowRuntime.WorkflowCreated += OnWorkflowCreated;
                    workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                    workflowRuntime.WorkflowIdled += OnWorkflowIdle;
                    workflowRuntime.WorkflowUnloaded += OnWorkflowUnload;
                    workflowRuntime.WorkflowLoaded += OnWorkflowLoad;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                    workflowRuntime.ServicesExceptionNotHandled += OnExceptionNotHandled;

                    workflowRuntime.CreateWorkflow(typeof(PersistenceServiceWorkflow)).Start();

                    waitHandle.WaitOne();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception \n\t Source: {0} \n\t Message: {1}", e.Source, e.Message);
                }
                finally
                {
                    workflowRuntime.StopRuntime();
                    Console.WriteLine("Workflow runtime stopped, program exiting... \n");
                }
            }
        }
Example #7
0
        static void Main()
        {
            // Create the WorkflowRuntime
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {

                // Set up the WorkflowRuntime events so that the host gets notified when the workflow
                // completes and terminates
                workflowRuntime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(OnWorkflowCompleted);
                workflowRuntime.WorkflowTerminated += new EventHandler<WorkflowTerminatedEventArgs>(OnWorkflowTerminated);

                // Load the workflow type
                Type type = typeof(ThrowWorkflow);

                //Start the workflow and wait for it to complete
                workflowRuntime.CreateWorkflow(type).Start();

                Console.WriteLine("Workflow Started.");
                waitHandle.WaitOne();

                Console.WriteLine("Workflow Completed.");

                workflowRuntime.StopRuntime();
            }
        }
Example #8
0
        static void Main()
        {
            string connectionString = "Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;";

            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                ExternalDataExchangeService dataService = new ExternalDataExchangeService();
                workflowRuntime.AddService(dataService);
                dataService.AddService(expenseService);

                workflowRuntime.AddService(new SqlWorkflowPersistenceService(connectionString));
                workflowRuntime.StartRuntime();

                workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                workflowRuntime.WorkflowIdled += OnWorkflowIdled;
                workflowRuntime.WorkflowAborted += OnWorkflowAborted;

                Type type = typeof(Microsoft.Samples.Workflow.CancelWorkflow.SampleWorkflow);
                WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(type);
                workflowInstance.Start();

                waitHandle.WaitOne();

                workflowRuntime.StopRuntime();
            }
        }
Example #9
0
        static void Main()
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {

                // Create our local service and add it to the workflow runtime's list of services
                ExternalDataExchangeService dataService = new ExternalDataExchangeService();
                workflowRuntime.AddService(dataService);
                VotingServiceImpl votingService = new VotingServiceImpl();
                dataService.AddService(votingService);

                // Start up the runtime and hook the creation and completion events
                workflowRuntime.StartRuntime();

                workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                workflowRuntime.WorkflowStarted += OnWorkflowStarted;

                // Create the workflow's parameters collection
                Dictionary<string, object> parameters = new Dictionary<string, object>();
                parameters.Add("Alias", "Jim");
                // Create and start the workflow
                Type type = typeof(HostCommunication.VotingServiceWorkflow);
                workflowRuntime.CreateWorkflow(type, parameters).Start();

                waitHandle.WaitOne();

                // Cleanly stop the runtime and all services
                workflowRuntime.StopRuntime();
            }
        }
 internal DebugController(WorkflowRuntime serviceContainer, string hostName)
 {
     if (serviceContainer == null)
     {
         throw new ArgumentNullException("serviceContainer");
     }
     try
     {
         this.programPublisher = new ProgramPublisher();
     }
     catch
     {
         return;
     }
     this.serviceContainer = serviceContainer;
     this.programId = Guid.Empty;
     this.controllerConduit = null;
     this.channel = null;
     this.isZombie = false;
     this.hostName = hostName;
     AppDomain.CurrentDomain.ProcessExit += new EventHandler(this.OnDomainUnload);
     AppDomain.CurrentDomain.DomainUnload += new EventHandler(this.OnDomainUnload);
     this.serviceContainer.Started += new EventHandler<WorkflowRuntimeEventArgs>(this.Start);
     this.serviceContainer.Stopped += new EventHandler<WorkflowRuntimeEventArgs>(this.Stop);
 }
Example #11
0
        static void Main()
        {
            // Start the engine.
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                workflowRuntime.StartRuntime();

                // Load the workflow type.
                Type type = typeof(SuspendAndTerminateWorkflow);

                workflowRuntime.WorkflowCompleted += OnWorkflowCompletion;
                workflowRuntime.WorkflowSuspended += OnWorkflowSuspend;
                workflowRuntime.WorkflowResumed += OnWorkflowResume;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminate;

                WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(type);
                workflowInstance.Start();

                waitHandle.WaitOne();

                if (workflowSuspended)
                {
                    Console.WriteLine("\r\nResuming Workflow Instance");
                    workflowInstance.Resume();
                    waitHandle.WaitOne();
                }

                workflowRuntime.StopRuntime();
            }

        }
Example #12
0
        static void Main()
        {
            // Start the engine.
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                workflowRuntime.StartRuntime();

                // Load the workflow type.
                Type type = typeof(IfElseWorkflow);

                workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                // The "OrderValueParameter" parameter is used to determine which branch of the IfElse should be executed
                // a value less than 10,000 will execute branch 1 - Get Manager Approval; any other value will execute branch 2 - Get VP Approval
                Dictionary<string, object> parameters = new Dictionary<string, object>();
                parameters.Add("OrderValue", 14000);
                WorkflowInstance workflow = workflowRuntime.CreateWorkflow(type, parameters);
                workflow.Start();

                waitHandle.WaitOne();

                workflowRuntime.StopRuntime();
            }
        }
Example #13
0
        public Mainform()
        {
            InitializeComponent();
            
            this.runtime = new WorkflowRuntime();

            runtime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(runtime_WorkflowCompleted);

            // Set up runtime to unload workflow instance from memory to file using FilePersistenceService
            FilePersistenceService filePersistence = new FilePersistenceService(true);
            runtime.AddService(filePersistence);

            // Add document approval service
            ExternalDataExchangeService dataService = new ExternalDataExchangeService();
            runtime.AddService(dataService);
            documentService = new DocumentApprovalService(this);
            dataService.AddService(documentService);

            // Search for workflows that have previously been persisted to file, and load into the listview control.
            // These workflows will be reloaded by the runtime when events are raised against them.
            LoadWorkflowData();

            // Start the runtime
            runtime.StartRuntime();
        }
Example #14
0
        protected override void Init()
        {
            Kernel.ComponentRegistered += Kernel_ComponentRegistered;

            _runtime = new WorkflowRuntime();
            Kernel.AddComponentInstance("workflowruntime", _runtime);
        }
Example #15
0
        static void Main(string[] args)
        {
            using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                AutoResetEvent waitHandle = new AutoResetEvent(false);
                workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) 
                {
                    Console.WriteLine("Workflow completed.");
                    waitHandle.Set();
                };
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                {
                    Console.WriteLine(e.Exception.Message);
                    waitHandle.Set();
                };

                WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(StateInitialization.SampleWorkflow));
                Console.WriteLine("Starting workflow.");
                instance.Start();

                waitHandle.WaitOne();

                workflowRuntime.StopRuntime();
            }
        }
Example #16
0
        /// <summary>
        /// 创建工作流运行时
        /// </summary>
        /// <param name="IsPer">是否使用持久化</param>
        /// <returns></returns>
        public static WorkflowRuntime CreateWorkFlowRuntime(bool IsPer)
        {
            try
            {
                WorkflowRuntime WfRuntime = new WorkflowRuntime();


                if (IsPer)
                {
                    ConnectionStringSettings defaultConnectionString = ConfigurationManager.ConnectionStrings["OracleConnection"];
                    WfRuntime.AddService(new AdoPersistenceService(defaultConnectionString, true, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(0)));
                    WfRuntime.AddService(new AdoTrackingService(defaultConnectionString));
                    WfRuntime.AddService(new AdoWorkBatchService());
                }

                FlowEvent ExternalEvent = new FlowEvent();
                ExternalDataExchangeService objService = new ExternalDataExchangeService();
                WfRuntime.AddService(objService);
                objService.AddService(ExternalEvent);

                ManualWorkflowSchedulerService scheduleService = new ManualWorkflowSchedulerService();
                WfRuntime.AddService(scheduleService);

                TypeProvider typeProvider = new TypeProvider(null);
                WfRuntime.AddService(typeProvider);
                WfRuntime.StartRuntime();
                return WfRuntime;
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("CreateWorkFlowRuntime异常信息 :" + ex.ToString());
                throw new Exception(ex.Message);
            }
        }
Example #17
0
        static void Main()
        {
            orderService = new OrderServiceImpl();

            // Start the workflow runtime engine.
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                ExternalDataExchangeService dataService = new ExternalDataExchangeService();
                workflowRuntime.AddService(dataService);
                dataService.AddService(orderService);

                workflowRuntime.StartRuntime();

                // Listen for the workflow events
                workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                workflowRuntime.WorkflowIdled += OnWorkflowIdled;

                // Start the workflow and wait for it to complete
                Type type = typeof(PurchaseOrderWorkflow);
                workflowRuntime.CreateWorkflow(type).Start();

                waitHandle.WaitOne();

                // Stop the workflow runtime engine.
                workflowRuntime.StopRuntime();
            }
        }
Example #18
0
        static void Main()
        {
            try
            {
                waitHandle = new AutoResetEvent(false);
                CreateAndInsertTrackingProfile();
                using (WorkflowRuntime runtime = new WorkflowRuntime())
                {
                    SqlTrackingService trackingService = new SqlTrackingService(connectionString);
                    runtime.AddService(trackingService);
                    runtime.StartRuntime();
                    runtime.WorkflowCompleted += OnWorkflowCompleted;
                    runtime.WorkflowTerminated += OnWorkflowTerminated;
                    runtime.WorkflowAborted += OnWorkflowAborted;

                    WorkflowInstance instance = runtime.CreateWorkflow(typeof(BankMachineWorkflow));
                    instance.Start();
                    waitHandle.WaitOne();

                    runtime.StopRuntime();
                    OutputTrackedData(instance.InstanceId);
                    
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                    Console.WriteLine(ex.InnerException.Message);
                else
                    Console.WriteLine(ex.Message);
            }
        }
Example #19
0
        static void Main()
        {
            // Create WorkflowRuntime
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                // Add ConsoleTrackingService
                workflowRuntime.AddService(new ConsoleTrackingService());

                // Subscribe to Workflow Completed WorkflowRuntime Event
                workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;

                // Subscribe to Workflow Terminated WorkflowRuntime Event
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                // Start WorkflowRuntime
                workflowRuntime.StartRuntime();

                // Execute the SampleWorkflow Workflow
                Console.WriteLine("Executing the workflow...");
                workflowRuntime.CreateWorkflow(typeof(SimplePolicyWorkflow)).Start();

                // Wait for the Workflow Completion
                waitHandle.WaitOne();

                // Stop Runtime
                workflowRuntime.StopRuntime();
            }
        }
Example #20
0
        static void Main()
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                try
                {
                    // Start the engine
                    workflowRuntime.StartRuntime();

                    // Subscribe to events
                    workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                    workflowRuntime.WorkflowIdled += OnWorkflowIdled;
                    workflowRuntime.ServicesExceptionNotHandled += OnServicesExceptionNotHandled;

                    // Start PO approval workflow with purchase less than $1000
                    System.Int32 poAmount = 750;
                    Type workflowType = typeof(Microsoft.Samples.Workflow.DynamicUpdateFromHost.DynamicUpdateWorkflow);
                    Dictionary<string, object> inputParameters = new Dictionary<string, object>();
                    inputParameters.Add("Amount", poAmount);
                    workflowRuntime.CreateWorkflow(workflowType, inputParameters).Start();
                    waitHandle.WaitOne();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception \n\t Source: {0} \n\t Message: {1}", e.Source, e.Message);
                }
                finally
                {
                    workflowRuntime.StopRuntime();
                    Console.WriteLine("Workflow runtime stopped, program exiting... \n");
                }
            }
        }
Example #21
0
        static void Main()
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                try
                {
                    // A workflow is always run asychronously; the main thread waits on this event so the program
                    // doesn't exit before the workflow completes
                    workflowRuntime.AddService(new SqlWorkflowPersistenceService("Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;"));

                    // Listen for the workflow events
                    workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                    workflowRuntime.WorkflowAborted += OnWorkflowAborted;

                    // Create an instance of the workflow
                    Type type = typeof(NestedExceptionsWorkflow);
                    workflowRuntime.CreateWorkflow(type).Start();
                    Console.WriteLine("Workflow Started.\n");

                    // Wait for the event to be signaled
                    waitHandle.WaitOne();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Source: {0}\nMessage: {1}", ex.Source, ex.Message);
                }
                finally
                {
                    workflowRuntime.StopRuntime();
                    Console.WriteLine("\nWorkflow Complete.");
                }
            }
        }
Example #22
0
        /////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////////
        public MainForm()
        {
            InitializeComponent();

            #region UI define
            GenerateButtons();
            GenerateAcctions();
            #endregion

            #region Bankomats Init

            currentAccountCulture = CultureInfo.CurrentCulture;

            #endregion

            #region IniT Workflow
            workflowRuntime = new WorkflowRuntime();
            ExternalDataExchangeService des = new ExternalDataExchangeService();
            workflowRuntime.AddService(des);
            des.AddService(this);

            workflowRuntime.StartRuntime();

            workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
            workflowRuntime.WorkflowTerminated += new EventHandler<WorkflowTerminatedEventArgs>(workflowRuntime_WorkflowTerminated);

            Type type = typeof(BankomatWorkflowLibrary.BankomatsWorkflow);
            workflowInstance = workflowRuntime.CreateWorkflow(type);
            workflowInstance.Start();
            #endregion
        }
Example #23
0
        public static WorkflowRuntime Init()
        {
            WorkflowRuntime workflowRuntime;

            // Running in local mode, create an return new runtime
            if( HttpContext.Current == null )
                workflowRuntime = new WorkflowRuntime();
            else
            {
                // running in web mode, runtime is initialized only once per 
                // application
                if( HttpContext.Current.Application["WorkflowRuntime"] == null )
                    workflowRuntime = new WorkflowRuntime();
                else
                    return HttpContext.Current.Application["WorkflowRuntime"] as WorkflowRuntime;
            }   

            var manualService = new ManualWorkflowSchedulerService();
            workflowRuntime.AddService(manualService);
            
            var syncCallService = new Activities.CallWorkflowService();
            workflowRuntime.AddService(syncCallService);

            workflowRuntime.StartRuntime();

            // on web mode, store the runtime in application context so that
            // it is initialized only once. On dekstop mode, ignore
            if( null != HttpContext.Current )
                HttpContext.Current.Application["WorkflowRuntime"] = workflowRuntime;

            return workflowRuntime;
        }
Example #24
0
        static void Main()
        {
            try
            {
                waitHandle = new AutoResetEvent(false);
                
                DataAccess.CreateAndInsertTrackingProfile();
                using (WorkflowRuntime runtime = new WorkflowRuntime())
                {
                    SqlTrackingService trackingService = new SqlTrackingService(DataAccess.connectionString);

                    /*
                     *  Set partitioning settings on Sql Tracking Service and database
                     */

                    //Turn on PartitionOnCompletion setting-- Default is false
                    trackingService.PartitionOnCompletion = true;

                    //Set partition interval-- Default is 'm' (monthly)
                    DataAccess.SetPartitionInterval('d');

                    runtime.AddService(trackingService);
                    runtime.StartRuntime();

                    runtime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
                    {
                       waitHandle.Set();
                    };
                    
                    runtime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                    {
                        Console.WriteLine(e.Exception.Message);
                        waitHandle.Set();
                    };

                    WorkflowInstance instance = runtime.CreateWorkflow(typeof(SimpleWorkflow));
                    instance.Start();
                    waitHandle.WaitOne();

                    runtime.StopRuntime();
                    DataAccess.GetWorkflowTrackingEvents(instance.InstanceId);
                    Console.WriteLine("\nDone running the workflow.");

                    /*
                     *  Show tracking partition information and tables
                     */

                    DataAccess.ShowTrackingPartitionInformation();
                    DataAccess.ShowPartitionTableInformation();
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                    Console.WriteLine(ex.InnerException.Message);
                else
                    Console.WriteLine(ex.Message);
            }
        }
		public void ThereCanBeOnlyOne () {
			CustomPersistenceService cp1 = new CustomPersistenceService ();
			CustomPersistenceService cp2 = new CustomPersistenceService ();

			WorkflowRuntime wr = new WorkflowRuntime ();
			wr.AddService (cp1);
			wr.AddService (cp2);
		}
		public void NoCorrelationParameter ()
		{
			SampleService1 sample = new SampleService1 ();
			WorkflowRuntime workflow = new WorkflowRuntime ();
			ExternalDataExchangeService data_change = new ExternalDataExchangeService ();
			workflow.AddService (data_change);
			data_change.AddService (sample);
		}
 public static WorkflowRuntime GetWorkflowRuntime(this Controller controller) {
     if (wfRuntime == null) {
         lock (padlock) {
             wfRuntime = new WorkflowRuntime();
         }
     }
     return wfRuntime;
 }
Example #28
0
		internal WorkflowInstance (Guid guid, WorkflowRuntime runtime, Activity root_activity)
		{
			this.guid = guid;
			this.runtime = runtime;
			this.root_activity = root_activity;
			subscription_collection = new TimerEventSubscriptionCollection ();
			queuing_service = new WorkflowQueuingService ();
		}
Example #29
0
		public JobWorkflow()
		{
			InitializeComponent();

            this.workflowRuntime = new WorkflowRuntime();
            this.workflowRuntime.StartRuntime();

            workflowRuntime.WorkflowCompleted +=   new EventHandler<WorkflowCompletedEventArgs> (workflowRuntime_WorkflowCompleted);
		}
Example #30
0
 static void Main(string[] args)
 {
     WorkflowRuntime workflowRuntime = new WorkflowRuntime();
     workflowRuntime.WorkflowCompleted += workflowRuntime_WorkflowCompleted;
     workflowRuntime.WorkflowTerminated += workflowRuntime_WorkflowTerminated;
     WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WorkflowMain));
     instance.Start();
     waitHandle.WaitOne();
 }
        private async Task <bool> ProjectHasAuthors(ProcessInstance processInstance, WorkflowRuntime runtime, string actionParameter, CancellationToken token)
        {
            using (var scope = ServiceProvider.CreateScope())
            {
                var productRepository = scope.ServiceProvider.GetRequiredService <IJobRepository <Product, Guid> >();
                var product           = await GetProductForProcess(processInstance, productRepository);

                var authorsRepository = scope.ServiceProvider.GetRequiredService <IJobRepository <Author> >();
                var authors           = await authorsRepository.Get()
                                        .Where(a => a.ProjectId == product.ProjectId)
                                        .ToListAsync();

                return((authors != null) && authors.Count > 0);
            }
        }
Example #32
0
 /// <summary>
 /// Start the workflow runtime
 /// </summary>
 private void InitializeWorkflowRuntime()
 {
     _workflowRuntime = new WorkflowRuntime();
     _workflowRuntime.WorkflowCompleted
         += delegate(object sender, WorkflowCompletedEventArgs e)
         {
         _waitHandle.Set();
         };
     _workflowRuntime.WorkflowTerminated
         += delegate(object sender, WorkflowTerminatedEventArgs e)
         {
         Console.WriteLine(e.Exception.Message);
         _waitHandle.Set();
         };
 }
Example #33
0
        public static void Detach()
        {
            WorkflowRuntime workflowRuntime = AppDomain.CurrentDomain.GetData(WorkflowRuntimeName) as WorkflowRuntime;

            if (workflowRuntime != null)
            {
                lock (AppDomain.CurrentDomain.FriendlyName)
                {
                    if (workflowRuntime != null)
                    {
                        workflowRuntime.StopRuntime();
                    }
                }
            }
        }
 /// <summary>
 /// Diposes the workflow runtime.
 /// </summary>
 public void DisposeRuntime()
 {
     // dispose runtime
     if (_workflowRuntime != null)
     {
         _workflowRuntime.Dispose();
     }
     _workflowRuntime = null;
     if (_waitHandle != null)
     {
         _waitHandle.Close();
     }
     _waitHandle = null;
     _instance   = null;
 }
        /// <summary>
        ///     Gets the workflow runtime.
        /// </summary>
        /// <returns>The runtime</returns>
        /// <externalUnit/>
        /// <revision revisor="dev14" date="8/6/2009" version="1.0.14.30">
        ///     Member Created
        /// </revision>
        public static WorkflowRuntime GetWorkflowRuntime()
        {
            lock (syncRoot)
            {
                // if the instance of the runtime does not exist yet, create it
                if (workflowRuntime == null)
                {
                    workflowRuntime = new WorkflowRuntime();
                    workflowRuntime.StartRuntime();
                }

                // return the singleton instance of the workflow
                return(workflowRuntime);
            }
        }
Example #36
0
        private static void DumpStateMachine(WorkflowRuntime runtime, Guid instanceID)
        {
            var instance =
                new StateMachineWorkflowInstance(runtime, instanceID);

            Console.WriteLine("Workflow ID: {0}", instanceID);
            Console.WriteLine("Current State: {0}",
                              instance.CurrentStateName);
            Console.WriteLine("Possible Transitions: {0}",
                              instance.PossibleStateTransitions.Count);
            foreach (string name in instance.PossibleStateTransitions)
            {
                Console.WriteLine("\t{0}", name);
            }
        }
Example #37
0
        public void FillInbox(Guid processId, WorkflowRuntime workflowRuntime)
        {
            var newActors      = workflowRuntime.GetAllActorsForDirectCommandTransitions(processId);
            var processIdBytes = processId.ToByteArray();

            foreach (var newActor in newActors)
            {
                var newInboxItem = new WorkflowInbox()
                {
                    Id = Guid.NewGuid().ToByteArray(), IdentityId = newActor, ProcessId = processIdBytes
                };
                _sampleContext.WorkflowInboxes.Add(newInboxItem);
            }
            _sampleContext.SaveChanges();
        }
Example #38
0
        private async Task ApiRequestAsync(ProcessInstance process, WorkflowRuntime runtime, string parameters, CancellationToken cancellationToken, JObject entity)
        {
            var source = Util.FindAutoMapExpression(parameters, entity);

            if (Util.TryDeserializeObject(source, out ApiRequestDtoInput apiRequestDtoInput))
            {
                var responce     = Helpers.ApiRequestAsync(apiRequestDtoInput, cancellationToken);
                var jtokenResult = JsonConvert.DeserializeObject <JToken>(await responce);
                entity.Add(apiRequestDtoInput.AttributeSuccessName, jtokenResult);
            }
            else
            {
                throw new Exception($"Can not Deserialize or are missed some input parameters");
            }
        }
Example #39
0
        /// <summary>
        /// 激发事件到一下状态,并获取状态代码
        /// </summary>
        /// <param name="WfRuntime"></param>
        /// <param name="instance"></param>
        /// <param name="CurrentStateName"></param>
        /// <param name="xml"></param>
        /// <returns></returns>
        public static string GetNextStateByEvent(WorkflowRuntime WfRuntime, WorkflowInstance instance, string CurrentStateName, string xml)
        {
            try
            {
                if (!WfRuntime.IsStarted)
                {
                    WfRuntime.StartRuntime();
                }
                WfRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
                {
                    instance = null;
                };
                StateMachineWorkflowInstance workflowinstance = new StateMachineWorkflowInstance(WfRuntime, instance.InstanceId);

                ManualWorkflowSchedulerService scheduleService = WfRuntime.GetService(typeof(ManualWorkflowSchedulerService)) as ManualWorkflowSchedulerService;
                scheduleService.RunWorkflow(workflowinstance.InstanceId);
                workflowinstance.SetState(CurrentStateName);

                FlowDataType.FlowData FlowData = new FlowDataType.FlowData();
                FlowData.xml = xml;

                scheduleService.RunWorkflow(instance.InstanceId);
                WfRuntime.GetService <FlowEvent>().OnDoFlow(instance.InstanceId, FlowData);//激发流程引擎流转到下一状态
                scheduleService.RunWorkflow(instance.InstanceId);
                //while (true)
                //{
                //    string stateName = workflowinstance.CurrentStateName;

                //    if (stateName != null && stateName.ToUpper().IndexOf("START") == -1)
                //    {
                //        break;
                //    }
                //}
                //System.Threading.Thread.Sleep(1000);
                if (instance == null)
                {
                    return("EndFlow");
                }
                StateMachineWorkflowInstance workflowinstance1 = new StateMachineWorkflowInstance(WfRuntime, instance.InstanceId);
                return(workflowinstance1.CurrentStateName);
                //return GetNextState(WfRuntime, instance, CurrentStateName);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("GetNextStateByEvent异常信息 :" + ex.ToString());
                throw new Exception(ex.Message);
            }
        }
Example #40
0
        static void Main()
        {
            // Create WorkflowRuntime
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                try
                {
                    // Add SqlTrackingService
                    SqlTrackingService sqlTrackingService = new SqlTrackingService(connectionString);
                    sqlTrackingService.IsTransactional = false;
                    workflowRuntime.AddService(sqlTrackingService);

                    // Subscribe to Workflow Suspended WorkflowRuntime Event
                    workflowRuntime.WorkflowSuspended += OnWorkflowSuspended;
                    // Subscribe to Workflow Terminated WorkflowRuntime Event
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                    // Start WorkflowRuntime
                    workflowRuntime.StartRuntime();

                    // Execute the ExceptionWorkflow Workflow
                    WriteTitle("Executing the exception workflow");
                    WorkflowInstance exceptionWorkflowInstance = workflowRuntime.CreateWorkflow(typeof(ExceptionWorkflow));
                    exceptionWorkflowInstance.Start();
                    waitHandle.WaitOne();
                    QueryAndWriteTrackingInformationToConsole(exceptionWorkflowInstance.InstanceId, TrackingWorkflowEvent.Exception);
                    QueryAndWriteTrackingInformationToConsole(exceptionWorkflowInstance.InstanceId, TrackingWorkflowEvent.Terminated);

                    // Execute the SuspendedWorkflow Workflow
                    WriteTitle("Executing the suspended workflow");
                    WorkflowInstance suspendedWorkflowInstance = workflowRuntime.CreateWorkflow(typeof(SuspendedWorkflow));
                    suspendedWorkflowInstance.Start();
                    waitHandle.WaitOne();
                    QueryAndWriteTrackingInformationToConsole(suspendedWorkflowInstance.InstanceId, TrackingWorkflowEvent.Suspended);

                    // Stop Runtime
                    workflowRuntime.StopRuntime();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Encountered an exception. Exception Source: {0}, Exception Message: {1} ", e.Source, e.Message);
                }
                finally
                {
                    workflowRuntime.StopRuntime();
                }
            }
        }
Example #41
0
        /// <summary>
        /// Stops this instance.
        /// </summary>
        public static void StopRuntime()
        {
            if (WorkflowRuntime != null)
            {
                WorkflowRuntime.StopRuntime();

                WorkflowRuntime.WorkflowCompleted  -= new EventHandler <WorkflowCompletedEventArgs>(WorkflowRuntime_WorkflowCompleted);
                WorkflowRuntime.WorkflowTerminated -= new EventHandler <WorkflowTerminatedEventArgs>(WorkflowRuntime_WorkflowTerminated);
                WorkflowRuntime.WorkflowSuspended  -= new EventHandler <WorkflowSuspendedEventArgs>(WorkflowRuntime_WorkflowSuspended);
                WorkflowRuntime.WorkflowResumed    -= new EventHandler <WorkflowEventArgs>(WorkflowRuntime_WorkflowResumed);


                WorkflowRuntime.Dispose();
                WorkflowRuntime = null;
            }
        }
 public static ApprovalHistoryItem FromDB(WorkflowRuntime runtime, WorkflowApprovalHistory historyItem)
 {
     return(new ApprovalHistoryItem()
     {
         Id = historyItem.Id,
         ProcessId = historyItem.ProcessId,
         IdentityId = historyItem.IdentityId,
         AllowedTo = HelperParser.SplitWithTrim(historyItem.AllowedTo, ","),
         TransitionTime = runtime.ToRuntimeTime(historyItem.TransitionTime),
         Sort = historyItem.Sort,
         InitialState = historyItem.InitialState,
         DestinationState = historyItem.DestinationState,
         TriggerName = historyItem.TriggerName,
         Commentary = historyItem.Commentary,
     });
 }
Example #43
0
        void IExtension <ServiceHostBase> .Attach(ServiceHostBase owner)
        {
            // When this Extension is attached within the Service Host, create a
            // new instance of the WorkflowServiceContainer
            workflowRuntime = new WorkflowRuntime(workflowServicesConfig);
            workflowRuntime.ServicesExceptionNotHandled +=
                new EventHandler <ServicesExceptionNotHandledEventArgs>(
                    workflowRuntime_ServicesExceptionNotHandled);

            ExternalDataExchangeService exSvc = new ExternalDataExchangeService();

            workflowRuntime.AddService(exSvc);

            // Start the services associated with the container
            workflowRuntime.StartRuntime();
        }
Example #44
0
 //
 // IsOwner
 //
 public IEnumerable <string> ProjectOwnerGet(ProcessInstance processInstance, WorkflowRuntime runtime, string parameter)
 {
     using (var scope = ServiceProvider.CreateScope())
     {
         var productRepository = scope.ServiceProvider.GetRequiredService <IJobRepository <Product, Guid> >();
         var product           = productRepository.Get()
                                 .Where(p => p.Id == processInstance.ProcessId)
                                 .Include(p => p.Project)
                                 .ThenInclude(p => p.Owner)
                                 .FirstOrDefault();
         var workflowUserId = product?.Project.Owner.WorkflowUserId;
         return(workflowUserId.HasValue ? new List <string> {
             workflowUserId.Value.ToString()
         } : new List <string>());
     }
 }
Example #45
0
        static void Main(string[] args)
        {
            WorkflowRuntime workflowRuntime = new WorkflowRuntime();

            AutoResetEvent waitHandle = new AutoResetEvent(false);

            workflowRuntime.WorkflowCompleted  += delegate(object sender, WorkflowCompletedEventArgs e) { waitHandle.Set(); };
            workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
            workflowRuntime.WorkflowSuspended  += OnWorkflowSuspended;

            WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(CDelaySuspendTerminateSequential.Workflow1));

            instance.Start();

            waitHandle.WaitOne();
        }
Example #46
0
        public void RunningSimpleWorkflow()
        {
            WorkflowRuntime runtime = _container.Resolve <WorkflowRuntime>();

            ManualResetEvent finished = new ManualResetEvent(false);

            runtime.WorkflowCompleted  += delegate(object sender, WorkflowCompletedEventArgs e) { finished.Set(); };
            runtime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { finished.Set(); };

            WorkflowInstance workflow = runtime.CreateWorkflow(typeof(SimpleWorkflow));

            workflow.Start();
            bool isFinished = finished.WaitOne(TimeSpan.FromSeconds(1), false);

            Assert.IsTrue(isFinished, "Workflow must finish in less than a second");
        }
Example #47
0
        public static Activity Create()
        {
            var openSesameProgram = new Sequence();
            var printKey          = new PrintKey();
            var read          = new ReadLine();
            var printGreeting = new PrintGreeting();

            WorkflowRuntime.Bind(printKey.Key, printGreeting.Key);
            WorkflowRuntime.Bind(read.Text, printGreeting.Input);

            openSesameProgram.Add(printKey);
            openSesameProgram.Add(read);
            openSesameProgram.Add(printGreeting);

            return(openSesameProgram);
        }
        private void SetEntityAttribute(ProcessInstance process, WorkflowRuntime runtime, string parameters, JObject entity)
        {
            var source = Util.FindAutoMapExpression(parameters, entity);

            if (Util.TryDeserializeObject(source, out ApiRequestDtoInput apiRequestDtoInput))
            {
                apiRequestDtoInput.UrlAddress = apiRequestDtoInput.UrlAddress + EngineConstants.SetEntityAttributeEndpoint;
                var responce     = Helpers.ApiRequest(apiRequestDtoInput);
                var jtokenResult = JsonConvert.DeserializeObject <JToken>(responce);
                entity.Add(apiRequestDtoInput.AttributeSuccessName, jtokenResult);
            }
            else
            {
                throw new Exception($"Can not Deserialize or are missed some input parameters");
            }
        }
 public WorkflowProductService(
     IJobRepository <Product, Guid> productRepository,
     IJobRepository <UserTask> taskRepository,
     IJobRepository <User> userRepository,
     IJobRepository <ProductTransition> productTransitionRepository,
     SendNotificationService sendNotificationService,
     WorkflowRuntime runtime
     )
 {
     ProductRepository           = productRepository;
     TaskRepository              = taskRepository;
     UserRepository              = userRepository;
     ProductTransitionRepository = productTransitionRepository;
     SendNotificationService     = sendNotificationService;
     Runtime = runtime;
 }
Example #50
0
        public static WorkflowRuntime CreateDefaultRuntime()
        {
            WorkflowRuntime workflowRuntime = new WorkflowRuntime();

            var manualService = new ManualWorkflowSchedulerService();

            workflowRuntime.AddService(manualService);

            var syncCallService = new Activities.CallWorkflowService();

            workflowRuntime.AddService(syncCallService);

            workflowRuntime.StartRuntime();

            return(workflowRuntime);
        }
Example #51
0
        public void ComponentsProvidedByConfiguration()
        {
            WorkflowRuntime  runtime  = _container.Resolve <WorkflowRuntime>();
            WorkflowInstance instance = runtime.CreateWorkflow(typeof(CreateNameWorkflow));

            instance.Start();

            ManualWorkflowSchedulerService scheduler = _container.Resolve <ManualWorkflowSchedulerService>();

            scheduler.RunWorkflow(instance.InstanceId);

            TestingExternalData testingExternalData = (TestingExternalData)_container.Resolve <ITestingExternalData>();

            Assert.AreEqual("You are \"{0} {1}\".", testingExternalData.FullNameFormat, "Format must have been provided by config");
            Assert.AreEqual("You are \"hello world\".", testingExternalData.MostRecentFullName, "Full name must have been set by workflow execution");
        }
Example #52
0
        public Register()
        {
            InitializeComponent();

            // Get Connection Strings from Application Settings
            Properties.Settings settings = Properties.Settings.Default;
            registrationConnectionString = settings.ClassRegistrationConnectionString;
            trackingConnectionString     = settings.ClassRegistrationTrackingConnectionString;

            // Get workflow runtime from application object
            workflowRuntime = Application.Current.Properties["WorkflowRuntime"] as WorkflowRuntime;

            if (workflowRuntime == null)
            {
                InitializeWorkflowRuntime();
            }
        }
Example #53
0
        static void Main()
        {
            try
            {
                // Create the WorkflowRuntime
                using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
                {
                    // Add the SqlWorkflowPersistenceService service
                    WorkflowPersistenceService persistenceService =
                        new SqlWorkflowPersistenceService(
                            "Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;",
                            false,
                            new TimeSpan(1, 0, 0),
                            new TimeSpan(0, 0, 5));
                    workflowRuntime.AddService(persistenceService);

                    // Set up the WorkflowRuntime event handlers
                    workflowRuntime.WorkflowCompleted  += OnWorkflowCompleted;
                    workflowRuntime.WorkflowIdled      += OnWorkflowIdled;
                    workflowRuntime.WorkflowPersisted  += OnWorkflowPersisted;
                    workflowRuntime.WorkflowUnloaded   += OnWorkflowUnloaded;
                    workflowRuntime.WorkflowLoaded     += OnWorkflowLoaded;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
                    workflowRuntime.WorkflowAborted    += OnWorkflowAborted;


                    // Load the workflow type
                    Type type = typeof(PersistenceServicesWorkflow);

                    // Create an instance of the workflow
                    Console.WriteLine("Workflow Started.");
                    workflowRuntime.CreateWorkflow(type).Start();

                    // Wait for the event to be signaled
                    waitHandle.WaitOne();

                    // Stop the runtime
                    workflowRuntime.StopRuntime();
                    Console.WriteLine("Program Complete.");
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Application exception occurred: " + exception.Message);
            }
        }
Example #54
0
        static void Main(string[] args)
        {
            try
            {
                // The program passes the one and only argument into the workflow
                //  as the order amount.
                if (args.Length < 1)
                {
                    Console.WriteLine("Usage: SequentialWorkflowWithParameters [amount]");
                    return;
                }

                // Create the WorkflowRuntime
                using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
                {
                    Console.WriteLine("Runtime Started.");

                    // Listen for the workflow events
                    workflowRuntime.WorkflowCompleted  += OnWorkflowCompleted;
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                    // Set up the parameters
                    // "amount" is an "in" parameter and specifies the order amount.
                    //  If the amount is < 500 the status is "approved"; "rejected" otherwise.
                    Dictionary <string, object> parameters = new Dictionary <string, object>();
                    parameters.Add("Amount", Convert.ToInt32(args[0], CultureInfo.InvariantCulture));

                    // Get the workflow type
                    Type type = typeof(SequentialWorkflow);

                    // Create and start an instance of the workflow
                    workflowRuntime.CreateWorkflow(type, parameters).Start();
                    Console.WriteLine("Workflow Started.");

                    // Wait for the event to be signaled
                    waitHandle.WaitOne();

                    workflowRuntime.StopRuntime();
                    Console.WriteLine("Program Complete.");
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception occurred: " + exception.Message);
            }
        }
Example #55
0
        static void Main()
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                workflowRuntime.StartRuntime();

                workflowRuntime.WorkflowCompleted  += OnWorkflowCompleted;
                workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                Type type = typeof(SendEmailWorkflow);
                workflowRuntime.CreateWorkflow(type).Start();

                waitHandle.WaitOne();

                workflowRuntime.StopRuntime();
            }
        }
Example #56
0
        public void ServicesAreUsedByWorkflows()
        {
            _container.AddComponent("explodingtracking.service", typeof(ExplodingTrackingService));

            WorkflowRuntime runtime = _container.Resolve <WorkflowRuntime>();

            ManualResetEvent finished = new ManualResetEvent(false);

            runtime.WorkflowCompleted  += delegate(object sender, WorkflowCompletedEventArgs e) { finished.Set(); };
            runtime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { finished.Set(); };

            WorkflowInstance workflow = runtime.CreateWorkflow(typeof(SimpleWorkflow));

            workflow.Start();

            bool isFinished = finished.WaitOne(TimeSpan.FromSeconds(1), false);
        }
Example #57
0
        public void CreateGetWorkflow()
        {
            Guid guid1 = Guid.NewGuid();
            Guid guid2 = Guid.NewGuid();

            WorkflowRuntime wr = new WorkflowRuntime();

            Assert.AreEqual(false, wr.IsStarted, "C1#1");
            WorkflowInstance wi1 = wr.CreateWorkflow(typeof(SequentialWorkflowActivity), null, guid1);

            Assert.AreEqual(wi1.InstanceId, guid1, "C1#2");

            Assert.AreEqual(true, wr.IsStarted, "C1#3");
            WorkflowInstance wi2 = wr.CreateWorkflow(typeof(SequenceActivity), null, guid2);

            Assert.AreEqual(wi2.InstanceId, guid2, "C1#4");
        }
Example #58
0
 /// <summary>
 /// 建立虚拟流程实例
 /// </summary>
 /// <param name="WfRuntime"></param>
 /// <param name="xmlFileName"></param>
 /// <returns></returns>
 public static WorkflowInstance CreateWorkflowInstance(WorkflowRuntime WfRuntime, string xmlFileName)
 {
     try
     {
         WorkflowInstance instance;
         string           Xml    = AppDomain.CurrentDomain.BaseDirectory + "\\" + xmlFileName;
         XmlReader        reader = XmlReader.Create(Xml);
         instance = WfRuntime.CreateWorkflow(reader);
         instance.Start();
         return(instance);
     }
     catch (Exception ex)
     {
         LogHelper.WriteLog("CreateWorkflowInstance异常信息 :" + ex.ToString());
         throw new Exception(ex.Message);
     }
 }
        private void DoInitialize(int delayedTime)
        {
            if (_workflowRuntime != null)
            {
                return;
            }

            using (GlobalInitializerFacade.CoreNotLockedScope)
                using (_resourceLocker.Locker)
                {
                    if (_workflowRuntime != null)
                    {
                        return;
                    }

                    Log.LogVerbose(LogTitleColored, "----------========== Initializing Workflows (Delayed: {0}) ==========----------", delayedTime);
                    int startTime = Environment.TickCount;

                    _resourceLocker.ResetInitialization();

                    _workflowRuntime = InitializeWorkflowRuntime();

                    InitializeFormsWorkflowRuntime();

                    if (!_workflowRuntime.IsStarted)
                    {
                        _workflowRuntime.StartRuntime();
                    }

                    DeleteOldWorkflows();


                    _fileWorkflowPersistenceService.ListenToDynamicallyAddedWorkflows(OnNewWorkflowFileAdded);
                    LoadPersistedWorkflows();
                    LoadPersistedFormData();

                    int endTime = Environment.TickCount;
                    Log.LogVerbose(LogTitleColored, "----------========== Done initializing Workflows ({0} ms ) ==========----------", endTime - startTime);

                    foreach (Action action in _actionToRunWhenInitialized)
                    {
                        action();
                    }
                }
        }
Example #60
0
        public override void ExecuteUnderTransaction(JobExecutionContext context)
        {
            logger.Info("Start ChargingOrderJob....");

            var paymentUrlProvider       = context.JobDetail.JobDataMap["PaymentUrlProvider"].ToString();
            var backupPaymentUrlProvider = context.JobDetail.JobDataMap["BackupPaymentUrlProvider"].ToString();

            var orderService = (IOrderService)ServiceLocator.Current.GetService(typeof(IOrderService));

            if (orderService == null)
            {
                throw new NullReferenceException("orderService must not be null");
            }

            var orders = orderService.GetOrdersByStatus(OrderStatusEnum.Verified);

            using (var workflowRuntime = new WorkflowRuntime())
            {
                workflowRuntime.AddService(new TerminateHelperService());

                using (var manager = new WorkflowRuntimeManager(workflowRuntime))
                {
                    manager.MessageEvent += manager_MessageEvent;

                    for (var i = 0; i < orders.Count; i++)
                    {
                        var wfArguments = new Dictionary <string, object> {
                            { "OrderId", orders[i].Id },
                            { "PaymentProviderUrl", paymentUrlProvider },
                            { "BackupPaymentProviderUrl", backupPaymentUrlProvider }
                        };
                        var wrapper  = manager.StartWorkflow(typeof(ChargingOrderWorkflow), wfArguments);
                        var testWait = manager.WaitOne(wrapper.Id, 30000);

                        if (wrapper.Exception != null)
                        {
                            logger.Error(wrapper.Exception.Message);
                        }
                    }

                    manager.WaitAll(300000);
                    manager.ClearAllWorkflows();
                }
            }
        }