示例#1
0
 public XPathNamespaceReply CheckXPaths(string xmlContent, int column, int row)
 {
     using (XmlReader reader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(xmlContent ?? string.Empty))))
     {
         var    root             = new NodeStructure(string.Empty, -1, null);
         var    globalNamespace  = GetItems(root, reader);
         string namespaceVirtual = string.Empty;
         if (globalNamespace.ContainsKey(string.Empty))
         {
             do
             {
                 namespaceVirtual += "a";
             } while (globalNamespace.ContainsKey(namespaceVirtual));
         }
         var item = SearchXPath(root.Items[0], column, row);
         if (item != null)
         {
             var namespaces = FoundXPath(item, namespaceVirtual);
             return(new XPathNamespaceReply()
             {
                 XPath = item.XPath,
                 Namespaces = namespaces,
                 NamespaceVirtual = namespaceVirtual
             });
         }
         else
         {
             return(null);
         }
     }
 }
    //Experimental Node creational method
    public static GameObject nCreateNode(string locString, NodeStructure nodeStruct)
    {
        GameObject nodePrefab   = Resources.Load <GameObject>("Prefabs/nNode");
        GameObject nodeInstance = MonoBehaviour.Instantiate(nodePrefab);
        Node       nodeCode     = nodeInstance.GetComponent <Node>();

        nodeCode.NodeStruct     = nodeStruct;
        nodeCode.LocationString = locString;

        return(nodeInstance);
    }
示例#3
0
 public SubNodeBase(double StartX, double StartY, double EndX, double EndY, int stage, NodeStructure configuration) : base()
 {
     this.StartX    = StartX;
     this.StartY    = StartY;
     this.EndX      = EndX;
     this.EndY      = EndY;
     this.nodeStage = stage;
     Canvas.SetLeft(this, StartX);
     Canvas.SetTop(this, StartY);
     _ignoreFirstMouseLeave = true;
     nodeConfig             = configuration;
 }
