예제 #1
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);
        }
예제 #2
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();
            }
        }