Example #1
0
        public override void DocumentDatabases(EDocumentDatabasesType databasesType, ISelectionCriterias criterias)
        {
            StringBuilder RetVal = new StringBuilder();

            RetVal.AppendLine(MakeSectionTitle($"Server : {_SqlServer.Name} - Databases list"));



            switch (databasesType)
            {
            case EDocumentDatabasesType.Stats:
                foreach (Database DatabaseItem in _SqlServer.Databases)
                {
                    if ((criterias.SelectUserData && !DatabaseItem.IsSystemObject) || (criterias.SelectSystemData && DatabaseItem.IsSystemObject))
                    {
                        Log(string.Format("accessing database {0}", DatabaseItem.Name));
                        #region stats
                        RetVal.Append($"-- {DatabaseItem.Name.TrimEnd()}".AlignedLeft(40, '.'));
                        RetVal.Append($"{DatabaseItem.Size:#,##0.00 MB}".AlignedRight(20, '.'));
                        RetVal.Append($" {DatabaseItem.SpaceAvailable:#,##0.00 MB free}".AlignedRight(25, '.'));
                        RetVal.Append($" (D={DatabaseItem.DataSpaceUsage:#,##0 KB})".AlignedRight(15, '.'));
                        RetVal.Append($" (I={DatabaseItem.IndexSpaceUsage:#,##0 KB})".AlignedRight(20, '.'));
                        RetVal.Append($" {DatabaseItem.Users.Count} users".AlignedLeft(10, '.'));

                        DatabaseOptions oDBO;
                        try {
                            oDBO = DatabaseItem.DatabaseOptions;
                            RetVal.Append($" | {SqlUtils.RecoveryModelText(oDBO.RecoveryModel)}");
                        } catch {
                            RetVal.Append(" | only for 2000+");
                        }
                        RetVal.AppendLine();
                    }
                }
                break;
                #endregion

            case EDocumentDatabasesType.Physical:
                #region physical

                const string COL_DBNAME                  = "Db name";
                const int    COL_DBNAME_WIDTH            = 30;
                const string COL_LOGICAL_FILENAME        = "Logical name";
                const int    COL_LOGICAL_FILENAME_WIDTH  = 40;
                const string COL_GROUP_NAME              = "Group";
                const int    COL_GROUP_NAME_WIDTH        = 20;
                const string COL_PHYSICAL_FILENAME       = "Physical name";
                const int    COL_PHYSICAL_FILENAME_WIDTH = 120;
                const string COL_CURRENT_SIZE            = "Current size";
                const int    COL_CURRENT_SIZE_WIDTH      = 20;
                const string COL_FREE_SPACE              = "Free space";
                const int    COL_FREE_SPACE_WIDTH        = 20;
                const string COL_GROWTH                  = "Growth parameters";

                #region --- Columns header --------------------------------------------
                RetVal.Append(COL_DBNAME.AlignedCenter(COL_DBNAME_WIDTH));
                RetVal.Append(COL_LOGICAL_FILENAME.AlignedCenter(COL_LOGICAL_FILENAME_WIDTH));
                RetVal.Append(COL_GROUP_NAME.AlignedCenter(COL_GROUP_NAME_WIDTH));
                RetVal.Append(COL_PHYSICAL_FILENAME.AlignedCenter(COL_PHYSICAL_FILENAME_WIDTH));
                RetVal.Append(COL_CURRENT_SIZE.AlignedCenter(COL_CURRENT_SIZE_WIDTH));
                RetVal.Append(COL_FREE_SPACE.AlignedCenter(COL_FREE_SPACE_WIDTH));
                RetVal.Append(COL_GROWTH);
                RetVal.AppendLine();
                #endregion --- Columns header --------------------------------------------

                foreach (Database DatabaseItem in _SqlServer.Databases)
                {
                    if ((criterias.SelectUserData && !DatabaseItem.IsSystemObject) || (criterias.SelectSystemData && DatabaseItem.IsSystemObject))
                    {
                        Log(string.Format("accessing database {0}", DatabaseItem.Name));

                        #region Data files
                        foreach (FileGroup FileGroupItem in DatabaseItem.FileGroups)
                        {
                            foreach (DataFile DataFileItem in FileGroupItem.Files)
                            {
                                RetVal.Append($"{DatabaseItem.Name.AlignedLeft(COL_DBNAME_WIDTH, '.')}");
                                RetVal.Append($"{DataFileItem.Name.AlignedLeft(COL_LOGICAL_FILENAME_WIDTH, '.')}");
                                RetVal.Append($"{FileGroupItem.Name.AlignedLeft(COL_GROUP_NAME_WIDTH, '.')}");
                                RetVal.Append($"{DataFileItem.FileName.AlignedLeft(COL_PHYSICAL_FILENAME_WIDTH, '.')}");
                                RetVal.Append($"{(float)(DataFileItem.Size / 1024.0):#0.00 MB}".AlignedRight(COL_CURRENT_SIZE_WIDTH, '.'));
                                RetVal.Append($"{DataFileItem.VolumeFreeSpace:#0.00 MB}".AlignedRight(COL_FREE_SPACE_WIDTH, '.'));

                                switch (DataFileItem.GrowthType)
                                {
                                case FileGrowthType.KB:
                                    #region Growth MB
                                    if (DataFileItem.Growth > 0)
                                    {
                                        RetVal.Append($" + {(int)(DataFileItem.Growth / 1024):#0 MB}");
                                        if (DataFileItem.MaxSize > 0)
                                        {
                                            RetVal.Append($", upto {DataFileItem.MaxSize:#0 MB}");
                                        }
                                        else
                                        {
                                            RetVal.Append(", no limit");
                                        }
                                    }
                                    else
                                    {
                                        RetVal.Append(" + no growth");
                                    }
                                    break;

                                    #endregion
                                case FileGrowthType.Percent:
                                    #region Growth Percent
                                    if (DataFileItem.Growth > 0)
                                    {
                                        RetVal.Append($" + {DataFileItem.Growth:#0} % ");
                                        if (DataFileItem.MaxSize > 0)
                                        {
                                            RetVal.Append($", upto {DataFileItem.MaxSize:#0 MB}");
                                        }
                                        else
                                        {
                                            RetVal.Append(", no limit");
                                        }
                                    }
                                    else
                                    {
                                        RetVal.Append(" + no growth");
                                    }
                                    break;

                                    #endregion
                                default:
                                    RetVal.Append(" + no growth");
                                    break;
                                }

                                RetVal.AppendLine();
                            }
                        }
                        #endregion

                        #region Log files
                        foreach (LogFile LogFileItem in DatabaseItem.LogFiles)
                        {
                            RetVal.Append($"{DatabaseItem.Name.AlignedLeft(COL_DBNAME_WIDTH, '.')}");
                            RetVal.Append($"{LogFileItem.Name.AlignedLeft(COL_LOGICAL_FILENAME_WIDTH, '.')}");
                            RetVal.Append($"{string.Empty.PadRight(COL_GROUP_NAME_WIDTH, '.')}");
                            RetVal.Append($"{LogFileItem.FileName.AlignedLeft(COL_PHYSICAL_FILENAME_WIDTH, '.')}");
                            RetVal.Append($"{(float)(LogFileItem.Size / 1024.0):#0.00 MB}".AlignedRight(COL_CURRENT_SIZE_WIDTH, '.'));
                            RetVal.Append($"{LogFileItem.VolumeFreeSpace:#0.00 MB}".AlignedRight(COL_FREE_SPACE_WIDTH, '.'));

                            switch (LogFileItem.GrowthType)
                            {
                            case FileGrowthType.KB:
                                #region Growth MB
                                if (LogFileItem.Growth > 0)
                                {
                                    RetVal.Append($" + {(float)(LogFileItem.Growth / 1024):#0 MB}");
                                    if (LogFileItem.MaxSize > 0)
                                    {
                                        RetVal.Append($", upto {LogFileItem.MaxSize:#0 MB}");
                                    }
                                    else
                                    {
                                        RetVal.Append(", no limit");
                                    }
                                }
                                else
                                {
                                    RetVal.Append(" + no growth");
                                }
                                break;

                                #endregion
                            case FileGrowthType.Percent:
                                #region Growth Percent
                                if (LogFileItem.Growth > 0)
                                {
                                    RetVal.Append($" + {LogFileItem.Growth:#0} % ");
                                    if (LogFileItem.MaxSize > 0)
                                    {
                                        RetVal.Append($", upto {LogFileItem.MaxSize:#0 MB}");
                                    }
                                    else
                                    {
                                        RetVal.Append(", no limit");
                                    }
                                }
                                else
                                {
                                    RetVal.Append(" + no growth");
                                }
                                break;

                                #endregion
                            default:
                                RetVal.Append(" + no growth");
                                break;
                            }

                            RetVal.AppendLine();
                        }
                        #endregion
                    }
                }
                break;
                #endregion

            case EDocumentDatabasesType.Full:
            case EDocumentDatabasesType.List:
            default:
                #region list
                foreach (Database DatabaseItem in _SqlServer.Databases)
                {
                    if ((criterias.SelectUserData && !DatabaseItem.IsSystemObject) || (criterias.SelectSystemData && DatabaseItem.IsSystemObject))
                    {
                        Log(string.Format("accessing database {0}", DatabaseItem.Name));
                        RetVal.Append($"-- Database : {DatabaseItem.Name.AlignedLeft(50, '.')}");
                        RetVal.Append($" {SqlUtils.DbStatusText(DatabaseItem.Status)}");
                        RetVal.AppendLine();
                    }
                }
                break;
                #endregion
            }

            Output?.Invoke(RetVal.ToString());
        }
Example #2
0
 public abstract void DocumentDatabases(EDocumentDatabasesType databasesType, ISelectionCriterias criterias);