Microsoft.Protocols.TestSuites.Common.ConnectSuccessResponseBody.Parse C# (CSharp) Method

Parse() public static method

Parse the Connect request type success response body.
public static Parse ( byte rawData ) : ConnectSuccessResponseBody
rawData byte The raw data which is returned by server.
return ConnectSuccessResponseBody
        public static ConnectSuccessResponseBody Parse(byte[] rawData)
        {
            ConnectSuccessResponseBody responseBody = new ConnectSuccessResponseBody();
            int index = 0;
            responseBody.StatusCode = BitConverter.ToUInt32(rawData, index);
            index += 4;
            responseBody.ErrorCode = BitConverter.ToUInt32(rawData, index);
            index += 4;
            responseBody.PollsMax = BitConverter.ToUInt32(rawData, index);
            index += 4;
            responseBody.RetryCount = BitConverter.ToUInt32(rawData, index);
            index += 4;
            responseBody.RetryDelay = BitConverter.ToUInt32(rawData, index);
            index += 4;

            // The length in bytes of the unicode string to parse
            int strBytesLen = 0;

            // Find the string with '\0' end
            for (int i = index; i < rawData.Length; i++)
            {
                strBytesLen++;
                if (rawData[i] == 0)
                {
                    break;
                }
            }

            byte[] prefixBuffer = new byte[strBytesLen];
            Array.Copy(rawData, index, prefixBuffer, 0, strBytesLen);
            index += strBytesLen;
            responseBody.DNPrefix = Encoding.ASCII.GetString(prefixBuffer);

            // The length in bytes of the unicode string to parse
            strBytesLen = 0;

            // Find the string with '\0''\0' end
            for (int i = index; i < rawData.Length; i += 2)
            {
                strBytesLen += 2;
                if ((rawData[i] == 0) && (rawData[i + 1] == 0))
                {
                    break;
                }
            }

            byte[] displayNameBuffer = new byte[strBytesLen];
            Array.Copy(rawData, index, displayNameBuffer, 0, strBytesLen);
            index += strBytesLen;
            responseBody.DisplayName = Encoding.Unicode.GetString(displayNameBuffer);
            responseBody.AuxiliaryBufferSize = BitConverter.ToUInt32(rawData, index);
            index += 4;
            responseBody.AuxiliaryBuffer = new byte[responseBody.AuxiliaryBufferSize];
            Array.Copy(rawData, index, responseBody.AuxiliaryBuffer, 0, responseBody.AuxiliaryBufferSize);
            return responseBody;
        }
    }

Usage Example

        /// <summary>
        /// The private method to connect the exchange server through MAPIHTTP transport.
        /// </summary>
        /// <param name="mailStoreUrl">The mail store Url.</param>
        /// <param name="domain">The domain the server is deployed.</param>
        /// <param name="userName">The domain account name</param>
        /// <param name="userDN">User's distinguished name (DN).</param>
        /// <param name="password">user Password.</param>
        /// <returns>If the method succeeds, the return value is 0. If the method fails, the return value is an implementation-specific error code.</returns>
        public uint Connect(string mailStoreUrl, string domain, string userName, string userDN, string password)
        {
            uint returnValue = 0;

            this.domain       = domain;
            this.userPassword = password;
            this.mailStoreUrl = mailStoreUrl;
            this.userName     = userName;

            ConnectRequestBody connectBody = new ConnectRequestBody();

            connectBody.UserDN = userDN;

            // The server MUST NOT compress ROP response payload (rgbOut) or auxiliary payload (rgbAuxOut).
            connectBody.Flags = 0x00000001;

            // The code page in which text data is sent.
            connectBody.Cpid = 1252;

            // The local ID for everything other than sorting.
            connectBody.LcidString = 0x00000409;

            // The local ID for sorting.
            connectBody.LcidSort            = 0x00000409;
            connectBody.AuxiliaryBufferSize = 0;
            connectBody.AuxiliaryBuffer     = new byte[] { };
            if (this.cookies == null)
            {
                this.cookies = new CookieCollection();
            }

            HttpWebResponse response         = SendMAPIHttpRequest(this.site, mailStoreUrl, userName, domain, password, connectBody, "Connect", this.cookies);
            string          transferEncoding = response.Headers["Transfer-Encoding"];
            string          pendingInterval  = response.Headers["X-PendingPeriod"];
            string          responseCode     = response.Headers["X-ResponseCode"];

            if (transferEncoding != null)
            {
                if (string.Compare(transferEncoding, "chunked") == 0)
                {
                    byte[] rawBuffer = ReadHttpResponse(response);

                    returnValue = uint.Parse(responseCode);
                    if (returnValue == 0)
                    {
                        ChunkedResponse            chunkedResponse = ChunkedResponse.ParseChunkedResponse(rawBuffer);
                        ConnectSuccessResponseBody responseSuccess = ConnectSuccessResponseBody.Parse(chunkedResponse.ResponseBodyRawData);
                    }
                    else
                    {
                        this.site.Assert.Fail("Can't connect the server through MAPI over HTTP, the error code is: {0}", responseCode);
                    }
                }
            }

            response.GetResponseStream().Close();
            this.cookies = response.Cookies;

            return(returnValue);
        }
ConnectSuccessResponseBody