Esempio n. 1
0
        public static DbExportArgs Merge(DbExportArgs args, DbExportArgs defaultArgs)
        {
            var result = new DbExportArgs();

            result.ConnectionStrings.AddRange(defaultArgs.ConnectionStrings);
            result.ConnectionStrings.AddRange(args.ConnectionStrings);
            result.ExportMode         = args.ExportMode ?? defaultArgs.ExportMode;
            result.FromConnectionName = args.FromConnectionName ?? defaultArgs.FromConnectionName;
            result.Queries.AddRange(defaultArgs.Queries);
            result.Queries.AddRange(args.Queries);
            foreach (var key in defaultArgs.QueryArguments.Keys)
            {
                result.QueryArguments[key] = defaultArgs.QueryArguments[key];
            }
            foreach (var key in args.QueryArguments.Keys)
            {
                result.QueryArguments[key] = args.QueryArguments[key];
            }
            result.RelationsToExclude.AddRange(defaultArgs.RelationsToExclude);
            result.RelationsToExclude.AddRange(args.RelationsToExclude);
            result.RelationsToInclude.AddRange(defaultArgs.RelationsToInclude);
            result.RelationsToInclude.AddRange(args.RelationsToInclude);
            result.TableFilters.AddRange(defaultArgs.TableFilters);
            result.TableFilters.AddRange(args.TableFilters);
            result.OnImportBefore.AddRange(defaultArgs.OnImportBefore);
            result.OnImportBefore.AddRange(args.OnImportBefore);
            result.OnImportAfter.AddRange(defaultArgs.OnImportAfter);
            result.OnImportAfter.AddRange(args.OnImportAfter);
            result.ToFileName    = args.ToFileName ?? defaultArgs.ToFileName;
            result.Repeat        = args.Repeat ?? defaultArgs.Repeat;
            result.Transactional = args.Transactional || defaultArgs.Transactional;
            return(result);
        }
Esempio n. 2
0
        public static DataSet Run(ISimpleTaskHost host, DbExportArgs args)
        {
            var connection = args.FromConnection;

            using (var xtool = new DbExportTool(connection.ConnectionString, connection.ProviderName ?? "System.Data.SqlClient"))
            {
                xtool.ExportMode = args.ExportMode ?? DbExportMode.None;
                foreach (var item in args.RelationsToExclude)
                {
                    xtool.ExcludeRelation(item);
                }
                foreach (var item in args.RelationsToInclude)
                {
                    xtool.IncludeRelation(item);
                }
                foreach (var item in args.TableFilters)
                {
                    xtool.AddTableFilter(item.TableName, item.WhereCondition);
                }
                foreach (var item in args.QueryArguments)
                {
                    xtool.QueryArguments[item.Key] = item.Value;
                }
                foreach (var item in args.Queries)
                {
                    xtool.Export(host, item.TableName, item.WhereCondition);
                }
                return(xtool.TargetDataSet);
            }
        }
Esempio n. 3
0
        public static DbExportArgs FromXmlFile(string filename)
        {
            var result = new DbExportArgs();
            var xdoc = new XmlDocument();
            xdoc.Load(filename);
            if (xdoc.DocumentElement.Attributes["mode"] != null && !String.IsNullOrWhiteSpace(xdoc.DocumentElement.Attributes["mode"].Value))
                result.ExportMode = (DbExportMode)Enum.Parse(typeof(DbExportMode), xdoc.DocumentElement.Attributes["mode"].Value, true);
            if (xdoc.DocumentElement.Attributes["connectionName"] != null && !String.IsNullOrWhiteSpace(xdoc.DocumentElement.Attributes["connectionName"].Value))
                result.FromConnectionName = xdoc.DocumentElement.Attributes["connectionName"].Value;
            if (xdoc.DocumentElement.Attributes["outputfile"] != null && !String.IsNullOrWhiteSpace(xdoc.DocumentElement.Attributes["outputfile"].Value))
                result.FromConnectionName = xdoc.DocumentElement.Attributes["outputfile"].Value;
            foreach (XmlElement element in xdoc.DocumentElement.SelectNodes("/*/connectionStrings/add"))
            { 
                var item = new ConnectionStringSettings();
                item.Name = element.Attributes["name"].Value;
                item.ConnectionString = element.Attributes["connectionString"].Value;
                if (element.Attributes["providerName"] != null && !String.IsNullOrWhiteSpace(element.Attributes["providerName"].Value))
                    item.ProviderName = element.Attributes["providerName"].Value;
                result.ConnectionStrings.Add(item);
            }
            foreach (XmlElement element in xdoc.DocumentElement.SelectNodes("/*/queries/add"))
            {
                var item = new DbExportArgsQuery();
                item.TableName = element.Attributes["table"].Value;
                item.WhereCondition = (element.Attributes["where"] == null) ? "(1=1)" : element.Attributes["where"].Value;
                result.Queries.Add(item);
            }
            foreach (XmlElement element in xdoc.DocumentElement.SelectNodes("/*/filters/add"))
            {
                if (element.Attributes["where"] != null)
                {
                    var item = new DbExportArgsQuery();
                    item.TableName = element.Attributes["table"].Value;
                    item.WhereCondition = element.Attributes["where"].Value;
                    result.TableFilters.Add(item);
                }
            }
            foreach (XmlElement element in xdoc.DocumentElement.SelectNodes("/*/includes/add"))
            {
                result.RelationsToInclude.Add(element.Attributes["relation"].Value);
            }
            foreach (XmlElement element in xdoc.DocumentElement.SelectNodes("/*/excludes/add"))
            {
                result.RelationsToExclude.Add(element.Attributes["relation"].Value);
            }
            foreach (XmlElement element in xdoc.DocumentElement.SelectNodes("/*/import/before"))
            {
                result.OnImportBefore.Add(element.InnerText);
            }
            foreach (XmlElement element in xdoc.DocumentElement.SelectNodes("/*/import/after"))
            {
                result.OnImportAfter.Add(element.InnerText);
            }

            return result;
        }
