private static Assembly LoadAdalAssembly()
        {
            List <Assembly> list;

            lock (ASAzureUtility.GetAppDomainLock("MICROSOFT_ANALYSISSERVICES_XMLA_LIBS_ADAL_LOADING_LOCK"))
            {
                list = (List <Assembly>)AppDomain.CurrentDomain.GetData("MICROSOFT_ANALYSISSERVICES_XMLA_LIBS_LOADED_ADAL_ASSEMBLIES");
                if (list != null)
                {
                    list.ForEach(delegate(Assembly assembly)
                    {
                        AdalRuntimeLibrary.AdalAssembliesDictionary.Add(assembly.FullName, assembly);
                    });
                }
                else
                {
                    list = new List <Assembly>();
                    string[] adalAssemblyNames = AdalRuntimeLibrary.AdalAssemblyNames;
                    for (int i = 0; i < adalAssemblyNames.Length; i++)
                    {
                        string   name      = adalAssemblyNames[i];
                        Assembly assembly2 = AdalRuntimeLibrary.LoadAssemblyFromLocalResource(name);
                        list.Add(assembly2);
                        AdalRuntimeLibrary.AdalAssembliesDictionary.Add(assembly2.FullName, assembly2);
                    }
                    AppDomain.CurrentDomain.SetData("MICROSOFT_ANALYSISSERVICES_XMLA_LIBS_LOADED_ADAL_ASSEMBLIES", list);
                }
            }
            return(list.First <Assembly>());
        }
        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);
        }
Exemple #3
0
 public override string GetExtendedErrorInfo()
 {
     if (!this.IsASAzure || this.httpResponse == null)
     {
         return(string.Empty);
     }
     return(ASAzureUtility.GetExtendedErrorInfo(this.httpResponse));
 }
 internal static void Invalidate()
 {
     lock (ASAzureUtility.GetAppDomainLock("MICROSOFT_ANALYSISSERVICES_XMLA_LIBS_DATA_SOURCE_CLUSTER_URIS_CACHE_USAGE_LOCK"))
     {
         Dictionary <string, Uri> dictionary = (Dictionary <string, Uri>)AppDomain.CurrentDomain.GetData("MICROSOFT_ANALYSISSERVICES_XMLA_LIBS_DATA_SOURCE_CLUSTER_URIS_CACHE");
         if (dictionary != null)
         {
             dictionary.Clear();
         }
     }
 }
            internal static Uri GetCluster(Uri dataSourceUri, string asAzureServerName)
            {
                Uri result;

                lock (ASAzureUtility.GetAppDomainLock("MICROSOFT_ANALYSISSERVICES_XMLA_LIBS_DATA_SOURCE_CLUSTER_URIS_CACHE_USAGE_LOCK"))
                {
                    string key = ASAzureUtility.ClustersCache.getKey(dataSourceUri, asAzureServerName);
                    Dictionary <string, Uri> dictionary = (Dictionary <string, Uri>)AppDomain.CurrentDomain.GetData("MICROSOFT_ANALYSISSERVICES_XMLA_LIBS_DATA_SOURCE_CLUSTER_URIS_CACHE");
                    result = ((dictionary != null) ? (dictionary.ContainsKey(key) ? dictionary[key] : null) : null);
                }
                return(result);
            }
 internal static void AddCluster(Uri dataSourceUri, string asAzureServerName, Uri clusterUri)
 {
     lock (ASAzureUtility.GetAppDomainLock("MICROSOFT_ANALYSISSERVICES_XMLA_LIBS_DATA_SOURCE_CLUSTER_URIS_CACHE_USAGE_LOCK"))
     {
         string key = ASAzureUtility.ClustersCache.getKey(dataSourceUri, asAzureServerName);
         if (AppDomain.CurrentDomain.GetData("MICROSOFT_ANALYSISSERVICES_XMLA_LIBS_DATA_SOURCE_CLUSTER_URIS_CACHE") == null)
         {
             AppDomain.CurrentDomain.SetData("MICROSOFT_ANALYSISSERVICES_XMLA_LIBS_DATA_SOURCE_CLUSTER_URIS_CACHE", new Dictionary <string, Uri>());
         }
         ((Dictionary <string, Uri>)AppDomain.CurrentDomain.GetData("MICROSOFT_ANALYSISSERVICES_XMLA_LIBS_DATA_SOURCE_CLUSTER_URIS_CACHE"))[key] = clusterUri;
     }
 }
        internal static void ThrowConnectionException(WebException ex)
        {
            string text = ex.Message;

            if (ex.Response != null && ex.Response is HttpWebResponse)
            {
                HttpWebResponse httpWebResponse = (HttpWebResponse)ex.Response;
                string          text2           = httpWebResponse.Headers["x-ms-xmlaerror-extended"];
                if (!string.IsNullOrEmpty(text2))
                {
                    text = text2;
                }
                text = string.Format("{0}{1}", text, ASAzureUtility.GetExtendedErrorInfo(httpWebResponse));
            }
            throw new AdomdConnectionException(text, ex);
        }
            internal CacheLocalStorage(object cache, string dataSource)
            {
                this.cache = cache;
                if (!Directory.Exists(AdalRuntimeLibrary.AdalCacheDirectory))
                {
                    Directory.CreateDirectory(AdalRuntimeLibrary.AdalCacheDirectory);
                }
                string mD5Hash = AdalRuntimeLibrary.CacheLocalStorage.GetMD5Hash(dataSource);

                this.cacheFilePath = string.Format("{0}\\{1}_{2}.dat", AdalRuntimeLibrary.AdalCacheDirectory, "managed_asazure", mD5Hash);
                this.cacheFileLock = ASAzureUtility.GetAppDomainLock("MICROSOFT_ANALYSISSERVICES_XMLA_LIBS_ADAL_CACHE_" + mD5Hash);
                this.dataSource    = dataSource;
                Delegate value  = Delegate.CreateDelegate(this.adal.TokenCacheNotificationT, this, AdalRuntimeLibrary.CacheLocalStorage.GetMethodInfo(new Action <object>(this.BeforeAccessNotification)));
                Delegate value2 = Delegate.CreateDelegate(this.adal.TokenCacheNotificationT, this, AdalRuntimeLibrary.CacheLocalStorage.GetMethodInfo(new Action <object>(this.AfterAccessNotification)));
                Delegate value3 = Delegate.CreateDelegate(this.adal.TokenCacheNotificationT, this, AdalRuntimeLibrary.CacheLocalStorage.GetMethodInfo(new Action <object>(this.BeforeWriteNotification)));

                this.adal.BeforeAccessP.SetValue(cache, value, null);
                this.adal.AfterAccessP.SetValue(cache, value2, null);
                this.adal.BeforeWriteP.SetValue(cache, value3, null);
            }
