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();
        }
Ejemplo n.º 2
0
        internal void LoadFromSmo(smo::LogFile smolf)
        {
            this.Name = smolf.Name;
            this.LogicalName = smolf.Name;
            this.Filename = smolf.FileName;
            this.DatabaseFileType = DatabaseFileType.Log;

            this.DeploymentState = Registry.DeploymentState.Deployed;
            this.RunningState = Registry.RunningState.Running;

            this.AllocatedSpace = (long)Math.Ceiling(smolf.Size * 0x400L);     // given in KB, bug in docs!
            this.UsedSpace = (long)(smolf.UsedSpace * 0x400L);
            this.ReservedSpace = smolf.MaxSize == -1 ? 0L : (long)(smolf.MaxSize * 0x400L);
        }
Ejemplo n.º 3
0
        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);
                }
            }
        }
        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);
            }
        }
        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 LoadFromSmo(smo::Database smodb)
        {
            this.Name = "LOG";
            this.FileGroupName = "LOG";
            this.FileGroupType = FileGroupType.Log;
            this.PartitionReference.Guid = Guid.Empty;

            this.DeploymentState = Registry.DeploymentState.Deployed;
            this.RunningState = Registry.RunningState.Running;

            // Calculate log size
            this.AllocatedSpace = 0;
            this.UsedSpace = 0;
            this.ReservedSpace = 0;
            foreach (var smolf in smodb.LogFiles.Cast<smo::LogFile>())
            {
                this.AllocatedSpace += (long)Math.Ceiling(smolf.Size * 0x400L);    // given in KB, bug in docs!
                this.UsedSpace += (long)Math.Ceiling(smolf.UsedSpace * 0x400L);
                this.ReservedSpace += smolf.MaxSize == -1 ? 0L : (long)Math.Ceiling(smolf.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;
        }
Ejemplo n.º 8
0
 public void LoadFromSmo(smo::Database smodb)
 {
     this.DatabaseName = smodb.Name;
 }
Ejemplo n.º 9
0
        /* *** 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));
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Drops file groups from the database
 /// </summary>
 /// <param name="dto">The SMO database object.</param>
 private static void DropFileGroups(smo::Database dto)
 {
     while (dto.FileGroups.Count > 0)
     {
         dto.FileGroups[0].Drop();
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Drops log files from the database.
 /// </summary>
 /// <param name="dto">The SMO database object.</param>
 private static void DropLogFiles(smo::Database dto)
 {
     while (dto.LogFiles.Count > 0)
     {
         dto.LogFiles[0].Drop();
     }
 }
 internal void DiscoverLogFile(smo::LogFile smofile, List<Entity> update, List<Entity> delete, List<Entity> create)
 {
     InitializeDiscovery(update, delete, create);
     LoadFromSmo(smofile);
     DiscoverDiskVolume();
 }
Ejemplo n.º 13
0
 internal connection set_connection(SMO.RegSvrEnum.UIConnectionInfo connection)
 {
     _connection = connection;
     return this;
 }
        private FileGroup DiscoverLogFileGroup(smo::Database smodb, FileGroup fg)
        {
            if (fg == null)
            {
                fg = new FileGroup(this);
            }

            fg.Name = "LOG";
            fg.FileGroupName = "LOG";
            fg.FileGroupType = FileGroupType.Log;
            fg.AllocationType = FileGroupAllocationType.CrossVolume;
            fg.LayoutType = FileGroupLayoutType.Monolithic;
            fg.DiskVolumeType = DiskVolumeType.Log;
            fg.FileCount = 0;   // TODO: check this to be one file/volume

            fg.DeploymentState = Registry.DeploymentState.Deployed;
            fg.RunningState = Registry.RunningState.Running;

            // Calculate log size
            fg.AllocatedSpace = 0;
            foreach (var smolf in smodb.LogFiles.Cast<smo::LogFile>())
            {
                fg.AllocatedSpace += (long)Math.Ceiling(smolf.Size * 0x400L);    // given in KB, bug in docs!
            }
            fg.AllocatedSpace = Math.Max(0x1000000L, fg.AllocatedSpace);            // 16 MB minimum

            return fg;
        }
Ejemplo n.º 15
0
        public CodeTypeDeclaration BuildDomainObject(String DataLayerNamespace,String DataBaseName, TSQL.TableViewTableTypeBase table)
        {
            String FullEntityDAL = DataLayerNamespace + "." + DataBaseName + "." + table.Name + "DAL";
            String FullEntityTypeName = DataLayerNamespace + "." +  DataBaseName + "." + table.Name;

            String TypeName = table.Name + "DomainObject";
            String DalTypeName = FullEntityDAL;

            CodeTypeDeclaration ctdService = FrameFactory.GetPartialClassFrame(TypeName);
            CodeTypeReference IEnumEntity = new CodeTypeReference("IEnumerable<" + FullEntityTypeName + ">");
            CodeTypeReference IEntity = new CodeTypeReference((FullEntityTypeName));
            CodeTypeReference IIntReturn = new CodeTypeReference("System.Int32");
            CodeTypeReference IEntityOrder = new CodeTypeReference("Func<" + FullEntityTypeName + ",Object>");
            CodeTypeReference IEntityRule = new CodeTypeReference("Func<" + FullEntityTypeName + ",Int32>");
            CodeParameterDeclarationExpression cpEntityQuery = new CodeParameterDeclarationExpression(IEntity, "Query");
            CodeParameterDeclarationExpression cpEntityRule = new CodeParameterDeclarationExpression(IEntityRule, "BusinessRule");
            CodeParameterDeclarationExpression cpEntityOrderBy = new CodeParameterDeclarationExpression(IEntityOrder, "Orderby");
            CodeParameterDeclarationExpression cpSkip = new CodeParameterDeclarationExpression(new CodeTypeReference("Int32"), "Skip");
            CodeParameterDeclarationExpression cpTake = new CodeParameterDeclarationExpression(new CodeTypeReference("Int32"), "Take");

            CodeTypeReference ctrDal = new CodeTypeReference(DalTypeName);
            CodeVariableDeclarationStatement varDal = new CodeVariableDeclarationStatement(ctrDal, "dal", new CodeSnippetExpression(" new " + DalTypeName + "()"));

            #region [ Search Methods ]
            CodeMemberMethod mSearchBasic = this.CreateServiceMethodBase("Search");
            mSearchBasic.Parameters.AddRange(new CodeParameterDeclarationExpression[] { cpEntityQuery });
            mSearchBasic.Statements.Add(varDal);
            mSearchBasic.Statements.Add(new CodeSnippetExpression("return dal.SelectObjects(Query)"));
            mSearchBasic.ReturnType = IEnumEntity;
            ctdService.Members.Add(mSearchBasic);

            CodeMemberMethod mSearch = this.CreateServiceMethodBase("Search");
            mSearch.Parameters.AddRange(new CodeParameterDeclarationExpression[] { cpEntityQuery, cpSkip, cpTake });
            mSearch.Statements.Add(varDal);
            mSearch.Statements.Add(new CodeSnippetExpression("return dal.SelectObjects(Query).Skip(Skip).Take(Take)"));
            mSearch.ReturnType = IEnumEntity;
            ctdService.Members.Add(mSearch);

            CodeMemberMethod mFullSearch = this.CreateServiceMethodBase("FullSearch");
            mFullSearch.Parameters.AddRange(new CodeParameterDeclarationExpression[] { cpEntityQuery, cpEntityOrderBy, cpSkip, cpTake });
            mFullSearch.Statements.Add(varDal);
            mFullSearch.Statements.Add(new CodeSnippetExpression("return dal.SelectObjects(Query).OrderBy(Orderby).Skip(Skip).Take(Take)"));
            mFullSearch.ReturnType = IEnumEntity;
            ctdService.Members.Add(mFullSearch);
            #endregion

            #region [ OML Methods ]
            /// If the parameter object is a Table then Generate OML methods
            if (table.GetType() == typeof(TSQL.Table))
            {
                CodeMemberMethod mUpdate = this.CreateServiceMethodBase("Update");
                mUpdate.Parameters.Add(cpEntityQuery);
                mUpdate.Statements.Add(varDal);
               // mUpdate.Statements.Add(new CodeSnippetExpression(" return dal.Update(Query)"));
                mUpdate.Statements.Add(FuncAction("dal","Update","Query"));
                mUpdate.ReturnType = IIntReturn;
                ctdService.Members.Add(mUpdate);

                CodeMemberMethod mInsert = this.CreateServiceMethodBase("Insert");
                mInsert.Parameters.Add(cpEntityQuery);
                mInsert.Statements.Add(varDal);
                mInsert.Statements.Add(new CodeSnippetExpression("Int32 rCode = new Int32()"));
                mInsert.Statements.Add(new CodeSnippetExpression("rCode = dal.Insert(Query)"));
                mInsert.Statements.Add(new CodeSnippetExpression("return rCode"));
                mInsert.ReturnType = IIntReturn;
                ctdService.Members.Add(mInsert);

                CodeMemberMethod mDelete = this.CreateServiceMethodBase("Delete");
                mDelete.Parameters.Add(cpEntityQuery);
                mDelete.Statements.Add(varDal);
                mDelete.Statements.Add(new CodeSnippetExpression("return dal.Delete(Query)"));
                mDelete.ReturnType = IIntReturn;
                ctdService.Members.Add(mDelete);
            }
            #endregion

            #region [ Validation Methods ]
            CodeMemberMethod cmVal = this.CreateServiceMethodBase("ValidateNew");
            cmVal.Parameters.Add(cpEntityQuery);
            cmVal.Statements.AddRange(GraphAttributeSet.BuildValidationSetStatement(table));
            cmVal.Statements.Add(new CodeSnippetExpression("return bResult"));
            cmVal.ReturnType = new CodeTypeReference("Boolean");
            //ctdService.Members.Add(cmVal);
            #endregion

            return ctdService;
        }
Ejemplo n.º 16
0
        public CodeTypeDeclaration BuildDomainServiceInterface(String DataLayerNamespace, String DataBaseName,TSQL.Table table)
        {
            String FullEntityTypeName = DataLayerNamespace + "." + DataBaseName + "." + table.Name;
            CodeTypeDeclaration ctdInterface = new CodeTypeDeclaration("I" + table.Name + "DomainService");
            CodeTypeReference IEnumEntity = new CodeTypeReference("IEnumerable<" + FullEntityTypeName + ">");
            CodeTypeReference IIntReturn = new CodeTypeReference("System.Int32");
            CodeTypeReference IEntity = new CodeTypeReference(FullEntityTypeName);
            CodeTypeReference IEntityOrder = new CodeTypeReference("Func<" + FullEntityTypeName + ",Object>");
            CodeTypeReference IEntityRule = new CodeTypeReference("Func<" + FullEntityTypeName + ",Int32>");

            CodeParameterDeclarationExpression cpEntityQuery = new CodeParameterDeclarationExpression(IEntity,"Query");
            CodeParameterDeclarationExpression cpEntityRule = new CodeParameterDeclarationExpression(IEntityRule, "BusinessRule");
            CodeParameterDeclarationExpression cpEntityOrderBy = new CodeParameterDeclarationExpression(IEntityOrder, "Orderby");
            CodeParameterDeclarationExpression cpSkip = new CodeParameterDeclarationExpression(new CodeTypeReference("Int32"),"Skip");
            CodeParameterDeclarationExpression cpTake = new CodeParameterDeclarationExpression(new CodeTypeReference("Int32"),"Take");

            // Build Interface
            ctdInterface.Attributes = MemberAttributes.Public;
            ctdInterface.IsInterface = true;
            ctdInterface.CustomAttributes.Add(new CodeAttributeDeclaration("ServiceContract"));

            CodeMemberMethod mSearch = this.CreateServiceInterfaceMethodBase("Search");
            mSearch.Parameters.AddRange(new CodeParameterDeclarationExpression[] { cpEntityQuery, cpSkip, cpTake });
            mSearch.ReturnType = IEnumEntity;

            CodeMemberMethod mFullSearch = this.CreateServiceInterfaceMethodBase("FullSearch");
            mFullSearch.Parameters.AddRange(new CodeParameterDeclarationExpression[] { cpEntityQuery,cpEntityOrderBy, cpSkip, cpTake });
            mFullSearch.ReturnType = IEnumEntity;

            CodeMemberMethod mUpdate = this.CreateServiceInterfaceMethodBase("Update");
            mUpdate.Parameters.Add(cpEntityQuery);
            mUpdate.ReturnType = IIntReturn;

            CodeMemberMethod mInsert = this.CreateServiceInterfaceMethodBase("Insert");
            mInsert.Parameters.Add(cpEntityQuery);
            mInsert.ReturnType = IIntReturn;

            CodeMemberMethod mDelete = this.CreateServiceInterfaceMethodBase("Delete");
            mDelete.Parameters.Add(cpEntityQuery);
            mDelete.ReturnType = IIntReturn;

            CodeMemberMethod mRule = this.CreateServiceInterfaceMethodBase("Rule");
            mRule.Parameters.Add(cpEntityRule);
            mRule.ReturnType = IIntReturn;

            ctdInterface.Members.Add(mSearch);
            ctdInterface.Members.Add(mFullSearch);
            ctdInterface.Members.Add(mUpdate);
            ctdInterface.Members.Add(mInsert);
            ctdInterface.Members.Add(mDelete);
            ctdInterface.Members.Add(mRule);

            return ctdInterface;
        }