コード例 #1
0
 //
 // Summary:
 //     Add Objects to the model based on the contents of a Microsoft.SqlServer.TransactSql.ScriptDom.TSqlScript
 //     object, plus additional metadata defined by a Microsoft.SqlServer.Dac.Model.TSqlObjectOptions
 //     object The script should be valid TSql with no parse errors. Objects added
 //     using this method cannot be updated or deleted at a later point as update/delete
 //     requires a script name to be specified when adding the objects. If this is
 //     a requirement use the Microsoft.SqlServer.Dac.Model.TSqlModel.AddOrUpdateObjects(Microsoft.SqlServer.TransactSql.ScriptDom.TSqlScript,System.String,Microsoft.SqlServer.Dac.Model.TSqlObjectOptions)
 //     method instead.
 //
 // Parameters:
 //   inputScript:
 //     The Microsoft.SqlServer.TransactSql.ScriptDom.TSqlScript to add
 //
 //   options:
 //     Options defining how to interpret the script
 //
 // Exceptions:
 //   System.ArgumentNullException:
 //     If the supplied inputScript is null.
 //
 //   System.Runtime.Remoting.RemotingException:
 //     If communication with the Microsoft.SqlServer.Dac.Model.TSqlObjectService
 //     fails.
 public void AddObjects(TSqlScript inputScript, TSqlObjectOptions options)
 {
     model.AddObjects(inputScript, options);
 }
コード例 #2
0
 //
 // Summary:
 //     Adds or updates the objects defined for a specified sourceName with the objects
 //     defined in the inputScript. If any objects were previously added with the
 //     same sourceName these will be completely replaced The object definitions
 //     are based on the contents of a TSql Script string plus additional metadata
 //     defined by a Microsoft.SqlServer.Dac.Model.TSqlObjectOptions object The script
 //     should consist of valid TSql DDL statements.
 //
 // Parameters:
 //   inputScript:
 //     Script containing TSql DDL statements
 //
 //   sourceName:
 //     A name to identify the inputScript, for example a fileName such as "MyTable.sql"
 //     or simply an alias like "dbo.Table". Scripts are cached and TSqlObjects are
 //     linked to the source name.  Any future Update/Delete operations will remove
 //     all existing objects with the same script name and replace them with the
 //     new objects.
 //
 //   options:
 //     Options defining how to interpret the script
 //
 // Exceptions:
 //   System.ArgumentNullException:
 //     If the supplied inputScript is null.
 //
 //   System.ArgumentException:
 //     If the supplied sourceName is null or whitespace, or if it ends in ".xsd".
 //     Note: source names ending in ".xsd" are currently not supported. These relate
 //     to Xml Schema Collections and adding of these is currently not supported
 //     in the public API.
 //
 //   System.Runtime.Remoting.RemotingException:
 //     If communication with the Microsoft.SqlServer.Dac.Model.TSqlObjectService
 //     fails.
 public void AddOrUpdateObjects(string inputScript, string sourceName, TSqlObjectOptions options)
 {
     model.AddOrUpdateObjects(inputScript, sourceName, options);
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: AeroXuk/DacpacMerge
        public void Merge()
        {
            var options = new TSqlObjectOptions();

            //var pre = String.Empty;
            //var post = String.Empty;
            //Dictionary<string, Reference> externalReferences = new Dictionary<string, Reference>();
            //Dictionary<string, SqlCmdVar> sqlVariables = new Dictionary<string, SqlCmdVar>();

            foreach (var source in _sources)
            {
                TSqlModel model = new TSqlModel(source);

                /*
                 * var customDatas = model.GetCustomData();
                 * foreach (CustomData customData in customDatas)
                 * {
                 *      if (customData.Category == "Reference" && customData.DataType == "SqlSchema")
                 *      {
                 *              var reference = new Reference(customData);
                 *              if (!reference.IsSameDatabaseReference && !externalReferences.ContainsKey(reference.LogicalName))
                 *              {
                 *                      externalReferences.Add(reference.LogicalName, reference);
                 *              }
                 *              Console.WriteLine("DacPac Reference: {0} / {1} / {2} / {3}",
                 *                      reference.Path,
                 *                      reference.LogicalName,
                 *                      reference.ExternalParts,
                 *                      reference.SuppressMissingDependenciesErrors);
                 *      }
                 *      else if (customData.Category == "SqlCmdVariables")
                 *      {
                 *              var sqlVars = SqlCmdVar.ParseCustomData(customData);
                 *              foreach (SqlCmdVar sqlVar in sqlVars)
                 *              {
                 *                      if (!sqlVariables.ContainsKey(sqlVar.Name))
                 *                      {
                 *                              sqlVariables.Add(sqlVar.Name, sqlVar);
                 *                      }
                 *                      Console.WriteLine("DacPac SQL Variable: {0} / {1}",
                 *                              sqlVar.Name,
                 *                              sqlVar.Value);
                 *              }
                 *      }
                 * }
                 */

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

                        if (!string.IsNullOrWhiteSpace(name) && !name.EndsWith(".xsd"))
                        {
                            _targetModel.AddOrUpdateObjects(ast, name, options);
                            //_targetModel.AddObjects(ast);
                        }
                    }
                }

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

            //Console.WriteLine("Start Compile...");
            //foreach (Reference reference in externalReferences.Values)
            //{
            //	_target.AddReference(
            //		reference.Path,
            //		reference.LogicalName,
            //		reference.ExternalParts,
            //		reference.SuppressMissingDependenciesErrors);
            //}
            //_target.AddSqlVariables(sqlVariables.Values.ToList());
            WriteFinalDacpac(_targetModel /*, pre, post*/);
        }