Exemplo n.º 1
0
 private TsmData GetTsmData(PfcExecutionContext parentPfcec)
 {
     Debug.Assert(!parentPfcec.IsStepCentric); // State is stored in the parent of the trans, a PFC.
     if (!parentPfcec.Contains(this))
     {
         parentPfcec.Add(this, new TsmData());
     }
     return((TsmData)parentPfcec[this]);
 }
Exemplo n.º 2
0
        private SsmData GetSsmData(PfcExecutionContext pfcec)
        {
            if (MyStep.Equals(pfcec.Step))
            {
                pfcec = (PfcExecutionContext)pfcec.Parent;
            }

            if (!pfcec.Contains(this))
            {
                SsmData retval = new SsmData();
                pfcec.Add(this, retval);
            }

            return((SsmData)pfcec[this]);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates pfc execution contexts, one per action under the step that is currently running. Each
        /// is given an instance count of zero, as a step can run its action only once, currently.
        /// </summary>
        /// <param name="parentContext">The parent context, that of the step that is currently running.</param>
        /// <param name="kids">The procedure function charts that live in the actions under the step that is currently running.</param>
        /// <param name="kidContexts">The pfc execution contexts that will correspond to the running of each of the child PFCs.</param>
        protected virtual void CreateChildContexts(PfcExecutionContext parentContext, out IProcedureFunctionChart[] kids, out PfcExecutionContext[] kidContexts)
        {
            int kidCount = MyStep.Actions.Count;

            kids        = new ProcedureFunctionChart[kidCount];
            kidContexts = new PfcExecutionContext[kidCount];
            int i = 0;

            foreach (KeyValuePair <string, IProcedureFunctionChart> kvp in MyStep.Actions)
            {
                IProcedureFunctionChart kid = kvp.Value;
                kids[i] = kid;
                Guid kidGuid = GuidOps.XOR(parentContext.Guid, kid.Guid);
                while (parentContext.Contains(kidGuid))
                {
                    kidGuid = GuidOps.Increment(kidGuid);
                }
                kidContexts[i] = new PfcExecutionContext(kid, kvp.Key, null, kidGuid, parentContext);
                kidContexts[i].InstanceCount = 0;
                i++;
            }
        }
Exemplo n.º 4
0
        private IProcedureFunctionChart CreatePfc(IModel model, string pfcName, double minutesPerTask, ExecutionEngineConfiguration eec)
        {
            //    Start
            //      |
            //      +T1   ----
            //      |     |  |
            //      -------  |
            //         |     |
            //       Step1   |
            //         |     |
            //         +T2   |
            //         |     |
            //       Step2   |
            //         |     |
            //      -------  |
            //     T3+   +T4 |
            //       |   |---
            //    Finish
            //       |
            //     T5+
            ProcedureFunctionChart pfc = new ProcedureFunctionChart(model, pfcName);

            pfc.ExecutionEngineConfiguration = eec;
            pfc.CreateStep(pfcName + "Start", "", Guid.NewGuid());
            pfc.CreateStep(pfcName + "Step1", "", Guid.NewGuid());
            pfc.CreateStep(pfcName + "Step2", "", Guid.NewGuid());
            pfc.CreateStep(pfcName + "Finish", "", Guid.NewGuid());
            pfc.CreateTransition(pfcName + "T1", "", Guid.NewGuid());
            pfc.CreateTransition(pfcName + "T2", "", Guid.NewGuid());
            pfc.CreateTransition(pfcName + "T3", "", Guid.NewGuid());
            pfc.CreateTransition(pfcName + "T4", "", Guid.NewGuid());
            pfc.CreateTransition(pfcName + "T5", "", Guid.NewGuid());
            pfc.Bind(pfc.Nodes[pfcName + "Start"], pfc.Nodes[pfcName + "T1"]);
            pfc.Bind(pfc.Nodes[pfcName + "T1"], pfc.Nodes[pfcName + "Step1"]);
            pfc.Bind(pfc.Nodes[pfcName + "Step1"], pfc.Nodes[pfcName + "T2"]);
            pfc.Bind(pfc.Nodes[pfcName + "T2"], pfc.Nodes[pfcName + "Step2"]);
            pfc.Bind(pfc.Nodes[pfcName + "Step2"], pfc.Nodes[pfcName + "T3"]);
            pfc.Bind(pfc.Nodes[pfcName + "Step2"], pfc.Nodes[pfcName + "T4"]);
            pfc.Bind(pfc.Nodes[pfcName + "T4"], pfc.Nodes[pfcName + "Step1"]);
            pfc.Bind(pfc.Nodes[pfcName + "T3"], pfc.Nodes[pfcName + "Finish"]);
            pfc.Bind(pfc.Nodes[pfcName + "Finish"], pfc.Nodes[pfcName + "T5"]);

            pfc.Steps.ForEach(delegate(IPfcStepNode psn) {
                psn.LeafLevelAction = new PfcAction(delegate(PfcExecutionContext pfcec, StepStateMachine ssm) {
                    StringBuilder sb = (StringBuilder)pfcec.Root.Payload["StringBuilder"];
                    string stepName  = pfc.Name + "." + psn.Name;
                    IExecutive exec  = psn.Model.Executive;
                    sb.AppendLine(string.Format("{0} : {1} is running its intrinsic action.", exec.Now, stepName));
                    exec.CurrentEventController.SuspendUntil(exec.Now + TimeSpan.FromMinutes(minutesPerTask));
                });
            });

            pfc.Transitions[pfcName + "T1"].ExpressionExecutable
                = new Highpoint.Sage.Graphs.PFC.Execution.ExecutableCondition(
                      delegate(object userData, Highpoint.Sage.Graphs.PFC.Execution.TransitionStateMachine tsm) {
                PfcExecutionContext execContext = (PfcExecutionContext)userData;
                string countKey = pfc.Guid.ToString() + ".Count";
                if (!execContext.Contains(countKey))
                {
                    execContext.Add(countKey, 1);
                }
                else
                {
                    execContext[countKey] = 1;
                }
                return(DEFAULT_EXECUTABLE_EXPRESSION(execContext, tsm));
            });

            pfc.Transitions[pfcName + "T3"].ExpressionExecutable
                = new Highpoint.Sage.Graphs.PFC.Execution.ExecutableCondition(
                      delegate(object userData, Highpoint.Sage.Graphs.PFC.Execution.TransitionStateMachine tsm) {
                PfcExecutionContext execContext = (PfcExecutionContext)userData;
                string countKey = pfc.Guid.ToString() + ".Count";
                return(DEFAULT_EXECUTABLE_EXPRESSION(execContext, tsm) && (((int)execContext[countKey]) >= 5));
            });

            pfc.Transitions[pfcName + "T4"].ExpressionExecutable
                = new Highpoint.Sage.Graphs.PFC.Execution.ExecutableCondition(
                      delegate(object userData, Highpoint.Sage.Graphs.PFC.Execution.TransitionStateMachine tsm) {
                PfcExecutionContext execContext = (PfcExecutionContext)userData;
                string countKey = pfc.Guid.ToString() + ".Count";
                if ((DEFAULT_EXECUTABLE_EXPRESSION(execContext, tsm) && (((int)execContext[countKey]) < 5)))
                {
                    execContext[countKey] = ((int)execContext[countKey]) + 1;
                    return(true);
                }
                else
                {
                    return(false);
                }
            });

            pfc.UpdateStructure();

            return(pfc);
        }