Exemplo n.º 1
0
		private void AddNewCommandExecuted(WorkflowInfo info)
		{
			if (info == null) throw new ArgumentNullException("WorkflowInfo不能为空");

			DiagramPageViewModel vw = new DiagramPageViewModel(info, WebInterAct);

			vw.RequestClose += this.Item_RequestClose;
			this.DiagramDataSource.Add(vw);
			WebInterAct.LoadProperty(WorkflowUtils.CLIENTSCRIPT_PARAM_WORKFLOW,
				vw.Key,
				WorkflowUtils.ExtractWorkflowInfoJson(vw));
		}
        public DiagramPageViewModel(WorkflowInfo info, IWebInterAction client)
        {
            this._clientProxy = client;
            InitCommand();
            this.WfInfo = info;
            this.Key = info.Key;
            this.Name = info.Name;

            if (!string.IsNullOrEmpty(info.GraphDescription))
            {
                DiagramModel.Load<ActivityNode, ActivityLink>(
                    XElement.Parse(info.GraphDescription),
                    WorkflowUtils.DIAGRAM_XELEMENT_NODENAME,
                    WorkflowUtils.DIAGRAM_XELEMENT_LINKNAME);

                foreach (var node in (ObservableCollection<ActivityNode>)DiagramModel.NodesSource)
                {
                    var actInfo = info.Activities.SingleOrDefault(p => p.Key == node.Key);
                    if (actInfo != null)
                    {
                        node.Category = actInfo.ActivityType.ToString();

                        if (actInfo.BranchProcessTemplates == null)
                            continue;

                        if (actInfo.BranchProcessTemplates.Count > 0)
                        {
                            node.WfHasBranchProcess = true;
                        }
                    }
                }
                //为兼容2011-04-22之前保存的数据
                foreach (var link in (ObservableCollection<ActivityLink>)DiagramModel.LinksSource)
                {
                    if (link.From == "N0" && link.FromPort == "portTop")
                    {
                        link.FromPort = "portBottom";
                    }
                }
                return;
            }

            foreach (ActivityInfo activity in info.Activities)
            {
                ActivityNode item = new ActivityNode()
                {
                    Key = activity.Key,
                    Category = activity.ActivityType.ToString(),
                    WfName = activity.Name,
                    WfDescription = activity.Description,
                    WfEnabled = activity.Enabled
                };

                this.DiagramModel.AddNode(item);
            }

            foreach (var transition in info.Transitions)
            {
                this.DiagramModel.AddLink(new ActivityLink()
                {
                    Key = transition.Key,
                    Text = transition.Name,
                    From = transition.FromActivityKey,
                    To = transition.ToActivityKey
                });
            }
        }