public void ParseFromNode(XmlNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (FSM == null)
            {
                throw new NullReferenceException("FSM");
            }

            value = new TransitionRes <StructAtom <string>, StructAtom <string> >();

            try
            {
                for (int i = 0; i < node.ChildNodes.Count; ++i)
                {
                    var childNode = node.ChildNodes[i];
                    switch (childNode.Name.ToLower())
                    {
                    case "deststate":
                    {
                        StateXmlWorker w = new StateXmlWorker();
                        w.FSM = this.FSM;
                        w.ParseFromNode(node.ChildNodes[i]);
                        var state = w.Value as FSMState <StructAtom <string>, StructAtom <string> >;
                        if (state != null)
                        {
                            var exState = FSM.StateSet.First(s => s.KeyName == state.KeyName);
                            if (exState != null)
                            {
                                state = exState;
                            }
                            value.DestState = state;
                        }
                    }
                    break;

                    case "output":
                    {
                        value.Output = new StructAtom <string>(childNode.InnerText);
                    }
                    break;

                    case "probability":
                    {
                        value.Probability = double.Parse(childNode.InnerText);
                    }
                    break;
                    }
                }
            }
            catch (Exception exc)
            {
                value = null;
                throw exc;
            }
        }
        public void ParseFromNode(XmlNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (this.FSM == null)
            {
                throw new NullReferenceException("FSM");
            }

            value = new Partition <FSMState <StructAtom <string>, StructAtom <string> > >();

            try
            {
                for (int i = 0; i < node.ChildNodes.Count; ++i)
                {
                    var childNode = node.ChildNodes[i];
                    if (childNode.Name.ToLower() == "block")
                    {
                        HashSet <FSMState <StructAtom <string>, StructAtom <string> > > block = new HashSet <FSMState <StructAtom <string>, StructAtom <string> > >();
                        for (int j = 0; j < childNode.ChildNodes.Count; ++j)
                        {
                            var            childChildNode = childNode.ChildNodes[j];
                            StateXmlWorker w = new StateXmlWorker();
                            w.FSM = this.FSM;
                            if (childChildNode.Name == w.NodeName)
                            {
                                w.ParseFromNode(childChildNode);
                                var state = w.Value as FSMState <StructAtom <string>, StructAtom <string> >;
                                if (state != null)
                                {
                                    var exState = FSM.StateSet.First(s => s.KeyName == state.KeyName);
                                    if (exState == null)
                                    {
                                        state = exState;
                                    }
                                    block.Add(state);
                                }
                            }
                        }
                        value.Add(block);
                    }
                }
            }
            catch (Exception exc)
            {
                value = null;
                throw exc;
            }
        }
