/// <summary>
        /// Create a copy of workflow step
        /// </summary>
        /// <returns>Copy of workflow step</returns>
        public WorkflowStep ReturnACopy()
        {
            WorkflowStep CopiedStep = new WorkflowStep();

            CopiedStep.nWorkflowStepId            = nWorkflowStepId;
            CopiedStep.strWorkflowStepName        = strWorkflowStepName;
            CopiedStep.strWorkflowStepDescription = strWorkflowStepDescription;
            CopiedStep.strWorkflowStepAction      = strWorkflowStepAction;
            CopiedStep.nHostedApplicationId       = nHostedApplicationId;
            CopiedStep.bIsStepComplete            = bIsStepComplete;

            return(CopiedStep);
        }
        /// <summary>
        /// Sets the workflow steps' content from the XML to the data structure.
        /// </summary>
        /// <param name="strWorkflowStepsXML">steps' content in the form of XML</param>
        /// <returns>true if successful and false if failed.</returns>
        public bool SetWorkflowStepsData(string strWorkflowStepsXML)
        {
            if (strWorkflowStepsXML == string.Empty)
            {
                return(false);
            }

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(strWorkflowStepsXML);

                XmlNode root         = doc.DocumentElement;
                XmlNode WorkflowNode = root.SelectSingleNode(XML_WORKFLOW);

                //verify if the workflow ids are correct.
                //there should not be a mismatch, but still.
                int nWorkflowIDFromXML = Convert.ToInt32(WorkflowNode.Attributes[XML_WORKFLOW_ID].InnerText, 10);
                if (nWorkflowIDFromXML != workflowId)
                {
                    return(false);
                }

                XmlNodeList Steps = WorkflowNode.SelectNodes(XML_STEP);
                if (Steps.Count == 0)                 //no steps for this workflow.
                {
                    Logging.Warn(this.ToString(), localizeWF.WORKFLOW_DATA_STRUCTURES_WORKFLOW_DATA_ERR_SET_WORKFLOW_STEPS_DATA);
                    return(false);
                }

                wfSteps = new WorkflowStepArray();
                foreach (XmlNode StepNode in Steps)
                {
                    //form the workflowstep structure
                    WorkflowStep Step = new WorkflowStep();
                    Step.SetStepData(StepNode.OuterXml);

                    //add the structure to the list.
                    wfSteps.Add(Step);
                }
            }
            catch (Exception exp)
            {
                Logging.Error(this.ToString(), localizeWF.WORKFLOW_DATA_STRUCTURES_WORKFLOW_DATA_ERR_SET_WORKFLOW_STEPS_DATA, exp);
                throw exp;
            }

            return(true);
        }
        /// <summary>
        /// creates a copy of workflow
        /// </summary>
        /// <returns>copy of workflow</returns>
        public WorkflowData ReturnACopy()
        {
            WorkflowData CopiedWorkflow = new WorkflowData();

            CopiedWorkflow.workflowId      = workflowId;
            CopiedWorkflow.strWorkflowName = strWorkflowName;
            CopiedWorkflow.isForced        = isForced;

            if (wfSteps != null && wfSteps.Count != 0)
            {
                CopiedWorkflow.wfSteps = new WorkflowStepArray();
                foreach (WorkflowStep Step in wfSteps)
                {
                    WorkflowStep StepOfalSteps = new WorkflowStep();
                    StepOfalSteps = Step.ReturnACopy();
                    CopiedWorkflow.wfSteps.Add(StepOfalSteps);
                }
                CopiedWorkflow.activeStepId = activeStepId;
            }

            return(CopiedWorkflow);
        }
 /// <summary>
 /// Public to allow serialization/deserialization
 /// </summary>
 public void Add(WorkflowStep wfs)
 {
     WorkflowSteps.Add(wfs);
 }
        public bool SetPendingWorkflowData(string pendingWorkflowData, bool bShowErr)
        {
            if (pendingWorkflowData == string.Empty)
            {
                return(false);
            }

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(pendingWorkflowData);

                XmlNode root = doc.DocumentElement;
                if (root.ChildNodes.Count == 0)
                {
                    // No steps in this workflow.
                    return(false);
                }

                XmlNodeList Steps = root.SelectNodes(XML_STEP);
                if (Steps.Count == 0)
                {
                    return(false);
                }

                if (wfSteps == null || wfSteps.Count == 0)
                {
                    Logging.Warn(this.ToString(), localizeWF.WORKFLOW_DATA_STRUCTURES_WORKFLOW_DATA_SET_PENDING_WORKFLOW_DATA);
                    return(false);
                }

                //parse through the xml to get to each of the steps.
                foreach (XmlNode StepNode in Steps)
                {
                    foreach (WorkflowStep Step in wfSteps)
                    {
                        if (Convert.ToInt32(StepNode.Attributes[XML_STEP_ID].InnerText, 10) == Step.Workflowstepid)
                        {
                            //step found. set the value, complete or not.
                            if (StepNode.SelectSingleNode(XML_STEP_COMPLETE).InnerText == STEP_COMPLETE_VAL)
                            {
                                Step.IsStepComplete = true;
                            }
                            else
                            {
                                //set the active step.
                                activeStepId = Step.Workflowstepid;
                            }
                        }
                    }
                }
                // Check if the active step was set in the previous iterations
                if (activeStepId == -1)
                {
                    if (bShowErr)
                    {
                        Logging.Error(this.ToString(), localizeWF.WORKFLOW_DATA_STRUCTURES_WORKFLOW_DATA_SET_PENDING_WORKFLOW_DATA_SET_TO_FIRST_STEP);
                    }
                    // Active step of the pending workflow was removed.
                    // set the active step to the first step in the workflow.
                    WorkflowStep firstStep = wfSteps[0] as WorkflowStep;
                    activeStepId = firstStep.Workflowstepid;
                }
            }
            catch (Exception exp)
            {
                if (bShowErr)
                {
                    Logging.Error(this.ToString(), localizeWF.WORKFLOW_DATA_STRUCTURES_WORKFLOW_DATA_SET_PENDING_WORKFLOW_DATA, exp);
                    throw exp;
                }
            }

            return(true);
        }