Ejemplo n.º 1
0
        /// <summary>
        /// Create a new <see cref="XmlManager"/> instance using the specified <see cref="ManagerElement"/>.
        /// </summary>
        /// <param name="element">The <see cref="ManagerElement"/> to use.</param>
        /// <returns>A new <see cref="XmlManager"/> instance.</returns>
        public static XmlManager Create(ManagerElement element)
        {
            FigaroEnv env = string.IsNullOrEmpty(element.Env) ? null : EnvFactory.Create(element.Env);

            if (env == null && !string.IsNullOrEmpty(element.Env))
            {
                throw new ConfigurationErrorsException(
                          $"The specified environment configuration instance '{element.Env}' does not exist.");
            }
            var opts = ManagerInitOptions.None;

            if (!string.IsNullOrEmpty(element.Options))
            {
                opts = (ManagerInitOptions)Enum.Parse(typeof(ManagerInitOptions), element.Options, true);
            }
            var mgr = env != null ?
                      new XmlManager(env, opts)
            {
                ConfigurationName = element.Name
            } :
            new XmlManager(opts)
            {
                ConfigurationName = element.Name
            };
            var ctype = XmlContainerType.NodeContainer;

            if (!string.IsNullOrEmpty(element.DefaultContainerType))
            {
                ctype = (XmlContainerType)Enum.Parse(typeof(XmlContainerType), element.DefaultContainerType, true);
            }

            mgr.DefaultContainerType = ctype;

            if (element.DefaultPageSize > 0)
            {
                mgr.DefaultPageSize = element.DefaultPageSize;
            }

            if (element.DefaultSequenceIncrement > 0)
            {
                mgr.DefaultSequenceIncrement = element.DefaultSequenceIncrement;
            }

            if (element.DefaultContainerSettings != null)
            {
                mgr.DefaultContainerSettings = ContainerConfigFactory.Create(element.DefaultContainerSettings);
            }

            return(mgr);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a new <see cref="XmlManager"/> instance using the specified <see cref="ManagerElement"/>.
        /// </summary>
        /// <param name="element">The <see cref="ManagerElement"/> to use.</param>
        /// <returns>A new <see cref="XmlManager"/> instance.</returns>
        public static XmlManager Create(ManagerElement element)
        {
            var opts     = ManagerInitOptions.None;
            var homePath = string.IsNullOrEmpty(element.Home) ? string.Empty : PathUtility.ResolvePath(element.Home);

            if (!string.IsNullOrEmpty(element.Options))
            {
                opts = (ManagerInitOptions)Enum.Parse(typeof(ManagerInitOptions), element.Options, true);
            }
            if (!string.IsNullOrEmpty(homePath) && !Directory.Exists(homePath))
            {
                Directory.CreateDirectory(homePath);
            }
            var mgr = string.IsNullOrEmpty(homePath) ?
                      new XmlManager(opts)
            {
                ConfigurationName = element.Name
            } :
            new XmlManager(homePath, opts)
            {
                ConfigurationName = element.Name
            };
            var ctype = XmlContainerType.NodeContainer;

            if (!string.IsNullOrEmpty(element.DefaultContainerType))
            {
                ctype = (XmlContainerType)Enum.Parse(typeof(XmlContainerType), element.DefaultContainerType, true);
            }

            mgr.DefaultContainerType = ctype;

            if (element.DefaultPageSize > 0)
            {
                mgr.DefaultPageSize = element.DefaultPageSize;
            }

            if (element.DefaultSequenceIncrement > 0)
            {
                mgr.DefaultSequenceIncrement = element.DefaultSequenceIncrement;
            }

            if (element.DefaultContainerSettings != null)
            {
                mgr.DefaultContainerSettings = ContainerConfigFactory.Create(element.DefaultContainerSettings);
            }

            return(mgr);
        }