Ejemplo n.º 1
0
        private DbServerContext GetDatabaseContext(bool loadAllFields = false)
        {
            DbServerContext  context          = new DbServerContext();
            SqlConnection    connection       = new SqlConnection(m_connectionBuilder.ConnectionString);
            ServerConnection serverConnection = new ServerConnection(connection);

            context.Server   = new Server(serverConnection);
            context.Database = context.Server.Databases[this.DatabaseName];

            context.Server.SetDefaultInitFields(loadAllFields);

            return(context);
        }
Ejemplo n.º 2
0
        protected void ScriptSynonyms(DbServerContext context, IEnumerable <ScriptObject> synonyms)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Synonym) == ObjectTypeEnum.Synonym)
            {
                string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameSynonyms);

                foreach (ScriptObject synonymObject in synonyms)
                {
                    Synonym curentSynonym = context.Database.Synonyms[synonymObject.ObjectName, synonymObject.ObjectSchema];
                    ScriptDefinition(synonymObject, outputDirectory, new Func <StringCollection>(() =>
                    {
                        return(curentSynonym.Script(m_options.ScriptingOptions));
                    }));
                }
            }
        }
Ejemplo n.º 3
0
        protected void ScriptAllUserDefinedTypes(DbServerContext context)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Type) == ObjectTypeEnum.Type)
            {
                List <ScriptObject> types = new List <ScriptObject>();
                foreach (UserDefinedType udt in context.Database.UserDefinedTypes)
                {
                    types.Add(new ScriptObject(ObjectTypeEnum.Type, ObjectActionEnum.Create)
                    {
                        ObjectName   = udt.Name,
                        ObjectSchema = udt.Schema
                    });
                }
                foreach (UserDefinedDataType udt in context.Database.UserDefinedDataTypes)
                {
                    types.Add(new ScriptObject(ObjectTypeEnum.Type, ObjectActionEnum.Create)
                    {
                        ObjectName   = udt.Name,
                        ObjectSchema = udt.Schema
                    });
                }
                foreach (UserDefinedFunction udt in context.Database.UserDefinedFunctions)
                {
                    if (!udt.IsSystemObject)
                    {
                        types.Add(new ScriptObject(ObjectTypeEnum.Type, ObjectActionEnum.Create)
                        {
                            ObjectName   = udt.Name,
                            ObjectSchema = udt.Schema
                        });
                    }
                }
                foreach (UserDefinedTableType udt in context.Database.UserDefinedTableTypes)
                {
                    if (udt.IsUserDefined)
                    {
                        types.Add(new ScriptObject(ObjectTypeEnum.Type, ObjectActionEnum.Create)
                        {
                            ObjectName   = udt.Name,
                            ObjectSchema = udt.Schema
                        });
                    }
                }

                ScriptUserDefinedTypes(context, types);
            }
        }