Пример #3
0
        public void ParseFromNode(XmlNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            value = new FiniteStateMachine <StructAtom <string>, StructAtom <string> >();

            try
            {
                for (int i = 0; i < node.ChildNodes.Count; ++i)
                {
                    var childNode = node.ChildNodes[i];
                    switch (childNode.Name.ToLower())
                    {
                    case "stateset":
                    {
                        for (int j = 0; j < childNode.ChildNodes.Count; ++j)
                        {
                            var childChildNode = childNode.ChildNodes[j];
                            if (childChildNode.Name.ToLower() == "transition")
                            {
                                StateXmlWorker w = new StateXmlWorker();
                                w.FSM = value;
                                w.ParseFromNode(childChildNode);
                                var state = w.Value as FSMState <StructAtom <string>, StructAtom <string> >;
                                if (state != null)
                                {
                                    value.AddState(state);
                                }
                            }
                        }
                    }
                    break;

                    case "inputset":
                    {
                        for (int j = 0; j < childNode.ChildNodes.Count; ++j)
                        {
                            var childChildNode = childNode.ChildNodes[j];
                            if (childChildNode.Name.ToLower() == "input")
                            {
                                StructAtomStringXmlWorker w = new StructAtomStringXmlWorker();
                                w.ParseFromNode(childChildNode);
                                var inp = w.Value as StructAtom <string>;
                                if (inp != null)
                                {
                                    value.AddInput(inp);
                                }
                            }
                        }
                    }
                    break;

                    case "outputset":
                    {
                        for (int j = 0; j < childNode.ChildNodes.Count; ++j)
                        {
                            var childChildNode = childNode.ChildNodes[j];
                            if (childChildNode.Name.ToLower() == "output")
                            {
                                StructAtomStringXmlWorker w = new StructAtomStringXmlWorker();
                                w.ParseFromNode(childChildNode);
                                var inp = w.Value as StructAtom <string>;
                                if (inp != null)
                                {
                                    value.AddOutput(inp);
                                }
                            }
                        }
                    }
                    break;

                    case "keyname":
                        value.KeyName = childNode.InnerText;
                        break;

                    case "initialstate":
                    {
                        StateXmlWorker w = new StateXmlWorker();
                        w.FSM = value;
                        w.ParseFromNode(childNode);
                        var state = w.Value as FSMState <StructAtom <string>, StructAtom <string> >;
                        if (state != null)
                        {
                            value.InitialState = state;
                        }
                    }
                    break;
                    }
                }

                for (int i = 0; i < node.ChildNodes.Count; ++i)
                {
                    var childNode = node.ChildNodes[i];
                    switch (childNode.Name.ToLower())
                    {
                    case "transitions":
                    {
                        for (int j = 0; j < childNode.ChildNodes.Count; ++j)
                        {
                            var childChildNode = childNode.ChildNodes[j];
                            if (childChildNode.Name.ToLower() == "transition")
                            {
                                TransitionXmlWorker w = new TransitionXmlWorker();
                                w.FSM = value;
                                w.ParseFromNode(childChildNode);
                                var tr = w.Value as Transition <StructAtom <string>, StructAtom <string> >;
                                if (tr != null)
                                {
                                    foreach (var destinationState in tr.destinationStates)
                                    {
                                        value.AddOutgoing(tr.SourceState, tr.Input, destinationState.DestState, destinationState.Output, destinationState.Probability);
                                    }
                                    //value.Transitions.Add(tr.ToString(), tr);
                                }
                            }
                        }
                    }
                    break;
                    }
                }
            }
            catch (Exception exc)
            {
                value = null;
                throw exc;
            }
        }
Пример #4
0
        public void ParseFromNode(XmlNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (FSM == null)
            {
                throw new NullReferenceException("FSM");
            }

            value = new Transition <StructAtom <string>, StructAtom <string> >(FSM);

            try
            {
                for (int i = 0; i < node.ChildNodes.Count; ++i)
                {
                    var childNode = node.ChildNodes[i];
                    switch (childNode.Name.ToLower())
                    {
                    case "sourcestate":
                    {
                        StateXmlWorker w = new StateXmlWorker();
                        w.FSM = this.FSM;
                        w.ParseFromNode(childNode);
                        var state = w.Value as FSMState <StructAtom <string>, StructAtom <string> >;
                        if (state != null)
                        {
                            var exState = this.FSM.StateSet.FirstOrDefault(s => s.KeyName == state.KeyName);
                            if (exState != null)
                            {
                                state = exState;
                            }
                            value.SourceState = state;
                        }
                    }
                    break;

                    case "input":
                    {
                        value.Input = new StructAtom <string>(childNode.InnerText);
                    }
                    break;

                    case "transitionresults":
                    {
                        for (int j = 0; j < childNode.ChildNodes.Count; ++j)
                        {
                            var childChildNodes = childNode.ChildNodes[j];
                            if (childChildNodes.Name.ToLower() == "transitionresult")
                            {
                                TransitionResXmlWorker w = new TransitionResXmlWorker();
                                w.FSM = this.FSM;
                                w.ParseFromNode(childChildNodes);
                                if (w.Value is TransitionRes <StructAtom <string>, StructAtom <string> > )
                                {
                                    value.destinationStates.Add(w.Value as TransitionRes <StructAtom <string>, StructAtom <string> >);
                                }
                            }
                        }
                    }
                    break;
                    }
                }
            }
            catch (Exception exc)
            {
                value = null;
                throw exc;
            }
        }