internal static Uri ResolveActualClusterUri(Uri dataSourceUri, string asAzureServerName, AadTokenHolder aadTokenHolder, ref TimeoutUtils.TimeLeft timeLeft, TimeoutUtils.OnTimoutAction timeoutAction)
        {
            Uri uri = ASAzureUtility.ClustersCache.GetCluster(dataSourceUri, asAzureServerName);

            if (uri != null)
            {
                return(uri);
            }
            try
            {
                using (new TimeoutUtils.TimeRestrictedMonitor(timeLeft, timeoutAction))
                {
                    Uri uri2 = new UriBuilder(dataSourceUri)
                    {
                        Path = "/webapi/clusterResolve"
                    }.Uri;
                    ASAzureUtility.NameResolutionRequest requestObject = new ASAzureUtility.NameResolutionRequest
                    {
                        ServerName = asAzureServerName
                    };
                    ASAzureUtility.NameResolutionResult nameResolutionResult = ASAzureUtility.PostHttpJsonData <ASAzureUtility.NameResolutionRequest, ASAzureUtility.NameResolutionResult>(uri2, requestObject, aadTokenHolder.GetValidAccessToken(), timeLeft.TimeMs);
                    uri = new UriBuilder(dataSourceUri)
                    {
                        Host = nameResolutionResult.ClusterFqdn
                    }.Uri;
                    ASAzureUtility.ClustersCache.AddCluster(dataSourceUri, asAzureServerName, uri);
                }
            }
            catch (WebException ex)
            {
                ASAzureUtility.ThrowConnectionException(ex);
            }
            return(uri);
        }
Example #2
0
        private void GetResponseStream()
        {
            if (this.outdatedVersion)
            {
                throw new AdomdConnectionException(XmlaSR.Connection_WorkbookIsOutdated);
            }
            if (this.httpResponseStream == null)
            {
                try
                {
                    if (this.logonWindowsIdentity != null)
                    {
                        using (WindowsIdentity current = WindowsIdentity.GetCurrent())
                        {
                            if (this.logonWindowsIdentity.User != current.User)
                            {
                                //using (this.logonWindowsIdentity.Impersonate())
                                //{
                                //	this.httpResponse = (HttpWebResponse)this.httpRequest.GetResponse();
                                //	goto IL_88;
                                //}
                            }
                            this.httpResponse = (HttpWebResponse)this.httpRequest.GetResponse();
IL_88:
                            goto IL_AA;
                        }
                    }
                    this.httpResponse = (HttpWebResponse)this.httpRequest.GetResponse();
IL_AA:
                    int statusCode = (int)this.httpResponse.StatusCode;
                    if (statusCode >= 300 && statusCode <= 399)
                    {
                        ASAzureUtility.ClustersCache.Invalidate();
                        throw new AdomdConnectionException(XmlaSR.Connection_AnalysisServicesInstanceWasMoved);
                    }
                    if (!this.hasASAzureHeaders)
                    {
                        string value = this.httpResponse.Headers["OutdatedVersion"];
                        if (!string.IsNullOrEmpty(value))
                        {
                            this.outdatedVersion = true;
                            throw new AdomdConnectionException(XmlaSR.Connection_WorkbookIsOutdated);
                        }
                    }
                    if (!this.hasASAzureHeaders)
                    {
                        this.RoutingToken = this.httpResponse.Headers["X-AS-Routing"];
                    }
                    this.DetermineNegotiatedOptions();
                }
                catch (WebException ex)
                {
                    if (ex.Response == null)
                    {
                        throw;
                    }
                    if (this.IsASAzure)
                    {
                        ASAzureUtility.ThrowConnectionException(ex);
                    }
                    HttpStatusCode statusCode2 = ((HttpWebResponse)ex.Response).StatusCode;
                    if (HttpStatusCode.InternalServerError == statusCode2)
                    {
                        this.httpResponse = (HttpWebResponse)ex.Response;
                        this.DetermineNegotiatedOptions();
                        Match match = HttpStream.contentTypeRegex.Match(this.httpResponse.ContentType);
                        if (!match.Success)
                        {
                            throw;
                        }
                        this.streamException = new XmlaStreamException(ex);
                    }
                    else
                    {
                        if (ex.Status == WebExceptionStatus.ProtocolError && statusCode2 == HttpStatusCode.Unauthorized)
                        {
                            throw new XmlaStreamException(ex, ConnectionExceptionCause.AuthenticationFailed);
                        }
                        throw;
                    }
                }
                finally
                {
                    this.httpRequestStream = null;
                }
                this.httpResponseStream = new BufferedStream(this.httpResponse.GetResponseStream(), XmlaClient.HttpStreamBufferSize);
            }
        }