public NodePathGeneratorTests()
        {
            var serverRoot = new TreeNode
            {
                NodeType  = "Server",
                NodeValue = serverName
            };

            serverSession = new ObjectExplorerService.ObjectExplorerSession("serverUri", serverRoot, null, null);

            var databaseRoot = new TreeNode
            {
                NodeType  = "Database",
                NodeValue = databaseName,
                Parent    = serverRoot
            };

            databaseSession = new ObjectExplorerService.ObjectExplorerSession("databaseUri", databaseRoot, null, null);
        }
Esempio n. 2
0
        internal static HashSet <string> FindNodePaths(ObjectExplorerService.ObjectExplorerSession objectExplorerSession, string typeName, string schema, string name, string databaseName, List <string> parentNames = null)
        {
            if (TreeRoot == null)
            {
                Initialize();
            }

            var returnSet     = new HashSet <string>();
            var matchingNodes = NodeTypeDictionary.GetValueOrDefault(typeName);

            if (matchingNodes == null)
            {
                return(returnSet);
            }

            var path = name;

            if (schema != null)
            {
                path = schema + "." + path;
            }

            if (path == null)
            {
                path = "";
            }

            foreach (var matchingNode in matchingNodes)
            {
                var paths = GenerateNodePath(objectExplorerSession, matchingNode, databaseName, parentNames, path);
                foreach (var newPath in paths)
                {
                    returnSet.Add(newPath);
                }
            }
            return(returnSet);
        }
Esempio n. 3
0
        private static HashSet <string> GenerateNodePath(ObjectExplorerService.ObjectExplorerSession objectExplorerSession, Node currentNode, string databaseName, List <string> parentNames, string path)
        {
            if (parentNames != null)
            {
                parentNames = parentNames.ToList();
            }

            if (currentNode.Name == "Server" || (currentNode.Name == "Database" && objectExplorerSession.Root.NodeType == "Database"))
            {
                var serverRoot = objectExplorerSession.Root;
                if (objectExplorerSession.Root.NodeType == "Database")
                {
                    serverRoot = objectExplorerSession.Root.Parent;
                    path       = objectExplorerSession.Root.NodeValue + (path.Length > 0 ? ("/" + path) : "");
                }

                path = serverRoot.NodeValue + (path.Length > 0 ? ("/" + path) : "");
                var returnSet = new HashSet <string>();
                returnSet.Add(path);
                return(returnSet);
            }

            var currentLabel = currentNode.Label();

            if (currentLabel != string.Empty)
            {
                path = currentLabel + "/" + path;
                var returnSet = new HashSet <string>();
                foreach (var parent in currentNode.ParentNodes())
                {
                    var paths = GenerateNodePath(objectExplorerSession, parent, databaseName, parentNames, path);
                    foreach (var newPath in paths)
                    {
                        returnSet.Add(newPath);
                    }
                }
                return(returnSet);
            }
            else
            {
                var returnSet = new HashSet <string>();
                if (currentNode.ContainedType() == "Database")
                {
                    path = databaseName + "/" + path;
                }
                else if (parentNames != null && parentNames.Count > 0)
                {
                    var parentName = parentNames.Last();
                    parentNames.RemoveAt(parentNames.Count - 1);
                    path = parentName + "/" + path;
                }
                else
                {
                    return(returnSet);
                }

                foreach (var parentNode in currentNode.ParentNodes())
                {
                    var newPaths = GenerateNodePath(objectExplorerSession, parentNode, databaseName, parentNames, path);
                    foreach (var newPath in newPaths)
                    {
                        returnSet.Add(newPath);
                    }
                }

                return(returnSet);
            }
        }