public class Config
{
private static Dictionary<int, string> _domainMap = null;
public static Dictionary<int, string> DomainMap
{
get
{
if (_domainMap == null)
{
_domainMap = GetPublicationDomainMapping(HttpContext.Current.Server.MapPath("~/bin"));
}
return _domainMap;
}
}
private static Dictionary<int, string> GetPublicationDomainMapping(string rootApplicationFolder)
{
Dictionary<int, string> data = new Dictionary<int, string>();
XDocument config = XDocument.Load(rootApplicationFolder + "/config/cd_link_conf.xml");
if (config != null)
{
foreach (var pub in config.Descendants("Publication"))
{
data.Add(Int32.Parse(pub.Attribute("Id").Value), GetHost(pub.Element("Host")));
}
}
return data;
}
private static string GetHost(XElement xElement)
{
string protocol = xElement.Attribute("Protocol") == null ? "http" : xElement.Attribute("Protocol").Value;
string domain = xElement.Attribute("Domain") == null ? "no-domain-in-cd_link_conf" : xElement.Attribute("Domain").Value;
string port = xElement.Attribute("Port") == null ? "" : ":" + xElement.Attribute("Port").Value;
string path = (xElement.Attribute("Path") == null || xElement.Attribute("Path").Value == "/") ? "" : xElement.Attribute("Path").Value;
return String.Format("{0}://{1}{2}{3}", protocol, domain, port, path);
}
}
public class Config
{
private static Dictionary<int, string> _domainMap = null;
public static Dictionary<int, string> DomainMap
{
get
{
if (_domainMap == null)
{
_domainMap = GetPublicationDomainMapping(HttpContext.Current.Server.MapPath("~/bin"));
}
return _domainMap;
}
}
private static Dictionary<int, string> GetPublicationDomainMapping(string rootApplicationFolder)
{
Dictionary<int, string> data = new Dictionary<int, string>();
XDocument config = XDocument.Load(rootApplicationFolder + "/config/cd_link_conf.xml");
if (config != null)
{
foreach (var pub in config.Descendants("Publication"))
{
data.Add(Int32.Parse(pub.Attribute("Id").Value), GetHost(pub.Element("Host")));
}
}
return data;
}
private static string GetHost(XElement xElement)
{
string protocol = xElement.Attribute("Protocol") == null ? "http" : xElement.Attribute("Protocol").Value;
string domain = xElement.Attribute("Domain") == null ? "no-domain-in-cd_link_conf" : xElement.Attribute("Domain").Value;
string port = xElement.Attribute("Port") == null ? "" : ":" + xElement.Attribute("Port").Value;
string path = (xElement.Attribute("Path") == null || xElement.Attribute("Path").Value == "/") ? "" : xElement.Attribute("Path").Value;
return String.Format("{0}://{1}{2}{3}", protocol, domain, port, path);
}
}