Beispiel #1
0
        public void Run()
        {
            DacServices services = new DacServices(@"Server=ITK\DEV17;Integrated Security=true;");
            DacPackage  package  = DacPackage.Load(file01, DacSchemaModelStorageType.Memory, FileAccess.ReadWrite);

            string dbName         = @"MojaBazaDAC";
            bool   updateExisting = true;

            TSqlModel tm01     = new TSqlModel(file01);
            TSqlModel newModel = new TSqlModel(tm01.Version, tm01.CopyModelOptions());

            //package.UpdateModel(filteredModel, new PackageMetadata())

            DacDeployOptions opts = new DacDeployOptions
            {
                ExcludeObjectTypes = new ObjectType[]
                {
                    ObjectType.Users,
                    ObjectType.RoleMembership
                }
            };

            services.Deploy(package,
                            dbName,
                            updateExisting,
                            opts
                            );
        }
        internal static void Merge()
        {
            var samplePackagagePath = @"C:\Dev\ed\DacMergeExample\SampleSQLProj\bin\Debug\Sample.dacpac";
            TSqlModel sampleModel = new TSqlModel(samplePackagagePath, DacSchemaModelStorageType.Memory);

            var targetPackagePath = @"merged.dacpac";

            DisposableList disposables = new DisposableList();

            var newModel = new TSqlModel(sampleModel.Version, sampleModel.CopyModelOptions());
            foreach (var item in sampleModel.GetObjects(DacQueryScopes.UserDefined))
            {
                string script;
                if (item.TryGetScript(out script))
                {
                    newModel.AddObjects(script);
                }
            }

            DacPackageExtensions.BuildPackage(
                    targetPackagePath,
                    newModel,
                    new PackageMetadata(), // Describes the dacpac.
                    new PackageOptions());  // Use this to specify the deployment contributors, refactor log to include in package

            //DacPackage package = disposables.Add(DacPackage.Load(targetPackagePath, DacSchemaModelStorageType.Memory, FileAccess.ReadWrite));
            //package.UpdateModel(cilModel, new PackageMetadata());
        }
Beispiel #3
0
        public DacpacMerge(string target, params string[] sources)
        {
            _sources = sources;
            _first   = new TSqlModel(sources.First <string>());
            var options = _first.CopyModelOptions();

            _target     = new TSqlModel(_first.Version, options);
            _targetPath = target;
        }
        public DacpacMerger(string target, string[] sources)
        {
            this.sources = sources;
            first        = new TSqlModel(sources.First());
            var options = first.CopyModelOptions();

            this.target = new TSqlModel(first.Version, options);
            targetPath  = target;
        }
        public UIElement GetPropertiesDisplayForDacpac(TSqlModel model)
        {
            var panel = GetPropertiesDisplayPanel("Target Sql Version: " + model.Version);

            var options = model.CopyModelOptions();
            panel.Children.Add(GetSimplePropertyLabel("Database Properties:"));

            foreach (var prop in options.GetType().GetProperties().OrderBy(p => p.Name))
            {
                var val = prop.GetValue(options) as object;
                if (val == null)
                {
                    val = "NULL";
                }

                panel.Children.Add(GetPropertyLabel(prop.Name, val.ToString()));
            }

            return panel;
        }