Esempio n. 4
0
        public static DbExportArgs FromXmlFile(string filename)
        {
            var result = new DbExportArgs();
            var xdoc   = new XmlDocument();

            xdoc.Load(filename);
            if (xdoc.DocumentElement.Attributes["mode"] != null && !String.IsNullOrWhiteSpace(xdoc.DocumentElement.Attributes["mode"].Value))
            {
                result.ExportMode = (DbExportMode)Enum.Parse(typeof(DbExportMode), xdoc.DocumentElement.Attributes["mode"].Value, true);
            }
            if (xdoc.DocumentElement.Attributes["connectionName"] != null && !String.IsNullOrWhiteSpace(xdoc.DocumentElement.Attributes["connectionName"].Value))
            {
                result.FromConnectionName = xdoc.DocumentElement.Attributes["connectionName"].Value;
            }
            if (xdoc.DocumentElement.Attributes["outputfile"] != null && !String.IsNullOrWhiteSpace(xdoc.DocumentElement.Attributes["outputfile"].Value))
            {
                result.FromConnectionName = xdoc.DocumentElement.Attributes["outputfile"].Value;
            }
            foreach (XmlElement element in xdoc.DocumentElement.SelectNodes("/*/connectionStrings/add"))
            {
                var item = new ConnectionStringSettings();
                item.Name             = element.Attributes["name"].Value;
                item.ConnectionString = element.Attributes["connectionString"].Value;
                if (element.Attributes["providerName"] != null && !String.IsNullOrWhiteSpace(element.Attributes["providerName"].Value))
                {
                    item.ProviderName = element.Attributes["providerName"].Value;
                }
                result.ConnectionStrings.Add(item);
            }
            foreach (XmlElement element in xdoc.DocumentElement.SelectNodes("/*/queries/add"))
            {
                var item = new DbExportArgsQuery();
                item.TableName      = element.Attributes["table"].Value;
                item.WhereCondition = (element.Attributes["where"] == null) ? "(1=1)" : element.Attributes["where"].Value;
                result.Queries.Add(item);
            }
            foreach (XmlElement element in xdoc.DocumentElement.SelectNodes("/*/filters/add"))
            {
                if (element.Attributes["where"] != null)
                {
                    var item = new DbExportArgsQuery();
                    item.TableName      = element.Attributes["table"].Value;
                    item.WhereCondition = element.Attributes["where"].Value;
                    result.TableFilters.Add(item);
                }
            }
            foreach (XmlElement element in xdoc.DocumentElement.SelectNodes("/*/includes/add"))
            {
                result.RelationsToInclude.Add(element.Attributes["relation"].Value);
            }
            foreach (XmlElement element in xdoc.DocumentElement.SelectNodes("/*/excludes/add"))
            {
                result.RelationsToExclude.Add(element.Attributes["relation"].Value);
            }
            foreach (XmlElement element in xdoc.DocumentElement.SelectNodes("/*/import/before"))
            {
                result.OnImportBefore.Add(element.InnerText);
            }
            foreach (XmlElement element in xdoc.DocumentElement.SelectNodes("/*/import/after"))
            {
                result.OnImportAfter.Add(element.InnerText);
            }

            return(result);
        }
Esempio n. 5
0
 public static DbExportArgs Merge(DbExportArgs args, DbExportArgs defaultArgs)
 {
     var result = new DbExportArgs();
     result.ConnectionStrings.AddRange(defaultArgs.ConnectionStrings);
     result.ConnectionStrings.AddRange(args.ConnectionStrings);
     result.ExportMode = args.ExportMode ?? defaultArgs.ExportMode;
     result.FromConnectionName = args.FromConnectionName ?? defaultArgs.FromConnectionName;
     result.Queries.AddRange(defaultArgs.Queries);
     result.Queries.AddRange(args.Queries);
     foreach (var key in defaultArgs.QueryArguments.Keys)
         result.QueryArguments[key] = defaultArgs.QueryArguments[key];
     foreach (var key in args.QueryArguments.Keys)
         result.QueryArguments[key] = args.QueryArguments[key];
     result.RelationsToExclude.AddRange(defaultArgs.RelationsToExclude);
     result.RelationsToExclude.AddRange(args.RelationsToExclude);
     result.RelationsToInclude.AddRange(defaultArgs.RelationsToInclude);
     result.RelationsToInclude.AddRange(args.RelationsToInclude);
     result.TableFilters.AddRange(defaultArgs.TableFilters);
     result.TableFilters.AddRange(args.TableFilters);
     result.OnImportBefore.AddRange(defaultArgs.OnImportBefore);
     result.OnImportBefore.AddRange(args.OnImportBefore);
     result.OnImportAfter.AddRange(defaultArgs.OnImportAfter);
     result.OnImportAfter.AddRange(args.OnImportAfter);
     result.ToFileName = args.ToFileName ?? defaultArgs.ToFileName;
     result.Repeat = args.Repeat ?? defaultArgs.Repeat;
     result.Transactional = args.Transactional || defaultArgs.Transactional;
     return result;
 }