Пример #1
0
		//Generate the Terms collection (of Term) based on an existing Template
		public static List<Workflow> Create(XmlDocument xmlTemplateDoc, Template template)
		{
			XmlNodeList nodeWorkflows = null;
			XmlNode nodeWorkflow = null;
			List<Workflow> rtn = new List<Workflow>();

			nodeWorkflows = xmlTemplateDoc.SelectNodes(Utility.XMLHelper.GetXPath(true, XMLNames._E_TemplateDef, XMLNames._E_Workflows, XMLNames._E_Workflow));
			if (nodeWorkflows.Count == 0)
			{
				nodeWorkflow = xmlTemplateDoc.SelectSingleNode(Utility.XMLHelper.GetXPath(true, XMLNames._E_TemplateDef, XMLNames._E_Workflow));
				if (nodeWorkflow == null)
				{
					//No Workflow defined
					throw new Exception(string.Format("No workflow defined for older structure template '{0}', ID = '{1}'", template.Name, template.ID.ToString()));
				}
				else
				{
					//This is the 'old' structure
                    Workflow workflow = new Workflow(nodeWorkflow, template is ManagedItem, template);
					template.ActiveWorkflowID = workflow.ID;
					Event revertToDraft = template.OldWorkflowRevertEvent;
					if (revertToDraft != null)
					{
						workflow.Events.Add(revertToDraft);
						template.OldWorkflowRevertEvent = null;
					}
					rtn.Add(workflow);
				}
			}
			else
			{
				//This is the 'new' structure - assume that RevertToDraft already set up properly.
				XmlNode singleNodeWorkflows = xmlTemplateDoc.SelectSingleNode(Utility.XMLHelper.GetXPath(true, XMLNames._E_TemplateDef, XMLNames._E_Workflows));
				foreach (XmlNode nodeEachWorkflow in nodeWorkflows)
				{
                    rtn.Add(new Workflow(nodeEachWorkflow, template is ManagedItem, template));
				}

				string sActiveWorkflowID = string.Empty; 
				//if (sActiveWorkflowID == null)
				//   throw new Exception("The Active Workflow ID is not defined");
				sActiveWorkflowID = Utility.XMLHelper.GetAttributeString(singleNodeWorkflows, XMLNames._A_ActiveWorkflowID);
				if (Utility.TextHelper.IsGuid(sActiveWorkflowID))
					template.ActiveWorkflowID = new Guid(sActiveWorkflowID);
				else
					if (rtn.Count > 0)
						template.ActiveWorkflowID = rtn[0].ID;
					else
						throw new Exception("Unable to set the Active Workflow because no workflows are defined for this template.");
			}

			return rtn;
		}
Пример #2
0
        public Action(Workflow workflow)
		{
            _workflow = workflow;
            _messages = new List<Message>(1);
			_messages.Add(new Message());
			_performers = new List<string>();
		}
Пример #3
0
		public Action Copy(Workflow destinationWorkflow)
		{
            Action action = new Action(destinationWorkflow);
			action.ButtonText = ButtonText;
            //Note - After all of the new States have been created, go back and assign the TargetStateID's by
            //matching on the equivalent State Names between the two workflows.
            action._targetState = TargetState;
			action.Messages.Clear();
			foreach (Message message in Messages)
			{
				action.Messages.Add(message.Copy());
			}
			action.Performers.Clear();
			foreach (string performer in Performers)
			{
				action.Performers.Add(performer);
			}

			return action;
		}
Пример #4
0
        public Action(XmlNode termNode, Workflow workflow)
		{
            _workflow = workflow;
			_buttonText = Utility.XMLHelper.GetAttributeString(termNode, XMLNames._A_ButtonText);
            _requiresConfirmation = Utility.XMLHelper.GetAttributeBool(termNode, XMLNames._A_RequiresConfirmation) ?? false;
            _confirmationText = Utility.XMLHelper.GetAttributeString(termNode, XMLNames._A_ConfirmationText);

            try
            {
                string targetStateID = Utility.XMLHelper.GetAttributeString(termNode, XMLNames._A_TargetStateID);
                _targetStateID = new Guid(targetStateID);
                _targetStateIDDefined = true;
            }
            catch
            {
                _targetStateIDDefined = false;
                try
                {
                    _targetState = Utility.XMLHelper.GetAttributeString(termNode, XMLNames._A_TargetState);
                }
                catch
                {
                }
            }
			 
			XmlNodeList listMessages = termNode.SelectNodes(Utility.XMLHelper.GetXPath(false, XMLNames._E_Messages,XMLNames._E_Message));

			if (listMessages != null && listMessages.Count > 0)
			{
				_messages = new List<Message>(listMessages.Count);
				foreach (XmlNode nodeMessage in listMessages)
				{
					Message message = new Message(nodeMessage);
					_messages.Add(message);
				}
			}
			else
			{
				_messages = new List<Message>(1);
				_messages.Add(new Message());
			}

			XmlNodeList listPerformers = termNode.SelectNodes(Utility.XMLHelper.GetXPath(false, XMLNames._E_Performers,XMLNames._E_Performer));
			if (listPerformers != null && listPerformers.Count > 0)
			{
				_performers = new List<string>(listPerformers.Count);
				foreach (XmlNode nodePerformer in listPerformers)
				{
					string sRole = Utility.XMLHelper.GetAttributeString(nodePerformer, XMLNames._A_Role);
					_performers.Add(sRole);
				}
			}
			else
			{
				_performers = new List<string>();
			}
		}