Ejemplo n.º 4
0
        protected void ScriptUserDefinedTypes(DbServerContext context, IEnumerable <ScriptObject> udts)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Type) == ObjectTypeEnum.Type)
            {
                string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameUserDefinedTypes);

                foreach (ScriptObject udtObject in udts)
                {
                    if (udtObject.ObjectAction == ObjectActionEnum.Drop)
                    {
                        DeleteScript(udtObject, outputDirectory);
                    }
                    else
                    {
                        if (context.Database.UserDefinedTypes.Contains(udtObject.ObjectName, udtObject.ObjectSchema))
                        {
                            var currentType = context.Database.UserDefinedTypes[udtObject.ObjectName, udtObject.ObjectSchema];
                            ScriptDefinition(udtObject, outputDirectory, new Func <StringCollection>(() => {
                                return(currentType.Script(m_options.ScriptingOptions));
                            }));
                        }
                        else if (context.Database.UserDefinedDataTypes.Contains(udtObject.ObjectName, udtObject.ObjectSchema))
                        {
                            var currentType = context.Database.UserDefinedDataTypes[udtObject.ObjectName, udtObject.ObjectSchema];
                            ScriptDefinition(udtObject, outputDirectory, new Func <StringCollection>(() => {
                                return(currentType.Script(m_options.ScriptingOptions));
                            }));
                        }
                        else if (context.Database.UserDefinedFunctions.Contains(udtObject.ObjectName, udtObject.ObjectSchema))
                        {
                            var currentType = context.Database.UserDefinedFunctions[udtObject.ObjectName, udtObject.ObjectSchema];
                            ScriptDefinition(udtObject, outputDirectory, new Func <StringCollection>(() => {
                                return(currentType.Script(m_options.ScriptingOptions));
                            }));
                        }
                        else
                        {
                            var currentType = context.Database.UserDefinedTableTypes[udtObject.ObjectName, udtObject.ObjectSchema];
                            ScriptDefinition(udtObject, outputDirectory, new Func <StringCollection>(() => {
                                return(currentType.Script(m_options.ScriptingOptions));
                            }));
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        protected void ScriptAllSynonyms(DbServerContext context)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Synonym) == ObjectTypeEnum.Synonym)
            {
                List <ScriptObject> synonyms = new List <ScriptObject>();
                foreach (Synonym synonym in context.Database.Synonyms)
                {
                    synonyms.Add(new ScriptObject(ObjectTypeEnum.Synonym, ObjectActionEnum.Create)
                    {
                        ObjectName   = synonym.Name,
                        ObjectSchema = synonym.Schema
                    });
                }

                ScriptSynonyms(context, synonyms);
            }
        }
Ejemplo n.º 6
0
        protected void ScriptAllViews(DbServerContext context)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.View) == ObjectTypeEnum.View)
            {
                List <ScriptObject> views = new List <ScriptObject>();
                foreach (View view in context.Database.Views)
                {
                    if (!view.IsSystemObject)
                    {
                        views.Add(new ScriptObject(ObjectTypeEnum.View, ObjectActionEnum.Create)
                        {
                            ObjectName   = view.Name,
                            ObjectSchema = view.Schema
                        });
                    }
                }

                ScriptViews(context, views);
            }
        }
Ejemplo n.º 7
0
        protected void ScriptAllStoredProcedures(DbServerContext context)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Procedure) == ObjectTypeEnum.Procedure)
            {
                List <ScriptObject> sprocs = new List <ScriptObject>();
                foreach (StoredProcedure sproc in context.Database.StoredProcedures)
                {
                    if (!sproc.IsSystemObject)
                    {
                        sprocs.Add(new ScriptObject(ObjectTypeEnum.Procedure, ObjectActionEnum.Create)
                        {
                            ObjectName   = sproc.Name,
                            ObjectSchema = sproc.Schema
                        });
                    }
                }

                ScriptStoredProcedures(context, sprocs);
            }
        }
Ejemplo n.º 8
0
        protected void ScriptAllFunctions(DbServerContext context)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Function) == ObjectTypeEnum.Function)
            {
                List <ScriptObject> tables = new List <ScriptObject>();
                foreach (UserDefinedFunction udf in context.Database.UserDefinedFunctions)
                {
                    if (!udf.IsSystemObject)
                    {
                        tables.Add(new ScriptObject(ObjectTypeEnum.Function, ObjectActionEnum.Create)
                        {
                            ObjectName   = udf.Name,
                            ObjectSchema = udf.Schema
                        });
                    }
                }

                ScriptFunctions(context, tables);
            }
        }
Ejemplo n.º 9
0
        protected void ScriptAllTables(DbServerContext context)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Table) == ObjectTypeEnum.Table)
            {
                List <ScriptObject> tables = new List <ScriptObject>();
                foreach (Table table in context.Database.Tables)
                {
                    if (!table.IsSystemObject)
                    {
                        tables.Add(new ScriptObject(ObjectTypeEnum.Table, ObjectActionEnum.Create)
                        {
                            ObjectName   = table.Name,
                            ObjectSchema = table.Schema
                        });
                    }
                }

                ScriptTables(context, tables);
            }
        }
