Exemplo n.º 1
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;
        }
Exemplo n.º 2
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);
        }