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);
        }
예제 #2
0
 /// <summary>
 /// Creates a deep copy of the passed object.
 /// </summary>
 /// <param name="old">A <b>Database Instance File</b> object to create the deep copy from.</param>
 private void CopyMembers(DatabaseInstanceFile old)
 {
     this.databaseFileType = old.databaseFileType;
     this.logicalName      = old.logicalName;
     this.filename         = old.filename;
     this.allocatedSpace   = old.allocatedSpace;
     this.usedSpace        = old.usedSpace;
     this.reservedSpace    = old.reservedSpace;
 }
        internal void DiscoverLogFileGroup(smo::Database smodb, List <Entity> update, List <Entity> delete, List <Entity> create)
        {
            InitializeDiscovery(update, delete, create);

            LoadFromSmo(smodb);

            DiscoverDatabaseDefinitionFileGroup();

            foreach (var smofile in smodb.LogFiles.Cast <smo::LogFile>())
            {
                var file = Files.Values.FirstOrDefault(i => Entity.StringComparer.Compare(i.LogicalName, smofile.Name) == 0);
                if (file == null)
                {
                    file = new DatabaseInstanceFile(this);
                }

                file.DiscoverLogFile(smofile, update, delete, create);
            }

            DiscoverDeletedFiles(update, delete, create);
        }
        internal void DiscoverLogFileGroup(smo::Database smodb, List<Entity> update, List<Entity> delete, List<Entity> create)
        {
            InitializeDiscovery(update, delete, create);

            LoadFromSmo(smodb);

            DiscoverDatabaseDefinitionFileGroup();

            foreach (var smofile in smodb.LogFiles.Cast<smo::LogFile>())
            {
                var file = Files.Values.FirstOrDefault(i => Entity.StringComparer.Compare(i.LogicalName, smofile.Name) == 0);
                if (file == null)
                {
                    file = new DatabaseInstanceFile(this);
                }

                file.DiscoverLogFile(smofile, update, delete, create);
            }

            DiscoverDeletedFiles(update, delete, create);
        }
예제 #5
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext activityContext, AsyncCallback callback, object state)
        {
            Guid sourcefileguid = SourceFileGuid.Get(activityContext);
            Guid destinationdatabaseinstanceguid = DestinationDatabaseInstanceGuid.Get(activityContext);
            FileCopyDirection filecopydirection = FileCopyDirection.Get(activityContext);

            string sourcefilename, destinationfilename;
            string hostname;

            // Load files
            using (Context context = ContextManager.Instance.CreateContext(this, activityContext, ConnectionMode.AutoOpen, TransactionMode.AutoCommit))
            {
                // Load destination database instance
                DatabaseInstance di = new DatabaseInstance(context);
                di.Guid = destinationdatabaseinstanceguid;
                di.Load();
                di.LoadFileGroups(false);

                EntityGuid.Set(activityContext, di.Guid);

                // Load database instance from the schema database
                DatabaseInstanceFile df;

                DatabaseInstanceFile sf = new DatabaseInstanceFile(context);
                sf.Guid = sourcefileguid;
                sf.Load();

                EntityGuidFrom.Set(activityContext, sourcefileguid);

                sourcefilename = sf.GetFullUncFilename();

                DatabaseInstanceFileGroup fg = di.FileGroups[sf.DatabaseInstanceFileGroup.Name];
                fg.LoadFiles(false);
                df = fg.Files[sf.Name];

                EntityGuidTo.Set(activityContext, df.Guid);

                destinationfilename = df.GetFullUncFilename();

                DatabaseInstanceFile ssf = filecopydirection == Jhu.Graywulf.Registry.FileCopyDirection.Push ? sf : df;
                hostname = ssf.DatabaseInstanceFileGroup.DatabaseInstance.ServerInstance.Machine.HostName.ResolvedValue;
            }

            Guid workflowInstanceGuid = activityContext.WorkflowInstanceId;
            string activityInstanceId = activityContext.ActivityInstanceId;
            return EnqueueAsync(_ => OnAsyncExecute(workflowInstanceGuid, activityInstanceId, hostname, sourcefilename, destinationfilename), callback, state);
        }
예제 #6
0
 /// <summary>
 /// Copy contructor for doing deep copy of the <b>Database Instance File</b> objects.
 /// </summary>
 /// <param name="old">The <b>Database Instance File</b> to copy from.</param>
 public DatabaseInstanceFile(DatabaseInstanceFile old)
     : base(old)
 {
     CopyMembers(old);
 }
