private void AddDatabaseContext(StringCollection output, SmoScriptingContext ctx) { string batch = String.Format("USE [{0}]", ctx.Connection.DatabaseName); output.Add(batch); AddLineEnding(output); }
private SqlSmoObject ViewObj(SmoScriptingContext ctx) { var view = new View(ctx.Database, ctx.Metadata.Name, ctx.Metadata.Schema); view.Refresh(); return(view); }
private SqlSmoObject TableObj(SmoScriptingContext ctx) { var table = new Table(ctx.Database, ctx.Metadata.Name, ctx.Metadata.Schema); table.Refresh(); return(table); }
private SqlSmoObject FunctionObj(SmoScriptingContext ctx) { var function = new UserDefinedFunction(ctx.Database, ctx.Metadata.Name, ctx.Metadata.Schema); function.Refresh(); return(function); }
private SqlSmoObject StoredProcedureObj(SmoScriptingContext ctx) { var storedProcedure = new StoredProcedure(ctx.Database, ctx.Metadata.Name, ctx.Metadata.Schema); storedProcedure.Refresh(); return(storedProcedure); }
private void AddAnsiNulls(StringCollection output, SmoScriptingContext ctx) { bool?value = ctx.Metadata.AnsiNullsStatus; if (value.HasValue) { output.Add(String.Format("SET ANSI_NULLS {0}", value.Value ? "ON" : "OFF")); AddLineEnding(output); } }
private void AddQuotedIdentifier(StringCollection output, SmoScriptingContext ctx) { bool?value = ctx.Metadata.QuotedIdentifierStatus; if (value.HasValue) { output.Add(String.Format("SET QUOTED_IDENTIFIER {0}", value.Value ? "ON" : "OFF")); AddLineEnding(output); } }
private SqlSmoObject TriggerObj(SmoScriptingContext ctx) { var table = new Table(ctx.Database, ctx.Metadata.ParentName, ctx.Metadata.ParentSchema); table.Refresh(); var trigger = new Trigger(table, ctx.Metadata.Name); trigger.Refresh(); return(trigger); }
public SmoScriptableObject Create(SmoScriptingContext context) { ObjectFactory <SmoScriptableObject> factory = null; SmoObjectType type = context.Metadata.Type; if (!_factories.TryGetValue(type, out factory)) { throw new InvalidOperationException("Unknown type of object"); } SmoScriptableObject obj = factory(context); return(obj); }
public override StringCollection Script(SmoScriptingContext context) { var textObject = ScriptedObject as ITextObject; if (textObject == null) { throw new InvalidOperationException( String.Format("ScriptedObject '{0}' cannot be scripted as alter", ScriptedObject.GetType().Name)); } StringCollection result = Script(textObject, context); return(result); }
private StringCollection Script(ITextObject obj, SmoScriptingContext ctx) { var output = new StringCollection(); if (ctx.ScriptDatabaseContext) { AddDatabaseContext(output, ctx); AddBatchSeparator(output, ctx); } AddAnsiNulls(output, ctx); AddBatchSeparator(output, ctx); AddQuotedIdentifier(output, ctx); AddBatchSeparator(output, ctx); AddHeader(output, obj); AddBody(output, obj); return(output); }
public override StringCollection Script(SmoScriptingContext context) { var scripter = new Microsoft.SqlServer.Management.Smo.Scripter(context.Server); Microsoft.SqlServer.Management.Smo.ScriptingOptions options = scripter.Options; options.IncludeDatabaseContext = context.ScriptDatabaseContext; StringCollection scriptingResult = scripter.Script(new[] { ScriptedObject }); var result = new StringCollection(); foreach (string scriptedBatch in scriptingResult) { result.Add(scriptedBatch); AddLineEnding(result); AddLineEnding(result); } return(result); }
private string Script(IDbConnection connection, string schema, string name) { var metadata = new SmoObjectMetadata(schema, name); metadata.Initialize(connection); var context = new SmoScriptingContext(connection, metadata); SmoScriptableObject obj = _objectFactory.Create(context); StringCollection batches = obj.Script(context); var builder = new StringBuilder(); foreach (string batch in batches) { builder.Append(batch); } string result = builder.ToString(); return(result); }
public void AddBatchSeparator(StringCollection output, SmoScriptingContext ctx) { output.Add(ctx.Connection.BatchSeparator); AddLineEnding(output); }
public abstract StringCollection Script(SmoScriptingContext context);