Ejemplo n.º 1
0
        /// <summary>
        /// Get the organization name and on-line region from the Uri
        /// </summary>
        /// <param name="serviceUri">Service Uri to parse</param>
        /// <param name="isOnPrem">if OnPrem, will be set to true, else false.</param>
        /// <param name="onlineRegion">Name of the CRM on line Region serving this request</param>
        /// <param name="organizationName">Name of the Organization extracted from the Service URI</param>
        public static void GetOrgnameAndOnlineRegionFromServiceUri(Uri serviceUri, out string onlineRegion, out string organizationName, out bool isOnPrem)
        {
            isOnPrem         = false;
            onlineRegion     = string.Empty;
            organizationName = string.Empty;

            //support for detecting a Online URI in the path and rerouting to use that..
            if (IsValidOnlineHost(serviceUri))
            {
                try
                {
                    // Determine deployment region from Uri
                    List <string> elements = new List <string>(serviceUri.Host.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries));
                    organizationName = elements[0];
                    elements.RemoveAt(0);                     // remove the first ( org name ) from the Uri.


                    // construct Prospective CRM Online path.
                    System.Text.StringBuilder buildPath = new System.Text.StringBuilder();
                    foreach (var item in elements)
                    {
                        if (item.Equals("api"))
                        {
                            continue;                             // Skip the .api. when running via this path.
                        }
                        buildPath.AppendFormat("{0}.", item);
                    }
                    string crmKey = buildPath.ToString().TrimEnd('.').TrimEnd('/');
                    buildPath.Clear();
                    if (!string.IsNullOrEmpty(crmKey))
                    {
                        using (CdsDiscoveryServers discoSvcs = new CdsDiscoveryServers())
                        {
                            // drop in the discovery region if it can be determined.  if not, default to scanning.
                            var locatedDiscoServer = discoSvcs.OSDPServers.Where(w => w.DiscoveryServer != null && w.DiscoveryServer.Host.Contains(crmKey)).FirstOrDefault();
                            if (locatedDiscoServer != null && !string.IsNullOrEmpty(locatedDiscoServer.ShortName))
                            {
                                onlineRegion = locatedDiscoServer.ShortName;
                            }
                        }
                    }
                    isOnPrem = false;
                }
                finally
                { }
            }
            else
            {
                isOnPrem = true;
                //Setting organization for the AD/Onpremise Oauth/IFD
                if (serviceUri.Segments.Count() >= 2)
                {
                    organizationName = serviceUri.Segments[1].TrimEnd('/');                     // Fix for bug 294040 http://vstfmbs:8080/tfs/web/wi.aspx?pcguid=12e6d33f-1461-4da4-b3d9-5517a4567489&id=294040
                }
            }
        }
Ejemplo n.º 2
0
 internal static CdsDiscoveryServer GetDiscoveryServerByUri(Uri orgUri)
 {
     if (orgUri != null)
     {
         string OnlineRegon = string.Empty;
         string OrgName     = string.Empty;
         bool   IsOnPrem    = false;
         Utilities.GetOrgnameAndOnlineRegionFromServiceUri(orgUri, out OnlineRegon, out OrgName, out IsOnPrem);
         if (!string.IsNullOrEmpty(OnlineRegon))
         {
             using (CdsDiscoveryServers discoSvcs = new CdsDiscoveryServers())
             {
                 return(discoSvcs.GetServerByShortName(OnlineRegon));
             };
         }
     }
     return(null);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Parses an OrgURI to determine what the supporting discovery server is.
        /// </summary>
        /// <param name="serviceUri">Service Uri to parse</param>
        /// <param name="Geo">Geo Code for region (Optional)</param>
        /// <param name="isOnPrem">if OnPrem, will be set to true, else false.</param>
        public static CdsDiscoveryServer DeterminDiscoveryDataFromOrgDetail(Uri serviceUri, out bool isOnPrem, string Geo = null)
        {
            isOnPrem = false;
            //support for detecting a Live/Online URI in the path and rerouting to use that..
            if (IsValidOnlineHost(serviceUri))
            {
                // Check for Geo code and to make sure that the region is not on our internal list.
                if (!string.IsNullOrEmpty(Geo) &&
                    !(serviceUri.Host.ToUpperInvariant().Contains("CRMLIVETIE.COM") ||
                      serviceUri.Host.ToUpperInvariant().Contains("CRMLIVETODAY.COM"))
                    )
                {
                    using (CdsDiscoveryServers discoSvcs = new CdsDiscoveryServers())
                    {
                        // Find by Geo, if null fall though to next check
                        var locatedDiscoServer = discoSvcs.OSDPServers.Where(w => !string.IsNullOrEmpty(w.GeoCode) && w.GeoCode == Geo).FirstOrDefault();
                        if (locatedDiscoServer != null && !string.IsNullOrEmpty(locatedDiscoServer.ShortName))
                        {
                            return(locatedDiscoServer);
                        }
                    }
                }

                try
                {
                    isOnPrem = false;

                    // Determine deployment region from Uri
                    List <string> elements = new List <string>(serviceUri.Host.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries));
                    elements.RemoveAt(0);                     // remove the first ( org name ) from the Uri.


                    // construct Prospective CDS Online path.
                    System.Text.StringBuilder buildPath = new System.Text.StringBuilder();
                    foreach (var item in elements)
                    {
                        if (item.Equals("api"))
                        {
                            continue;                             // Skip the .api. when running via this path.
                        }
                        buildPath.AppendFormat("{0}.", item);
                    }
                    string crmKey = buildPath.ToString().TrimEnd('.').TrimEnd('/');
                    buildPath.Clear();
                    if (!string.IsNullOrEmpty(crmKey))
                    {
                        using (CdsDiscoveryServers discoSvcs = new CdsDiscoveryServers())
                        {
                            // drop in the discovery region if it can be determined.  if not, default to scanning.
                            var locatedDiscoServer = discoSvcs.OSDPServers.Where(w => w.DiscoveryServer != null && w.DiscoveryServer.Host.Contains(crmKey)).FirstOrDefault();
                            if (locatedDiscoServer != null && !string.IsNullOrEmpty(locatedDiscoServer.ShortName))
                            {
                                return(locatedDiscoServer);
                            }
                        }
                    }
                }
                finally
                {}
            }
            else
            {
                isOnPrem = true;
                return(null);
            }
            return(null);
        }