Пример #1
0
        /// <summary>
        /// Parse a included configuration reference.
        /// </summary>
        /// <param name="parent">Parent Config Node</param>
        /// <param name="elem">XML Element</param>
        private void AddIncludeNode(ConfigPathNode parent, XmlElement elem)
        {
            string configName = elem.GetAttribute(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_NAME);

            if (String.IsNullOrWhiteSpace(configName))
            {
                throw ConfigurationException.PropertyMissingException(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_NAME);
            }
            string path = elem.GetAttribute(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_PATH);

            if (String.IsNullOrWhiteSpace(path))
            {
                throw ConfigurationException.PropertyMissingException(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_PATH);
            }
            string st = elem.GetAttribute(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_TYPE);

            if (String.IsNullOrWhiteSpace(st))
            {
                throw ConfigurationException.PropertyMissingException(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_TYPE);
            }
            EUriScheme type = EUriScheme.none.ParseScheme(st);

            if (type == EUriScheme.none)
            {
                throw ConfigurationException.PropertyMissingException(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_TYPE);
            }
            string vs = elem.GetAttribute(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_VERSION);

            if (String.IsNullOrWhiteSpace(vs))
            {
                throw ConfigurationException.PropertyMissingException(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_VERSION);
            }
            Version version = Version.Parse(vs);

            ConfigIncludeNode node = new ConfigIncludeNode(configuration, parent);

            node.Name       = elem.Name;
            node.ConfigName = configName;
            node.Path       = ReaderTypeHelper.ParseUri(path);
            node.ReaderType = type;
            node.Version    = version;

            using (AbstractReader reader = ReaderTypeHelper.GetReader(type, node.Path))
            {
                reader.Open();
                XmlConfigParser parser = new XmlConfigParser();
                parser.Parse(node.ConfigName, reader, node.Version, settings);
                Configuration config = parser.GetConfiguration();
                node.Reference = config;
                node.Node      = config.RootConfigNode;
                node.UpdateConfiguration(configuration);
            }
            parent.AddChildNode(node);
        }
Пример #2
0
        /// <summary>
        /// Download a resource file specified in the configuration node passed.
        /// </summary>
        /// <param name="fnode">File Resource Node</param>
        /// <returns>Downloaded File path</returns>
        public static string DownloadResource(ConfigResourceFile fnode)
        {
            using (AbstractReader reader = ReaderTypeHelper.GetReader(fnode.Location))
            {
                Conditions.NotNull(reader);
                reader.Open();
                string   f  = FileUtils.WriteLocalFile(reader.GetStream(), fnode.ResourceName, fnode.Configuration.Settings.GetTempDirectory());
                FileInfo fi = new FileInfo(f);
                if (!fi.Exists)
                {
                    throw new ConfigurationException(String.Format("Erorr downloading file: File not created. [file={0}]", fi.FullName));
                }
                fnode.File       = fi;
                fnode.Downloaded = true;

                return(fi.FullName);
            }
        }