Exemple #9
0
 private void GetRequestStream()
 {
     if (this.httpRequestStream == null)
     {
         this.httpRequest = (HttpWebRequest)WebRequest.Create(this.webSite);
         this.httpRequest.ServicePoint.SetTcpKeepAlive(true, 30000, 30000);
         this.httpRequest.Method            = "POST";
         this.httpRequest.Credentials       = this.credentials;
         this.httpRequest.AllowAutoRedirect = this.allowAutoRedirect;
         this.httpRequest.UserAgent         = "ADOMD.NET";
         this.httpRequest.ContentType       = DataTypes.GetDataTypeFromEnum(this.GetRequestDataType());
         this.httpRequest.SendChunked       = true;
         this.httpRequest.KeepAlive         = true;
         this.httpRequest.UnsafeAuthenticatedConnectionSharing = true;
         this.httpRequest.ConnectionGroupName    = this.connectionSecureGroupName;
         this.httpRequest.AutomaticDecompression = (this.acceptCompressedResponses ? DecompressionMethods.GZip : DecompressionMethods.None);
         this.httpRequest.Timeout         = this.timeoutMs;
         this.httpRequest.CookieContainer = this.cookieContainer;
         if (this.clientCertificate != null)
         {
             this.httpRequest.ClientCertificates.Add(this.clientCertificate);
         }
         if (!this.hasASAzureHeaders && this.soapAction != null)
         {
             this.httpRequest.Headers.Add(this.soapAction);
         }
         this.httpRequest.Headers.Add(this.hasASAzureHeaders ? "x-ms-xmlacaps-negotiation-flags" : "X-Transport-Caps-Negotiation-Flags", base.GetTransportCapabilitiesString());
         if (!this.hasASAzureHeaders && !string.IsNullOrEmpty(this.applicationName))
         {
             this.httpRequest.Headers.Add("SspropInitAppName", this.applicationName);
         }
         if (!string.IsNullOrEmpty(base.SessionID))
         {
             this.httpRequest.Headers.Add(this.hasASAzureHeaders ? "x-ms-xmlasession-id" : "X-AS-SessionID", base.SessionID);
         }
         if (!this.hasASAzureHeaders && base.IsSessionTokenNeeded)
         {
             this.httpRequest.Headers.Add("X-AS-GetSessionToken", true.ToString());
         }
         else
         {
             this.httpRequest.Headers.Remove("X-AS-GetSessionToken");
         }
         if (!this.IsInternalASAzure && !object.Equals(this.ActivityID, Guid.Empty))
         {
             this.httpRequest.Headers.Add(this.hasASAzureHeaders ? "x-ms-parent-activity-id" : "X-AS-ActivityID", this.ActivityID.ToString());
         }
         if (!this.hasASAzureHeaders && !object.Equals(this.RequestID, Guid.Empty))
         {
             this.httpRequest.Headers.Add("X-AS-RequestID", this.RequestID.ToString());
         }
         if (!this.hasASAzureHeaders && !object.Equals(this.CurrentActivityID, Guid.Empty))
         {
             this.httpRequest.Headers.Add("X-AS-CurrentActivityID", this.CurrentActivityID.ToString());
         }
         if (!string.IsNullOrEmpty(this.authorizationHeader))
         {
             this.httpRequest.Headers.Add("Authorization", this.authorizationHeader);
         }
         else if (this.aadTokenHolder != null)
         {
             this.httpRequest.Headers.Add("Authorization", "Bearer " + this.aadTokenHolder.GetValidAccessToken());
         }
         if (this.IsASAzure)
         {
             if (!this.hasASAzureHeaders)
             {
                 throw new ArgumentOutOfRangeException("hasASAzureHeaders");
             }
             if (string.IsNullOrEmpty(this.xmlaServerHeader))
             {
                 throw new ArgumentOutOfRangeException("xmlaServerHeader");
             }
             this.httpRequest.Headers.Add("x-ms-xmlaserver", this.xmlaServerHeader);
         }
         if (this.IsASAzure)
         {
             string generalInfoHeaderValue = ASAzureUtility.GetGeneralInfoHeaderValue(this.connectionInfo.UseAdalCache, this.connectionInfo.UserID);
             this.httpRequest.Headers.Add("x-ms-xmlaapp-general-info", generalInfoHeaderValue);
         }
         if (this.IsInternalASAzure)
         {
             if (this.ParentActivityID == Guid.Empty)
             {
                 throw new ArgumentNullException(string.Format("{0} not set on call context for internal AS Azure usage.", "x-ms-parent-activity-id"));
             }
             if (this.RootActivityID == Guid.Empty)
             {
                 throw new ArgumentNullException(string.Format("{0} not set on call context for internal AS Azure usage.", "x-ms-root-activity-id"));
             }
             this.httpRequest.Headers.Add("x-ms-root-activity-id", this.RootActivityID.ToString());
             this.httpRequest.Headers.Add("x-ms-parent-activity-id", this.ParentActivityID.ToString());
         }
         if (!this.hasASAzureHeaders && !string.IsNullOrEmpty(this.authorizedUserName))
         {
             this.httpRequest.Headers.Add("X-AS-AuthorizedUserName", this.authorizedUserName);
         }
         if (!this.hasASAzureHeaders && !string.IsNullOrEmpty(this.authorizedUserID))
         {
             this.httpRequest.Headers.Add("X-AS-AuthorizedUserID", this.authorizedUserID);
         }
         if (!this.hasASAzureHeaders && !string.IsNullOrEmpty(this.authorizedUserTenant))
         {
             this.httpRequest.Headers.Add("X-AS-AuthorizedUserTenant", this.authorizedUserTenant);
         }
         if (!this.hasASAzureHeaders && !string.IsNullOrEmpty(this.asdbAccessToken))
         {
             this.httpRequest.Headers.Add("X-SAAS-DatabaseAccessToken", this.asdbAccessToken);
         }
         if (!this.hasASAzureHeaders && !string.IsNullOrEmpty(this.RoutingToken))
         {
             this.httpRequest.Headers.Add("X-AS-Routing", this.RoutingToken);
         }
         this.httpRequestStream = new BufferedStream(this.httpRequest.GetRequestStream(), XmlaClient.HttpStreamBufferSize);
     }
 }
Exemple #10
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);
            }
        }