예제 #7
0
        public void GenerateInstanceFiles(List <DiskVolume> dataDiskVolumes, double sizeFactor)
        {
            Dictionary <string, DatabaseInstanceFile> files = new Dictionary <string, DatabaseInstanceFile>();

            List <DiskVolume> diskVolumes = new List <DiskVolume>();

            if (dataDiskVolumes == null)
            {
                this.DatabaseInstance.ServerInstance.Machine.LoadDiskVolumes(false);
                diskVolumes.AddRange(this.DatabaseInstance.ServerInstance.Machine.DiskVolumes.Values.Where <DiskVolume>(d => (d.DiskVolumeType & FileGroup.DiskVolumeType) > 0).OrderBy(i => i.Number));
            }
            else
            {
                diskVolumes.AddRange(dataDiskVolumes);
            }

            int  q = 0;
            bool primary;
            int  filecount = FileGroup.FileCount != 0 ? FileGroup.FileCount : diskVolumes.Count;

            for (int i = 0; i < filecount; i++)
            {
                DatabaseInstanceFile nf = new DatabaseInstanceFile(this);
                nf.DiskVolumeReference.Guid = diskVolumes[q % diskVolumes.Count].Guid;
                switch (fileGroupType)
                {
                case FileGroupType.Data:
                    nf.DatabaseFileType = DatabaseFileType.Data;
                    break;

                case FileGroupType.Log:
                    nf.DatabaseFileType = DatabaseFileType.Log;
                    break;

                default:
                    throw new NotImplementedException();
                }
                nf.LogicalName = string.Format("{0}_{1}", FileGroupName, i);
                nf.Name        = nf.LogicalName;
                if (fileGroupType == FileGroupType.Log)
                {
                    primary     = false;
                    nf.Filename = nf.LogicalName + ".ldf";
                }
                else if (i == 0 && StringComparer.InvariantCultureIgnoreCase.Compare(FileGroup.FileGroupName, "primary") == 0)
                {
                    primary     = true;
                    nf.Filename = nf.LogicalName + ".mdf";
                }
                else
                {
                    primary     = false;
                    nf.Filename = nf.LogicalName + ".ndf";
                }

                q++;

                // Set minimum file sizes
                nf.AllocatedSpace = Math.Max((long)(FileGroup.AllocatedSpace / filecount * sizeFactor), 0x80000);
                if (primary)
                {
                    nf.AllocatedSpace = Math.Max(nf.AllocatedSpace, 0x300000);
                }
                nf.Save();

                files.Add(nf.Name, nf);
            }

            this.Files = files;
        }
        public void GenerateInstanceFiles(List<DiskVolume> dataDiskVolumes, double sizeFactor)
        {
            Dictionary<string, DatabaseInstanceFile> files = new Dictionary<string, DatabaseInstanceFile>();

            List<DiskVolume> diskVolumes = new List<DiskVolume>();
            if (dataDiskVolumes == null)
            {
                this.DatabaseInstance.ServerInstance.Machine.LoadDiskVolumes(false);
                diskVolumes.AddRange(this.DatabaseInstance.ServerInstance.Machine.DiskVolumes.Values.Where<DiskVolume>(d => (d.DiskVolumeType & FileGroup.DiskVolumeType) > 0).OrderBy(i => i.Number));
            }
            else
            {
                diskVolumes.AddRange(dataDiskVolumes);
            }

            int q = 0;
            bool primary;
            int filecount = FileGroup.FileCount != 0 ? FileGroup.FileCount : diskVolumes.Count;

            for (int i = 0; i < filecount; i++)
            {
                DatabaseInstanceFile nf = new DatabaseInstanceFile(this);
                nf.DiskVolumeReference.Guid = diskVolumes[q % diskVolumes.Count].Guid;
                switch (fileGroupType)
                {
                    case FileGroupType.Data:
                        nf.DatabaseFileType = DatabaseFileType.Data;
                        break;
                    case FileGroupType.Log:
                        nf.DatabaseFileType = DatabaseFileType.Log;
                        break;
                    default:
                        throw new NotImplementedException();
                }
                nf.LogicalName = string.Format("{0}_{1}", FileGroupName, i);
                nf.Name = nf.LogicalName;
                if (fileGroupType == FileGroupType.Log)
                {
                    primary = false;
                    nf.Filename = nf.LogicalName + ".ldf";
                }
                else if (i == 0 && StringComparer.InvariantCultureIgnoreCase.Compare(FileGroup.FileGroupName, "primary") == 0)
                {
                    primary = true;
                    nf.Filename = nf.LogicalName + ".mdf";
                }
                else
                {
                    primary = false;
                    nf.Filename = nf.LogicalName + ".ndf";
                }

                q++;

                // Set minimum file sizes
                nf.AllocatedSpace = Math.Max((long)(FileGroup.AllocatedSpace / filecount * sizeFactor), 0x80000);
                if (primary)
                {
                    nf.AllocatedSpace = Math.Max(nf.AllocatedSpace, 0x300000);
                }
                nf.Save();

                files.Add(nf.Name, nf);
            }

            this.Files = files;
        }
예제 #9
0
 /// <summary>
 /// Copy contructor for doing deep copy of the <b>Database Instance File</b> objects.
 /// </summary>
 /// <param name="old">The <b>Database Instance File</b> to copy from.</param>
 public DatabaseInstanceFile(DatabaseInstanceFile old)
     : base(old)
 {
     CopyMembers(old);
 }
예제 #10
0
 /// <summary>
 /// Creates a deep copy of the passed object.
 /// </summary>
 /// <param name="old">A <b>Database Instance File</b> object to create the deep copy from.</param>
 private void CopyMembers(DatabaseInstanceFile old)
 {
     this.databaseFileType = old.databaseFileType;
     this.logicalName = old.logicalName;
     this.filename = old.filename;
     this.allocatedSpace = old.allocatedSpace;
     this.usedSpace = old.usedSpace;
     this.reservedSpace = old.reservedSpace;
 }