private bool SupportAutoReconnect()
        {
            ITsCapsSet capset = GetServerCapSet(capabilitySetType_Values.CAPSTYPE_GENERAL);

            if (capset != null)
            {
                TS_GENERAL_CAPABILITYSET generalCap = (TS_GENERAL_CAPABILITYSET)capset;
                if (generalCap.extraFlags.HasFlag(extraFlags_Values.AUTORECONNECT_SUPPORTED))
                {
                    return(true);
                }
            }
            return(false);
        }
        private bool SupportFastPathInput()
        {
            ITsCapsSet capset = GetServerCapSet(capabilitySetType_Values.CAPSTYPE_INPUT);

            if (capset != null)
            {
                TS_INPUT_CAPABILITYSET inputCap = (TS_INPUT_CAPABILITYSET)capset;
                if (inputCap.inputFlags.HasFlag(inputFlags_Values.INPUT_FLAG_FASTPATH_INPUT) ||
                    inputCap.inputFlags.HasFlag(inputFlags_Values.INPUT_FLAG_FASTPATH_INPUT2))
                {
                    return(true);
                }
            }
            return(false);
        }
        /// <summary>
        /// Establish RDP Connection
        /// </summary>
        private void EstablishRDPConnection()
        {
            sessionContext = rdpbcgrServerStack.ExpectConnect(timeout);

            #region Connection Initial
            x224ConnectionRequest = ExpectPacket <Client_X_224_Connection_Request_Pdu>(sessionContext, timeout);
            Server_X_224_Connection_Confirm_Pdu confirmPdu
                = rdpbcgrServerStack.CreateX224ConnectionConfirmPdu(sessionContext, selectedProtocols_Values.PROTOCOL_RDP_FLAG, RDP_NEG_RSP_flags_Values.DYNVC_GFX_PROTOCOL_SUPPORTED | RDP_NEG_RSP_flags_Values.EXTENDED_CLIENT_DATA_SUPPORTED);

            SendPdu(confirmPdu);

            if (bool.Parse(detectInfo.IsWindowsImplementation))
            {
                RdpbcgrServerSessionContext orgSession = sessionContext;
                sessionContext = rdpbcgrServerStack.ExpectConnect(timeout);
                if (sessionContext.Identity == orgSession.Identity)
                {
                    sessionContext = rdpbcgrServerStack.ExpectConnect(timeout);
                }
                x224ConnectionRequest = ExpectPacket <Client_X_224_Connection_Request_Pdu>(sessionContext, timeout);
                confirmPdu            = rdpbcgrServerStack.CreateX224ConnectionConfirmPdu(sessionContext, selectedProtocols_Values.PROTOCOL_RDP_FLAG, RDP_NEG_RSP_flags_Values.DYNVC_GFX_PROTOCOL_SUPPORTED | RDP_NEG_RSP_flags_Values.EXTENDED_CLIENT_DATA_SUPPORTED);

                SendPdu(confirmPdu);
            }
            #endregion Connection Initial

            #region Basic Setting Exchange

            mscConnectionInitialPDU = ExpectPacket <Client_MCS_Connect_Initial_Pdu_with_GCC_Conference_Create_Request>(sessionContext, timeout);

            SERVER_CERTIFICATE cert = null;
            int certLen             = 0;
            int dwKeysize           = 2048;

            byte[] privateExp, publicExp, modulus;
            cert    = rdpbcgrServerStack.GenerateCertificate(dwKeysize, out privateExp, out publicExp, out modulus);
            certLen = 120 + dwKeysize / 8;

            Server_MCS_Connect_Response_Pdu_with_GCC_Conference_Create_Response connectRespPdu = rdpbcgrServerStack.CreateMCSConnectResponsePduWithGCCConferenceCreateResponsePdu(
                sessionContext,
                EncryptionMethods.ENCRYPTION_METHOD_128BIT,
                EncryptionLevel.ENCRYPTION_LEVEL_LOW,
                cert,
                certLen,
                MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECL | MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECR);
            SendPdu(connectRespPdu);

            sessionContext.ServerPrivateExponent = new byte[privateExp.Length];
            Array.Copy(privateExp, sessionContext.ServerPrivateExponent, privateExp.Length);

            #endregion Basic Setting Exchange

            #region Channel Connection

            ExpectPacket <Client_MCS_Erect_Domain_Request>(sessionContext, timeout);
            ExpectPacket <Client_MCS_Attach_User_Request>(sessionContext, timeout);

            Server_MCS_Attach_User_Confirm_Pdu attachUserConfirmPdu = rdpbcgrServerStack.CreateMCSAttachUserConfirmPdu(sessionContext);
            SendPdu(attachUserConfirmPdu);

            //Join Channel
            int channelNum = 2;
            if (sessionContext.VirtualChannelIdStore != null)
            {
                channelNum += sessionContext.VirtualChannelIdStore.Length;
            }
            if (sessionContext.IsServerMessageChannelDataSend)
            {
                channelNum++;
            }
            for (int i = 0; i < channelNum; i++)
            {
                Client_MCS_Channel_Join_Request     channelJoinPdu      = ExpectPacket <Client_MCS_Channel_Join_Request>(sessionContext, timeout);
                Server_MCS_Channel_Join_Confirm_Pdu channelJoinResponse = rdpbcgrServerStack.CreateMCSChannelJoinConfirmPdu(
                    sessionContext,
                    channelJoinPdu.mcsChannelId);
                SendPdu(channelJoinResponse);
            }
            #endregion Channel Connection

            #region RDP Security Commencement

            securityExchangePDU = ExpectPacket <Client_Security_Exchange_Pdu>(sessionContext, timeout);

            #endregion RDP Security Commencement

            #region Secure Setting Exchange
            clientInfoPDU = ExpectPacket <Client_Info_Pdu>(sessionContext, timeout);
            #endregion Secure Setting Exchange

            #region Licensing
            Server_License_Error_Pdu_Valid_Client licensePdu = rdpbcgrServerStack.CreateLicenseErrorMessage(sessionContext);
            SendPdu(licensePdu);
            #endregion Licensing

            #region Capabilities Exchange

            RdpbcgrCapSet capSet = new RdpbcgrCapSet();
            capSet.GenerateCapabilitySets();
            Server_Demand_Active_Pdu demandActivePdu = rdpbcgrServerStack.CreateDemandActivePdu(sessionContext, capSet.CapabilitySets);
            SendPdu(demandActivePdu);

            confirmActivePDU            = ExpectPacket <Client_Confirm_Active_Pdu>(sessionContext, timeout);
            clientCapSet                = new RdpbcgrCapSet();
            clientCapSet.CapabilitySets = confirmActivePDU.confirmActivePduData.capabilitySets;
            #endregion Capabilities Exchange

            #region Connection Finalization
            ExpectPacket <Client_Synchronize_Pdu>(sessionContext, timeout);

            Server_Synchronize_Pdu synchronizePdu = rdpbcgrServerStack.CreateSynchronizePdu(sessionContext);
            SendPdu(synchronizePdu);

            Server_Control_Pdu controlCooperatePdu = rdpbcgrServerStack.CreateControlCooperatePdu(sessionContext);
            SendPdu(controlCooperatePdu);

            ExpectPacket <Client_Control_Pdu_Cooperate>(sessionContext, timeout);

            ExpectPacket <Client_Control_Pdu_Request_Control>(sessionContext, timeout);

            Server_Control_Pdu controlGrantedPdu = rdpbcgrServerStack.CreateControlGrantedPdu(sessionContext);
            SendPdu(controlGrantedPdu);


            ITsCapsSet cap = this.clientCapSet.FindCapSet(capabilitySetType_Values.CAPSTYPE_BITMAPCACHE_REV2);
            if (cap != null)
            {
                TS_BITMAPCACHE_CAPABILITYSET_REV2 bitmapCacheV2 = (TS_BITMAPCACHE_CAPABILITYSET_REV2)cap;
                if ((bitmapCacheV2.CacheFlags & CacheFlags_Values.PERSISTENT_KEYS_EXPECTED_FLAG) != 0)
                {
                    ExpectPacket <Client_Persistent_Key_List_Pdu>(sessionContext, timeout);
                }
            }

            ExpectPacket <Client_Font_List_Pdu>(sessionContext, timeout);

            Server_Font_Map_Pdu fontMapPdu = rdpbcgrServerStack.CreateFontMapPdu(sessionContext);
            SendPdu(fontMapPdu);

            #endregion Connection Finalization

            // Init for RDPEDYC
            try
            {
                rdpedycServer = new RdpedycServer(rdpbcgrServerStack, sessionContext);
                rdpedycServer.ExchangeCapabilities(timeout);
            }
            catch (Exception)
            {
                rdpedycServer = null;
            }
        }
        private void CheckSupportedFeatures()
        {
            DetectorUtil.WriteLog("Check specified features support...");

            // Set result according to messages during connection
            if (mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData != null && mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData.earlyCapabilityFlags != null)
            {
                detectInfo.IsSupportNetcharAutoDetect = ((mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData.earlyCapabilityFlags.actualData & (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_NETWORK_AUTODETECT)
                                                         == (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_NETWORK_AUTODETECT);

                detectInfo.IsSupportRDPEGFX = ((mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData.earlyCapabilityFlags.actualData & (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL)
                                               == (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL);

                detectInfo.IsSupportHeartbeatPdu = ((mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData.earlyCapabilityFlags.actualData & (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_HEARTBEAT_PDU)
                                                    == (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_HEARTBEAT_PDU);
            }
            else
            {
                detectInfo.IsSupportNetcharAutoDetect = false;
                detectInfo.IsSupportRDPEGFX           = false;
                detectInfo.IsSupportHeartbeatPdu      = false;
            }

            if (mscConnectionInitialPDU.mcsCi.gccPdu.clientMultitransportChannelData != null)
            {
                detectInfo.IsSupportTransportTypeUdpFECR = (mscConnectionInitialPDU.mcsCi.gccPdu.clientMultitransportChannelData.flags.HasFlag(MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECR));
                detectInfo.IsSupportTransportTypeUdpFECL = (mscConnectionInitialPDU.mcsCi.gccPdu.clientMultitransportChannelData.flags.HasFlag(MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECL));
            }
            else
            {
                detectInfo.IsSupportTransportTypeUdpFECR = false;
                detectInfo.IsSupportTransportTypeUdpFECL = false;
            }

            if (mscConnectionInitialPDU.mcsCi.gccPdu.clientClusterData != null)
            {
                detectInfo.IsSupportServerRedirection = (mscConnectionInitialPDU.mcsCi.gccPdu.clientClusterData.Flags.HasFlag(Flags_Values.REDIRECTION_SUPPORTED));
            }
            else
            {
                detectInfo.IsSupportServerRedirection = false;
            }

            if (mscConnectionInitialPDU.mcsCi.gccPdu.clientNetworkData != null && mscConnectionInitialPDU.mcsCi.gccPdu.clientNetworkData.channelCount > 0)
            {
                detectInfo.IsSupportStaticVirtualChannel = true;
            }
            else
            {
                detectInfo.IsSupportStaticVirtualChannel = false;
            }

            TS_GENERAL_CAPABILITYSET generalCapSet = (TS_GENERAL_CAPABILITYSET)this.clientCapSet.FindCapSet(capabilitySetType_Values.CAPSTYPE_GENERAL);

            if (generalCapSet.extraFlags.HasFlag(extraFlags_Values.AUTORECONNECT_SUPPORTED))
            {
                detectInfo.IsSupportAutoReconnect = true;
            }
            else
            {
                detectInfo.IsSupportAutoReconnect = false;
            }

            detectInfo.IsSupportRDPRFX = false;
            ITsCapsSet codecCapSet = this.clientCapSet.FindCapSet(capabilitySetType_Values.CAPSETTYPE_BITMAP_CODECS);

            if (codecCapSet != null)
            {
                foreach (TS_BITMAPCODEC codec in ((TS_BITMAPCODECS_CAPABILITYSET)codecCapSet).supportedBitmapCodecs.bitmapCodecArray)
                {
                    if (is_REMOTEFX_CODEC_GUID(codec.codecGUID))
                    {
                        detectInfo.IsSupportRDPRFX = true;
                        break;
                    }
                }
            }
            if (detectInfo.IsSupportRDPRFX.Value)
            {
                ITsCapsSet surfcmdCapSet = this.clientCapSet.FindCapSet(capabilitySetType_Values.CAPSETTYPE_SURFACE_COMMANDS);
                if (!((TS_SURFCMDS_CAPABILITYSET)surfcmdCapSet).cmdFlags.HasFlag(CmdFlags_Values.SURFCMDS_STREAMSURFACEBITS))
                {
                    detectInfo.IsSupportRDPRFX = false;
                }
            }
            // Notify the UI for detecting feature finished
            DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);
        }
        /// <summary>
        ///  Expect a client initiated RDP connection sequence.
        /// </summary>
        /// <param name="serverSelectedProtocol">The server selected security protocol.</param>
        /// <param name="enMethod">The server selected security method.</param>
        /// <param name="enLevel">The server selected security level.</param>
        /// <param name="isExtendedClientDataSupported">Indicates if server supports Extended Client Data Blocks.</param>
        /// <param name="expectAutoReconnect">Indicates if expect an Auto-Connect sequence.</param>
        /// <param name="rdpServerVersion">The RDP Sever version</param>
        /// <param name="isMultitransportSupported">Whether support multitransport</param>
        /// <param name="supportRDPEGFX">Whether support RDPEGFX</param>
        /// <param name="supportRestrictedAdminMode">Whether support restricted admin mode</param>
        public void EstablishRDPConnection(
            selectedProtocols_Values serverSelectedProtocol,
            EncryptionMethods enMethod,
            EncryptionLevel enLevel,
            bool isExtendedClientDataSupported,
            bool expectAutoReconnect,
            TS_UD_SC_CORE_version_Values rdpServerVersion,
            bool isMultitransportSupported = false,
            bool supportRDPEGFX            = false, bool supportRestrictedAdminMode = false)
        {
            #region Logging
            this.site.Log.Add(LogEntryKind.Comment, @"EstablishRDPConnection(
                Selected Protocol = {0},
                Encyrption Method = {1},
                Encyrption Level = {2},
                Extended Client Data Supported = {3},
                Auto-Reconnection Expected = {4},
                RDP Version Code= {5}).",
                              serverSelectedProtocol.ToString(), enMethod.ToString(), enLevel.ToString(), isExtendedClientDataSupported, expectAutoReconnect, rdpServerVersion.ToString());
            #endregion

            //Update server config context.
            serverConfig.selectedProtocol = serverSelectedProtocol;
            serverConfig.encryptionMethod = enMethod;
            serverConfig.encryptionLevel  = enLevel;
            serverConfig.isExtendedClientDataSupported = isExtendedClientDataSupported;

            #region Connection Initiation
            //5.4.2.1   Negotiation-Based Approach
            //Once the External Security Protocol (section 5.4.5) handshake has successfully run to completion,
            //the RDP messages resume, continuing with the MCS Connect Initial PDU (section 2.2.1.3).
            //if (serverConfig.encryptedProtocol != EncryptedProtocol.NegotiationCredSsp)
            //{

            ExpectPacket <Client_X_224_Connection_Request_Pdu>(sessionContext, pduWaitTimeSpan);

            RDP_NEG_RSP_flags_Values RDP_NEG_RSP_flags = RDP_NEG_RSP_flags_Values.None;
            if (serverConfig.isExtendedClientDataSupported)
            {
                RDP_NEG_RSP_flags |= RDP_NEG_RSP_flags_Values.EXTENDED_CLIENT_DATA_SUPPORTED;
            }
            if (supportRDPEGFX)
            {
                RDP_NEG_RSP_flags |= RDP_NEG_RSP_flags_Values.DYNVC_GFX_PROTOCOL_SUPPORTED;
            }
            if (supportRestrictedAdminMode)
            {
                RDP_NEG_RSP_flags |= RDP_NEG_RSP_flags_Values.RESTRICTED_ADMIN_MODE_SUPPORTED;
            }
            Server_X_224_Connection_Confirm(serverConfig.selectedProtocol, RDP_NEG_RSP_flags);

            //}
            #endregion

            #region Basic Setting Exchange
            ExpectPacket <Client_MCS_Connect_Initial_Pdu_with_GCC_Conference_Create_Request>(sessionContext, pduWaitTimeSpan);

            Server_MCS_Connect_Response(enMethod, enLevel, rdpServerVersion, NegativeType.None, isMultitransportSupported);
            #endregion

            #region Channel Connection
            ExpectPacket <Client_MCS_Erect_Domain_Request>(sessionContext, pduWaitTimeSpan);

            ExpectPacket <Client_MCS_Attach_User_Request>(sessionContext, pduWaitTimeSpan);

            MCSAttachUserConfirm(NegativeType.None);

            //Join Channel
            int channelNum = 2;
            if (sessionContext.VirtualChannelIdStore != null)
            {
                channelNum += sessionContext.VirtualChannelIdStore.Length;
            }
            if (sessionContext.IsServerMessageChannelDataSend)
            {
                channelNum++;
            }
            for (int i = 0; i < channelNum; i++)
            {
                ExpectPacket <Client_MCS_Channel_Join_Request>(sessionContext, pduWaitTimeSpan);
                MCSChannelJoinConfirm(lastRequestJoinChannelId, NegativeType.None);
            }
            #endregion

            #region RDP Security Commencement
            if (serverConfig.encryptedProtocol == EncryptedProtocol.Rdp)
            {
                ExpectPacket <Client_Security_Exchange_Pdu>(sessionContext, pduWaitTimeSpan);
            }
            #endregion

            #region Secure Setting Exchange
            ExpectPacket <Client_Info_Pdu>(sessionContext, pduWaitTimeSpan);
            if (expectAutoReconnect)
            {
                site.Assert.IsNotNull(tsInfoPacket.extraInfo, "TS_EXTENDED_INFO_PACKET should be provided in Auto-Reconnect sequence.");
                site.Assert.AreNotEqual <ushort>(0, tsInfoPacket.extraInfo.cbAutoReconnectLen, "The autoReconnectCookie should be provided in Auto-Reconnect sequence.");
            }
            #endregion

            #region Licensing
            Server_License_Error_Pdu_Valid_Client(NegativeType.None);
            #endregion

            #region Capabilities Exchange
            Server_Demand_Active(NegativeType.None);

            //Once the Confirm Active PDU has been sent, the client can start sending input PDUs (see section 2.2.8) to the server.
            ExpectPacket <Client_Confirm_Active_Pdu>(sessionContext, pduWaitTimeSpan);
            #endregion

            #region Connection Finalization
            WaitForPacket <Client_Synchronize_Pdu>(sessionContext, pduWaitTimeSpan);

            ServerSynchronize();

            ServerControlCooperate();

            WaitForPacket <Client_Control_Pdu_Cooperate>(sessionContext, pduWaitTimeSpan);

            WaitForPacket <Client_Control_Pdu_Request_Control>(sessionContext, pduWaitTimeSpan);

            ServerControlGrantedControl();

            if (serverConfig.CapabilitySetting.BitmapCacheHostSupportCapabilitySet)
            {
                ITsCapsSet cap = this.clientCapSet.FindCapSet(capabilitySetType_Values.CAPSTYPE_BITMAPCACHE_REV2);
                if (cap != null)
                {
                    TS_BITMAPCACHE_CAPABILITYSET_REV2 bitmapCacheV2 = (TS_BITMAPCACHE_CAPABILITYSET_REV2)cap;
                    if ((bitmapCacheV2.CacheFlags & CacheFlags_Values.PERSISTENT_KEYS_EXPECTED_FLAG) != 0)
                    {
                        WaitForPacket <Client_Persistent_Key_List_Pdu>(sessionContext, pduWaitTimeSpan);
                    }
                }
            }

            WaitForPacket <Client_Font_List_Pdu>(sessionContext, pduWaitTimeSpan);

            ServerFontMap();
            #endregion
        }
        /// <summary>
        /// Establish a RDP connection to detect RDP feature
        /// </summary>
        /// <returns></returns>
        public bool DetectRDPFeature()
        {
            // Establish a RDP connection with RDP client
            try
            {
                StartRDPListening();
                triggerClientRDPConnect(detectInfo.TriggerMethod);
                EstablishRDPConnection();
            }
            catch (Exception e)
            {
                DetectorUtil.WriteLog("Exception occured when establishing RDP connection: " + e.Message);
                DetectorUtil.WriteLog("" + e.StackTrace);
                if (e.InnerException != null)
                {
                    DetectorUtil.WriteLog("**" + e.InnerException.Message);
                    DetectorUtil.WriteLog("**" + e.InnerException.StackTrace);
                }
                DetectorUtil.WriteLog("Failed", false, LogStyle.StepFailed);
                return(false);
            }

            // Notify the UI for establishing RDP connection successfully.
            DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);

            // Set result according to messages during connection
            if (mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData != null && mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData.earlyCapabilityFlags != null)
            {
                detectInfo.IsSupportNetcharAutoDetect = ((mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData.earlyCapabilityFlags.actualData & (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_NETWORK_AUTODETECT)
                                                         == (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_NETWORK_AUTODETECT);

                detectInfo.IsSupportRDPEGFX = ((mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData.earlyCapabilityFlags.actualData & (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL)
                                               == (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL);

                detectInfo.IsSupportHeartbeatPdu = ((mscConnectionInitialPDU.mcsCi.gccPdu.clientCoreData.earlyCapabilityFlags.actualData & (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_HEARTBEAT_PDU)
                                                    == (ushort)earlyCapabilityFlags_Values.RNS_UD_CS_SUPPORT_HEARTBEAT_PDU);
            }
            else
            {
                detectInfo.IsSupportNetcharAutoDetect = false;
                detectInfo.IsSupportRDPEGFX           = false;
                detectInfo.IsSupportHeartbeatPdu      = false;
            }

            if (mscConnectionInitialPDU.mcsCi.gccPdu.clientMultitransportChannelData != null)
            {
                detectInfo.IsSupportTransportTypeUdpFECR = (mscConnectionInitialPDU.mcsCi.gccPdu.clientMultitransportChannelData.flags.HasFlag(MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECR));
                detectInfo.IsSupportTransportTypeUdpFECL = (mscConnectionInitialPDU.mcsCi.gccPdu.clientMultitransportChannelData.flags.HasFlag(MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECL));
            }
            else
            {
                detectInfo.IsSupportTransportTypeUdpFECR = false;
                detectInfo.IsSupportTransportTypeUdpFECL = false;
            }

            if (mscConnectionInitialPDU.mcsCi.gccPdu.clientClusterData != null)
            {
                detectInfo.IsSupportServerRedirection = (mscConnectionInitialPDU.mcsCi.gccPdu.clientClusterData.Flags.HasFlag(Flags_Values.REDIRECTION_SUPPORTED));
            }
            else
            {
                detectInfo.IsSupportServerRedirection = false;
            }

            if (mscConnectionInitialPDU.mcsCi.gccPdu.clientNetworkData != null && mscConnectionInitialPDU.mcsCi.gccPdu.clientNetworkData.channelCount > 0)
            {
                detectInfo.IsSupportStaticVirtualChannel = true;
            }
            else
            {
                detectInfo.IsSupportStaticVirtualChannel = false;
            }

            TS_GENERAL_CAPABILITYSET generalCapSet = (TS_GENERAL_CAPABILITYSET)this.clientCapSet.FindCapSet(capabilitySetType_Values.CAPSTYPE_GENERAL);

            if (generalCapSet.extraFlags.HasFlag(extraFlags_Values.AUTORECONNECT_SUPPORTED))
            {
                detectInfo.IsSupportAutoReconnect = true;
            }
            else
            {
                detectInfo.IsSupportAutoReconnect = false;
            }

            detectInfo.IsSupportRDPRFX = false;
            ITsCapsSet codecCapSet = this.clientCapSet.FindCapSet(capabilitySetType_Values.CAPSETTYPE_BITMAP_CODECS);

            if (codecCapSet != null)
            {
                foreach (TS_BITMAPCODEC codec in ((TS_BITMAPCODECS_CAPABILITYSET)codecCapSet).supportedBitmapCodecs.bitmapCodecArray)
                {
                    if (is_REMOTEFX_CODEC_GUID(codec.codecGUID))
                    {
                        detectInfo.IsSupportRDPRFX = true;
                        break;
                    }
                }
            }
            if (detectInfo.IsSupportRDPRFX.Value)
            {
                ITsCapsSet surfcmdCapSet = this.clientCapSet.FindCapSet(capabilitySetType_Values.CAPSETTYPE_SURFACE_COMMANDS);
                if (!((TS_SURFCMDS_CAPABILITYSET)surfcmdCapSet).cmdFlags.HasFlag(CmdFlags_Values.SURFCMDS_STREAMSURFACEBITS))
                {
                    detectInfo.IsSupportRDPRFX = false;
                }
            }
            // Notify the UI for detecting feature finished
            DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);
            detectInfo.IsSupportRDPEFS = false;
            if (mscConnectionInitialPDU.mcsCi.gccPdu.clientNetworkData != null && mscConnectionInitialPDU.mcsCi.gccPdu.clientNetworkData.channelCount > 0)
            {
                List <CHANNEL_DEF> channels = mscConnectionInitialPDU.mcsCi.gccPdu.clientNetworkData.channelDefArray;
                foreach (CHANNEL_DEF channel in channels)
                {
                    if (channel.name.ToUpper().Contains("RDPDR"))
                    {
                        detectInfo.IsSupportRDPEFS = true;
                        break;
                    }
                }
            }

            // Create Dynamic Virtual Channels to detect protocols supported
            detectInfo.IsSupportRDPEDISP = (CreateEDYCChannel(RDPDetector.RdpedispChannelName));

            if (detectInfo.IsSupportRDPEGFX != null && detectInfo.IsSupportRDPEGFX.Value)
            {
                detectInfo.IsSupportRDPEGFX = CreateEDYCChannel(RDPDetector.RdpegfxChannelName);
            }

            detectInfo.IsSupportRDPEI = (CreateEDYCChannel(RDPDetector.rdpeiChannelName));

            detectInfo.IsSupportRDPEUSB = (CreateEDYCChannel(RDPDetector.RdpeusbChannelName));

            detectInfo.IsSupportRDPEVOR = (CreateEDYCChannel(RDPDetector.RdpegtChannelName) &&
                                           CreateEDYCChannel(RDPDetector.RdpevorControlChannelName) &&
                                           CreateEDYCChannel(RDPDetector.RdpevorDataChannelName));

            // Trigger client to close the RDP connection
            TriggerClientDisconnectAll(detectInfo.TriggerMethod);

            if (detectInfo.IsSupportStaticVirtualChannel != null && detectInfo.IsSupportStaticVirtualChannel.Value &&
                ((detectInfo.IsSupportTransportTypeUdpFECR != null && detectInfo.IsSupportTransportTypeUdpFECR.Value) ||
                 (detectInfo.IsSupportTransportTypeUdpFECL != null && detectInfo.IsSupportTransportTypeUdpFECL.Value)))
            {
                detectInfo.IsSupportRDPEMT  = true;
                detectInfo.IsSupportRDPEUDP = true;
            }
            else
            {
                detectInfo.IsSupportRDPEMT  = false;
                detectInfo.IsSupportRDPEUDP = false;
            }
            // Notify the UI for detecting protocol supported finished
            DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);

            if (this.rdpedycServer != null)
            {
                this.rdpedycServer.Dispose();
                this.rdpedycServer = null;
            }
            if (this.rdpbcgrServerStack != null)
            {
                this.rdpbcgrServerStack.Dispose();
                this.rdpbcgrServerStack = null;
            }

            return(true);
        }