Пример #5
0
		public Workflow Copy(string newName, bool IsManagedItem, Template template)
		{
            Workflow workflow = new Workflow(newName, IsManagedItem, template);
			workflow.States.Clear();
			workflow.UseFunction = UseFunction;
			workflow.DaysAfterWorkflowEntry = DaysAfterWorkflowEntry;
			workflow.DateExitedBaseState = DateExitedBaseState;

			//TODO - Does it make sense here to make copies of Events?
			foreach (Event eachEvent in Events)
			{
				workflow.Events.Add(eachEvent.Copy(IsManagedItem));
			}

			foreach (State state in States)
			{
                workflow.States.Add(state.Copy(template, workflow));
			}

            foreach (State state in workflow.States)
            {
                foreach (Action action in state.Actions)
                {
                    action.TargetStateID = workflow.FindState(action.TargetState).ID;
                }
            }

			return workflow;
		}
Пример #6
0
        public State Copy(Template sourceTemplate, Workflow destinationWorkflow)
		{
            State state = new State(sourceTemplate);
			state.Name = Name;
			state.Status = Status;
			state.IsDraft = IsDraft;
			state.IsBase = IsBase;
			state.IsExit = IsExit;
			state.RequiresValidation = RequiresValidation;
            state.StateTermGroups.Clear();
            foreach (StateTermGroup stateTermGroup in StateTermGroups)
			{
                state.StateTermGroups.Add(stateTermGroup.Copy());
			}
			state.Actions.Clear();
			foreach (Action action in Actions)
			{
                state.Actions.Add(action.Copy(destinationWorkflow));
			}
			return state;
		}
Пример #7
0
		public State(XmlNode termNode, Template template, Workflow workflow)
		{
			_name = Utility.XMLHelper.GetAttributeString(termNode, XMLNames._A_Name);

            _id = Guid.Empty;
            string id = Utility.XMLHelper.GetAttributeString(termNode, XMLNames._A_ID);
            if (!string.IsNullOrEmpty(id))
            {
                try
                {
                    _id = new Guid(id);
                }
                catch
                {
                }
            }
            //If an ID was not assigned before, assign it now....
            if (_id == Guid.Empty)
                _id = Guid.NewGuid();

			_status = Utility.XMLHelper.GetAttributeString(termNode, XMLNames._A_Status);
			_isDraft = Utility.XMLHelper.GetAttributeBool(termNode, XMLNames._A_IsDraft);
			_isBase = Utility.XMLHelper.GetAttributeBool(termNode, XMLNames._A_IsBase);
			_isExit = Utility.XMLHelper.GetAttributeBool(termNode, XMLNames._A_IsExit);
			_requiresValidation = Utility.XMLHelper.GetAttributeBool(termNode, XMLNames._A_RequiresValidation);

            _stateTermGroups = new List<StateTermGroup>();
            XmlNodeList listStateTermGroups = termNode.SelectNodes(Utility.XMLHelper.GetXPath(false, XMLNames._E_StateTermGroups, XMLNames._E_StateTermGroup));
            bool bInitializeStateTermGroups = false;
            try
            {
                bInitializeStateTermGroups = listStateTermGroups.Count == 0;
            }
            catch
            {
                bInitializeStateTermGroups = true;
            }

            if (bInitializeStateTermGroups)
            {
                //Read in the old version - list of editor roles
                List<Role> editors = new List<Role>();
                XmlNodeList listEditors = termNode.SelectNodes(Utility.XMLHelper.GetXPath(false, XMLNames._E_Editors, XMLNames._E_Editor));
                if (listEditors != null)
                {
                    foreach (XmlNode nodeEditor in listEditors)
                    {
                        Role role = new Role();
                        role.Name = Utility.XMLHelper.GetAttributeString(nodeEditor, XMLNames._A_Role);
                        editors.Add(role);
                    }
                }
                StateTermGroup stateTermGroup = new StateTermGroup(template.BasicSecurityTermGroupID);
                stateTermGroup.Editors = editors;
                ITATSystem system = ITATSystem.Get(template.SystemID);
                stateTermGroup.Viewers = system.Roles;
                stateTermGroup.AttachmentRemovers = editors;
                stateTermGroup.ScannedAttachmentRemovers = Role.FromNames(system.AllowedRoles(Business.XMLNames._AF_EditAttachment));
                _stateTermGroups.Add(stateTermGroup);
            }
            else
            {
                foreach (XmlNode nodeStateTermGroup in listStateTermGroups)
                {
                    StateTermGroup stateTermGroup = new StateTermGroup(nodeStateTermGroup);
                    _stateTermGroups.Add(stateTermGroup);
                }
            }
 
			XmlNodeList listActions = termNode.SelectNodes(Utility.XMLHelper.GetXPath(false, XMLNames._E_Actions,XMLNames._E_Action));
			if (listActions != null)
			{
				_actions = new List<Action>(listActions.Count);
				foreach (XmlNode nodeAction in listActions)
				{
                    Action action = new Action(nodeAction, workflow);
					_actions.Add(action);
				}
			}
			else
			{
				_actions = new List<Action>();
			}

		}