Exemple #1
0
        static UrlManager()
        {
            // Create the dictionaries
            HostNameDictionary =
                new Dictionary <string, HostNameInfo>(StringComparer.OrdinalIgnoreCase);
            StateCodeDictionary =
                new Dictionary <string, HostNameInfo>(StringComparer.OrdinalIgnoreCase);
            DesignCodeDictionary =
                new Dictionary <string, HostNameInfo>(StringComparer.OrdinalIgnoreCase);
            CurrentDomainDataCodeCache =
                new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            CurrentDomainOrganizationCodeCache =
                new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            // Get the live host name / test host name mode
            if (
                !bool.TryParse(
                    ConfigurationManager.AppSettings[UseLiveHostNamesKey], out UseLiveHostNames))
            {
                UseLiveHostNames = false;
            }

            if (HttpContext.Current != null)
            {
                var port = HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
                if (!int.TryParse(port, out CurrentPort))
                {
                    CurrentPort = 80;
                }
            }

            var table = Domains.GetAllUrlManagerData();

            foreach (var row in table)
            {
                // We only process entries with the blessed DomainOrganizationCode
                // and that have a non-empty TestServer name
                if (row.DomainOrganizationCode == BlessedDomainOrganizationCode &&
                    !string.IsNullOrWhiteSpace(row.TestServerName))
                {
                    // Create a HostNameInfo object
                    var hostNameInfo = new HostNameInfo
                    {
                        Name        = UseLiveHostNames ? row.DomainServerName : row.TestServerName,
                        LiveName    = row.DomainServerName,
                        IsCanonical = row.IsCanonical,
                        StateCode   = row.StateCode,
                        DesignCode  = row.DomainDesignCode
                    };

                    // Add to the DomainNameDictionary
                    if (HostNameDictionary.ContainsKey(hostNameInfo.Name))
                    {
                        throw new VoteException(
                                  "UrlManager: duplicate host name \"{0\"", hostNameInfo.Name);
                    }
                    HostNameDictionary.Add(hostNameInfo.Name, hostNameInfo);

                    // If canonical, add to the StateCodeDictionary and DesignCodeDictionary
                    if (hostNameInfo.IsCanonical)
                    {
                        if (StateCodeDictionary.ContainsKey(hostNameInfo.StateCode))
                        {
                            throw new VoteException(
                                      "UrlManager: duplicate canonical host name \"{0\" for state \"{1}\"",
                                      hostNameInfo.Name, hostNameInfo.StateCode);
                        }
                        StateCodeDictionary.Add(hostNameInfo.StateCode, hostNameInfo);

                        if (DesignCodeDictionary.ContainsKey(hostNameInfo.DesignCode))
                        {
                            throw new VoteException(
                                      "UrlManager: duplicate canonical host name \"{0\" for design code \"{1}\"",
                                      hostNameInfo.Name, hostNameInfo.DesignCode);
                        }
                        DesignCodeDictionary.Add(hostNameInfo.DesignCode, hostNameInfo);
                    }
                }
            }

            if (!StateCodeDictionary.ContainsKey(AllStatesStateCode))
            {
                throw new VoteException(
                          "UrlManager: there is no canonical host name for the all-states state code (\"{0}\")",
                          AllStatesStateCode);
            }
            CanonicalSiteNameInfo = StateCodeDictionary[AllStatesStateCode];
        }