Beispiel #1
0
        /// <summary>
        /// Create from a DbManager node containing a type
        ///
        /// <DbManager type="assembly.class, assembly">
        ///   <DbDescription type="assembly.class, assembly>
        ///     <!-- see DbDescription.cs -->
        ///   </DbDescription>
        /// </DbManager>
        ///
        /// </summary>
        /// <param name="xmlRoot"></param>
        /// <returns></returns>
        public static IDbManager Create(string xmlRoot, string baseDirectory = null)
        {
            if (string.IsNullOrWhiteSpace(xmlRoot))
            {
                throw new ArgumentException("xmlRoot is invalid", "xmlRoot");
            }


            var root = XElement.Parse(xmlRoot);

            var typeAttribute = root.Attribute("type");

            if (typeAttribute == null)
            {
                throw new ArgumentException("Root element is missing the required 'type' attribute", "xmlRoot");
            }

            IDbManager dbManager;

            try
            {
                dbManager = new ReflectionType(typeAttribute.Value).CreateObject <IDbManager>();
            }
            catch (Exception e)
            {
                throw new ArgumentException(string.Format("Could not create database manager type '{0}'", typeAttribute.Value), "xmlRoot", e);
            }

            dbManager.Description = DbDescription.Create(root.FirstNode.ToString(), baseDirectory);

            return(dbManager);
        }
Beispiel #2
0
        /// <summary>
        /// Create from a DbDescription node containing a type
        ///
        /// &lt;DbDescription type="assembly.class, assembly"&gt;
        ///   ...
        /// &lt;/DbDescription&gt;
        ///
        /// If the DbDescription element does not have an explicit 'type' attribute, Utility.Database.DbDescription is used
        /// </summary>
        /// <param name="xmlRoot"></param>
        /// <returns></returns>
        public static IDbDescription Create(string xmlRoot, string baseDirectory = null)
        {
            if (string.IsNullOrWhiteSpace(xmlRoot))
            {
                throw new ArgumentException("xmlRoot is invalid", "xmlRoot");
            }

            var root = XElement.Parse(xmlRoot);

            DbDescription dbDescription;

            var typeAttribute = root.Attribute("type");

            if (typeAttribute == null)
            {
                dbDescription = new DbDescription();
            }
            else
            {
                try
                {
                    dbDescription = new ReflectionType(typeAttribute.Value).CreateObject <DbDescription>();
                }
                catch (Exception e)
                {
                    throw new ArgumentException(string.Format("Could not create database description type '{0}'", typeAttribute.Value), "xmlRoot", e);
                }
            }

            dbDescription.XmlRoot = xmlRoot;
            if (baseDirectory != null)
            {
                dbDescription.baseDirectory = baseDirectory;
            }

            return(dbDescription);
        }
        /// <summary>
        /// Create from a DbDescription node containing a type
        /// 
        /// &lt;DbDescription type="assembly.class, assembly"&gt;
        ///   ...
        /// &lt;/DbDescription&gt;
        /// 
        /// If the DbDescription element does not have an explicit 'type' attribute, Utility.Database.DbDescription is used
        /// </summary>
        /// <param name="xmlRoot"></param>
        /// <returns></returns>
        public static IDbDescription Create(string xmlRoot, string baseDirectory = null)
        {
            if (string.IsNullOrWhiteSpace(xmlRoot)) throw new ArgumentException("xmlRoot is invalid", "xmlRoot");

            var root = XElement.Parse(xmlRoot);

            DbDescription dbDescription;

            var typeAttribute = root.Attribute("type");
            if (typeAttribute == null)
            {
                dbDescription = new DbDescription();
            }
            else
            {
                try
                {
                    dbDescription = new ReflectionType(typeAttribute.Value).CreateObject<DbDescription>();
                }
                catch (Exception e)
                {
                    throw new ArgumentException(string.Format("Could not create database description type '{0}'", typeAttribute.Value), "xmlRoot", e);
                }
            }

            dbDescription.XmlRoot = xmlRoot;
            if (baseDirectory != null)
            {
                dbDescription.baseDirectory = baseDirectory;
            }

            return dbDescription;
        }