示例#1
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);
            }
        }
示例#2
0
        /// <summary>
        /// Parse a new configuration instance.
        /// </summary>
        /// <param name="name">Configuration name.</param>
        /// <param name="reader">Configuration Data reader</param>
        /// <param name="version">Expected configuration version</param>
        /// <param name="settings">Configuration Settings</param>
        /// <param name="password">Decryption Password (if required)</param>
        public override void Parse(string name, AbstractReader reader, Version version, ConfigurationSettings settings, string password = null)
        {
            Preconditions.CheckArgument(name);
            Preconditions.CheckArgument(reader);
            Preconditions.CheckArgument(version);

            if (settings == null)
            {
                settings = new ConfigurationSettings();
            }
            configuration = new Configuration(settings);
            this.settings = settings;
            LogUtils.Info(String.Format("Loading Configuration: [name={0}]", name));
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(reader.GetStream());

                XmlElement root = doc.DocumentElement;
                ParseRootNode(name, version, root, password);

                PostLoad(settings.ReplaceProperties);

                if (!String.IsNullOrWhiteSpace(password))
                {
                    ZConfigEnv.Vault.AddPasscode(configuration, password);
                    LogUtils.Info(String.Format("Added passcode to vault. [configuration={0}]", configuration.Header.Name));
                }
                LogUtils.Debug(String.Format("Configuration Loaded: [name={0}]", configuration.Header.Name), configuration);
            }
            catch (Exception ex)
            {
                LogUtils.Error(ex);
                configuration.SetError(ex);
                throw ex;
            }
        }