Example #1
0
        public TreeNode FindNodeByPath(string path, bool expandIfNeeded = false)
        {
            TreeNode nodeForPath = ObjectExplorerUtils.FindNode(this, node =>
            {
                return(node.GetNodePath() == path);
            }, nodeToFilter =>
            {
                return(path.StartsWith(nodeToFilter.GetNodePath()));
            }, expandIfNeeded);

            return(nodeForPath);
        }
Example #2
0
        public TreeNode FindNodeByPath(string path)
        {
            TreeNode nodeForPath = ObjectExplorerUtils.FindNode(this, node =>
            {
                return(node.GetNodePath() == path);
            }, nodeToFilter =>
            {
                return(path.StartsWith(nodeToFilter.GetNodePath()));
            });

            return(nodeForPath);
        }
Example #3
0
        public void FindNodeCanExpandParentNodes()
        {
            var mockTreeNode = new Mock <TreeNode>();

            object[] populateChildrenArguments = { ItExpr.Is <bool>(x => x == false), ItExpr.IsNull <string>() };
            mockTreeNode.Protected().Setup("PopulateChildren", populateChildrenArguments);
            mockTreeNode.Object.IsAlwaysLeaf = false;

            // If I try to find a child node of the mock tree node with the expand parameter set to true
            ObjectExplorerUtils.FindNode(mockTreeNode.Object, node => false, node => false, true);

            // Then PopulateChildren gets called to expand the tree node
            mockTreeNode.Protected().Verify("PopulateChildren", Times.Once(), populateChildrenArguments);
        }
Example #4
0
        /// <summary>
        /// Returns the label to display to the user.
        /// </summary>
        internal string GetConnectionLabel()
        {
            string userName = connectionSummary.UserName;

            // TODO Domain and username is not yet supported on .Net Core.
            // Consider passing as an input from the extension where this can be queried
            //if (string.IsNullOrWhiteSpace(userName))
            //{
            //    userName = Environment.UserDomainName + @"\" + Environment.UserName;
            //}

            // TODO Consider adding IsAuthenticatingDatabaseMaster check in the code and
            // referencing result here
            if (!ObjectExplorerUtils.IsSystemDatabaseConnection(connectionSummary.DatabaseName))
            {
                // We either have an azure with a database specified or a Denali database using a contained user
                if (string.IsNullOrWhiteSpace(userName))
                {
                    userName = connectionSummary.DatabaseName;
                }
                else
                {
                    userName += ", " + connectionSummary.DatabaseName;
                }
            }

            string label;

            if (string.IsNullOrWhiteSpace(userName))
            {
                label = string.Format(
                    CultureInfo.InvariantCulture,
                    "{0} ({1} {2})",
                    connectionSummary.ServerName,
                    "SQL Server",
                    serverInfo.ServerVersion);
            }
            else
            {
                label = string.Format(
                    CultureInfo.InvariantCulture,
                    "{0} ({1} {2} - {3})",
                    connectionSummary.ServerName,
                    "SQL Server",
                    serverInfo.ServerVersion,
                    userName);
            }

            return(label);
        }
Example #5
0
        private void GenerateNodePath()
        {
            string path = "";

            ObjectExplorerUtils.VisitChildAndParents(this, node =>
            {
                if (string.IsNullOrEmpty(node.NodeValue))
                {
                    // Hit a node with no NodeValue. This indicates we need to stop traversing
                    return(false);
                }
                // Otherwise add this value to the beginning of the path and keep iterating up
                path = string.Format(CultureInfo.InvariantCulture,
                                     "{0}{1}{2}", node.NodePathName, string.IsNullOrEmpty(path) ? "" : PathPartSeperator.ToString(), path);
                return(true);
            });
            nodePath = path;
        }
Example #6
0
        protected virtual void PopulateChildren(bool refresh, string name = null)
        {
            Logger.Write(LogLevel.Verbose, string.Format(CultureInfo.InvariantCulture, "Populating oe node :{0}", this.GetNodePath()));
            Debug.Assert(IsAlwaysLeaf == false);

            SmoQueryContext context = this.GetContextAs <SmoQueryContext>();
            bool            includeSystemObjects = context != null && context.Database != null?ObjectExplorerUtils.IsSystemDatabaseConnection(context.Database.Name) : true;


            if (children.IsPopulating || context == null)
            {
                return;
            }

            children.Clear();
            BeginChildrenInit();

            try
            {
                IEnumerable <ChildFactory> childFactories = context.GetObjectExplorerService().GetApplicableChildFactories(this);
                if (childFactories != null)
                {
                    foreach (var factory in childFactories)
                    {
                        try
                        {
                            IEnumerable <TreeNode> items = factory.Expand(this, refresh, name, includeSystemObjects);
                            if (items != null)
                            {
                                foreach (TreeNode item in items)
                                {
                                    children.Add(item);
                                    item.Parent = this;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            string error = string.Format(CultureInfo.InvariantCulture, "Failed populating oe children. error:{0} inner:{1} stacktrace:{2}",
                                                         ex.Message, ex.InnerException != null ? ex.InnerException.Message : "", ex.StackTrace);
                            Logger.Write(LogLevel.Error, error);
                            ErrorMessage = ex.Message;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string error = string.Format(CultureInfo.InvariantCulture, "Failed populating oe children. error:{0} inner:{1} stacktrace:{2}",
                                             ex.Message, ex.InnerException != null ? ex.InnerException.Message : "", ex.StackTrace);
                Logger.Write(LogLevel.Error, error);
                ErrorMessage = ex.Message;
            }
            finally
            {
                EndChildrenInit();
            }
        }