Ejemplo n.º 10
0
        protected void ScriptAllUserStoredProceduresModifiedSince(DbServerContext context, DateTime modifiedSince)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Procedure) == ObjectTypeEnum.Procedure)
            {
                var sprocs = new List <ScriptObject>();
                foreach (StoredProcedure sproc in context.Database.StoredProcedures)
                {
                    if (!sproc.IsSystemObject && sproc.DateLastModified > modifiedSince)
                    {
                        sprocs.Add(
                            new ScriptObject(ObjectTypeEnum.Procedure, ObjectActionEnum.Create)
                        {
                            ObjectName   = sproc.Name,
                            ObjectSchema = sproc.Schema
                        });
                    }
                }

                ScriptStoredProcedures(context, sprocs);
            }
        }
Ejemplo n.º 11
0
        protected void ScriptAllUserTablesModifiedSince(DbServerContext context, DateTime modifiedSince)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Table) == ObjectTypeEnum.Table)
            {
                var tables = new List <ScriptObject>();
                foreach (Table table in context.Database.Tables)
                {
                    if (!table.IsSystemObject && table.DateLastModified > modifiedSince)
                    {
                        tables.Add(
                            new ScriptObject(ObjectTypeEnum.Table, ObjectActionEnum.Create)
                        {
                            ObjectName   = table.Name,
                            ObjectSchema = table.Schema
                        });
                    }
                }

                ScriptTables(context, tables);
            }
        }
Ejemplo n.º 12
0
        protected void ScriptAllUserViewsModifiedSince(DbServerContext context, DateTime modifiedSince)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.View) == ObjectTypeEnum.View)
            {
                var views = new List <ScriptObject>();
                foreach (View view in context.Database.Views)
                {
                    if (!view.IsSystemObject && view.DateLastModified > modifiedSince)
                    {
                        views.Add(
                            new ScriptObject(ObjectTypeEnum.View, ObjectActionEnum.Create)
                        {
                            ObjectName   = view.Name,
                            ObjectSchema = view.Schema
                        });
                    }
                }

                ScriptViews(context, views);
            }
        }
Ejemplo n.º 13
0
        protected void ScriptFunctions(DbServerContext context, IEnumerable <ScriptObject> udfs)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Function) == ObjectTypeEnum.Function)
            {
                string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameFunctions);

                foreach (ScriptObject udfObject in udfs)
                {
                    if (udfObject.ObjectAction == ObjectActionEnum.Drop)
                    {
                        DeleteScript(udfObject, outputDirectory);
                    }
                    else
                    {
                        UserDefinedFunction currentUdf = context.Database.UserDefinedFunctions[udfObject.ObjectName, udfObject.ObjectSchema];
                        ScriptDefinition(udfObject, outputDirectory, new Func <StringCollection>(() =>
                        {
                            return(currentUdf.Script(m_options.ScriptingOptions));
                        }));
                    }
                }
            }
        }
Ejemplo n.º 14
0
        protected void ScriptStoredProcedures(DbServerContext context, IEnumerable <ScriptObject> sprocs)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Procedure) == ObjectTypeEnum.Procedure)
            {
                string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameProcedures);

                foreach (ScriptObject sprocObject in sprocs)
                {
                    if (sprocObject.ObjectAction == ObjectActionEnum.Drop)
                    {
                        DeleteScript(sprocObject, outputDirectory);
                    }
                    else
                    {
                        StoredProcedure currentSproc = context.Database.StoredProcedures[sprocObject.ObjectName, sprocObject.ObjectSchema];
                        ScriptDefinition(sprocObject, outputDirectory, new Func <StringCollection>(() =>
                        {
                            return(currentSproc.Script(m_options.ScriptingOptions));
                        }));
                    }
                }
            }
        }
Ejemplo n.º 15
0
        protected void ScriptViews(DbServerContext context, IEnumerable <ScriptObject> views)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.View) == ObjectTypeEnum.View)
            {
                string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameViews);

                foreach (ScriptObject viewObject in views)
                {
                    if (viewObject.ObjectAction == ObjectActionEnum.Drop)
                    {
                        DeleteScript(viewObject, outputDirectory);
                    }
                    else
                    {
                        View currentView = context.Database.Views[viewObject.ObjectName, viewObject.ObjectSchema];
                        ScriptDefinition(viewObject, outputDirectory, new Func <StringCollection>(() =>
                        {
                            return(currentView.Script(m_options.ScriptingOptions));
                        }));
                    }
                }
            }
        }