Beispiel #6
0
        public void Run()
        {
            TSqlModel tm01     = new TSqlModel(folderPath01 + file01);
            TSqlModel newModel = new TSqlModel(tm01.Version, tm01.CopyModelOptions());

            List <TSqlObject> objs = tm01.GetObjects(DacQueryScopes.UserDefined).ToList();
            List <TSqlObject> delt = new List <TSqlObject>();

            foreach (var r in objs.Where(x => x.ObjectType.Name == "Schema"))
            {
                delt.Add(r);
                AddChildren(r, delt);
            }

            objs.RemoveAll(z => delt.Contains(z));

            foreach (TSqlObject o in objs.Where(z => !delt.Contains(z)))
            {
                if (o.TryGetScript(out string s))
                {
                    newModel.AddObjects(s);
                }
            }

            PackageMetadata m = new PackageMetadata()
            {
                Name        = "Nazwa",
                Version     = "1.0",
                Description = ""
            };

            DacPackageExtensions.BuildPackage
            (
                @"C:\Users\XTOKO\Desktop\NewDacpacSchemaFilter.dacpac"
                , newModel
                , m
            );

            Console.WriteLine("==> koniec");
            Console.ReadLine();
        }
        public UIElement GetPropertiesDisplayForDacpac(TSqlModel model)
        {
            var panel = GetPropertiesDisplayPanel("Target Sql Version: " + model.Version);

            var options = model.CopyModelOptions();

            panel.Children.Add(GetSimplePropertyLabel("Database Properties:"));

            foreach (var prop in options.GetType().GetProperties().OrderBy(p => p.Name))
            {
                var val = prop.GetValue(options) as object;
                if (val == null)
                {
                    val = "NULL";
                }

                panel.Children.Add(GetPropertyLabel(prop.Name, val.ToString()));
            }

            return(panel);
        }
Beispiel #8
0
 //
 // Summary:
 //     Copies the Microsoft.SqlServer.Dac.Model.DatabaseOptions for the model to
 //     a Microsoft.SqlServer.Dac.Model.TSqlModelOptions object.  This is useful
 //     if you wish to duplicate the options for a model when creating a new model.
 //
 // Returns:
 //     Microsoft.SqlServer.Dac.Model.TSqlModelOptions with settings matching the
 //     database options of the model
 public TSqlModelOptions CopyModelOptions()
 {
     return(model.CopyModelOptions());
 }
Beispiel #9
0
        public void Merge()
        {
            var pre  = String.Empty;
            var post = String.Empty;

            foreach (var source in _sources)
            {
                if (!File.Exists(source))
                {
                    Console.WriteLine("File {0} does not exist and is being skipped.", source);
                    continue;
                }

                Console.WriteLine("{0} : Processing dacpac {1}", DateTimeOffset.Now.ToString("o", System.Globalization.CultureInfo.InvariantCulture), source);


                if (source == _sources.First())
                {
                    Console.WriteLine("{0}: Copying dacpac options from {1} to {2}", DateTimeOffset.Now.ToString("o", System.Globalization.CultureInfo.InvariantCulture), source, _targetPath);

                    _first = new TSqlModel(_sources.First());
                    var options = _first.CopyModelOptions();
                    _target = new TSqlModel(_first.Version, options);
                }

                var model = getModel(source);

                foreach (var obj in model.GetObjects(DacQueryScopes.UserDefined))
                {
                    TSqlScript ast;
                    if (obj.TryGetAst(out ast))
                    {
                        var name = obj.Name.ToString();
                        var info = obj.GetSourceInformation();
                        if (info != null && !string.IsNullOrWhiteSpace(info.SourceName))
                        {
                            name = info.SourceName;
                        }

                        if (!string.IsNullOrWhiteSpace(name) && !name.EndsWith(".xsd"))
                        {
                            _target.AddOrUpdateObjects(ast, name, new TSqlObjectOptions());    //WARNING throwing away ansi nulls and quoted identifiers!
                        }
                    }
                }

                AddGlobalCustomData(new HeaderParser(source).GetCustomData()
                                    .Where(x => x.Type != "Assembly").ToList());

                using (var package = DacPackage.Load(source))
                {
                    if (!(package.PreDeploymentScript is null))
                    {
                        pre += new StreamReader(package.PreDeploymentScript).ReadToEnd();
                    }
                    if (!(package.PostDeploymentScript is null))
                    {
                        post += new StreamReader(package.PostDeploymentScript).ReadToEnd();
                    }
                }
            }

            WriteFinalDacpac(_target, pre, post);
        }