Exemplo n.º 1
0
 /// <summary>
 /// Creates a deep copy of the passed object.
 /// </summary>
 /// <param name="old">A <b>Database Instance File Group</b> object to create the deep copy from.</param>
 private void CopyMembers(DatabaseInstanceFileGroup old)
 {
     this.fileGroupName  = old.fileGroupName;
     this.fileGroupType  = old.fileGroupType;
     this.allocatedSpace = old.allocatedSpace;
     this.usedSpace      = old.usedSpace;
     this.reservedSpace  = old.reservedSpace;
 }
        private void Discover(smo::Database smodb, List <Entity> update, List <Entity> delete, List <Entity> create)
        {
            InitializeDiscovery(update, delete, create);

            if (smodb != null)
            {
                LoadFromSmo(smodb);

                // Process file groups
                // --- add standard file groups
                foreach (var smofg in smodb.FileGroups.Cast <smo::FileGroup>())
                {
                    var fg = FileGroups.Values.FirstOrDefault(i => Entity.StringComparer.Compare(i.FileGroupName, smofg.Name) == 0);
                    if (fg == null)
                    {
                        fg = new DatabaseInstanceFileGroup(this);
                    }

                    fg.DiscoverFileGroup(smofg, update, delete, create);
                }

                // --- add dummy file group for logs
                {
                    var fg = FileGroups.Values.FirstOrDefault(i => i.FileGroupType == FileGroupType.Log);
                    if (fg == null)
                    {
                        fg = new DatabaseInstanceFileGroup(this);
                    }

                    fg.DiscoverLogFileGroup(smodb, update, delete, create);
                }

                DiscoverDeletedFileGroups(update, delete, create);
            }
            else
            {
                foreach (var fg in FileGroups.Values)
                {
                    fg.DiscoverFileGroup(null, update, delete, create);
                }
            }
        }
        private void Discover(smo::Database smodb, List<Entity> update, List<Entity> delete, List<Entity> create)
        {
            InitializeDiscovery(update, delete, create);

            if (smodb != null)
            {
                LoadFromSmo(smodb);

                // Process file groups
                // --- add standard file groups
                foreach (var smofg in smodb.FileGroups.Cast<smo::FileGroup>())
                {
                    var fg = FileGroups.Values.FirstOrDefault(i => Entity.StringComparer.Compare(i.FileGroupName, smofg.Name) == 0);
                    if (fg == null)
                    {
                        fg = new DatabaseInstanceFileGroup(this);
                    }

                    fg.DiscoverFileGroup(smofg, update, delete, create);
                }

                // --- add dummy file group for logs
                {
                    var fg = FileGroups.Values.FirstOrDefault(i => i.FileGroupType == FileGroupType.Log);
                    if (fg == null)
                    {
                        fg = new DatabaseInstanceFileGroup(this);
                    }

                    fg.DiscoverLogFileGroup(smodb, update, delete, create);
                }

                DiscoverDeletedFileGroups(update, delete, create);
            }
            else
            {
                foreach (var fg in FileGroups.Values)
                {
                    fg.DiscoverFileGroup(null, update, delete, create);
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Constructor for creating a new entity with object context and parent entity set.
 /// </summary>
 /// <param name="context">An object context class containing session information.</param>
 /// <param name="parent">The parent entity in the entity hierarchy.</param>
 public DatabaseInstanceFile(DatabaseInstanceFileGroup parent)
     : base(parent.Context, parent)
 {
     InitializeMembers();
 }
        public DatabaseInstance GenerateDatabaseInstance(ServerInstance serverInstance, List<DiskVolume> dataDiskVolumes, List<DiskVolume> logDiskVolumes, Slice slice, DatabaseVersion databaseVersion, string namePattern, string databaseNamePattern, double sizeFactor, bool generateFileGroups)
        {
            // --- Create the new database instance and set name
            DatabaseInstance ndi = new DatabaseInstance(databaseDefinition);

            ndi.ServerInstanceReference.Guid = serverInstance.Guid;
            ndi.SliceReference.Guid = slice.Guid;
            ndi.DatabaseVersionReference.Guid = databaseVersion.Guid;

            ndi.Name = ExpressionProperty.ResolveExpression(ndi, namePattern);
            ndi.DatabaseName = ExpressionProperty.ResolveExpression(ndi, databaseNamePattern);

            ndi.Save();

            if (generateFileGroups)
            {
                ndi.ServerInstance.Machine.LoadDiskVolumes(false);

                databaseDefinition.LoadFileGroups(false);

                slice.LoadPartitions(false);
                List<Partition> partitions = new List<Partition>(slice.Partitions.Values.OrderBy(i => i.Number));
                List<FileGroup> filegroups = new List<FileGroup>(databaseDefinition.FileGroups.Values.OrderBy(i => i.Number));

                for (int fi = 0; fi < filegroups.Count; fi++)
                {
                    // --- Create data and "log" file groups ---
                    if (filegroups[fi].LayoutType == FileGroupLayoutType.Monolithic ||
                        filegroups[fi].FileGroupType == FileGroupType.Log)
                    {
                        DatabaseInstanceFileGroup nfg = new DatabaseInstanceFileGroup(ndi);
                        nfg.FileGroupType = filegroups[fi].FileGroupType;
                        nfg.FileGroupName = nfg.Name = filegroups[fi].FileGroupName;
                        nfg.FileGroupReference.Guid = filegroups[fi].Guid;
                        nfg.PartitionReference.Guid = Guid.Empty;
                        nfg.AllocatedSpace = (long)(filegroups[fi].AllocatedSpace * sizeFactor);
                        nfg.Save();

                        nfg.GenerateInstanceFiles(dataDiskVolumes, sizeFactor);
                    }
                    else if (filegroups[fi].LayoutType == FileGroupLayoutType.Sliced)
                    {
                        for (int pi = 0; pi < partitions.Count; pi++)
                        {
                            DatabaseInstanceFileGroup nfg = new DatabaseInstanceFileGroup(ndi);
                            nfg.FileGroupType = filegroups[fi].FileGroupType;
                            nfg.FileGroupName = nfg.Name = string.Format("{0}_{1}", filegroups[fi].FileGroupName, pi);
                            nfg.FileGroupReference.Guid = filegroups[fi].Guid;
                            nfg.PartitionReference.Guid = partitions[pi].Guid;
                            nfg.AllocatedSpace = (long)(filegroups[fi].AllocatedSpace * sizeFactor);
                            nfg.Save();

                            nfg.GenerateInstanceFiles(dataDiskVolumes, sizeFactor);
                        }
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
            }

            return ndi;
        }
 internal smo::LogFile GetSmoLogFile()
 {
     return(DatabaseInstanceFileGroup.GetSmoDatabase().LogFiles[Name]);
 }
 internal smo::DataFile GetSmoFile()
 {
     return(DatabaseInstanceFileGroup.GetSmoFileGroup().Files[Name]);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Copy contructor for doing deep copy of the <b>Database Instance File Group</b> objects.
 /// </summary>
 /// <param name="old">The <b>Database Instance File Group</b> to copy from.</param>
 public DatabaseInstanceFileGroup(DatabaseInstanceFileGroup old)
     : base(old)
 {
     CopyMembers(old);
 }
 /// <summary>
 /// Copy contructor for doing deep copy of the <b>Database Instance File Group</b> objects.
 /// </summary>
 /// <param name="old">The <b>Database Instance File Group</b> to copy from.</param>
 public DatabaseInstanceFileGroup(DatabaseInstanceFileGroup old)
     : base(old)
 {
     CopyMembers(old);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Creates a deep copy of the passed object.
 /// </summary>
 /// <param name="old">A <b>Database Instance File Group</b> object to create the deep copy from.</param>
 private void CopyMembers(DatabaseInstanceFileGroup old)
 {
     this.fileGroupName = old.fileGroupName;
     this.fileGroupType = old.fileGroupType;
     this.allocatedSpace = old.allocatedSpace;
     this.usedSpace = old.usedSpace;
     this.reservedSpace = old.reservedSpace;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Constructor for creating a new entity with object context and parent entity set.
 /// </summary>
 /// <param name="context">An object context class containing session information.</param>
 /// <param name="parent">The parent entity in the entity hierarchy.</param>
 public DatabaseInstanceFile(DatabaseInstanceFileGroup parent)
     : base(parent.Context, parent)
 {
     InitializeMembers();
 }