Beispiel #1
0
        /// <summary>
        /// Custom Script method for database objects.
        /// </summary>
        /// <param name="sqlSmoObject">The database.</param>
        /// <param name="urn">The urn.</param>
        /// <param name="scriptingOptions">The scripting options.</param>
        /// <returns>Empty string collection (no residual statements)</returns>
        private StringCollection ScriptDatabase(SqlSmoObject sqlSmoObject, Urn urn, ScriptingOptions scriptingOptions)
        {
            Database         database           = sqlSmoObject as Database;
            StringCollection databaseStatements = database.Script(scriptingOptions);

            this.WriteScript(urn.Type, sqlSmoObject.ToString(), databaseStatements.ToString());

            foreach (DatabaseDdlTrigger databaseDdlTrigger in database.Triggers)
            {
                StringCollection databaseDdlTriggerStatements = databaseDdlTrigger.Script(scriptingOptions);
                this.WriteScript(databaseDdlTrigger.Urn.Type, databaseDdlTrigger.ToString(), CleanStatements(databaseDdlTriggerStatements));
            }

            // Return empty collection
            return(new StringCollection());
        }
Beispiel #2
0
        String ObjectName(SqlSmoObject sqlSmoObject)
        {
            String Name;

            if (sqlSmoObject is ForeignKey)
            {
                Name = ObjectName((sqlSmoObject as ForeignKey).Parent) + "." + (sqlSmoObject as ForeignKey).ToString();
            }
            else if (!config.scriptSchemaQualify && sqlSmoObject is ScriptSchemaObjectBase)
            {
                Name = "[" + (sqlSmoObject as ScriptSchemaObjectBase).Name + "]";
            }
            else
            {
                Name = sqlSmoObject.ToString();
            }
            return(Name);
        }
Beispiel #3
0
        private string ObjectName(SqlSmoObject sqlSmoObject)
        {
            string name;

            if (sqlSmoObject is ForeignKey)
            {
                name = this.ObjectName((sqlSmoObject as ForeignKey).Parent) + "." + (sqlSmoObject as ForeignKey).ToString();
            }
            else if (!this.config.scriptSchemaQualify && sqlSmoObject is ScriptSchemaObjectBase)
            {
                name = "[" + (sqlSmoObject as ScriptSchemaObjectBase).Name + "]";
            }
            else
            {
                name = sqlSmoObject.ToString();
            }

            return(name);
        }
Beispiel #4
0
        /// <summary>
        /// Determines whether the specified SqlSmoObject is excluded from scripting.
        /// </summary>
        /// <param name="sqlSmoObject">The SqlSmoObject.</param>
        /// <returns>
        ///     <c>true</c> if the SqlSmoObject is system or default and shoudl be excludeed; otherwise, <c>false</c>.
        /// </returns>
        private static bool IsExcludedObject(SqlSmoObject sqlSmoObject)
        {
            // Exclude "IsSystemObject" objects
            try
            {
                bool isSystemObject = (bool)sqlSmoObject.GetType().InvokeMember(
                    "IsSystemObject",
                    BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty,
                    null,
                    sqlSmoObject,
                    null);
                if (isSystemObject)
                {
                    return(true);
                }
            }
            catch (MissingMemberException)
            {
            }

            // Exclude default system MessageTypes
            if (sqlSmoObject is MessageType)
            {
                if (((MessageType)sqlSmoObject).ID <= 65535)
                {
                    return(true);
                }
            }

            // Exclude default system ServiceContractS
            if (sqlSmoObject is ServiceContract)
            {
                if (((ServiceContract)sqlSmoObject).ID <= 65535)
                {
                    return(true);
                }
            }

            // Exclude default system ServiceQueues (Bit 7 128?)
            if (sqlSmoObject is ServiceQueue)
            {
                if (Array.IndexOf(Config.aDefaultServiceQueues, sqlSmoObject.ToString()) != -1)
                {
                    return(true);
                }
            }

            // Exclude default system ServiceRoutes
            // A single default route [AutoCreatedLocal] ID:65536 exists
            // 65537 is user created
            if (sqlSmoObject is ServiceRoute)
            {
                if (((ServiceRoute)sqlSmoObject).ID <= 65536)
                {
                    return(true);
                }
            }

            // Exclude default system BrokerService
            if (sqlSmoObject is BrokerService)
            {
                if (((BrokerService)sqlSmoObject).ID <= 65535)
                {
                    return(true);
                }
            }

            // Exclude "microsoft_database_tools_support" objects
            try
            {
                ExtendedPropertyCollection epc =
                    (ExtendedPropertyCollection)sqlSmoObject.GetType().InvokeMember(
                        "ExtendedProperties",
                        BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty,
                        null,
                        sqlSmoObject,
                        null);
                if (epc.Contains("microsoft_database_tools_support"))
                {
                    return(true);
                }
            }
            catch (MissingMemberException)
            {
            }

            return(false);
        }