// This supports loading objects instead of xaml into the designer public void Load(object instance) { if (isLoaded) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.WorkflowDesignerLoadShouldBeCalledOnlyOnce)); } isLoaded = true; if (instance == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("instance")); } DesignerConfigurationService configurationService = this.context.Services.GetService <DesignerConfigurationService>(); configurationService.ApplyDefaultPreference(); // Because we want AutoConnect/AutoSplit to be on even in Dev10 if PU1 is installed. // But we cannot know whether PU1 is installed or not, we decide to enable these 2 features for all Dev10. if (configurationService.WorkflowDesignerHostId == WorkflowDesignerHostId.Dev10) { configurationService.AutoConnectEnabled = true; configurationService.AutoSplitEnabled = true; } configurationService.IsWorkflowLoaded = true; configurationService.Validate(); if (this.PreviewLoad != null) { this.PreviewLoad(this, new PreviewLoadEventArgs(instance, this.context)); } if (configurationService.TargetFrameworkName.IsLessThan45()) { TargetFrameworkPropertyFilter.FilterOut45Properties(); } modelTreeManager = new ModelTreeManager(this.context); modelTreeManager.Load(instance); this.context.Services.Publish(typeof(ModelTreeManager), modelTreeManager); viewManager = GetViewManager(this.modelTreeManager.Root); this.context.Services.Publish <ModelSearchService>(this.ModelSearchService); view.Children.Add((UIElement)viewManager.View); modelTreeManager.EditingScopeCompleted += new EventHandler <EditingScopeEventArgs>(OnEditingScopeCompleted); this.view.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() => { this.perfEventProvider.WorkflowDesignerApplicationIdleAfterLoad(); })); //Subscribe to the ViewStateChanged event of ViewStateService to show document dirty. It would be published in the call to GetViewManager(). WorkflowViewStateService wfViewStateService = this.Context.Services.GetService(typeof(ViewStateService)) as WorkflowViewStateService; if (wfViewStateService != null) { wfViewStateService.UndoableViewStateChanged += new ViewStateChangedEventHandler(OnViewStateChanged); } this.isModelChanged = false; }
public static Dictionary <string, object> getNodeViewState(object activity) { Dictionary <string, object> list = WorkflowViewStateService.GetViewState(activity); foreach (var v in list) { System.Console.WriteLine(v); } return(list); }
/// <summary> /// Generate activity templates based on contract /// </summary> /// <param name="contractType">The contract type</param> /// <returns>The list of all activity templates, each represent an operation.</returns> public static IEnumerable <ActivityTemplateFactoryBuilder> GenerateActivityTemplates(Type contractType) { if (contractType == null) { throw FxTrace.Exception.ArgumentNull("contractType"); } ContractDescription contract = null; try { contract = ContractDescription.GetContract(contractType); } catch (InvalidOperationException e) { if (e.InnerException != null) { throw new InvalidOperationException(e.Message + Environment.NewLine + Environment.NewLine + e.InnerException.GetType().ToString() + Environment.NewLine + e.InnerException.Message, e); } else { throw; } } // if (contract.Operations != null) { foreach (OperationDescription operation in contract.Operations) { Activity generatedActivity = GenerateActivity(operation); WorkflowViewStateService.SetViewState( generatedActivity, new Dictionary <string, object> { { ContractTypeViewStateKey, contractType }, }); yield return(new ActivityTemplateFactoryBuilder { Name = contractType.Name + "." + generatedActivity.DisplayName, TargetType = generatedActivity.GetType(), Implementation = generatedActivity, }); } } }
//得到自定义流程图 public static flowcharStruct getFlowcharStruct(string xaml) { char[] sp = { ',' }; char[] sl = { ' ' }; //(1) WorkflowStruct.flowcharStruct flowcharStruct = new WorkflowStruct.flowcharStruct(); //(2) DynamicActivity dynamicActivity = tool.activityByXaml(xaml) as DynamicActivity; Activity activity = tool.getImplementation(dynamicActivity); Flowchart flowchar = activity as Flowchart; if (flowchar == null) { return(null); } //(3)===================================== //(3.1)---------------------------------------------------------------------------------- flowcharStruct.beginNode.DisplayName = "开始"; flowcharStruct.beginNode.id = "begin"; //(3.1.1) if (WorkflowViewStateService.GetViewState(flowchar)["ShapeLocation"] != null) { string ShapeLocation = WorkflowViewStateService.GetViewState(flowchar)["ShapeLocation"].ToString(); flowcharStruct.beginNode.ShapeSize.x = double.Parse(ShapeLocation.Split(sp)[0]); flowcharStruct.beginNode.ShapeSize.y = double.Parse(ShapeLocation.Split(sp)[1]); } //(3.1.2) if (WorkflowViewStateService.GetViewState(flowchar)["ShapeSize"] != null) { string ShapeSize = WorkflowViewStateService.GetViewState(flowchar)["ShapeSize"].ToString(); flowcharStruct.beginNode.ShapeSize.width = double.Parse(ShapeSize.Split(sp)[0]); flowcharStruct.beginNode.ShapeSize.height = double.Parse(ShapeSize.Split(sp)[1]); } //(3.1.3) if (WorkflowViewStateService.GetViewState(flowchar)["ConnectorLocation"] != null) { string ConnectorLocation = WorkflowViewStateService.GetViewState(flowchar)["ConnectorLocation"].ToString(); string[] points = ConnectorLocation.Split(sl); WorkflowStruct.line oneline = new WorkflowStruct.line(); oneline.beginNodeID = flowchar.Id; oneline.text = flowchar.DisplayName; foreach (string item in points) { double x = double.Parse(item.Split(sp)[0]); double y = double.Parse(item.Split(sp)[1]); oneline.connectorPoint.Add(new WorkflowStruct.point() { x = x, y = y }); } flowcharStruct.lineList.Add(oneline); } //(3.2)-------------------------------------------------------------------------------- foreach (FlowNode flowNode in flowchar.Nodes) { FlowStep flowStep = flowNode as FlowStep; if (flowStep != null) { WorkflowStruct.node node = new WorkflowStruct.node(); node.DisplayName = flowStep.Action.DisplayName; node.id = flowStep.Action.Id; //(3.2.1) if (WorkflowViewStateService.GetViewState(flowStep)["ShapeLocation"] != null) { string ShapeLocation = WorkflowViewStateService.GetViewState(flowStep)["ShapeLocation"].ToString(); node.ShapeSize.x = double.Parse(ShapeLocation.Split(sp)[0]); node.ShapeSize.y = double.Parse(ShapeLocation.Split(sp)[1]); } //(3.2.2) if (WorkflowViewStateService.GetViewState(flowStep)["ShapeSize"] != null) { string ShapeSize = WorkflowViewStateService.GetViewState(flowStep)["ShapeSize"].ToString(); node.ShapeSize.width = double.Parse(ShapeSize.Split(sp)[0]); node.ShapeSize.height = double.Parse(ShapeSize.Split(sp)[1]); } //(3.2.3) if (WorkflowViewStateService.GetViewState(flowStep).Count(p => p.Key == "ConnectorLocation") == 1) { string ConnectorLocation = WorkflowViewStateService.GetViewState(flowStep)["ConnectorLocation"].ToString(); string[] points = ConnectorLocation.Split(sl); WorkflowStruct.line line = new WorkflowStruct.line(); line.beginNodeID = flowStep.Action.Id; line.text = flowStep.Action.DisplayName; foreach (string item in points) { double x = double.Parse(item.Split(sp)[0]); double y = double.Parse(item.Split(sp)[1]); line.connectorPoint.Add(new WorkflowStruct.point() { x = x, y = y }); } flowcharStruct.lineList.Add(line); } flowcharStruct.nodeList.Add(node); } } //(3.3)------------------------------------------------------------- foreach (FlowNode flowNode in flowchar.Nodes) { FlowSwitch <string> flowSwitch = flowNode as FlowSwitch <string>; if (flowSwitch != null) { WorkflowStruct.node node = new WorkflowStruct.node(); node.DisplayName = flowSwitch.Expression.DisplayName; node.id = flowSwitch.Expression.Id; //(3.3.1) if (WorkflowViewStateService.GetViewState(flowSwitch)["ShapeLocation"] != null) { string ShapeLocation = WorkflowViewStateService.GetViewState(flowSwitch)["ShapeLocation"].ToString(); node.ShapeSize.x = double.Parse(ShapeLocation.Split(sp)[0]); node.ShapeSize.y = double.Parse(ShapeLocation.Split(sp)[1]); } //(3.3.2) if (WorkflowViewStateService.GetViewState(flowSwitch)["ShapeSize"] != null) { string ShapeSize = WorkflowViewStateService.GetViewState(flowSwitch)["ShapeSize"].ToString(); node.ShapeSize.width = double.Parse(ShapeSize.Split(sp)[0]); node.ShapeSize.height = double.Parse(ShapeSize.Split(sp)[1]); } //(3.3.3) if (WorkflowViewStateService.GetViewState(flowSwitch).Count(p => p.Key == "Default") == 1) { string ConnectorLocation = WorkflowViewStateService.GetViewState(flowSwitch)["Default"].ToString(); string[] points = ConnectorLocation.Split(sl); WorkflowStruct.line line = new WorkflowStruct.line(); line.beginNodeID = flowSwitch.Expression.Id; line.text = flowSwitch.Expression.DisplayName; foreach (string item in points) { double x = double.Parse(item.Split(sp)[0]); double y = double.Parse(item.Split(sp)[1]); line.connectorPoint.Add(new WorkflowStruct.point() { x = x, y = y }); } flowcharStruct.lineList.Add(line); } //(3.3.4) foreach (var v in flowSwitch.Cases) { System.Activities.Statements.FlowNode next = v.Value; System.Console.WriteLine(v.Key); string caseValue = v.Key + "Connector"; if (WorkflowViewStateService.GetViewState(flowSwitch).Count(p => p.Key == caseValue) == 1) { string ConnectorLocation = WorkflowViewStateService.GetViewState(flowSwitch)[caseValue].ToString(); string[] points = ConnectorLocation.Split(sl); WorkflowStruct.line line = new WorkflowStruct.line(); line.beginNodeID = flowSwitch.Expression.Id; line.text = flowSwitch.Expression.DisplayName; foreach (string item in points) { double x = double.Parse(item.Split(sp)[0]); double y = double.Parse(item.Split(sp)[1]); line.connectorPoint.Add(new WorkflowStruct.point() { x = x, y = y }); } flowcharStruct.lineList.Add(line); } } flowcharStruct.nodeList.Add(node); } } return(flowcharStruct); }//end