Skip to main content
changed language to c#
Source Link
Nuno Linhares
  • 29.1k
  • 3
  • 42
  • 91
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);
    }

    
}
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);
    }

    
}
added 29 characters in body
Source Link
Will Price
  • 16.4k
  • 1
  • 21
  • 61
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);
    }

    
}
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);
    }

    
}
Source Link
Will Price
  • 16.4k
  • 1
  • 21
  • 61

I am almost 100% sure its not possible now, so here is a .NET class to get what you need (as a static property which is loaded only once...

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);
    }

    
}