コード例 #1
0
        /// <summary>
        /// Gets the endpoint for a given MDM monitoring account.
        /// </summary>
        /// <param name="monitoringAccount">Monitoring account for which we want to retrieve the endpoint.</param>
        /// <returns>Returns the URI of the given account, or the fixed endpoint if one was specified at construction time.</returns>
        public Uri GetEndpoint(string monitoringAccount)
        {
            if (this.Endpoint != null)
            {
                // This instance is fixed on a endpoint always return that endpoint.
                return(this.Endpoint);
            }

            StampInformation endpoint = this.GetAndUpdateIfRequiredStampInformation(monitoringAccount);

            return(endpoint.StampMainUri);
        }
コード例 #2
0
        /// <summary>
        /// Gets the endpoint for querying metrics data information of MDM monitoring account.
        /// </summary>
        /// <param name="monitoringAccount">Monitoring account for which we want to retrieve the endpoint.</param>
        /// <returns>Returns the URI of the given account, or the fixed endpoint if one was specified at construction time.</returns>
        public Uri GetMetricsDataQueryEndpoint(string monitoringAccount)
        {
            if (this.Endpoint != null)
            {
                // This instance is fixed on a endpoint always return that endpoint.
                return(this.Endpoint);
            }

            if (this.UseAadUserAuthentication)
            {
                return(this.GetEndpoint(monitoringAccount));
            }

            StampInformation endpoint = this.GetAndUpdateIfRequiredStampInformation(monitoringAccount);

            return(endpoint.StampQueryUri);
        }
コード例 #3
0
        /// <summary>
        /// Helper method that gets the URI for a given account and updates the mapping from account to home stamp.
        /// </summary>
        /// <param name="httpClient">Helper object to be used in the operation.</param>
        /// <param name="globalStampUrl">Global stamp to be targeted in the operation.</param>
        /// <param name="gslbToUris">Stores all created home stamp URI objects in order to avoid duplications.</param>
        /// <param name="targetMap">Map to be updated with the latest information retrived remotely.</param>
        /// <param name="account">Account for which the URI should be retrieved.</param>
        /// <returns>
        /// The URI for the requested account.
        /// </returns>
        private static async Task <StampInformation> GetAndUpdateStampInfoAsync(HttpClient httpClient, string globalStampUrl, ConcurrentDictionary <string, Uri> gslbToUris, ConcurrentDictionary <string, StampInformation> targetMap, string account)
        {
            var requestUrl = $"{globalStampUrl}/public/monitoringAccount/{account}/homeStamp";
            var response   = await HttpClientHelper.GetResponse(new Uri(requestUrl), HttpMethod.Get, httpClient, null, null).ConfigureAwait(false);

            var    homeStampGslbHostname = JsonConvert.DeserializeObject <string>(response.Item1);
            string queryEndpoint         = null;

            if (!string.IsNullOrEmpty(homeStampGslbHostname))
            {
                queryEndpoint = await SafeGetStampMetricDataQueryEndpointHostNameAsync(httpClient, "https://" + homeStampGslbHostname).ConfigureAwait(false);
            }

            Uri homeGslbUri;
            var homeGslbKey = string.IsNullOrWhiteSpace(homeStampGslbHostname) ? string.Empty : homeStampGslbHostname;

            if (!gslbToUris.TryGetValue(homeGslbKey, out homeGslbUri))
            {
                homeGslbUri = new Uri("https://" + homeStampGslbHostname);
                gslbToUris.AddOrUpdate(homeGslbKey, homeGslbUri, (_, uri) => homeGslbUri);
            }

            Uri queryEndpointUri;

            if (!string.IsNullOrEmpty(queryEndpoint))
            {
                queryEndpointUri = new Uri("https://" + queryEndpoint);
            }
            else
            {
                queryEndpointUri = homeGslbUri;
            }

            var stampInfo = new StampInformation(homeGslbUri, queryEndpointUri);

            targetMap.AddOrUpdate(
                account,
                stampInfo,
                (_, uri) => stampInfo);

            return(stampInfo);
        }