Beispiel #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]);
 }
Beispiel #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]);
        }
        public void TestSmallLoopbackHierarchical()
        {
            DateTime start = DateTime.Now;
            Model    model = new Model("MyTestModel");

            ExecutionEngineConfiguration eec = new ExecutionEngineConfiguration();

            eec.ScanningPeriod = TimeSpan.FromSeconds(60.0);

            IProcedureFunctionChart pfc       = CreatePfc(model, "RootPfc", 15.0, eec);
            IProcedureFunctionChart pfcChild1 = CreatePfc(model, "Step1Child", 15.0, eec);

            ((PfcStep)pfc.Nodes["RootPfc" + "Step1"]).AddAction("Alice", pfcChild1);
            IProcedureFunctionChart pfcGrandChild1 = CreatePfc(model, "Step1GrandChild", 15.0, eec);

            ((PfcStep)pfcChild1.Nodes["Step1Child" + "Step1"]).AddAction("Bob", pfcGrandChild1);

            PfcExecutionContext dictionary = new PfcExecutionContext(pfc, "MyPfcExecutionContext", "", Guid.NewGuid(), null);

            dictionary.Add("StringBuilder", new StringBuilder());
            pfc.Model.Executive.RequestEvent(new ExecEventReceiver(pfc.Run), DateTime.MinValue, 0.0, dictionary, ExecEventType.Detachable);

            pfc.Model.Start();

            int resultHashCode = dictionary["StringBuilder"].ToString().GetHashCode();

            foreach (object obj in dictionary.Values)
            {
                if (obj is PfcExecutionContext)
                {
                    Console.WriteLine(obj.ToString() + " contains " + ((PfcExecutionContext)obj).Values.Count + " members.");
                }
            }

            Console.WriteLine(dictionary["StringBuilder"]);
            DateTime finish = DateTime.Now;

            Console.WriteLine("The test took " + ((TimeSpan)(finish - start)));
        }
        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);
        }