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

            FSMVTrigger t = new FSMVTrigger();

            try
            {
                foreach (FSMVState state in this.Configuration.ArrayOfFSMVState)
                {
                    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 FSMVState OneStep(FSMStep currentStep, FSMVState currentState, Color color)
        {
            this.MyGraph.ChangeOneVertexColor(currentState.Name, color);
            FSMVState   newState       = new FSMVState();
            FSMVTrigger triggerFounded = this.Configuration.FoundSteppInTriggerList(currentStep);

            if (triggerFounded != null)
            {
                AllowedTrigger allowedTrigger = new AllowedTrigger();
                allowedTrigger = currentState.FoundTriggerInCureentState(triggerFounded);
                if (allowedTrigger != null)
                {
                    newState = new FSMVState();
                    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)
        {
            FSMVState      state = new FSMVState();
            AllowedTrigger aw    = new AllowedTrigger();
            FSMVTrigger    trig  = new FSMVTrigger();

            state.Name = vertexFrom.Text;
            if (string.IsNullOrEmpty(trigger))
            {
                CustomEdge edge = new CustomEdge(vertexTo.Text, vertexFrom, vertexTo);
                this.MyGraph.AddNewEdge(vertexTo.Text, vertexFrom, vertexTo);
                aw.StateAndTriggerName = trig.CommonID = vertexTo.Text;
            }
            else
            {
                CustomEdge edge = new CustomEdge(trigger, vertexFrom, vertexTo);
                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.ArrayOfFSMVState)
            {
                if (item.Name == state.Name)
                {
                    if (item.ArrayOfAllowedTrigger == null)
                    {
                        item.ArrayOfAllowedTrigger = new Collection <AllowedTrigger>();
                    }

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

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

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

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

            return(sequence);
        }