Example #1
0
        public override DataType GetResponseDataType()
        {
            DataType result;

            try
            {
                if (this.endOfStream)
                {
                    result = DataType.Undetermined;
                }
                else
                {
                    if (this.dimeReader == null)
                    {
                        this.dimeReader        = new DimeReader(this.bufferedStream);
                        this.dimeRecordForRead = this.dimeReader.ReadRecord();
                        if (TcpStream.TRACESWITCH.TraceVerbose)
                        {
                            StackTrace stackTrace = new StackTrace();
                            stackTrace.GetFrame(1).GetMethod();
                        }
                        this.DetermineNegotiatedOptions();
                    }
                    if (this.dimeRecordForRead == null)
                    {
                        if (TcpStream.TRACESWITCH.TraceVerbose)
                        {
                            StackTrace stackTrace2 = new StackTrace();
                            stackTrace2.GetFrame(1).GetMethod();
                        }
                        this.dimeReader.Close();
                        this.dimeReader  = null;
                        this.endOfStream = true;
                        result           = DataType.Undetermined;
                    }
                    else
                    {
                        DataType dataTypeFromString = DataTypes.GetDataTypeFromString(this.dimeRecordForRead.Type);
                        if (TcpStream.TRACESWITCH.TraceVerbose)
                        {
                            StackTrace stackTrace3 = new StackTrace();
                            stackTrace3.GetFrame(1).GetMethod();
                        }
                        if (dataTypeFromString == DataType.Unknown)
                        {
                            throw new AdomdUnknownResponseException(XmlaSR.Dime_DataTypeNotSupported(this.dimeRecordForRead.Type), "");
                        }
                        result = dataTypeFromString;
                    }
                }
            }
            catch (XmlaStreamException)
            {
                throw;
            }
            catch (IOException innerException)
            {
                throw new XmlaStreamException(innerException);
            }
            catch (SocketException innerException2)
            {
                throw new XmlaStreamException(innerException2);
            }
            return(result);
        }
Example #2
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);
     }
 }
Example #3
0
 public override void Write(byte[] buffer, int offset, int size)
 {
     if (this.disposed)
     {
         throw new ObjectDisposedException(null);
     }
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer");
     }
     if (offset < 0)
     {
         throw new ArgumentOutOfRangeException("offset");
     }
     if (size < 0)
     {
         throw new ArgumentOutOfRangeException("size");
     }
     if (size + offset > buffer.Length)
     {
         throw new ArgumentException(XmlaSR.InvalidArgument, "buffer");
     }
     try
     {
         if (size > 0)
         {
             if (this.dimeWriter == null)
             {
                 this.dimeWriter = new DimeWriter(this.bufferedStream);
                 this.dimeWriter.DefaultChunkSize = this.dimeChunkSize;
                 this.dimeWriter.Options          = base.GetTransportCapabilities();
                 this.dimeRecordForWrite          = this.dimeWriter.CreateRecord(null, DataTypes.GetDataTypeFromEnum(this.GetRequestDataType()), TypeFormatEnum.MediaType, -1);
                 if (TcpStream.TRACESWITCH.TraceVerbose)
                 {
                     StackTrace stackTrace = new StackTrace();
                     stackTrace.GetFrame(1).GetMethod();
                 }
             }
             this.dimeRecordForWrite.WriteBody(buffer, offset, size);
         }
     }
     catch (XmlaStreamException)
     {
         throw;
     }
     catch (IOException innerException)
     {
         throw new XmlaStreamException(innerException);
     }
     catch (SocketException innerException2)
     {
         throw new XmlaStreamException(innerException2);
     }
 }
Example #4
0
        private void ReadHeader()
        {
            byte[] array = new byte[12];
            DimeRecord.ForceRead(this.m_stream, array, 12);
            this.m_version = (byte)((array[0] & 248) >> 3);
            if (this.m_version != 1)
            {
                throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_VersionNotSupported((int)this.m_version), "");
            }
            DimeRecord.HeaderFlagsEnum headerFlagsEnum = (DimeRecord.HeaderFlagsEnum)(array[0] & 7);
            this.m_chunked        = ((byte)(headerFlagsEnum & DimeRecord.HeaderFlagsEnum.ChunkedRecord) != 0);
            this.m_beginOfMessage = ((byte)(headerFlagsEnum & DimeRecord.HeaderFlagsEnum.BeginOfMessage) != 0);
            this.m_endOfMessage   = ((byte)(headerFlagsEnum & DimeRecord.HeaderFlagsEnum.EndOfMessage) != 0);
            if (this.m_chunked && this.m_endOfMessage)
            {
                throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_InvalidHeaderFlags(this.m_beginOfMessage ? 1 : 0, 1, 1), "");
            }
            if ((!this.m_chunked && !this.m_endOfMessage) || (!this.m_firstChunk && this.m_beginOfMessage))
            {
                throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_OnlySingleRecordMessagesAreSupported, "");
            }
            this.m_typeFormat = (TypeFormatEnum)((array[1] & 240) >> 4);
            this.m_reserved   = (byte)(array[1] & 15);
            int num  = ((int)array[2] << 8) + (int)array[3];
            int num2 = ((int)array[4] << 8) + (int)array[5];
            int num3 = ((int)array[6] << 8) + (int)array[7];

            this.m_contentLength = ((int)array[8] << 24) + ((int)array[9] << 16) + ((int)array[10] << 8) + (int)array[11];
            if (this.m_firstChunk)
            {
                if (this.m_typeFormat != TypeFormatEnum.MediaType)
                {
                    throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_TypeFormatShouldBeMedia(this.m_typeFormat.ToString()), "");
                }
                if (num3 <= 0)
                {
                    throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_DataTypeShouldBeSpecifiedOnTheFirstChunk, "");
                }
            }
            else
            {
                if (this.m_typeFormat != TypeFormatEnum.Unchanged)
                {
                    throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_TypeFormatShouldBeUnchanged(this.m_typeFormat.ToString()), "");
                }
                if (num3 != 0)
                {
                    throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_DataTypeIsOnlyForTheFirstChunk, "");
                }
                if (num2 != 0)
                {
                    throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_IDIsOnlyForFirstChunk, "");
                }
                if (num != 0)
                {
                    throw new AdomdUnknownResponseException(XmlaSR.UnknownServerResponseFormat, "Unexpected non-zero options length");
                }
            }
            if (this.m_reserved != 0)
            {
                throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_ReservedFlagShouldBeZero(this.m_reserved), "");
            }
            if (num > 0)
            {
                array = new byte[DimeRecord.RoundUp(num)];
                DimeRecord.ForceRead(this.m_stream, array, array.Length);
                this.m_Options.FromBytes(array);
            }
            if (num2 > 0)
            {
                array = new byte[DimeRecord.RoundUp(num2)];
                DimeRecord.ForceRead(this.m_stream, array, array.Length);
            }
            if (num3 > 0)
            {
                array = new byte[DimeRecord.RoundUp(num3)];
                DimeRecord.ForceRead(this.m_stream, array, array.Length);
                this.m_type = Encoding.ASCII.GetString(array, 0, num3);
                if (!DataTypes.IsSupportedDataType(this.m_type))
                {
                    throw new AdomdUnknownResponseException(XmlaSR.DimeRecord_DataTypeNotSupported(this.m_type), "");
                }
            }
            this.m_firstChunk = false;
        }