コード例 #1
0
        /// <summary>
        /// Initializes a database definition.
        /// </summary>
        /// <param name="serverVersion"></param>
        public void GenerateDefaultChildren(ServerVersion serverVersion, string databaseVersionName)
        {
            // If not sliced, then create a default slice of FULL
            if (databaseDefinition.LayoutType == DatabaseLayoutType.Mirrored ||
                databaseDefinition.LayoutType == DatabaseLayoutType.Monolithic)
            {
                Slice sl = new Slice(databaseDefinition)
                {
                    Name   = Constants.FullSliceName,
                    System = databaseDefinition.System,
                };
                sl.Save();
            }
            else
            {
                throw new InvalidOperationException();
                // Use slicing wizard instead
            }

            // Add primary filegroup
            FileGroupLayoutType fglayout;

            switch (databaseDefinition.LayoutType)
            {
            case DatabaseLayoutType.Sliced:
                fglayout = FileGroupLayoutType.Sliced;
                break;

            case DatabaseLayoutType.Monolithic:
            case DatabaseLayoutType.Mirrored:
                fglayout = FileGroupLayoutType.Monolithic;
                break;

            default:
                throw new NotImplementedException();
            }

            FileGroup fg = new FileGroup(databaseDefinition)
            {
                Name           = Constants.PrimaryFileGroupName,
                System         = databaseDefinition.System,
                FileGroupType  = FileGroupType.Data,
                LayoutType     = fglayout,
                AllocationType = FileGroupAllocationType.CrossVolume,
                DiskVolumeType = DiskVolumeType.Data,
                FileGroupName  = Constants.PrimaryFileGroupName,
                AllocatedSpace = Constants.PrimaryFileGroupSize,
                FileCount      = 0,
            };

            fg.Save();

            // Add "log" file group
            fg = new FileGroup(databaseDefinition)
            {
                Name           = Constants.LogFileGroupName,
                System         = databaseDefinition.System,
                FileGroupType  = FileGroupType.Log,
                LayoutType     = FileGroupLayoutType.Monolithic,
                AllocationType = FileGroupAllocationType.CrossVolume,
                DiskVolumeType = DiskVolumeType.Log,
                FileGroupName  = Constants.LogFileGroupName,
                AllocatedSpace = Constants.LogFileGroupSize,
                FileCount      = 0
            };
            fg.Save();

            // Create default database version
            DatabaseVersion dv = new DatabaseVersion(databaseDefinition)
            {
                Name           = databaseVersionName,
                System         = databaseDefinition.System,
                ServerVersion  = serverVersion,
                SizeMultiplier = 1.0f,
            };

            dv.Save();
        }