/// <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); } }
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; }
static void Main(string[] args) { Console.WriteLine("Starting CRySTAL..."); Console.WriteLine("Linking Workflow Runtime Services..."); CRySTAL.WorkflowInterface.WorkflowInterface.CustomerWF = new CRySTAL.WorkflowInterface.CustomerWorkflowInterface(); WorkflowRuntime workflowRuntime = new WorkflowRuntime(); AppDomain.CurrentDomain.SetData("WorkflowRuntime", workflowRuntime); ManualWorkflowSchedulerService manualScheduler = new ManualWorkflowSchedulerService(true); AppDomain.CurrentDomain.SetData("ManualScheduler", manualScheduler); workflowRuntime.AddService(manualScheduler); ExternalDataExchangeService des = new ExternalDataExchangeService(); workflowRuntime.AddService(des); des.AddService(CRySTAL.WorkflowInterface.WorkflowInterface.CustomerWF); TimeSpan reloadIntevral = new TimeSpan(0, 0, 0, 20, 0); TimeSpan ownershipDuration = new TimeSpan(0, 0, 30, 0); string connectionString = @"Data Source=ETHIELE-LENOVO\SQLEXPRESS;Initial Catalog=WFTrackingAndPersistence;Integrated Security=True"; SqlWorkflowPersistenceService sqlPersistenceService = new SqlWorkflowPersistenceService(connectionString, true, ownershipDuration, reloadIntevral); workflowRuntime.AddService(sqlPersistenceService); SqlTrackingService sts = new SqlTrackingService(connectionString); workflowRuntime.AddService(sts); Console.WriteLine("Starting Workflow Runtime..."); workflowRuntime.StartRuntime(); //AppDomain.CurrentDomain.SetData("firstNamestr", "thisisatest"); List<ServiceHost> hosts = new List<ServiceHost>(); hosts.Add(new ServiceHost(typeof(CRySTAL.CookService))); hosts.Add(new ServiceHost(typeof(CRySTAL.BusBoyService))); hosts.Add(new ServiceHost(typeof(CRySTAL.HostService))); hosts.Add(new ServiceHost(typeof(CRySTAL.LoginService))); hosts.Add(new ServiceHost(typeof(CRySTAL.MenuService))); hosts.Add(new ServiceHost(typeof(CRySTAL.WaiterService))); foreach (ServiceHost host in hosts) { host.Open(); Console.WriteLine("CRySTAL: Service Running: " + host.BaseAddresses[0].ToString()); } Console.WriteLine("CRySTAL Ready"); Console.ReadLine(); Console.WriteLine("Shutting down CRySTAL..."); foreach (ServiceHost host in hosts) { host.Close(); Console.WriteLine("CRySTAL: Shutingdown Service :" + host.BaseAddresses[0].ToString()); } Console.WriteLine("Shutting down runtime..."); workflowRuntime.StopRuntime(); Console.WriteLine("CRySTAL shutdown complete"); Console.ReadLine(); }
private WorkflowRuntime InitializeWorkflowRuntime() { WorkflowRuntime workflowRuntime; if (WorkflowRuntimeProviderPluginFacade.HasConfiguration) { string providerName = WorkflowRuntimeProviderRegistry.DefaultWorkflowRuntimeProviderName; workflowRuntime = WorkflowRuntimeProviderPluginFacade.GetWorkflowRuntime(providerName); } else { Log.LogVerbose(LogTitle, "Using default workflow runtime"); workflowRuntime = new WorkflowRuntime(); } _manualWorkflowSchedulerService = new ManualWorkflowSchedulerService(true); workflowRuntime.AddService(_manualWorkflowSchedulerService); _fileWorkflowPersistenceService = new FileWorkflowPersistenceService(SerializedWorkflowsDirectory); workflowRuntime.AddService(_fileWorkflowPersistenceService); _externalDataExchangeService = new ExternalDataExchangeService(); workflowRuntime.AddService(_externalDataExchangeService); AddWorkflowLoggingEvents(workflowRuntime); workflowRuntime.WorkflowCompleted += (sender, args) => { using (ThreadDataManager.EnsureInitialize()) { OnWorkflowInstanceTerminatedCleanup(args.WorkflowInstance.InstanceId); } }; workflowRuntime.WorkflowAborted += (sender, args) => { using (ThreadDataManager.EnsureInitialize()) { OnWorkflowInstanceTerminatedCleanup(args.WorkflowInstance.InstanceId); } }; workflowRuntime.WorkflowTerminated += (sender, args) => { using (ThreadDataManager.EnsureInitialize()) { OnWorkflowInstanceTerminatedCleanup(args.WorkflowInstance.InstanceId); } using (_resourceLocker.Locker) { _resourceLocker.Resources.ExceptionFromWorkflow.Add(Thread.CurrentThread.ManagedThreadId, args.Exception); } }; workflowRuntime.WorkflowCreated += (sender, args) => SetWorkflowInstanceStatus(args.WorkflowInstance.InstanceId, WorkflowInstanceStatus.Idle, true); workflowRuntime.WorkflowIdled += (sender, args) => SetWorkflowInstanceStatus(args.WorkflowInstance.InstanceId, WorkflowInstanceStatus.Idle, false); workflowRuntime.WorkflowLoaded += (sender, args) => SetWorkflowInstanceStatus(args.WorkflowInstance.InstanceId, WorkflowInstanceStatus.Idle, true); return workflowRuntime; }
public void Flush() { _workflowRuntime = null; _externalDataExchangeService = null; _manualWorkflowSchedulerService = null; _fileWorkflowPersistenceService = null; _formsWorkflowEventService = null; _resourceLocker.ResetInitialization(); }
static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Usage WorkflowThreading.exe [Single | Multi] [Delay | WaitForMessage]"); return; } if (!args[0].Equals("Single", StringComparison.OrdinalIgnoreCase) && !args[0].Equals("Multi", StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("Specify Single or Multi as a first command line parameter"); return; } if (!args[1].Equals("Delay", StringComparison.OrdinalIgnoreCase) && !args[1].Equals("WaitForMessage", StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("Specify Delay or WaitForMessage as a second command line parameter"); return; } ThreadMonitor.Enlist(Thread.CurrentThread, "Host"); Console.ForegroundColor = ConsoleColor.White; // Start the engine using (workflowRuntime = new WorkflowRuntime()) { ManualWorkflowSchedulerService scheduler = null; if (args[0].ToString().Equals("Single", StringComparison.OrdinalIgnoreCase)) { scheduler = new ManualWorkflowSchedulerService(); workflowRuntime.AddService(scheduler); } workflowRuntime.StartRuntime(); // Set up the workflow runtime event handlers workflowRuntime.WorkflowCompleted += OnWorkflowCompleted; workflowRuntime.WorkflowTerminated += OnWorkflowTerminated; workflowRuntime.WorkflowIdled += OnWorkflowIdled; workflowRuntime.WorkflowCreated += OnWorkflowCreated; // Load the workflow type Type type = typeof(ThreadingWorkflow); Dictionary<string, object> workflowParameters = new Dictionary<string, object>(); workflowParameters.Add("BranchFlag", args[1]); Console.WriteLine("\n--- Before Starting Workflow ---\n"); // Create an instance of the workflow workflowInstance = workflowRuntime.CreateWorkflow(type, workflowParameters); workflowInstance.Start(); Console.WriteLine("\n--- After Starting Workflow ---\n"); if (scheduler != null) scheduler.RunWorkflow(workflowInstance.InstanceId); readyHandle.WaitOne(); if (args[1].Equals("WaitForMessage", StringComparison.OrdinalIgnoreCase)) { // Send message to WaitForMessageActivity's queue workflowInstance.EnqueueItem("WaitForMessageActivityQueue", "Hello", null, null); } if (scheduler != null) scheduler.RunWorkflow(workflowInstance.InstanceId); waitHandle.WaitOne(); workflowRuntime.StopRuntime(); } }
public override void Initialize(string name, NameValueCollection config) { base.Initialize(name, config); if (!string.IsNullOrEmpty(config["applicationName"])) { this._applicationName = config["applicationName"]; config.Remove("applicationName"); } if (!string.IsNullOrEmpty(config["connectionStringName"])) { this._connectionStringName = config["connectionStringName"]; config.Remove("connectionStringName"); } if (!string.IsNullOrEmpty(config["synchronousExecution"])) { this._synchronousExecution = Convert.ToBoolean(config["synchronousExecution"]); config.Remove("synchronousExecution"); } if (!string.IsNullOrEmpty(config["defaultStartTime"])) { this._defaultEndTime = config["defaultStartTime"]; config.Remove("defaultStartTime"); } if (!string.IsNullOrEmpty(config["defaultEndTime"])) { this._defaultEndTime = config["defaultEndTime"]; config.Remove("defaultEndTime"); } if (!string.IsNullOrEmpty(config["timeToExpire"])) { this._timeToExpire = TimeSpan.Parse(config["timeToExpire"]); config.Remove("timeToExpire"); } if (!string.IsNullOrEmpty(config["includeWeekends"])) { this._includeWeekends = Convert.ToBoolean(config["includeWeekends"]); config.Remove("includeWeekends"); } if (!string.IsNullOrEmpty(config["requestSchemaPath"])) { this._requestSchemaPath = config["requestSchemaPath"]; config.Remove("requestSchemaPath"); } if (!string.IsNullOrEmpty(config["responseSchemaPath"])) { this._responseSchemaPath = config["responseSchemaPath"]; config.Remove("responseSchemaPath"); } if (config.Count > 0) throw new ProviderException(string.Format("Unknown config attribute '{0}'", config.GetKey(0))); #region Workflow Runtime Initialization if (theWorkflowRuntime == null) { lock (this) { if (theWorkflowRuntime == null) { theWorkflowRuntime = new WorkflowRuntime(); theWorkflowRuntime.WorkflowLoaded += new EventHandler<WorkflowEventArgs>(theWorkflowRuntime_WorkflowLoaded); theWorkflowRuntime.WorkflowIdled += new EventHandler<WorkflowEventArgs>(theWorkflowRuntime_WorkflowIdled); theWorkflowRuntime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(theWorkflowRuntime_WorkflowCompleted); theWorkflowRuntime.WorkflowTerminated += new EventHandler<WorkflowTerminatedEventArgs>(theWorkflowRuntime_WorkflowTerminated); theWorkflowRuntime.WorkflowSuspended += new EventHandler<WorkflowSuspendedEventArgs>(theWorkflowRuntime_WorkflowSuspended); // Used for synchronous execution of workflow instances. if (this.SynchronousExecution) theSchedulerService = theWorkflowRuntime.GetService<ManualWorkflowSchedulerService>(); // Add the external data service ExternalDataExchangeService dataService = new ExternalDataExchangeService(); theWorkflowRuntime.AddService(dataService); // Add custom wiki management service. theServiceProvider = new ServiceProviderHelper(); dataService.AddService(theServiceProvider); // Add system SQL state service. SqlWorkflowPersistenceService stateService = new SqlWorkflowPersistenceService( ConfigurationManager.ConnectionStrings[this.ConnectionStringName].ConnectionString); theWorkflowRuntime.AddService(stateService); try { Trace.TraceInformation("Starting workflow engine."); // Start theWorkflowRuntime.StartRuntime(); Trace.TraceInformation("Workflow engine was sucessfully started."); } catch (Exception ex) { Trace.TraceError(string.Format( "Error while starting the workflow engine. Description: {0}", ex.Message)); theWorkflowRuntime.Dispose(); throw; } } } } #endregion }
private static System.Workflow.Runtime.WorkflowRuntime CreateRuntime() { var runtime = new System.Workflow.Runtime.WorkflowRuntime(); var manualService = new ManualWorkflowSchedulerService(); runtime.AddService(manualService); return runtime; }