A connect request body for Mailbox Server Endpoint.
상속: MailboxRequestBodyBase
        /// <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);
        }
        /// <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;
        }
        /// <summary>
        /// This method is used to establish a Session Context with the server with specified user.
        /// </summary>
        /// <param name="userName">The UserName used to connect with server.</param>
        /// <param name="password">The password used to connect with server.</param>
        /// <param name="userDN">The UserESSDN used to connect with server.</param>
        /// <param name="cookies">Cookies used to identify the Session Context.</param>
        /// <param name="responseBody">The response body of the Connect request type.</param>
        /// <param name="webHeaderCollection">The web headers of the Connect request type.</param>
        /// <param name="httpStatus">The HTTP call response status.</param>
        /// <returns>The status code of the Connect request type.</returns>
        public uint Connect(string userName, string password, string userDN, ref CookieCollection cookies, out MailboxResponseBodyBase responseBody, ref WebHeaderCollection webHeaderCollection, out HttpStatusCode httpStatus)
        {
            responseBody = null;
            byte[] rgbAuxIn = new byte[] { };
            byte[] rawBuffer;

            // Prepare the connect request body.
            ConnectRequestBody connectRequestBody = new ConnectRequestBody();
            connectRequestBody.UserDN = userDN;
            connectRequestBody.Flags = ConstValues.ConnectionFlag;
            connectRequestBody.Cpid = ConstValues.CodePageId;
            connectRequestBody.LcidString = ConstValues.DefaultLocale;
            connectRequestBody.LcidSort = ConstValues.DefaultLocale;
            connectRequestBody.AuxiliaryBufferSize = (uint)rgbAuxIn.Length;
            connectRequestBody.AuxiliaryBuffer = rgbAuxIn;
                        
            // Send the HTTP request and get the HTTP response.
            HttpWebResponse response = this.SendMAPIHttpRequest(userName, password, connectRequestBody, ServerEndpoint.MailboxServerEndpoint, cookies, webHeaderCollection, out rawBuffer);
            webHeaderCollection = response.Headers;
            httpStatus = response.StatusCode;
            uint responseCode = AdapterHelper.GetFinalResponseCode(response.Headers["X-ResponseCode"]);
            
            if (httpStatus != HttpStatusCode.OK)
            {
                return 0;
            }

            // Read the HTTP response buffer and parse the response to correct format.
            CommonResponse commonResponse = CommonResponse.ParseCommonResponse(rawBuffer);
            
            if (responseCode == 0)
            {
                Site.Assert.IsNotNull(commonResponse.ResponseBodyRawData, "The response body should contains data.");
                uint statusCode = BitConverter.ToUInt32(commonResponse.ResponseBodyRawData, 0);
                if (statusCode == 0)
                {
                    // Connect succeeded when the StatusCode field equals zero.
                    ConnectSuccessResponseBody responseSuccess = ConnectSuccessResponseBody.Parse(commonResponse.ResponseBodyRawData);
                    responseBody = responseSuccess;

                    this.VerifyConnectSuccessResponseBody(responseSuccess);
                }
                
                this.VerifyHTTPS(response);
                this.VerifyAuthentication(response);
                this.VerifyAutoDiscover(httpStatus, ServerEndpoint.MailboxServerEndpoint);
                this.VerifyHTTPHeaders(response.Headers);
                this.VerifyAdditionalHeaders(commonResponse.AdditionalHeaders);
                this.VerifyConnectResponse(response);
                this.VerifyConnectOrBindResponse(response.Headers);
                this.VerifyRequestTypesForMailboxServerEndpoint(response.Headers, commonResponse);
                this.VerifyResponseMetaTags(commonResponse.MetaTags);
            }

            this.VerifyRespondingToAllRequestTypeRequests(response, commonResponse, responseCode);
            response.GetResponseStream().Close();
            AdapterHelper.SessionContextCookies = response.Cookies;
            cookies = response.Cookies;
            return responseCode;
        }