Microsoft.Protocols.TestSuites.Common.RpcAdapter.Connect C# (CSharp) Method

Connect() public method

It establishes a new Session Context with the server by calling native methods.
public Connect ( string server, string domain, string userName, string userDN, string password, string userSpn, MapiContext mapiContext, string options ) : IntPtr
server string The server name.
domain string The domain the server is deployed
userName string The domain account name.
userDN string User's distinguished name (DN).
password string >user Password.
userSpn string User's SPN.
mapiContext MapiContext The default parameters for rpc call, such as authentication level, authentication method, whether to compress request.
options string proxy attribute
return System.IntPtr
        public IntPtr Connect(string server, string domain, string userName, string userDN, string password, string userSpn, MapiContext mapiContext, string options)
        {
            // The default parameter for out session handle.
            IntPtr pcxh = IntPtr.Zero;

            // CreateIdentity
            NativeMethods.CreateIdentity(
                domain,
                userName,
                password);

            uint status = NativeMethods.BindToServer(server, mapiContext.AuthenLevel, mapiContext.AuthenService, mapiContext.TransportSequence.ToLower(), mapiContext.RpchUseSsl, mapiContext.RpchAuthScheme, userSpn, options, mapiContext.SetUuid);
            if (status != 0)
            {
                throw new Exception("Could not create binding handle with server");
            }

            this.bindingHandle = NativeMethods.GetBindHandle();

            int waitTime = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.site));
            int maxRetryCount = int.Parse(Common.GetConfigurationPropertyValue("ConnectRetryCount", this.site));

            int retryCount = 0;
            do
            {
                status = this.Connect_Internal(ref pcxh, userDN, ref mapiContext);
                if (status >= 1700 && status <= 1799)
                {
                    // If status is between 1700 and 1799, try to connect again.
                    retryCount++;
                    System.Threading.Thread.Sleep(waitTime);

                    if (retryCount > 0)
                    {
                        this.site.Log.Add(LogEntryKind.Comment, "Can't connect to RPC server, will try to connect the server again. Current retry number is {0}.", retryCount);
                    }
                }
                else
                {
                    break;
                }
            }
            while (retryCount < maxRetryCount);

            if (status != 0)
            {
                string errorCodeHexString = "0x" + status.ToString("X8");
                string errorCodeMeaning = GetErrorCodeMeaning(errorCodeHexString);
                string errorCodeDescription = string.Empty;
                if (string.IsNullOrEmpty(errorCodeMeaning))
                {
                    errorCodeDescription = string.Format("Error code '{0}' is not defined in protocol MS-OXCRPC. The error message is: {1}", errorCodeHexString, (new Win32Exception((int)status)).ToString());
                }
                else
                {
                    errorCodeDescription = string.Format("Error code '{0}' is defined in protocol MS-OXCRPC as: {1}", errorCodeHexString, errorCodeMeaning);
                }

                this.site.Assert.Fail("Connect method returned an error: {0}. {1}", errorCodeHexString, errorCodeDescription);
            }

            return pcxh;
        }