/// <summary> /// Parses specified host and returns the organization and instance. /// </summary> /// <param name="host">Host component of the URL.</param> /// <param name="organization">An organization.</param> /// <param name="instance">An instance.</param> public static void ParseHost(string host, ref Organization organization, ref Instance instance) { Guid[] values = GetCustomUrlFromCache(host); if (values != null) { organization = OrganizationProvider.GetOrganizationFromCache(values[0], true); if (values.Length > 1) { instance = InstanceProvider.GetInstanceFromCache(values[1], values[0], true); } return; } MasterDataSet.CustomUrlRow row = GetCustomUrl(host); if (row != null) { organization = OrganizationProvider.GetOrganizationFromCache(row.OrganizationId, true); if (instance == null) { if (!row.IsInstanceIdNull()) { instance = InstanceProvider.GetInstanceFromCache(row.InstanceId, row.OrganizationId, true); } } } else { string[] segments = host.ToLowerInvariant().Split('.'); if (segments.Length < 2) { return; } string segment = segments[0]; if (string.Compare(segment, FrameworkConfiguration.Current.WebApplication.CustomUrl.AuthenticationTicketDomain, StringComparison.OrdinalIgnoreCase) == 0) { return; } MasterDataSet.CustomUrlRow customUrlRow = null; string instPseudoId = null; string[] pseudos = segment.Split('-'); if (pseudos.Length > 1) { organization = OrganizationProvider.GetOrganizationByPseudoIdFromCache(pseudos[0]); instPseudoId = pseudos[1]; if (organization == null) { customUrlRow = GetCustomUrl(pseudos[0]); if (customUrlRow != null) { organization = OrganizationProvider.GetOrganizationFromCache(customUrlRow.OrganizationId, true); } } } else { organization = OrganizationProvider.GetOrganizationByPseudoIdFromCache(segment); } if (organization == null) { customUrlRow = GetCustomUrl(segment); if (customUrlRow != null) { organization = OrganizationProvider.GetOrganizationFromCache(customUrlRow.OrganizationId, true); if (instance == null) { if (!customUrlRow.IsInstanceIdNull()) { instance = InstanceProvider.GetInstanceFromCache(customUrlRow.InstanceId, customUrlRow.OrganizationId, true); } } } } if (organization != null) { if (instance == null) { if (!string.IsNullOrEmpty(instPseudoId)) { instance = InstanceProvider.GetInstanceByPseudoIdFromCache(instPseudoId, organization.OrganizationId); } } } } if (organization != null) { if (instance == null) { values = new Guid[] { organization.OrganizationId } } ; else { values = new Guid[] { organization.OrganizationId, instance.InstanceId } }; PutCustomUrlToCache(host, values); } }