Ejemplo n.º 16
0
        protected void ScriptTables(DbServerContext context, IEnumerable <ScriptObject> tables)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Table) == ObjectTypeEnum.Table)
            {
                string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameTables);

                foreach (ScriptObject tableObject in tables)
                {
                    if (tableObject.ObjectAction == ObjectActionEnum.Drop)
                    {
                        DeleteScript(tableObject, outputDirectory);
                    }
                    else
                    {
                        Table currentTable = context.Database.Tables[tableObject.ObjectName, tableObject.ObjectSchema];

                        ScriptDefinition(tableObject, outputDirectory, new Func <StringCollection>(() =>
                        {
                            return(currentTable.Script(m_options.ScriptingOptions));
                        }));
                    }
                }
            }
        }
        private DbServerContext GetDatabaseContext(bool loadAllFields = false)
        {
            DbServerContext context = new DbServerContext();
            SqlConnection connection = new SqlConnection(m_connectionBuilder.ConnectionString);
            ServerConnection serverConnection = new ServerConnection(connection);
            context.Server = new Server(serverConnection);
            context.Database = context.Server.Databases[this.DatabaseName];

            context.Server.SetDefaultInitFields(loadAllFields);

            return context;
        }
        protected void ScriptAllTables(DbServerContext context)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Table) == ObjectTypeEnum.Table)
            {
                List<ScriptObject> tables = new List<ScriptObject>();
                foreach (Table table in context.Database.Tables)
                {
                    if (!table.IsSystemObject)
                    {
                        tables.Add(new ScriptObject(ObjectTypeEnum.Table, ObjectActionEnum.Create)
                        {
                            ObjectName = table.Name,
                            ObjectSchema = table.Schema
                        });
                    }
                }

                ScriptTables(context, tables);
            }
        }
        protected void ScriptTables(DbServerContext context, IEnumerable<ScriptObject> tables)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Table) == ObjectTypeEnum.Table)
            {
                string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameTables);

                foreach (ScriptObject tableObject in tables)
                {
                    if (tableObject.ObjectAction == ObjectActionEnum.Drop)
                    {
                        DeleteScript(tableObject, outputDirectory);
                    }
                    else
                    {
                        Table currentTable = context.Database.Tables[tableObject.ObjectName, tableObject.ObjectSchema];

                        ScriptDefinition(tableObject, outputDirectory, new Func<StringCollection>(() =>
                        {
                            return currentTable.Script(m_options.ScriptingOptions);
                        }));
                    }
                }
            }
        }
        protected void ScriptAllViews(DbServerContext context)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.View) == ObjectTypeEnum.View)
            {
                List<ScriptObject> views = new List<ScriptObject>();
                foreach (View view in context.Database.Views)
                {
                    if (!view.IsSystemObject)
                    {
                        views.Add(new ScriptObject(ObjectTypeEnum.View, ObjectActionEnum.Create)
                        {
                            ObjectName = view.Name,
                            ObjectSchema = view.Schema
                        });
                    }
                }

                ScriptViews(context, views);
            }
        }
        protected void ScriptViews(DbServerContext context, IEnumerable<ScriptObject> views)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.View) == ObjectTypeEnum.View)
            {
                string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameViews);

                foreach (ScriptObject viewObject in views)
                {
                    if (viewObject.ObjectAction == ObjectActionEnum.Drop)
                    {
                        DeleteScript(viewObject, outputDirectory);
                    }
                    else
                    {
                        View currentView = context.Database.Views[viewObject.ObjectName, viewObject.ObjectSchema];
                        ScriptDefinition(viewObject, outputDirectory, new Func<StringCollection>(() =>
                        {
                            return currentView.Script(m_options.ScriptingOptions);
                        }));
                    }
                }
            }
        }
        protected void ScriptAllStoredProcedures(DbServerContext context)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Procedure) == ObjectTypeEnum.Procedure)
            {
                List<ScriptObject> sprocs = new List<ScriptObject>();
                foreach (StoredProcedure sproc in context.Database.StoredProcedures)
                {
                    if (!sproc.IsSystemObject)
                    {
                        sprocs.Add(new ScriptObject(ObjectTypeEnum.Procedure, ObjectActionEnum.Create)
                        {
                            ObjectName = sproc.Name,
                            ObjectSchema = sproc.Schema
                        });
                    }
                }

                ScriptStoredProcedures(context, sprocs);
            }
        }
        protected void ScriptStoredProcedures(DbServerContext context, IEnumerable<ScriptObject> sprocs)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Procedure) == ObjectTypeEnum.Procedure)
            {
                string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameProcedures);

                foreach (ScriptObject sprocObject in sprocs)
                {
                    if (sprocObject.ObjectAction == ObjectActionEnum.Drop)
                    {
                        DeleteScript(sprocObject, outputDirectory);
                    }
                    else
                    {
                        StoredProcedure currentSproc = context.Database.StoredProcedures[sprocObject.ObjectName, sprocObject.ObjectSchema];
                        ScriptDefinition(sprocObject, outputDirectory, new Func<StringCollection>(() =>
                        {
                            return currentSproc.Script(m_options.ScriptingOptions);
                        }));
                    }
                }
            }
        }
        protected void ScriptAllFunctions(DbServerContext context)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Function) == ObjectTypeEnum.Function)
            {
                List<ScriptObject> tables = new List<ScriptObject>();
                foreach (UserDefinedFunction udf in context.Database.UserDefinedFunctions)
                {
                    if (!udf.IsSystemObject)
                    {
                        tables.Add(new ScriptObject(ObjectTypeEnum.Function, ObjectActionEnum.Create)
                        {
                            ObjectName = udf.Name,
                            ObjectSchema = udf.Schema
                        });
                    }
                }

                ScriptFunctions(context, tables);
            }
        }
        protected void ScriptFunctions(DbServerContext context, IEnumerable<ScriptObject> udfs)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Function) == ObjectTypeEnum.Function)
            {
                string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameFunctions);

                foreach (ScriptObject udfObject in udfs)
                {
                    if (udfObject.ObjectAction == ObjectActionEnum.Drop)
                    {
                        DeleteScript(udfObject, outputDirectory);
                    }
                    else
                    {
                        UserDefinedFunction currentUdf = context.Database.UserDefinedFunctions[udfObject.ObjectName, udfObject.ObjectSchema];
                        ScriptDefinition(udfObject, outputDirectory, new Func<StringCollection>(() =>
                        {
                            return currentUdf.Script(m_options.ScriptingOptions);
                        }));
                    }
                }
            }
        }
        protected void ScriptSynonyms(DbServerContext context, IEnumerable<ScriptObject> synonyms)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Synonym) == ObjectTypeEnum.Synonym)
            {
                string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameSynonyms);

                foreach (ScriptObject synonymObject in synonyms)
                {
                    Synonym curentSynonym = context.Database.Synonyms[synonymObject.ObjectName, synonymObject.ObjectSchema];
                    ScriptDefinition(synonymObject, outputDirectory, new Func<StringCollection>(() =>
                        {
                            return curentSynonym.Script(m_options.ScriptingOptions);
                        }));
                }
            }
        }
        protected void ScriptAllSynonyms(DbServerContext context)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Synonym) == ObjectTypeEnum.Synonym)
            {
                List<ScriptObject> synonyms = new List<ScriptObject>();
                foreach (Synonym synonym in context.Database.Synonyms)
                {
                    synonyms.Add(new ScriptObject(ObjectTypeEnum.Synonym, ObjectActionEnum.Create)
                        {
                            ObjectName = synonym.Name,
                            ObjectSchema = synonym.Schema
                        });
                }

                ScriptSynonyms(context, synonyms);
            }
        }