internal void DiscoverFile(smo::DataFile smofile, List <Entity> update, List <Entity> delete, List <Entity> create) { InitializeDiscovery(update, delete, create); if (smofile != null) { LoadFromSmo(smofile); } DiscoverDiskVolume(); }
internal void LoadFromSmo(smo::DataFile smofile) { this.Name = smofile.Name; this.LogicalName = smofile.Name; this.Filename = smofile.FileName; this.DatabaseFileType = DatabaseFileType.Data; this.DeploymentState = Registry.DeploymentState.Deployed; this.RunningState = Registry.RunningState.Running; this.AllocatedSpace = (long)Math.Ceiling(smofile.Size * 0x400L); // given in KB, bug in docs! this.UsedSpace = (long)(smofile.UsedSpace * 0x400L); this.ReservedSpace = smofile.MaxSize == -1 ? 0L : (long)(smofile.MaxSize * 0x400L); }
/* *** 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)); }