// after the above 3 functions(conditions) are satisfied(return false) the employee is allowed to sign-in. public void SignIn(SignInSignOutModel objSignInSignOutModel) { try { SqlDataReader sdrSignIn = objSignInSignOutBOL.SignIn(objSignInSignOutModel); Guid gSignInSignOutWFID = new Guid("00000000-0000-0000-0000-000000000000"); int SignInSignOutID = 0; while (sdrSignIn.Read()) { if (sdrSignIn[1].ToString() != "") { SignInSignOutID = Convert.ToInt32(sdrSignIn[0].ToString()); gSignInSignOutWFID = new Guid(sdrSignIn[1].ToString()); System.Workflow.Runtime.WorkflowRuntime wr = (System.Workflow.Runtime.WorkflowRuntime)Application["WokflowRuntime"]; Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("SignInSignOutID", SignInSignOutID); WorkflowInstance wi = wr.CreateWorkflow(typeof(SignInSignOutWF.SignInSignOutWF), parameters, gSignInSignOutWFID); wi.Start(); } } } catch (V2Exceptions ex) { throw; } catch (System.Exception ex) { FileLog objFileLog = FileLog.GetLogger(); objFileLog.WriteLine(LogType.Error, ex.Message, "SignInSignOut.cs", "SignIn", ex.StackTrace); throw new V2Exceptions(); } }
/// <summary> /// Execute un workflow de manière manuelle, le thread est bloqué /// jusqu'a la fin. /// </summary> /// <param name="workflowType">Type of the workflow.</param> /// <param name="properties">The properties.</param> public static void ExecuteManualWorkflow(Type workflowType, Dictionary<string, object> properties) { if (m_Runtime == null) { m_Runtime = CreateRuntime(); var logger = DependencyResolver.Current.GetService<Logging.ILogger>(); m_Runtime.AddService(new Workflows.LoggerTrackingService(logger)); } var manualScheduler = m_Runtime.GetService<ManualWorkflowSchedulerService>(); var instance = m_Runtime.CreateWorkflow(workflowType, properties); Exception ex = null; EventHandler<WorkflowCompletedEventArgs> completedHandler = null; completedHandler = (o, e) => { if (e.WorkflowInstance.InstanceId != instance.InstanceId) { return; } m_Runtime.WorkflowCompleted -= completedHandler; var enumerator = e.OutputParameters.GetEnumerator(); while (enumerator.MoveNext()) { var pair = enumerator.Current; if (properties != null && properties.ContainsKey(pair.Key)) { properties[pair.Key] = pair.Value; } } }; EventHandler<WorkflowTerminatedEventArgs> terminatedHandler = null; terminatedHandler = delegate(object o, WorkflowTerminatedEventArgs e) { if (e.WorkflowInstance.InstanceId != instance.InstanceId) { return; } m_Runtime.WorkflowTerminated -= terminatedHandler; ex = e.Exception; }; m_Runtime.WorkflowCompleted += completedHandler; instance.Start(); manualScheduler.RunWorkflow(instance.InstanceId); if (ex != null) { throw ex; } }
internal void Initialize(WorkflowRuntime runtime) { lock (this) { this._services = runtime.TrackingServices; this._profileManager.Initialize(runtime); runtime.WorkflowExecutorInitializing += new EventHandler <WorkflowRuntime.WorkflowExecutorInitializingEventArgs>(this.WorkflowExecutorInitializing); this._timer = new Timer(); this._timer.Interval = this._interval; this._timer.AutoReset = false; this._timer.Elapsed += new ElapsedEventHandler(this.Cleanup); this._timer.Start(); this._initialized = true; } }
internal void Uninitialize() { lock (this._cacheLock) { if (this._runtime != null) { foreach (TrackingService service in this._services) { if (service is IProfileNotification) { ((IProfileNotification)service).ProfileUpdated -= new EventHandler <ProfileUpdatedEventArgs>(this.ProfileUpdated); ((IProfileNotification)service).ProfileRemoved -= new EventHandler <ProfileRemovedEventArgs>(this.ProfileRemoved); } } } this._runtime = null; this._services = null; this._init = false; } }
internal void Register(WorkflowRuntime workflowRuntime, bool validate) { if (workflowRuntime == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("workflowRuntime"); } this.workflowRuntime = workflowRuntime; OnRegister(); if (!this.workflowRuntime.IsStarted) { this.workflowRuntime.StartRuntime(); } if (validate) { ValidateDefinition(); } }
internal void Initialize(WorkflowRuntime runtime) { runtime.WorkflowExecutorInitializing += new EventHandler <WorkflowRuntime.WorkflowExecutorInitializingEventArgs>(this.WorkflowExecutorInitializing); }
public static void ClearCache() { WorkflowRuntime.ClearTrackingProfileCache(); }
void IDisposable.Dispose() { workflowRuntime = null; }
public RuntimeEnvironment(WorkflowRuntime runtime) { workflowRuntime = runtime; }
internal void ValidateDefinition(Activity root, bool isNewType, ITypeProvider typeProvider) { if (!this.validateOnCreate) { return; } ValidationErrorCollection errors = new ValidationErrorCollection(); // For validation purposes, create a type provider in the type case if the // host did not push one. if (typeProvider == null) { typeProvider = WorkflowRuntime.CreateTypeProvider(root); } // Validate that we are purely XAML. if (!isNewType) { if (!string.IsNullOrEmpty(root.GetValue(WorkflowMarkupSerializer.XClassProperty) as string)) { errors.Add(new ValidationError(ExecutionStringManager.XomlWorkflowHasClassName, ErrorNumbers.Error_XomlWorkflowHasClassName)); } Queue compositeActivities = new Queue(); compositeActivities.Enqueue(root); while (compositeActivities.Count > 0) { Activity activity = compositeActivities.Dequeue() as Activity; if (activity.GetValue(WorkflowMarkupSerializer.XCodeProperty) != null) { errors.Add(new ValidationError(ExecutionStringManager.XomlWorkflowHasCode, ErrorNumbers.Error_XomlWorkflowHasCode)); } CompositeActivity compositeActivity = activity as CompositeActivity; if (compositeActivity != null) { foreach (Activity childActivity in compositeActivity.EnabledActivities) { compositeActivities.Enqueue(childActivity); } } } } ServiceContainer serviceContainer = new ServiceContainer(); serviceContainer.AddService(typeof(ITypeProvider), typeProvider); ValidationManager validationManager = new ValidationManager(serviceContainer); using (WorkflowCompilationContext.CreateScope(validationManager)) { foreach (Validator validator in validationManager.GetValidators(root.GetType())) { foreach (ValidationError error in validator.Validate(validationManager, root)) { if (!error.UserData.Contains(typeof(Activity))) { error.UserData[typeof(Activity)] = root; } errors.Add(error); } } } if (errors.HasErrors) { throw new WorkflowValidationFailedException(ExecutionStringManager.WorkflowValidationFailure, errors); } }
internal void Uninitialize(WorkflowRuntime runtime) { runtime.WorkflowExecutorInitializing -= WorkflowExecutorInitializing; }
// Workflow processor internal static void RunWorkflow(Object stateInfo) { Stack <Activity> stack = new Stack <Activity> (); WorkflowInstance wi = WorkflowRuntime.GetInstanceFromGuid((Guid)stateInfo); wi.timer_subscriptions = new Timer(TimerSubscriptionsCallback, wi, 0, 1000); Activity activity = wi.GetWorkflowDefinition(); Activity next_activity; ActivityExecutionContextManager manager = new ActivityExecutionContextManager(wi); ActivityExecutionContext context; List <DelayActivity> waiting = new List <DelayActivity> (); bool wait = false; StateMachineWorkflowActivity state_machine = null; #if DEBUG_EXECUTIONLOOP Console.WriteLine("Initiating thread for activity {0}", wi.GetWorkflowDefinition()); #endif context = manager.CreateExecutionContext(activity); // Main Workflow execution loop while (activity != null) { next_activity = null; if (activity.NeedsExecution) { #if DEBUG_EXECUTIONLOOP Console.WriteLine("*** Executing {0}, parallel {1}", activity, activity.ParallelParent); #endif context.ExecuteActivity(activity); } // If this a state machine changing its statge update StateMachineWorkflowActivity if (state_machine != null && IsBasedOnType(activity, typeof(SetStateActivity))) { state_machine.SetCurrentStateName(((SetStateActivity)activity).TargetStateName); } #if DEBUG_EXECUTIONLOOP Console.WriteLine(" ActivitiesToExecute.Count {0}, stack {1}, waiting {2}", activity.ActivitiesToExecute.Count, stack.Count, waiting.Count); #endif wait = false; // State machine workflow, first activity is InitialStateName if (IsBasedOnType(activity, typeof(StateMachineWorkflowActivity))) { state_machine = (StateMachineWorkflowActivity)activity; stack.Push(activity.GetActivityByName(state_machine.InitialStateName)); state_machine.SetCurrentStateName(state_machine.InitialStateName); #if DEBUG_EXECUTIONLOOP Console.WriteLine(" StateMachineWorkflowActivity, pushing {0}", activity.GetActivityByName(sm.InitialStateName)); #endif } // TODO: if (IsBasedOnType (current, typeof (CompositeActivity))) { if (activity.GetType() == typeof(DelayActivity)) { if (activity.ParallelParent == null) { wi.WorkflowRuntime.OnWorkflowIdled(wi); waiting.Add((DelayActivity)activity); wait = true; } else { // Continue from parent activities // TODO: This can be moved to the Execute method // of the paralell activity if (activity.ParallelParent.ActivitiesToExecute.Count > 0) { stack.Push(activity.ParallelParent); #if DEBUG_EXECUTIONLOOP Console.WriteLine("Pushing parent {0}", activity.ParallelParent); #endif waiting.Add((DelayActivity)activity); } else // If not possible, wait for the delay { #if DEBUG_EXECUTIONLOOP Console.WriteLine("Schedule Waiting"); #endif waiting.Add((DelayActivity)activity); wait = true; } } } if (activity.NeedsExecution) // ex. While { stack.Push(activity); } if (activity.ActivitiesToExecute.Count == 0 && stack.Count == 0 && waiting.Count == 0) { #if DEBUG_EXECUTIONLOOP Console.WriteLine("Exiting..."); #endif break; } // Does it have sub-activities to run? // Delay is not composite, cannot have children activities if (wait == false) { if (activity.ActivitiesToExecute.Count > 0) { next_activity = activity.ActivitiesToExecute.Dequeue(); #if DEBUG_EXECUTIONLOOP Console.WriteLine("Next Activity A {0}", next_activity); #endif if (activity.ActivitiesToExecute.Count > 0) { stack.Push(activity); } } else { if (stack.Count > 0) { next_activity = stack.Pop(); } if (next_activity != null && next_activity.NeedsExecution == false) { if (next_activity.ActivitiesToExecute.Count > 0) { next_activity = next_activity.ActivitiesToExecute.Dequeue(); } } #if DEBUG_EXECUTIONLOOP Console.WriteLine("Next Activity B {0}", next_activity); #endif } } if (next_activity == null) { if (waiting.Count > 0) { #if DEBUG_EXECUTIONLOOP Console.WriteLine("Waiting for {0} handles...", waiting.Count); #endif wi.WorkflowRuntime.OnWorkflowIdled(wi); DelayActivity.WaitEvent.WaitOne(); } } // Do we have delay activities no longer waiting? foreach (DelayActivity delay in waiting) { if (delay.Delayed == false) { bool flag = false; // Continue with the list of activities pending in the parent next_activity = delay.Parent; waiting.Remove(delay); #if DEBUG_EXECUTIONLOOP Console.WriteLine("Delayed Parent {0}", next_activity); #endif if (next_activity.ActivitiesToExecute.Count > 0) { if (next_activity.ActivitiesToExecute.Count > 1) { flag = true; } if (next_activity != null) { next_activity = next_activity.ActivitiesToExecute.Dequeue(); if (flag == true) { stack.Push(delay.Parent); } } } break; } } #if DEBUG_EXECUTIONLOOP Console.WriteLine("Next activity to process {0}", next_activity); #endif activity = next_activity; } wi.WorkflowRuntime.OnWorkflowCompleted(wi); }
private static System.Workflow.Runtime.WorkflowRuntime CreateRuntime() { var runtime = new System.Workflow.Runtime.WorkflowRuntime(); var manualService = new ManualWorkflowSchedulerService(); runtime.AddService(manualService); return runtime; }