Exemplo n.º 1
0
        /// <summary>
        /// Gets the nodes and represents them.
        /// </summary>
        public override void SetGraphNodes()
        {
            foreach (FSMState state in this.Configuration.ArrayOfFSMState)
            {
                CustomVertex vertex = new CustomVertex(state.Name, Colors.Wheat, true);
                this.MyGraph.AddVertex(vertex);
            }

            FSMTrigger t = new FSMTrigger();

            try
            {
                foreach (FSMState state in this.Configuration.ArrayOfFSMState)
                {
                    foreach (AllowedTrigger trigger in state.ArrayOfAllowedTrigger)
                    {
                        t = this.Configuration.FoundTriggerInList(trigger);
                        if (string.IsNullOrEmpty(trigger.TriggerName))
                        {
                            this.MyGraph.AddNewEdge(trigger.StateAndTriggerName, this.MyGraph.GetVertexByName(state.Name), this.MyGraph.GetVertexByName(trigger.StateAndTriggerName));
                        }
                        else
                        {
                            this.MyGraph.AddNewEdge(trigger.TriggerName, this.MyGraph.GetVertexByName(state.Name), this.MyGraph.GetVertexByName(trigger.StateName));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the machine to next state with given step.
        /// </summary>
        /// <param name="curredntStep">The currednt step.</param>
        /// <param name="currentState">State of the current.</param>
        /// <returns></returns>
        public FSMState OneStep(FSMStep currentStep, FSMState currentState, Color color)
        {
            this.MyGraph.ChangeOneVertexColor(currentState.Name, color);
            FSMState   newState       = new FSMState();
            FSMTrigger triggerFounded = this.Configuration.FoundSteppInTriggerList(currentStep);

            if (triggerFounded != null)
            {
                AllowedTrigger allowedTrigger = new AllowedTrigger();
                allowedTrigger = currentState.FoundTriggerInCureentState(triggerFounded);
                if (allowedTrigger != null)
                {
                    newState = new FSMState();
                    if (string.IsNullOrEmpty(allowedTrigger.StateName))
                    {
                        newState = this.Configuration.FoundNextState(allowedTrigger.StateAndTriggerName);
                    }
                    else
                    {
                        newState = this.Configuration.FoundNextState(allowedTrigger.StateName);
                    }

                    if (newState != null)
                    {
                        this.MyGraph.ChangeOneVertexColor(newState.Name, color);
                        CustomEdge edge = new CustomEdge(null, null);

                        if (string.Compare(currentState.Name, newState.Name) == 0)
                        {
                            this.MyGraph.Vertices.Where(v => (string.Compare(v.Text, currentState.Name) == 0)).FirstOrDefault().Represented = true;
                        }

                        edge = this.MyGraph.GetEdgeBetween(currentState.Name, newState.Name);
                        this.MyGraph.ChangeOneEdgeColor(edge, Colors.Yellow);
                    }
                }
            }

            return(newState);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a new edge, a new allowed trigger to source vertex, a new trigger if it doesn't exist.
        /// </summary>
        /// <param name="vertexFrom">The vertex from.</param>
        /// <param name="trigger">The trigger.</param>
        /// <param name="vertexTo">The vertex to.</param>
        public override void AddNewEdge(CustomVertex vertexFrom, string trigger, CustomVertex vertexTo)
        {
            FSMState state = new FSMState();

            FSMControl.DomainModel.FirstVersion.AllowedTrigger aw = new FSMControl.DomainModel.FirstVersion.AllowedTrigger();
            FSMTrigger trig = new FSMTrigger();

            state.Name = vertexFrom.Text;
            if (string.IsNullOrEmpty(trigger))
            {
                this.MyGraph.AddNewEdge(vertexTo.Text, vertexFrom, vertexTo);
                aw.StateAndTriggerName = trig.CommonID = vertexTo.Text;
            }
            else
            {
                this.MyGraph.AddNewEdge(vertexTo.Text, vertexFrom, vertexTo);
                aw.StateName    = vertexTo.Text;
                aw.TriggerName  = trigger;
                trig.Name       = vertexTo.Text;
                trig.SequenceID = trigger;
            }

            foreach (var item in this.Configuration.ArrayOfFSMState)
            {
                if (item.Name == state.Name)
                {
                    if (item.ArrayOfAllowedTrigger == null)
                    {
                        item.ArrayOfAllowedTrigger = new Collection <FSMControl.DomainModel.FirstVersion.AllowedTrigger>();
                    }

                    item.ArrayOfAllowedTrigger.Add(aw);
                    break;
                }
            }

            this.Configuration.AddNewTrigger(trig);
        }
Exemplo n.º 4
0
        public FSMSequence AddNewStep(FSMSequence sequence, string steppTrigger)
        {
            FSMStep    step  = new FSMStep();
            FSMTrigger triig = new FSMTrigger();

            triig = this.Configuration.FoundStringTriggerList(steppTrigger);
            if (string.IsNullOrEmpty(triig.SequenceID))
            {
                step.Name = triig.CommonID;
            }
            else
            {
                step.Name = triig.SequenceID;
            }

            step.Weight           = "2";
            step.TimeoutInSeconds = " 2";
            if (!string.IsNullOrEmpty(step.Name))
            {
                sequence.ArrayOfStep.Add(step);
            }

            return(sequence);
        }