public WorkFlowIfElseRule() { IfElseActivity ifelse_activity = new IfElseActivity(); branch1 = new IfElseBranchActivity(); CodeActivity code_branch1 = new CodeActivity(); CodeActivity code_branch2 = new CodeActivity(); branch2 = new IfElseBranchActivity(); code_branch1.Name = "Code1"; code_branch2.Name = "Code2"; code_branch1.ExecuteCode += new EventHandler(ExecuteCode1); code_branch2.ExecuteCode += new EventHandler(ExecuteCode2); branch1.Activities.Add(code_branch1); branch2.Activities.Add(code_branch2); RuleConditionReference condition1 = new RuleConditionReference(); condition1.ConditionName = "Condition1"; RuleExpressionCondition rc = new RuleExpressionCondition("Condition1", RulesBinaryOpTest.check_condition); definitions.Conditions.Add(rc); branch1.Condition = condition1; ifelse_activity.Activities.Add(branch1); ifelse_activity.Activities.Add(branch2); SetValue(RuleDefinitions.RuleDefinitionsProperty, definitions); Activities.Add(ifelse_activity); }
public override object GetValue(object component) { if (component == null) { throw new ArgumentNullException("component"); } RuleConditionReference conditionDecl = component as RuleConditionReference; if (conditionDecl == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Messages.NotARuleConditionReference, "component"), "component"); } if (conditionDecl.ConditionName != null) { RuleDefinitions rules = GetRuleDefinitions(component); if (rules != null) { RuleConditionCollection conditionDefs = rules.Conditions; if (conditionDefs != null && conditionDefs.Contains(conditionDecl.ConditionName)) { //in this case, RuleExpressionCondition is the only type allowed in the ruleConditionCollection RuleExpressionCondition conditionDefinition = (RuleExpressionCondition)conditionDefs[conditionDecl.ConditionName]; return(conditionDefinition.Expression); } } } return(null); }
public override void SetValue(object component, object value) { if (component == null) { throw new ArgumentNullException("component"); } RuleConditionReference reference = component as RuleConditionReference; if (reference == null) { throw new ArgumentNullException("component"); } CodeExpression expression = value as CodeExpression; if (reference.ConditionName != null) { ISite serviceProvider = PropertyDescriptorUtils.GetSite(base.ServiceProvider, component); if (serviceProvider == null) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.MissingService, new object[] { typeof(ISite).FullName })); } RuleConditionCollection conditions = null; RuleDefinitions definitions = ConditionHelper.Load_Rules_DT(serviceProvider, Helpers.GetRootActivity(serviceProvider.Component as Activity)); if (definitions != null) { conditions = definitions.Conditions; } if ((conditions != null) && conditions.Contains(reference.ConditionName)) { RuleExpressionCondition condition = (RuleExpressionCondition)conditions[reference.ConditionName]; condition.Expression = expression; ConditionHelper.Flush_Rules_DT(serviceProvider, Helpers.GetRootActivity(serviceProvider.Component as Activity)); } } }
public override object GetValue(object component) { if (component == null) { throw new ArgumentNullException("component"); } RuleConditionReference reference = component as RuleConditionReference; if (reference == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Messages.NotARuleConditionReference, new object[] { "component" }), "component"); } if (reference.ConditionName != null) { RuleDefinitions ruleDefinitions = base.GetRuleDefinitions(component); if (ruleDefinitions != null) { RuleConditionCollection conditions = ruleDefinitions.Conditions; if ((conditions != null) && conditions.Contains(reference.ConditionName)) { RuleExpressionCondition condition = (RuleExpressionCondition)conditions[reference.ConditionName]; return(condition.Expression); } } } return(null); }
public override object EditValue(ITypeDescriptorContext typeDescriptorContext, IServiceProvider serviceProvider, object o) { if (typeDescriptorContext == null) { throw new ArgumentNullException("typeDescriptorContext"); } if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } object obj2 = o; RuleConditionReference instance = typeDescriptorContext.Instance as RuleConditionReference; if (((instance == null) || (instance.ConditionName == null)) || (instance.ConditionName.Length <= 0)) { throw new ArgumentException(Messages.ConditionNameNotSet); } Activity component = null; IReferenceService service = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService; if (service != null) { component = service.GetComponent(typeDescriptorContext.Instance) as Activity; } RuleConditionCollection conditions = null; RuleDefinitions definitions = ConditionHelper.Load_Rules_DT(serviceProvider, Helpers.GetRootActivity(component)); if (definitions != null) { conditions = definitions.Conditions; } if ((conditions != null) && !conditions.Contains(instance.ConditionName)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Messages.ConditionNotFound, new object[] { instance.ConditionName })); } this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService)); if (this.editorService != null) { CodeExpression expression = typeDescriptorContext.PropertyDescriptor.GetValue(typeDescriptorContext.Instance) as CodeExpression; try { using (RuleConditionDialog dialog = new RuleConditionDialog(component, expression)) { if (DialogResult.OK == this.editorService.ShowDialog(dialog)) { obj2 = dialog.Expression; } } } catch (NotSupportedException) { DesignerHelpers.DisplayError(Messages.Error_ExpressionNotSupported, Messages.ConditionEditor, serviceProvider); } } return(obj2); }
public override void SetValue(object component, object value) { if (component == null) { throw new ArgumentNullException("component"); } RuleConditionReference conditionDecl = component as RuleConditionReference; if (conditionDecl == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Messages.NotARuleConditionReference, "component"), "component"); } string conditionName = value as string; if ((conditionName == null) || (conditionName.TrimEnd().Length == 0)) { conditionName = string.Empty; } ISite site = PropertyDescriptorUtils.GetSite(this.ServiceProvider, component); if (site == null) { string message = string.Format(CultureInfo.CurrentCulture, Messages.MissingService, typeof(ISite).FullName); throw new InvalidOperationException(message); } RuleConditionCollection conditionDefinitions = null; RuleDefinitions rules = ConditionHelper.Load_Rules_DT(site, Helpers.GetRootActivity(site.Component as Activity)); if (rules != null) { conditionDefinitions = rules.Conditions; } if (conditionDefinitions != null && conditionName.Length != 0 && !conditionDefinitions.Contains(conditionName)) { //in this case, RuleExpressionCondition is the only type allowed in the ruleConditionCollection RuleExpressionCondition newCondition = new RuleExpressionCondition(); newCondition.Name = conditionName; conditionDefinitions.Add(newCondition); ConditionHelper.Flush_Rules_DT(site, Helpers.GetRootActivity(site.Component as Activity)); } // Cause component change events to be fired. PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(component)["ConditionName"]; if (propertyDescriptor != null) { PropertyDescriptorUtils.SetPropertyValue(site, propertyDescriptor, component, conditionName); } }
public override object GetValue(object component) { if (component == null) { throw new ArgumentNullException("component"); } RuleConditionReference reference = component as RuleConditionReference; if (reference == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Messages.NotARuleConditionReference, new object[] { "component" }), "component"); } if (reference.ConditionName != null) { return(reference.ConditionName); } return(null); }
public override void SetValue(object component, object value) { if (component == null) { throw new ArgumentNullException("component"); } RuleConditionReference conditionDecl = component as RuleConditionReference; if (conditionDecl == null) { throw new ArgumentNullException("component"); } CodeExpression expression = value as CodeExpression; if (conditionDecl.ConditionName != null) { ISite site = PropertyDescriptorUtils.GetSite(this.ServiceProvider, component); if (site == null) { string message = string.Format(CultureInfo.CurrentCulture, Messages.MissingService, typeof(ISite).FullName); throw new InvalidOperationException(message); } RuleConditionCollection conditionDefs = null; RuleDefinitions rules = ConditionHelper.Load_Rules_DT(site, Helpers.GetRootActivity(site.Component as Activity)); if (rules != null) { conditionDefs = rules.Conditions; } if (conditionDefs != null && conditionDefs.Contains(conditionDecl.ConditionName)) { //in this case, RuleExpressionCondition is the only type allowed in the ruleConditionCollection RuleExpressionCondition conditionDefinition = (RuleExpressionCondition)conditionDefs[conditionDecl.ConditionName]; conditionDefinition.Expression = expression; ConditionHelper.Flush_Rules_DT(site, Helpers.GetRootActivity(site.Component as Activity)); } } }
public T GetFlowObject <T>(FlowChart flowChart) { string lzm = string.Format(Resource.myState, "结束状态", "900", "700"); //------------------------------------------------------------------------- wxwinter.wf.WFLib.状态机模板 workflow = new wxwinter.wf.WFLib.状态机模板(); RuleConditionReference ruleconditionreference1 = new RuleConditionReference(); ruleconditionreference1.ConditionName = "启用"; workflow.SetValue(WorkflowChanges.ConditionProperty, ruleconditionreference1); FlowChartData fcd = flowChart.FlowData as FlowChartData; if (fcd != null) { workflow.模板版本 = fcd.模板版本; workflow.模板编号 = fcd.模板编号; workflow.模板名称 = fcd.模板名称; workflow.模板说明 = fcd.模板说明; workflow.启动时填写的表单 = fcd.启动时填写的表单; workflow.数据表单列表 = fcd.数据表单列表; } //-开始结点 workflow.InitialStateName = "开始状态"; StateActivity 开始状态 = new StateActivity("开始状态"); StateInitializationActivity 开始状态自动容器 = new StateInitializationActivity("开始状态自动容器"); wxwinter.wf.WFLib.初始化 开始启动流程 = new wxwinter.wf.WFLib.初始化(); 开始启动流程.Name = "开始启动流程"; workflow.Activities.Add(开始状态); 开始状态.Activities.Add(开始状态自动容器); 开始状态自动容器.Activities.Add(开始启动流程); //////////////// foreach (var node in flowChart.ElementList) { lzm = lzm + string.Format(Resource.myState, node.Name, node.X坐标, node.Y坐标); if (node.类型 == "头") { var r = flowChart.ElementRelationList.FirstOrDefault(p => p.起点 == node.Name && p.路由 == "开始状态"); if (r != null) { SetStateActivity 启动流程 = new SetStateActivity("启动流程"); 启动流程.TargetStateName = r.目标; 开始状态自动容器.Activities.Add(启动流程); } } } //---------------------------------------------------------------- //-完成结点 StateActivity 结束状态 = new StateActivity("结束状态"); workflow.Activities.Add(结束状态); workflow.CompletedStateName = "结束状态"; StateActivity 归档状态 = new StateActivity("归档状态"); StateInitializationActivity 归档状态自动容器 = new StateInitializationActivity("归档状态自动容器"); wxwinter.wf.WFLib.归档 流程归档 = new wxwinter.wf.WFLib.归档(); 流程归档.Name = "流程归档"; workflow.Activities.Add(归档状态); 归档状态.Activities.Add(归档状态自动容器); 归档状态自动容器.Activities.Add(流程归档); SetStateActivity 完成流程 = new SetStateActivity("完成流程"); 完成流程.TargetStateName = "结束状态"; 归档状态自动容器.Activities.Add(完成流程); // WindowsWorkflowObject wf = new WindowsWorkflowObject(); foreach (var node in flowChart.ElementList) { if (node.类型 == "节") { string n = node.Name; System.Workflow.Activities.StateActivity state = new System.Workflow.Activities.StateActivity(); state.Name = n; System.Workflow.Activities.EventDrivenActivity eda = new System.Workflow.Activities.EventDrivenActivity(); eda.Name = n + "_等待容器"; wxwinter.wf.WFLib.等待提交 waitsubmit = new wxwinter.wf.WFLib.等待提交(); waitsubmit.Name = n + "_处理中"; waitsubmit.状态名称 = n + "_处理中"; WaitControlData wd = node.结点数据 as WaitControlData; waitsubmit.办理查看业务表单 = wd.办理查看业务表单; waitsubmit.办理人员 = wd.办理人员; waitsubmit.办理时限 = wd.办理时限; waitsubmit.办理提交选项 = wd.办理提交选项; waitsubmit.办理添写业务表单 = wd.办理添写业务表单; waitsubmit.处理方式 = wd.处理方式; waitsubmit.接件部门 = wd.接件部门; waitsubmit.接件职能 = wd.接件职能; waitsubmit.启动窗体 = wd.启动窗体; waitsubmit.Description = wd.说明; wxwinter.wf.WFLib.条件容器 ir = new wxwinter.wf.WFLib.条件容器(); ir.Name = n + "_处理分支"; string ts = ""; foreach (var v in node.分支集合) { wxwinter.wf.WFLib.条件分支 fz = new wxwinter.wf.WFLib.条件分支(); fz.Name = n + "_处理分支_" + v.ToString(); fz.条件 = v.ToString(); ir.Activities.Add(fz); ts = ts + v.ToString() + ","; var r = flowChart.ElementRelationList.FirstOrDefault(p => p.起点 == node.Name && p.路由 == v); if (r == null) { wf = null; T tp = (T)((object)wf); return((T)tp); } else { SetStateActivity tp = new SetStateActivity(node.Name + "_到_" + r.目标); tp.TargetStateName = r.目标; fz.Activities.Add(tp); } } if (ts != "") { waitsubmit.办理提交选项 = ts.Remove(ts.Length - 1); } eda.Activities.Add(waitsubmit); eda.Activities.Add(ir); state.Activities.Add(eda); workflow.Activities.Add(state); } } string q = WorkflowClassToXomlString(workflow); wf.Xoml = q.Replace("utf-16", "utf-8"); wf.Rules = Resource.myRule; wf.Layout = string.Format(Resource.myLayout, lzm); T t = (T)((object)wf); return((T)t); }
/// <summary> /// Create a workflow by hand /// </summary> /// <returns></returns> private static Activity CreateWorkflowInCode() { MarkupOnlyBaseWorkflow workflow = null; //create the root workflow object workflow = new MarkupOnlyBaseWorkflow(); workflow.Name = "CodedWorkflow"; //create an IfElseActivity IfElseActivity ifElse = new IfElseActivity("ifElseActivity1"); // //Add the left side branch to the IfElseActivity // IfElseBranchActivity branch = new IfElseBranchActivity("ifElseBranchActivity1"); #if COMPILE_RULES_WORKFLOW //add a rule condition to the branch RuleConditionReference ruleCondition = new RuleConditionReference(); ruleCondition.ConditionName = "IsNumberPositive"; branch.Condition = ruleCondition; #else //add a condition to the branch CodeCondition condition = new CodeCondition(); //bind the ConditionEvent to the IsNumberPositive member ActivityBind bind = new ActivityBind( "CodedWorkflow", "IsNumberPositive"); condition.SetBinding(CodeCondition.ConditionEvent, bind); branch.Condition = condition; #endif //add a custom WriteMessageActivity to the branch WriteMessageActivity writeMessage = new WriteMessageActivity(); writeMessage.Name = "writeMessagePositive"; writeMessage.Message = "The number is positive"; branch.Activities.Add(writeMessage); //add the branch to the IfElseActivity ifElse.Activities.Add(branch); // //add the right side branch to the IfElseActivity // branch = new IfElseBranchActivity("ifElseBranchActivity2"); //add a custom WriteMessageActivity to the branch writeMessage = new WriteMessageActivity(); writeMessage.Name = "writeMessageNotPositive"; writeMessage.Message = "The number is NOT positive"; branch.Activities.Add(writeMessage); //add the branch to the IfElseActivity ifElse.Activities.Add(branch); //add the IfElseActivity to the workflow workflow.Activities.Add(ifElse); #if COMPILE_WORKFLOW //provide a class name for the new workflow workflow.SetValue(WorkflowMarkupSerializer.XClassProperty, "ProWF.MyNewWorkflowClass"); #endif return(workflow); }
public override object EditValue(ITypeDescriptorContext typeDescriptorContext, IServiceProvider serviceProvider, object o) { if (typeDescriptorContext == null) { throw new ArgumentNullException("typeDescriptorContext"); } if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } object returnVal = o; // Do not allow editing expression if the name is not set. RuleConditionReference conditionDeclaration = typeDescriptorContext.Instance as RuleConditionReference; if (conditionDeclaration == null || conditionDeclaration.ConditionName == null || conditionDeclaration.ConditionName.Length <= 0) { throw new ArgumentException(Messages.ConditionNameNotSet); } Activity baseActivity = null; IReferenceService rs = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService; if (rs != null) { baseActivity = rs.GetComponent(typeDescriptorContext.Instance) as Activity; } RuleConditionCollection conditionDefinitions = null; RuleDefinitions rules = ConditionHelper.Load_Rules_DT(serviceProvider, Helpers.GetRootActivity(baseActivity)); if (rules != null) { conditionDefinitions = rules.Conditions; } if (conditionDefinitions != null && !conditionDefinitions.Contains(conditionDeclaration.ConditionName)) { string message = string.Format(CultureInfo.CurrentCulture, Messages.ConditionNotFound, conditionDeclaration.ConditionName); throw new ArgumentException(message); } this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService)); if (editorService != null) { CodeExpression experssion = typeDescriptorContext.PropertyDescriptor.GetValue(typeDescriptorContext.Instance) as CodeExpression; try { using (RuleConditionDialog dlg = new RuleConditionDialog(baseActivity, experssion)) { if (DialogResult.OK == editorService.ShowDialog(dlg)) { returnVal = dlg.Expression; } } } catch (NotSupportedException) { DesignerHelpers.DisplayError(Messages.Error_ExpressionNotSupported, Messages.ConditionEditor, serviceProvider); } } return(returnVal); }
internal static string ConvertRuleConditionReference(RuleDefinitions ruleDefinitions, RuleConditionReference ruleRef) { var builder = new StringBuilder(); builder.AppendFormat("This activity gets executed only if condition '{0}' is true", ruleRef.ConditionName); try { RuleCondition condition = ruleDefinitions.Conditions.First(x => x.Name != null && x.Name == ruleRef.ConditionName); builder.AppendFormat("[Condition Code: {0}]", ConvertRuleCondition(condition)); } catch { // no condition, so don't append anything } return(builder.ToString()); }