コード例 #1
0
        public static Transition Create(XElement element, KeyMapping keyMapping)
        {
            var transition = new Transition();

            transition.Load(element, keyMapping);
            return(transition);
        }
コード例 #2
0
        public static Node Create(XElement element, KeyMapping keyMapping)
        {
            var node = new Node();

            node.Load(element, keyMapping);
            return(node);
        }
コード例 #3
0
        public override void Load(XElement element, KeyMapping keyMapping)
        {
            base.Load(element, keyMapping);

            var dataElements = element
                               .Elements(XName.Get("data", element.GetDefaultNamespace().NamespaceName))
                               .ToArray();

            var initialElem = dataElements
                              .Where(x => (string)x.Attribute("key") == keyMapping.InitialStateId)
                              .FirstOrDefault();

            var finalElem = dataElements
                            .Where(x => (string)x.Attribute("key") == keyMapping.FinalStateId)
                            .FirstOrDefault();

            IsInitial = ParsingUtility.ElementContentToBoolean(initialElem, keyMapping.InitialStateDefaultValue);
            IsFinal   = ParsingUtility.ElementContentToBoolean(finalElem, keyMapping.FinalStateDefaultValue);

            if (IsFinal)
            {
                if (Description == null)
                {
                    Description = "[FINAL]";
                }
            }

            CheckIdProperty(element);
            CheckDescriptionProperty(element);
        }
コード例 #4
0
ファイル: Graph.cs プロジェクト: whuacn/finite-state-machine
        public static Graph CreateFromRootXml(XElement root)
        {
            if (root == null)
            {
                throw new ArgumentNullException(nameof(root));
            }

            var km = new KeyMapping(root);

            var graphElement = root
                               .Elements(XName.Get("graph", root.GetDefaultNamespace().NamespaceName))
                               .FirstOrDefault();

            return(Create(graphElement, km));
        }
コード例 #5
0
ファイル: Graph.cs プロジェクト: whuacn/finite-state-machine
        public static Graph Create(XElement element, KeyMapping keyMapping)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }
            if (keyMapping == null)
            {
                throw new ArgumentNullException(nameof(keyMapping));
            }

            var graph = new Graph();

            graph.Load(element, keyMapping);
            return(graph);
        }
コード例 #6
0
        public override void Load(XElement element, KeyMapping keyMapping)
        {
            base.Load(element, keyMapping);

            CheckIdProperty(element);

            Source = (string)element.Attribute("source");
            Target = (string)element.Attribute("target");

            if (Source != null)
            {
                Source = Source.Trim();
            }

            if (Target != null)
            {
                Target = Target.Trim();
            }
        }
コード例 #7
0
        public virtual void Load(XElement element, KeyMapping keyMapping)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }
            if (keyMapping == null)
            {
                throw new ArgumentNullException(nameof(keyMapping));
            }

            Identifier = (string)element.Attribute("id");
            if (Identifier != null)
            {
                Identifier = Identifier.Trim();
            }

            var dataElements = element
                               .Elements(XName.Get("data", element.GetDefaultNamespace().NamespaceName));

            var descriptionContent = dataElements
                                     .Where(x => (string)x.Attribute("key") == keyMapping.NodeDescrionId || (string)x.Attribute("key") == keyMapping.GraphDescrionId || (string)x.Attribute("key") == keyMapping.EdgeDescrionId)
                                     .FirstOrDefault();

            if (descriptionContent != null && descriptionContent.FirstNode != null)
            {
                if (descriptionContent.FirstNode.NodeType == XmlNodeType.CDATA)
                {
                    Description = ((XCData)descriptionContent.FirstNode).Value;
                }
                else if (descriptionContent.FirstNode.NodeType == XmlNodeType.Text)
                {
                    Description = ((XText)descriptionContent.FirstNode).Value;
                }
            }

            if (Description != null)
            {
                Description = Description.Trim();
            }
        }
コード例 #8
0
ファイル: Graph.cs プロジェクト: whuacn/finite-state-machine
        public override void Load(XElement element, KeyMapping keyMapping)
        {
            base.Load(element, keyMapping);

            Nodes = element
                    .Elements(XName.Get("node", element.GetDefaultNamespace().NamespaceName))
                    .Select(x => Node.Create(x, keyMapping))
                    .ToArray();

            Transitions = element
                          .Elements(XName.Get("edge", element.GetDefaultNamespace().NamespaceName))
                          .Select(x => Transition.Create(x, keyMapping))
                          .Distinct(new TransitionEqualityComparer())
                          .ToArray();

            var initialNodes = Nodes
                               .Where(n => n.IsInitial)
                               .ToArray();

            if (initialNodes.Length == 1)
            {
                InitialNode = initialNodes[0];
            }
            else if (initialNodes.Length > 1)
            {
                throw new FormatException("Several nodes are declared as initial, however there can be at most one.");
            }

            // find not properly connected transitions
            foreach (var t in Transitions)
            {
                if (Nodes.Any(n => n.Identifier == t.Source) == false)
                {
                    throw new FormatException(string.Format("Source of transition '{0}' is invalid.", t.Description));
                }
                if (Nodes.Any(n => n.Identifier == t.Target) == false)
                {
                    throw new FormatException(string.Format("Target of transition '{0}' is invalid.", t.Description));
                }

                if (t.Description == null)
                {
                    t.UpdateDescription(Nodes.First(n => n.Identifier == t.Target).Description);
                }
            }

            //foreach (var grp in Transitions.GroupBy(t => t.Description))
            //{
            //    var orderedTransitions = grp.OrderBy(t => t.Source).ToArray();
            //    for (int i = 0; i < orderedTransitions.Length - 1; i++)
            //    {
            //        if (orderedTransitions[i].Source == orderedTransitions[i + 1].Source)
            //        {
            //            var from = Nodes.Single(x => x.Identifier == orderedTransitions[i].Source).Description;
            //            var to1 = Nodes.Single(x => x.Identifier == orderedTransitions[i].Target).Description;
            //            var to2 = Nodes.Single(x => x.Identifier == orderedTransitions[i + 1].Target).Description;
            //            throw new FormatException(string.Format("Illegal transitions from '{0}' to '{1}' and '{2}'.", from, to1, to2));
            //        }
            //    }
            //}
        }