示例#4
0
        // TODO: replace with some (cached!) path lookup
        public NodeStructure GetStructure(string path, bool showDeleted = false, int?revision = null)
        {
            IList <Node> nodes = new List <Node> {
                Root
            };
            var result = new NodeStructure
            {
                Nodes        = nodes,
                OriginalPath = path
            };

            var isNode = string.IsNullOrEmpty(path) || path.EndsWith("/");

            if (path != null)
            {
                var chunks = path.Split('/');
                chunks = chunks.Where(x => !string.IsNullOrEmpty(x)).ToArray();
                try
                {
                    for (var i = 0; i < chunks.Length; i++)
                    {
                        // fetch next deeper chunk
                        var name    = chunks[i];
                        var current = nodes.Last();
                        if (!string.IsNullOrEmpty(name))
                        {
                            if (i + 1 < chunks.Length)
                            {
                                nodes.Add(_proxy.GetBranchByName(name.FromWikiUrlString(), current.Id));
                            }
                            else if (isNode)
                            {
                                nodes.Add(_proxy.GetBranchByName(name.FromWikiUrlString(), current.Id, revision));
                            }
                            else
                            {
                                nodes.Add(GetLeafByWikiName(name, current.Id, revision));
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    result.SetPathError(new InvalidPathError("Path does not exist"));
                }
            }

            GetChildren(nodes.Last(), showDeleted);
            return(result);
        }
示例#5
0
        private NodeStructure SearchXPath(NodeStructure root, int column, int row)
        {
            NodeStructure CheckItems()
            {
                var coll = root.Items;

                foreach (var item in coll)
                {
                    var reply = SearchXPath(item, column, row);
                    if (reply != null)
                    {
                        return(reply);
                    }
                }

                return(root);
            }

            if (root.LineNumberStart <= row && root.LineNumberEnd >= row)
            {
                if (root.LineNumberEnd == root.LineNumberStart)
                {
                    if (root.PositionStart <= column && root.PositionEnd >= column)
                    {
                        return(CheckItems());
                    }
                }
                else if (root.LineNumberStart == row)
                {
                    if (root.PositionStart <= column)
                    {
                        return(CheckItems());
                    }
                }
                else if (root.LineNumberEnd == row)
                {
                    if (root.PositionEnd >= column)
                    {
                        return(CheckItems());
                    }
                }
                else
                {
                    return(CheckItems());
                }
            }

            return(null);
        }
    /* 1st Overload ---
     * New Parameters:
     *    -> NodeStructure nodeStruct: Create a Node by passing a reference to a NodeStructure
     */
    public static GameObject CreateNode(string locString, NodeStructure nodeStruct)
    {
        if (NodeStructuresByName.ContainsValue(nodeStruct))
        {
            GameObject nodePrefab   = Resources.Load <GameObject>("Prefabs/Node");
            GameObject nodeInstance = MonoBehaviour.Instantiate(nodePrefab);
            Node       nodeCode     = nodeInstance.GetComponent <Node>();

            nodeCode.NodeStruct     = nodeStruct;
            nodeCode.LocationString = locString;

            return(nodeInstance);
        }

        throw new ArgumentException("Non-existent NodeStruct passed to CreateNode.");
    }
示例#7
0
        private SubNodeBase DefineNode(int index, int max, NodeStructure configuration)
        {
            var minusHalfMax          = -(max / 2);
            var indexFromMinusHalfMax = minusHalfMax + index;
            var multiplierForLeftMove = Math.Sin(Math.PI / 2 + (Math.PI / 3.95 * indexFromMinusHalfMax));
            var multiplierForTopMove  = Math.Cos(Math.PI / 2 + (Math.PI / 3.95 * indexFromMinusHalfMax));
            var radius     = 120 + 5 * max / 2;
            var newSubNode = new SubNode(Canvas.GetLeft(this),
                                         Canvas.GetTop(this),
                                         Canvas.GetLeft(this) - multiplierForLeftMove * radius,
                                         Canvas.GetTop(this) - multiplierForTopMove * radius,
                                         //Canvas.GetTop(this) + ((max - 1) * 100 / 2) - index * 100,
                                         nodeStage + 1, configuration);

            //newSubNode.StartEjecting();
            return(newSubNode);
        }
    //Experimental Node creational method
    public static GameObject nCreateNode(string locString)
    {
        GameObject nodePrefab   = Resources.Load <GameObject>("Prefabs/nNode");
        GameObject nodeInstance = MonoBehaviour.Instantiate(nodePrefab);
        Node       nodeCode     = nodeInstance.GetComponent <Node>();

        IList <Type> values = new List <Type>(NodeStructTypesByName.Values);
        int          size   = values.Count;
        int          roll   = UnityEngine.Random.Range(0, size);

        NodeStructure _nodeStruct = Activator.CreateInstance(values[roll]) as NodeStructure;

        nodeCode.NodeStruct     = _nodeStruct;
        nodeCode.LocationString = locString;

        return(nodeInstance);
    }
    /* 2nd Overload ---
     * Takes only a location as an argument. Returns a Node with a random NodeStructure.
     */
    public static GameObject CreateNode(string locString)
    {
        GameObject nodePrefab   = Resources.Load <GameObject>("Prefabs/Node");
        GameObject nodeInstance = MonoBehaviour.Instantiate(nodePrefab);
        Node       nodeCode     = nodeInstance.GetComponent <Node>();

        // Select a random NodeStructure from the dictionary
        System.Random rand   = new System.Random();
        IList <Type>  values = new List <Type>(NodeStructTypesByName.Values);
        int           size   = values.Count;
        int           roll   = rand.Next(size);

        NodeStructure _nodeStruct = Activator.CreateInstance(values[roll]) as NodeStructure;

        nodeCode.NodeStruct     = _nodeStruct;
        nodeCode.LocationString = locString;

        return(nodeInstance);
    }
    /* Main creational methods for Nodes within the NodeFactory
     * Parameters:
     *    -> string locString: longitudinal and latitudinal coordinates of Node
     *    -> string nodeStructureType: string representation of the NodeStructure to be returned
     * Returns:
     *    -> A GameObject: the Node prefab to be placed in the Unity scene via Mapbox
     */
    public static GameObject CreateNode(string locString, string nodeStructureType)
    {
        // If the given NodeStructure exists then attach it to a new Node and return it
        if (NodeStructuresByName.ContainsKey(nodeStructureType))
        {
            NodeStructure nodeStruct = NodeStructuresByName[nodeStructureType];

            // Create a new Node prefab and initialize its fields
            GameObject nodePrefab   = Resources.Load <GameObject>("Prefabs/Node");
            GameObject nodeInstance = MonoBehaviour.Instantiate(nodePrefab);
            Node       nodeCode     = nodeInstance.GetComponent <Node>();

            nodeCode.NodeStruct     = nodeStruct;
            nodeCode.LocationString = locString;

            return(nodeInstance);
        }

        throw new ArgumentException("Non-existent NodeStruct passed to CreateNode.");
    }
示例#11
0
    public static bool Open(int instanceID, int line)
    {
        UnityEngine.Object asset        = EditorUtility.InstanceIDToObject(instanceID);
        BehaviorTree       behaviorTree = asset as BehaviorTree;

        if (behaviorTree)
        {
            var editor = BehaviorTreeEditorView.OpenBehaviorTreeWindow();
            editor.Load(behaviorTree);
            string name = EditorUtility.InstanceIDToObject(instanceID).name;
            return(true);
        }

        NodeStructure nodeStructure = asset as NodeStructure;

        if (nodeStructure)
        {
            var editor = NodeBasedEditorView.OpenWindow();
            editor.Load(asset as NodeStructure);
            string name = EditorUtility.InstanceIDToObject(instanceID).name;
            return(true);
        }
        return(false);
    }
示例#12
0
        private SortedDictionary <string, string> FoundXPath(NodeStructure root, string namespaceVirtual)
        {
            var actual     = root;
            var namespaces = new SortedDictionary <string, string>();
            Func <NodeStructure, string> getNodeNameCustom = (customNode) =>
            {
                string namespaceString = string.Empty;
                if (!string.IsNullOrEmpty(customNode.Namespace))
                {
                    namespaceString = (string.IsNullOrEmpty(customNode.Prefix) ? namespaceVirtual : customNode.Prefix) + ":";
                }

                return(namespaceString + customNode.NodeName);
            };

            string getNodeName() => getNodeNameCustom(actual);

            string xpath = string.Empty;

            while (actual.Parent != null)
            {
                if (!string.IsNullOrEmpty(actual.Namespace))
                {
                    if (!namespaces.ContainsKey(actual.Prefix))
                    {
                        namespaces.Add(actual.Prefix, actual.Namespace);
                    }
                }

                var items = actual.Parent.Items;
                if (items.Count == 1)
                {
                    xpath  = $"/{getNodeName()}{xpath}";
                    actual = actual.Parent;
                    continue;
                }

                if (items.Where(t => t.NodeName == actual.NodeName).Count() == 1)
                {
                    xpath  = $"/{getNodeName()}{xpath}";
                    actual = actual.Parent;
                    continue;
                }

                var subItems = items.Where(t => getNodeNameCustom(t) == getNodeName() && t.Attributes.Count == 0 && actual.Attributes.Count == 0).ToList();
                if (subItems.Count > 1)
                {
                    for (int i = 0; i < subItems.Count; i++)
                    {
                        if (subItems[i] == actual)
                        {
                            xpath = $"/{getNodeName()}[{i + 1}]{xpath}";
                            break;
                        }
                    }

                    actual = actual.Parent;
                    continue;
                }

                var subItems2 = items.Where(t => getNodeNameCustom(t) == getNodeName() && t.HashFromAttribute == actual.HashFromAttribute).ToList();
                if (subItems2.Count == 1)
                {
                    var attrs = new StringBuilder();
                    if (actual.Attributes.Count > 0)
                    {
                        foreach (KeyValuePair <string, string> item in actual.Attributes)
                        {
                            attrs.Append((attrs.Length == 0) ? "[" : " and ");
                            string quote = item.Value.Contains("\"") ? "'" : "\"";
                            attrs.Append($"@{item.Key}={quote}{item.Value}{quote}");
                        }

                        attrs.Append("]");
                    }

                    xpath  = $"/{getNodeName()}{attrs}{xpath}";
                    actual = actual.Parent;
                    continue;
                }

                {
                    var attrs = new StringBuilder();
                    if (actual.Attributes.Count > 0)
                    {
                        foreach (KeyValuePair <string, string> item in actual.Attributes)
                        {
                            attrs.Append((attrs.Length == 0) ? "[" : " and ");
                            string quote = item.Value.Contains("\"") ? "'" : "\"";
                            attrs.Append($"@{item.Key}={quote}{item.Value}{quote}");
                        }

                        attrs.Append("]");
                    }

                    for (int i = 0; i < subItems2.Count; i++)
                    {
                        if (subItems2[i] == actual)
                        {
                            xpath = $"/{getNodeName()}{attrs}[{i + 1}]{xpath}";
                            break;
                        }
                    }

                    actual = actual.Parent;
                    continue;
                }
            }

            root.XPath = xpath;
            return(namespaces);
        }
示例#13
0
        internal SortedDictionary <string, string> GetItems(NodeStructure root, XmlReader reader)
        {
            var           namespaces = new SortedDictionary <string, string>();
            NodeStructure buffer     = root;
            bool          closePrev  = false;

            while (reader.Read())
            {
                int ln = reader.LineNumber();
                int lp = reader.LinePosition();

                if (closePrev)
                {
                    buffer.LineNumberEnd = ln;
                    buffer.PositionEnd   = lp - 1;
                    buffer    = buffer.Parent;
                    closePrev = false;
                }

                if (reader.NodeType == XmlNodeType.Element)
                {
                    //sb.Append($"{ln} {lp} {reader.Depth} {reader.LocalName}\r\n");
                    buffer = new NodeStructure(reader.LocalName, reader.Depth, buffer)
                    {
                        Namespace       = reader.NamespaceURI,
                        LineNumberStart = ln,
                        PositionStart   = lp - 2,
                        Prefix          = reader.Prefix
                    };

                    buffer.Parent.Items.Add(buffer);
                    if (reader.AttributeCount > 0)
                    {
                        for (int i = 0; i < reader.AttributeCount; i++)
                        {
                            reader.MoveToAttribute(i);
                            string nameAttribute = reader.Name;
                            if (nameAttribute != "xmlns" && !nameAttribute.StartsWith("xmlns:"))
                            {
                                buffer.Attributes.Add(nameAttribute, reader.Value);
                            }
                        }

                        reader.MoveToElement();
                    }

                    if (!string.IsNullOrEmpty(buffer.Namespace) && !namespaces.ContainsKey(buffer.Prefix))
                    {
                        namespaces.Add(buffer.Prefix, buffer.Namespace);
                    }

                    closePrev = reader.IsEmptyElement;
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (buffer != null)
                    {
                        buffer.LineNumberEnd = ln;
                        buffer.PositionEnd   = lp + buffer.NodeName.Length + (!string.IsNullOrEmpty(buffer.Prefix) ? buffer.Prefix.Length + 1 : 0);
                        buffer = buffer.Parent;
                    }
                }
            }

            return(namespaces);
        }
示例#14
0
        public override bool Load(NodeStructure tree)
        {
            if (!UnsavedChangesCheck())
            {
                return(false);
            }
            if (tree == null)
            {
                NewFile();
                return(true);
            }

            // Make a copy of the reference structure
            behaviorTree = (tree as BehaviorTree).Clone();

            nodeViews   = new List <NodeView>();
            connections = new List <Connection>();
            UnityEngine.Debug.Log("Found a root node and " + behaviorTree.nodes.Count + " nodes");

            // Create a view for the root node
            CreateNodeView(behaviorTree.root, GetDefaultRootPosition());

            // Create node views for every other node
            foreach (var node in behaviorTree.nodes)
            {
                CreateNodeView(node);
            }

            // Connect the node views
            foreach (var nodeView in nodeViews)
            {
                var multipleConnectionsNode = nodeView.node as NodeInterfaces.IMultipleConnection;
                if (multipleConnectionsNode != null)
                {
                    // For every child of the node,
                    foreach (var nodeChild in multipleConnectionsNode.GetChildren())
                    {
                        CreateConnection(nodeView, nodeViews.Find(x => x.node.guid == nodeChild.guid));
                    }
                    continue;
                }
                var singleConnectionNode = nodeView.node as NodeInterfaces.ISingleConnection;
                if (singleConnectionNode != null)
                {
                    Node nodeChild = singleConnectionNode.GetChild();
                    if (nodeChild != null)
                    {
                        UnityEngine.Debug.Log(nodeView.node + " has a child");
                        CreateConnection(nodeView, nodeViews.Find(x => x.node.guid == nodeChild.guid));
                    }
                    else
                    {
                        UnityEngine.Debug.Log(nodeView.node + " has no child");
                    }
                    continue;
                }
            }

            // Set the reference to the reference file
            file = tree;
            hasUnsavedChanges = false;
            ClearConnectionSelection();
            return(true);
        }
示例#15
0
        public SubNode(double StartX, double StartY, double EndX, double EndY, int stage, NodeStructure configuration)
            : base(StartX, StartY, EndX, EndY, stage, configuration)
        {
            InitializeComponent();

            A_EjectX_DA.From = StartX;
            A_EjectX_DA.To   = EndX;
            A_EjectY_DA.From = StartY;
            A_EjectY_DA.To   = EndY;

            A_HideX_DA.From = EndX;
            A_HideX_DA.To   = StartX;
            A_HideY_DA.From = EndY;
            A_HideY_DA.To   = StartY;

            S_Eject.Storyboard.Begin();

            base.S_Eject = this.S_Eject;
            base.S_Hide  = this.S_Hide;

            C_NodeContainer_G.Width  = System.Windows.SystemParameters.PrimaryScreenWidth;
            C_NodeContainer_G.Height = System.Windows.SystemParameters.PrimaryScreenHeight;

            if (configuration != null)
            {
                C_Name.Text = configuration.Details.Name;
            }
        }