/// <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); }
/// <summary> /// Constructor with file URI. /// </summary> /// <param name="location">File URI</param> public FileReader(Uri location) { Preconditions.CheckArgument(location); EUriScheme type = EUriScheme.none.GetUriType(location); if (type != EUriScheme.file) { var ex = new ReaderException(String.Format("Invalid URI : [expected={0}][actual={1}]", EUriScheme.file.ToString(), type.ToString())); State.SetError(EReaderState.Error, ex); throw ex; } filename = location.LocalPath; }
/// <summary> /// Get a configuration reader instance based on the type. /// </summary> /// <param name="type">Reader Type</param> /// <param name="uri">URI</param> /// <returns>Configuration Reader</returns> public static AbstractReader GetReader(EUriScheme type, Uri uri) { switch (type) { case EUriScheme.file: return(new FileReader(uri)); case EUriScheme.http: case EUriScheme.https: return(new RemoteReader(uri)); case EUriScheme.ftp: return(new FtpRemoteReader(uri)); } return(null); }
/// <summary> /// Generate the URI scheme prefix for the Scheme type. /// </summary> /// <param name="type">URI Scheme Type</param> /// <returns>URI Scheme prefix</returns> public static string GetUriScheme(EUriScheme type) { switch (type) { case EUriScheme.file: return(String.Format("{0}{1}", Uri.UriSchemeFile, Uri.SchemeDelimiter)); case EUriScheme.ftp: return(String.Format("{0}{1}", Uri.UriSchemeFtp, Uri.SchemeDelimiter)); case EUriScheme.http: return(String.Format("{0}{1}", Uri.UriSchemeHttp, Uri.SchemeDelimiter)); case EUriScheme.https: return(String.Format("{0}{1}", Uri.UriSchemeHttps, Uri.SchemeDelimiter)); } return(null); }
/// <summary> /// Parse the reader type based on the URI. /// </summary> /// <param name="type">Reference Type</param> /// <param name="uri">URI Path</param> /// <returns>Reader Type.</returns> public static EUriScheme GetUriType(this EUriScheme type, Uri location) { if (location.Scheme == Uri.UriSchemeFile) { return(EUriScheme.file); } else if (location.Scheme == Uri.UriSchemeFtp) { return(EUriScheme.ftp); } else if (location.Scheme == Uri.UriSchemeHttp) { return(EUriScheme.http); } else if (location.Scheme == Uri.UriSchemeHttps) { return(EUriScheme.https); } return(EUriScheme.none); }
/// <summary> /// Get a configuration reader instance based on the URI. /// </summary> /// <param name="uri">URI</param> /// <returns>Configuration Reader</returns> public static AbstractReader GetReader(Uri uri) { EUriScheme type = EUriScheme.none.GetUriType(uri); return(GetReader(type, uri)); }
/// <summary> /// Parse the input string as the URI scheme enum. /// /// </summary> /// <param name="type">URI Scheme Enum</param> /// <param name="value">String input</param> /// <returns>URI Scheme Enum</returns> public static EUriScheme ParseScheme(this EUriScheme type, string value) { value = value.ToLower(); return((EUriScheme)Enum.Parse(typeof(EUriScheme), value)); }
/// <summary> /// Parse the input string as the URI scheme enum. /// /// </summary> /// <param name="type">URI Scheme Enum</param> /// <param name="value">String input</param> /// <returns>URI Scheme Enum</returns> public static EUriScheme ParseScheme(this EUriScheme type, string value) { value = value.ToLower(); return(Enum.Parse <EUriScheme>(value)); }