Exemplo n.º 1
0
        /// <summary>
        /// Executes the while step.  
        /// </summary>
        /// <param name="context">Context for the workflow to run</param>
        /// <param name="stepId">Step at which to start execution.  Execution starts at first step
        /// if this is null or an empty string.</param>
        /// <returns>State of the workflow after executing the steps.</returns>
        public override string Run(WorkflowContext context, string stepId)
        {
            //var currentState = WorkFlowState.Done.ToString();
            //if (!String.IsNullOrEmpty(stepId))
            //{
            //    // we must be restarting after an event
            //    // execute from where we left off and then perform while logic as normal
            //    currentState = base.Run(context, stepId);
            //    if (currentState != WorkFlowState.Done.ToString())
            //    {
            //        return currentState;
            //    }
            //}

            //while (this.IsConditionTrue(context))
            //{
            //    currentState = base.Run(context, stepId);
            //    if (currentState != WorkFlowState.Done.ToString())
            //    {
            //        return currentState;
            //    }
            //}

            //return currentState;
            return string.Empty;
        }
Exemplo n.º 2
0
 public override string Run(WorkflowContext context, string stepId)
 {
     foreach (var workflowStep in _workflowSteps)
     {
         return workflowStep.Run(context, stepId);
     }
     return string.Empty;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Executes the OnPick step
        /// Checks if an event or timeout has occurred and executes specified steps for the event found.
        /// Nested events are not supported! (This means that the steps in an onMessage step cannot 
        /// also wait for events.  
        /// </summary>
        /// <param name="context">Context for the workflow to run</param>
        /// <param name="stepId">Step at which to start execution.  Execution starts at first step
        /// if this is null or an empty string.</param>
        /// <returns>State of the workflow after executing the steps.</returns>
        public override string Run(WorkflowContext workflowContext, string stepId)
        {
            //WorkFlowState state = WorkFlowState.Done;

            // Check for event first.  Go though the possible OnMessage activities and see if any succeed. 
            // If there is an event to process, we're done.  Only one event per execution (check BPEL spec)
            // If not event, start alarm timer. 



            return string.Empty;// state.ToString();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Runs this OnMessage step.  If message has been received, executes the defined steps,
        /// otherwise returns a waiting status.
        /// </summary>
        /// <param name="context">Context for the workflow to run</param>
        /// <param name="stepId">Step at which to start execution.  Execution starts at first step
        /// if this is null or an empty string.</param>
        /// <returns>State of the workflow after executing the steps.</returns>
        public string Run(WorkflowContext context, string stepId)
        {
            var currentState = this.receiveStep.Run(context, stepId);
            //if (currentState != WorkFlowState.Done.ToString())
            //{
            //    // Have the event so run
            //    return base.Run(context, null);
            //}

            //// Check the workflow name whether in the continueworkflowList, If in the list, then don't report error status, continue running the workflow
            //if (currentState == WorkFlowState.Manager.ToString())
            //{
            //    return base.Run(context, null);
            //}
            return currentState;
        }
 public IWorkflowStep ExecuteWorkflowByCurrentState(WorkflowContext context, string currentState)
 {
     if (string.IsNullOrEmpty(currentState))
         currentState = (from stepRunnerStep in context.WorkflowStepList.OfType<StepRunnerStep>()
                        let subStep =
                            stepRunnerStep.WorkflowSteps.First()
                        select  subStep.StepId).First();
     return (from stepRunnerStep in context.WorkflowStepList.OfType<StepRunnerStep>()
             let subStep =
                 stepRunnerStep.WorkflowSteps.Find(entity => entity.StepId.CompareEqualIgnoreCase(currentState))
             let invokeStep = subStep as InvokeStep
             where invokeStep != null
             select
                 stepRunnerStep.WorkflowSteps.Find(
                     entity => entity.StepId.CompareEqualIgnoreCase(invokeStep.InvokeContext.PortType)))
         .FirstOrDefault();
 }
Exemplo n.º 6
0
        //private void AddCaseStepRelation(WorkflowContext workflowContext)
        //{
        //    var caseStepList = GetCaseStepFromContext(workflowContext);
        //    if (caseStepList != null&&caseStepList.Any())
        //    {
        //        foreach (var caseStep in caseStepList)
        //        {
        //            AddActionByCondition(workflowContext.WorkflowName, caseStep.CaseContext.Condition);
        //        }
        //    }
        //}

        private void AddRoleActionRelation(WorkflowContext workflowContext)
        {
            var switchStepList = GetSwitchStepFromContext(workflowContext);
            var invokeStepList = GetInvokeStepFromContext(workflowContext);
            if (invokeStepList != null)
                foreach (var switchStep in switchStepList)
                {
                    var invokeStep =
                        invokeStepList.FirstOrDefault(entity => entity.InvokeContext.PortType.CompareEqualIgnoreCase(switchStep.SwitchContext.Name));
                    if (invokeStep != null)
                    {
                        var partnerLinkEntity =
                            workflowContext.PartnerLinkList.First(
                                entity => entity.Name.CompareEqualIgnoreCase(invokeStep.InvokeContext.PartnerLink));
                        if (partnerLinkEntity != null)
                        {
                            var roleInfoEntity =
                                UserOperationDAL.QueryRoleInfoByCondition(workflowContext.WorkflowName,partnerLinkEntity.MyRole);
                            foreach (var actionEntity in switchStep.WorkflowSteps.OfType<ICaseStep>().Select(caseStep => AddActionByCondition(workflowContext.WorkflowName, caseStep.CaseContext.Condition)))
                            {
                                //UserOperationDAL.QueryOperationActionByCondition(workflowContext.WorkflowName,
                                //                                                         caseStep.CaseContext.Condition);
                                var relationEntity =
                                    UserOperationDAL.QueryRelationByActionIdAndRoleId(actionEntity.Id,
                                                                                              roleInfoEntity.Id);
                                if (relationEntity == null)
                                UserOperationDAL.AddOperationActionInRole(actionEntity.Id, roleInfoEntity.Id);
                            }
                        }
                    }
                }
        }
Exemplo n.º 7
0
 private IEnumerable<IInvokeStep> GetInvokeStepFromContext(WorkflowContext workflowContext)
 {
     return workflowContext.WorkflowStepList.OfType<IStepRunnerStep>().Select(stepRunnerStep => (from invokeStep in stepRunnerStep.WorkflowSteps.OfType<IInvokeStep>() select invokeStep)).FirstOrDefault();
 }
Exemplo n.º 8
0
 private void AddInvokeStepRelation(WorkflowContext workflowContext)
 {
     var invokeStepList = GetInvokeStepFromContext(workflowContext);
     if (invokeStepList != null)
         foreach (var workflowStep in invokeStepList)
         {
             AddWorkflowStateInfoByCondition(workflowContext.WorkflowName, workflowStep);
             if (workflowStep == null) continue;
             var partnerLinkEntity =
                 workflowContext.PartnerLinkList.First(
                     entity => entity.Name.CompareEqualIgnoreCase(workflowStep.InvokeContext.PartnerLink));
             if (partnerLinkEntity != null)
                 AddStateRoleByCondition(workflowContext.WorkflowName, workflowStep.InvokeContext.Name, partnerLinkEntity);
         }
 }
Exemplo n.º 9
0
 public override string Run(WorkflowContext workflowContext, string stepId)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 10
0
 /// <summary>
 /// Remove workflow and all its subworkflow from list
 /// </summary>
 /// <param name="context">the conext associated with the workflow.</param>
 private void RemoveWorkflowAndSubWorkflows(WorkflowContext context)
 {
     if (context == null)
         return;
 }
        private void FillPartnerLinkList(WorkflowContext workflowContext, XmlNode currentStep)
        {
            if (currentStep.LocalName == "partnerLinks")
            {
                foreach (XmlNode variableNode in currentStep.ChildNodes)
                {
                    if (variableNode.LocalName == "partnerLink")
                    {
                        var partnerLinkEntity = new PartnerLinkModel();
                        if (variableNode.Attributes != null)
                            foreach (XmlAttribute variableAttribute in variableNode.Attributes)
                            {
                                if (variableAttribute.LocalName == "name")
                                {
                                    partnerLinkEntity.Name = variableAttribute.Value;
                                }
                                else if (variableAttribute.LocalName == "partnerLinkType")
                                {
                                    partnerLinkEntity.PartnerLinkType = variableAttribute.Value;
                                }
                                else if (variableAttribute.LocalName == "myRole")
                                {
                                    partnerLinkEntity.MyRole = variableAttribute.Value;
                                }
                                else if (variableAttribute.LocalName == "partnerRole")
                                {
                                    partnerLinkEntity.PartnerRole = variableAttribute.Value;
                                }
                            }
                        if (!string.IsNullOrEmpty(partnerLinkEntity.Name))
                        {
                            workflowContext.PartnerLinkList.Add(partnerLinkEntity);
                        }
                    }
                }
            }


        }
 /// <summary>
 /// Fill the WorkflowVariable and Handler field in workflow context. The workflowSteps will not be load from the bpel in this method.
 /// For the workflowSteps may be cached.
 /// </summary>
 /// <param name="workflowContext">Dictionary of workflow variables to populate with any
 /// variables defined in the BPEL file.</param>
 /// <param name="currentStep">XmlNode containing the BPEL data from the BPEL file</param>
 private void FillVariableList(WorkflowContext workflowContext, XmlNode currentStep)
 {
     if (currentStep.LocalName == "variables")
     {
         foreach (XmlNode variableNode in currentStep.ChildNodes)
         {
             if (variableNode.LocalName == "variable")
             {
                 string variableName = null;
                 string variableType = null;
                 if (variableNode.Attributes != null)
                     foreach (XmlAttribute variableAttribute in variableNode.Attributes)
                     {
                         if (variableAttribute.LocalName == "name")
                         {
                             variableName = variableAttribute.Value;
                         }
                         else if (variableAttribute.LocalName == "messageType")
                         {
                             variableType = variableAttribute.Value;
                         }
                         else if (variableAttribute.LocalName == "type")
                         {
                             variableType = variableAttribute.Value;
                         }
                     }
                 if ((variableName != null) && (variableType != null))
                 {
                     workflowContext.WorkflowVariables.Add(variableName, variableType);
                 }
             }
         }
     }
 }
        /// <summary>
        /// Fill the various structures with step data from the BPEL XML file
        /// </summary>
        /// <param name="workflowContext"> workflowcontextModel class</param>
        /// <param name="startElement">Integer value representing the starting element in the nodeList.</param>
        /// <param name="nodeList">XmlNodeList containing the BPEL data from the BPEL file</param>
        /// <param name="cancelEventHandlerName">cancelEventHandlerName</param>
        private void FillStepList(WorkflowContext workflowContext, List<IWorkflowStep> workflowStepList, int startElement, XmlNodeList nodeList, ref string cancelEventHandlerName)
        {
            for (int i = startElement; i < nodeList.Count; i++)
            {
                var currentStep = nodeList[i];

                if (!string.IsNullOrEmpty(currentStep.Prefix))
                {
                    currentStep.Prefix = "bpel";
                }

                if (currentStep is XmlComment)
                {
                    continue;
                }

                if (currentStep.LocalName == "invoke")
                {
                    var workflowStep = new InvokeStep(currentStep.Attributes);
                    workflowStepList.Add(workflowStep);
                }
                else if (currentStep.LocalName == "sequence")
                {
                    var sequenceStep = new SequenceStep(currentStep.Attributes);
                    workflowStepList.Add(sequenceStep);
                    FillStepList(workflowContext, sequenceStep.WorkflowSteps, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "scope")
                {
                    // can't get tool to produce invoke without having it enclosed in a scope.
                    // just ignore scope for now but get the internals as if at the same level.
                    FillStepList(workflowContext, workflowStepList, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "receive")
                {
                    var receiveStep = new ReceiveStep(currentStep.Attributes);
                    workflowStepList.Add(receiveStep);
                    string messageName = String.Empty;
                    string timesetTime = String.Empty;
                    if (currentStep.Attributes != null)
                        foreach (XmlAttribute attrib in currentStep.Attributes)
                        {
                            if (attrib.LocalName == "timeout")
                            {
                                timesetTime = attrib.Value;
                            }
                            if (attrib.LocalName == "variable")
                            {
                                messageName = attrib.Value;
                            }
                        }
                    if (!timeoutParameters.ContainsKey(messageName))
                    {
                        timeoutParameters.Add(messageName, timesetTime);
                    }
                }
                else if (currentStep.LocalName == "switch")
                {
                    var switchStep = new SwitchStep(currentStep.Attributes);
                    workflowStepList.Add(switchStep);

                    // Fill case/otherwise steps inside of switch step
                    FillStepList(workflowContext, switchStep.WorkflowSteps, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "case")
                {
                    var caseStep = new CaseStep(currentStep.Attributes, false);
                    workflowStepList.Add(caseStep);
                    FillStepList(workflowContext, caseStep.WorkflowSteps, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "otherwise")
                {
                    var caseStep = new CaseStep(currentStep.Attributes, true);
                    workflowStepList.Add(caseStep);
                    FillStepList(workflowContext, caseStep.WorkflowSteps, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "while")
                {
                    var whileStep = new WhileStep(currentStep.Attributes);
                    workflowStepList.Add(whileStep);
                    FillStepList(workflowContext, whileStep.WorkflowSteps, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "pick")
                {
                    var pickStep = new PickStep(currentStep.Attributes);
                    workflowStepList.Add(pickStep);
                    FillStepList(workflowContext, pickStep.WorkflowSteps, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "eventHandlers")
                {
                    //we will handle this section as same as handl scope
                    FillStepList(workflowContext, workflowStepList, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "onMessage")
                {
                    var messageStep = new OnMessageStep(currentStep.Attributes);
                    workflowStepList.Add(messageStep);

                    string messageName = String.Empty;
                    string timesetTime = String.Empty;
                    if (currentStep.Attributes != null)
                        foreach (XmlAttribute attrib in currentStep.Attributes)
                        {
                            if (attrib.LocalName == "timeout")
                            {
                                timesetTime = attrib.Value;
                            }
                            if (attrib.LocalName == "variable")
                            {
                                messageName = attrib.Value;
                            }
                        }
                    if (!timeoutParameters.ContainsKey(messageName))
                    {
                        timeoutParameters.Add(messageName, timesetTime);
                    }

                    FillStepList(workflowContext, messageStep.WorkflowSteps, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "onEvent")
                {
                    var onEventStep = new OnEventStep(currentStep.Attributes);
                    workflowContext.MessageTimeoutEventHanlderDict.Add(onEventStep.EventKey, onEventStep.StepId);
                    workflowStepList.Add(onEventStep);
                    FillStepList(workflowContext, onEventStep.WorkflowSteps, 0, currentStep.ChildNodes, ref cancelEventHandlerName);
                }
                else if (currentStep.LocalName == "partnerLinks")
                {
                    FillPartnerLinkList(workflowContext, currentStep);
                }
                else if (currentStep.LocalName == "variables")
                {
                    FillVariableList(workflowContext, currentStep);
                }
                else if (currentStep.LocalName == "faultHandlers")
                {
                    foreach (XmlNode childNode in currentStep.ChildNodes)
                    {
                        var faultHandler = new FaultHandler(childNode);
                        workflowStepList.Add(faultHandler);
                        FillStepList(workflowContext, faultHandler.WorkflowSteps, 0, childNode.ChildNodes, ref cancelEventHandlerName);
                    }
                }
                else
                {
                    Debug.Fail("Unhandled " + currentStep.Name + " of " + currentStep.InnerText);
                }
            }
        }
        /// <summary>
        /// Loads latest version of a workflow from given workflow name.  
        /// Initialize context with all workflow information
        /// </summary>
        /// <param name="context">contains workflow name</param>
        /// <returns>true if workflow was found and successfully loaded. False otherwise</returns>
        public bool LoadNewWorkflow(WorkflowContext context)
        {
            lock (this.lockObject)
            {
                XmlElement rootElement = this.LoadWorkflowFile(context.WorkflowName, context.Version);
                if (rootElement == null)
                {
                    return false;
                }

                XmlNodeList childList = rootElement.ChildNodes;
                this.CloseWorkflowFile();

                // Set this before doing actual load so it doesn't trigger
                // a load on its own.
                context.IsWorkflowStepsLoaded = true;

                if (_cachedWorkflowSteps.ContainsKey(context.WorkflowName) && _cachedFaultHandler.ContainsKey(context.WorkflowName) && _cachedMessageTimeoutHandler.ContainsKey(context.WorkflowName) && _cachedCancelHandler.ContainsKey(context.WorkflowName))
                {
                    //this.FillVariableList(context.WorkflowVariables, childList);
                    foreach (FaultHandler handler in _cachedFaultHandler[context.WorkflowName])
                    {
                        context.FaultHandlers.Add(handler);
                    }

                    foreach (WorkflowStep step in _cachedWorkflowSteps[context.WorkflowName])
                    {
                        context.WorkflowStepList.Add(step);
                    }

                    foreach (var dict in _cachedMessageTimeoutHandler[context.WorkflowName])
                    {
                        context.MessageTimeoutEventHanlderDict.Add(dict.Key, dict.Value);
                    }

                    foreach (var cachedVariable in _cachedVariables[context.WorkflowName])
                    {
                        context.WorkflowVariables.Add(cachedVariable.Key, cachedVariable.Value);
                    }

                    foreach (var cachedPartnerLink in _cachedPartnerLinks[context.WorkflowName])
                    {
                        context.PartnerLinkList.Add(cachedPartnerLink);
                    }

                    context.CancelEventHandlerName = _cachedCancelHandler[context.WorkflowName];
                }
                else
                {
                    // Do the actual load
                    string cancelEventHandlerName = string.Empty;
                    this.FillStepList(context, context.WorkflowStepList, 0, childList, ref cancelEventHandlerName);
                    context.CancelEventHandlerName = cancelEventHandlerName;
                    _cachedWorkflowSteps.Add(context.WorkflowName, context.WorkflowStepList);
                    _cachedFaultHandler.Add(context.WorkflowName, context.FaultHandlers);
                    _cachedMessageTimeoutHandler.Add(context.WorkflowName, context.MessageTimeoutEventHanlderDict);
                    _cachedCancelHandler.Add(context.WorkflowName, cancelEventHandlerName);
                    _cachedVariables.Add(context.WorkflowName, context.WorkflowVariables);
                    _cachedPartnerLinks.Add(context.WorkflowName, context.PartnerLinkList);
                }

                return true;
            }
        }
Exemplo n.º 15
0
 /// <summary>
 /// evaluate the condition and return true/false
 /// e.g. getVariableData('isLastUamReplica') = 'True'
 /// </summary>
 /// <param name="context">WorkflowContext of executing workflow</param>
 /// <returns>True if condition is met, false otherwise</returns>
 public bool IsConditionTrue(WorkflowContext context)
 {
     return true;
 }
Exemplo n.º 16
0
 private IEnumerable<ICaseStep> GetCaseStepFromContext(WorkflowContext workflowContext)
 {
     foreach (var stepRunnerStep in workflowContext.WorkflowStepList.OfType<IStepRunnerStep>())
     {
         foreach (var switchStep in stepRunnerStep.WorkflowSteps.OfType<ISwitchStep>())
         {
             foreach (var caseStep in switchStep.WorkflowSteps.OfType<ICaseStep>())
             {
                 yield return caseStep;
             }
         }
     }
 }
Exemplo n.º 17
0
 /// <summary>
 /// Run anti workflow. This method depends on breadcrumbs having been stored
 /// during the workflow's execution. If there is no named 
 /// </summary>
 /// <param name="context">workflow context</param>
 public void RunAntiWorkflow(WorkflowContext context)
 {
     if (context == null) return;
 }
Exemplo n.º 18
0
 /// <summary>
 /// Used to run a workflow step
 /// </summary>
 /// <param name="context">Context for the workflow</param>
 /// <param name="stepId">Step at which to start execution.  Ignored</param>
 /// <returns>State of the workflow after executing the steps.</returns>
 public abstract string Run(WorkflowContext context, string stepId);