internal void DiscoverFileGroup(smo::FileGroup smofg, List <Entity> update, List <Entity> delete, List <Entity> create) { InitializeDiscovery(update, delete, create); DiscoverDatabaseDefinitionFileGroup(); if (smofg != null) { LoadFromSmo(smofg); // Query database definition for filegroups // --- add files foreach (var smofile in smofg.Files.Cast <smo::DataFile>()) { var file = Files.Values.FirstOrDefault(i => Entity.StringComparer.Compare(i.LogicalName, smofile.Name) == 0); if (file == null) { file = new DatabaseInstanceFile(this); } file.DiscoverFile(smofile, update, delete, create); } } else { foreach (var file in Files.Values) { file.DiscoverFile(null, update, delete, create); } } DiscoverDeletedFiles(update, delete, create); }
internal void LoadFromSmo(smo::FileGroup smofg) { this.Name = smofg.Name; this.FileGroupName = smofg.Name; this.FileGroupType = FileGroupType.Data; // this.PartitionReference // TODO: how to discover it automatically? this.DeploymentState = Registry.DeploymentState.Deployed; this.RunningState = Registry.RunningState.Running; this.AllocatedSpace = 0; this.UsedSpace = 0; this.ReservedSpace = 0; foreach (var smofile in smofg.Files.Cast <smo::DataFile>()) { this.AllocatedSpace += (long)Math.Ceiling(smofile.Size * 0x400L); // given in KB, bug in docs! this.UsedSpace += (long)Math.Ceiling(smofile.UsedSpace * 0x400L); this.ReservedSpace += smofile.MaxSize == -1 ? 0L : (long)Math.Ceiling(smofile.MaxSize * 0x400L); } }
private FileGroup DiscoverFileGroup(smo::FileGroup smofg, FileGroup fg) { if (fg == null) { fg = new FileGroup(this); } fg.Name = smofg.Name; fg.FileGroupName = smofg.Name; fg.FileGroupType = FileGroupType.Data; fg.AllocationType = FileGroupAllocationType.CrossVolume; fg.LayoutType = FileGroupLayoutType.Monolithic; fg.DiskVolumeType = DiskVolumeType.Data; fg.FileCount = 0; // TODO: check this to be one file/volume fg.DeploymentState = Registry.DeploymentState.Deployed; fg.RunningState = Registry.RunningState.Running; fg.AllocatedSpace = (long)Math.Ceiling(smofg.Size * 0x400L); // given in KB, bug in docs! fg.AllocatedSpace = Math.Max(0x1000000L, fg.AllocatedSpace); // 16 MB minimum return(fg); }
/* *** TODO: delete /// <summary> /// Adds files to a database based on the cluster schema information. /// </summary> /// <param name="databaseInstance">The database instance object.</param> /// <param name="dto">The SMO object pointing to the target database.</param> private void CreateFiles(smo::Database dto) { this.LoadFiles(false); foreach (DatabaseInstanceFile f in this.Files.Values) { f.DeploymentState = DeploymentState.Deploying; f.Save(); string localFilename = f.GetFullLocalFilename(); string networkFilename = f.GetFullUncFilename(); // Check directory string dir = Path.GetDirectoryName(networkFilename); if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); // Create new file logfile if (f.DatabaseFileType == DatabaseFileType.Log) { smo::LogFile lf = new smo::LogFile(dto, f.Filename); lf.FileName = localFilename; lf.Growth = 0; lf.GrowthType = smo::FileGrowthType.None; //nf.MaxSize = (double)fi.AllocatedSpace / 0x400; // in kilobytes lf.Size = (double)f.AllocatedSpace / 0x400; // in kilobytes dto.LogFiles.Add(lf); } f.DeploymentState = DeploymentState.Deployed; f.Save(); } }*/ /// <summary> /// Adds file group to a database based on the cluster schema information. /// </summary> /// <param name="databaseInstance">The database instance object.</param> /// <param name="dto">The SMO object pointing to the target database.</param> private void CreateFileGroups(smo::Database dto) { // Add FileGroups this.LoadFileGroups(false); foreach (DatabaseInstanceFileGroup fg in this.FileGroups.Values) { fg.DeploymentState = DeploymentState.Deploying; fg.Save(); if (fg.FileGroupType == FileGroupType.Log) { fg.LoadFiles(false); foreach (DatabaseInstanceFile fi in fg.Files.Values) { fi.DeploymentState = DeploymentState.Deploying; fi.Save(); string localFilename = fi.GetFullLocalFilename(); string networkFilename = fi.GetFullUncFilename(); // Check directory string dir = Path.GetDirectoryName(networkFilename); if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); // Create new File smo::LogFile lf = new smo::LogFile(dto, fi.LogicalName); lf.FileName = localFilename; lf.Growth = 0; lf.GrowthType = smo::FileGrowthType.None; //nf.MaxSize = (double)fi.AllocatedSpace / 0x400; // in kilobytes lf.Size = (double)fi.AllocatedSpace / 0x400; // in kilobytes dto.LogFiles.Add(lf); fi.DeploymentState = DeploymentState.Deployed; fi.Save(); } } else if (fg.FileGroupType == FileGroupType.Data) { // Create new File Group smo::FileGroup nfg = new smo::FileGroup(dto, fg.FileGroupName); // Add files to the File Group fg.LoadFiles(false); foreach (DatabaseInstanceFile fi in fg.Files.Values) { fi.DeploymentState = DeploymentState.Deploying; fi.Save(); string localFilename = fi.GetFullLocalFilename(); string networkFilename = fi.GetFullUncFilename(); // Check directory string dir = Path.GetDirectoryName(networkFilename); if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); // Create new File smo::DataFile nf = new smo::DataFile(nfg, fi.LogicalName); nf.FileName = localFilename; nf.Growth = 0; nf.GrowthType = smo::FileGrowthType.None; //nf.MaxSize = (double)fi.AllocatedSpace / 0x400; // in kilobytes nf.Size = (double)fi.AllocatedSpace / 0x400; // in kilobytes nfg.Files.Add(nf); fi.DeploymentState = DeploymentState.Deployed; fi.Save(); } // Add new File Group to the Database dto.FileGroups.Add(nfg); } else { throw new NotImplementedException(); } fg.DeploymentState = DeploymentState.Deployed; fg.Save(); } this.Context.LogEvent(new Event("Jhu.Graywulf.Registry.DatabaseInstance.CreateFileGroups", this.Guid)); }