Inheritance: IDisposable
        /// <summary>
        /// Initialize this protocol with create control and data channels.
        /// </summary>
        /// <param name="rdpedycServer">RDPEDYC Server instance</param>
        /// <param name="transportType">selected transport type for created channels</param>
        /// <returns>true if client supports this protocol; otherwise, return false.</returns>
        public bool ProtocolInitialize(RdpedycServer rdpedycServer, DynamicVC_TransportType transportType = DynamicVC_TransportType.RDP_TCP)
        {
            if (!rdpedycServer.IsMultipleTransportCreated(transportType))
            {
                rdpedycServer.CreateMultipleTransport(transportType);
            }

            this.rdpegtServer = new RdpegtServer(rdpedycServer);

            bool success = false;

            // Create RDPEGT Channel
            try
            {
                success = rdpegtServer.CreateRdpegtDvc(waitTime);
            }
            catch (Exception e)
            {
                Site.Log.Add(LogEntryKind.Comment, "Exception occurred when creating RDPEGT channels: {1}", e.Message);
            }

            return success;
        }
        /// <summary>
        /// Initialize this protocol with create graphic DVC channels.
        /// </summary>
        /// <param name="rdpedycServer">RDPEDYC server instance</param>
        /// <param name="transportType">Transport type</param>
        /// <returns>True if client supports this protocol; otherwise, return false.</returns>
        public bool ProtocolInitialize(RdpedycServer rdpedycServer, DynamicVC_TransportType transportType = DynamicVC_TransportType.RDP_TCP)
        {
            if (!rdpedycServer.IsMultipleTransportCreated(transportType))
            {
                rdpedycServer.CreateMultipleTransport(transportType);
            }

            return CreateEGFXDvc(rdpedycServer, transportType);
        }
        /// <summary>
        /// Create graphic DVC channel.
        /// </summary>
        /// <param name="rdpedycServer">RDPEDYC server instance</param>
        /// <param name="transportType">Transport type</param>
        /// <param name="channelId">Channel Id</param>
        /// <returns>True if success; otherwise, return false.</returns>
        public bool CreateEGFXDvc(RdpedycServer rdpedycServer, DynamicVC_TransportType transportType, uint? channelId = null)
        {
            this.egfxServer = new RdpegfxServer(rdpedycServer);

            bool success = false;

            try
            {
                success = egfxServer.CreateRdpegfxDvc(waitTime, transportType, channelId);
            }
            catch (Exception e)
            {
                Site.Log.Add(LogEntryKind.Comment, "Exception occurred when creating RDPEGFX channel: {0}.", e.Message);
            }

            return success;
        }
        /// <summary>
        /// Inherited from ManagedAdapterBase.
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                rdpedycServer = null;
            }

            base.Dispose(disposing);
        }
        /// <summary>
        /// Inherited from ManagedAdapterBase.
        /// </summary>
        public override void Reset()
        {
            rdpedycServer = null;

            base.Reset();
        }
 /// <summary>
 /// Initialize this protocol with create control and data channels.
 /// </summary>
 /// <param name="rdpedycServer">RDPEDYC Server instance</param>
 /// <param name="transportType">selected transport type for created channels</param>
 /// <returns>true if client supports this protocol; otherwise, return false.</returns>
 public bool ProtocolInitialize(RdpedycServer rdpedycServer)
 {
     this.rdpedycServer = rdpedycServer;
     this.rdpeusbServer = new RdpeusbServer(rdpedycServer);
     return true;
 }
        //Start RDP connection.
        private void StartRDPConnection(bool createReliableUDPtransport = false,
            bool createLossyUDPtransport = false)
        {
            #region Trigger client to connect
            //Trigger client to connect.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Triggering SUT to initiate a RDP connection to server.");
            triggerClientRDPConnect(transportProtocol, true);
            #endregion

            #region RDPBCGR Connection

            //Waiting for the transport level connection request.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting the transport layer connection request.");
            this.rdpbcgrAdapter.ExpectTransportConnection(RDPSessionType.Normal);

            //Set Server Capability with RomoteFX codec supported.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Setting Server Capability.");
            SetServerCapabilitiesWithRemoteFxSupported();

            //Waiting for the RDP connection sequence.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Establishing RDP connection.");
            this.rdpbcgrAdapter.EstablishRDPConnection(selectedProtocol, enMethod, enLevel, true, false, rdpServerVersion);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server Save Session Info PDU to SUT to notify user has logged on.");
            this.rdpbcgrAdapter.ServerSaveSessionInfo(LogonNotificationType.UserLoggedOn, ErrorNotificationType_Values.LOGON_FAILED_OTHER);

            #endregion
            rdpedycServer = new RdpedycServer(this.rdpbcgrAdapter.ServerStack, this.rdpbcgrAdapter.SessionContext);
            rdpedycServer.ExchangeCapabilities(waitTime);
            rdpeiServer = new RdpeiServer(rdpedycServer);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="rdpedycServer"></param>
 public RdpegtServer(RdpedycServer rdpedycServer)
 {
     this.rdpedycServer = rdpedycServer;
 }
        /// <summary>
        /// Establish EMT connection and soft sync.
        /// </summary>
        private void StartSoftSyncConnection(TransportMode mode)
        {
            StartRDPConnection(false, true);
            this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} UDP connection.", mode);
            this.EstablishUDPConnection(mode, waitTime);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Create a {0} RDPEMT connection.", mode);
            this.EstablishRdpemtConnection(mode, waitTime, true);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Expect for Client Initiate Multitransport PDU to indicate that the client was able to successfully complete the multitransport initiation request.");
            this.rdpbcgrAdapter.WaitForPacket<Client_Initiate_Multitransport_Response_PDU>(waitTime);

            // This response code MUST only be sent to a server that advertises the SOFTSYNC_TCP_TO_UDP (0x200) flag in the Server Multitransport Channel Data.
            // Indicates that the client was able to successfully complete the multitransport initiation request.
            if (requestIdList.Count == 1)
                VerifyClientInitiateMultitransportResponsePDU(rdpbcgrAdapter.SessionContext.ClientInitiateMultitransportResponsePDU, requestIdList[0], HrResponse_Value.S_OK);

            #region Start EDYC soft sync
            if(rdpedycServer == null)
            {
                rdpedycServer = new Microsoft.Protocols.TestTools.StackSdk.RemoteDesktop.Rdpedyc.RdpedycServer(this.rdpbcgrAdapter.ServerStack, this.rdpbcgrAdapter.SessionContext);
            }

            this.TestSite.Log.Add(LogEntryKind.Comment, "Start Dynamic VC Version Negotiation");
            rdpedycServer.ExchangeCapabilities(waitTime);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Start Soft-Sync");
            rdpedycServer.SoftSyncNegotiate(waitTime);
            #endregion
        }
        // Default is using RDPEFS static virtual channel. Now is using DVC named "rdpdr".
        private void EstablishTunnelingStaticVCTrafficConnection(string staticChannelName = "RDPDR")
        {
            this.TestSite.Log.Add(LogEntryKind.Comment, "Start RDP connection, support soft sync and UDP perferred.");
            StartRDPConnection(false, true, true);

            // Check whether 'rdpdr' channel has been created
            if (this.rdpbcgrAdapter.GetStaticVirtualChannelId(staticChannelName) == 0)
            {
                this.TestSite.Assume.Fail("The necessary channel {0} has not been created, so stop running this test case.", staticChannelName);
            }

            if (rdpefsAdapter == null)
            {
                this.TestSite.Log.Add(LogEntryKind.Comment, "Create rdpefs adapter.");
                this.rdpefsAdapter = (IRdpefsAdapter)this.TestSite.GetAdapter(typeof(IRdpefsAdapter));
                this.rdpefsAdapter.Reset();
                this.rdpefsAdapter.AttachRdpbcgrAdapter(this.rdpbcgrAdapter);
            }

            if (rdpedycServer == null)
            {
                rdpedycServer = new RdpedycServer(this.rdpbcgrAdapter.ServerStack, this.rdpbcgrAdapter.SessionContext);
            }

            this.TestSite.Log.Add(LogEntryKind.Comment, "Start Dynamic VC Version Negotiation");
            ushort version = rdpedycServer.ExchangeCapabilities(waitTime);
            if(version < 0x0003)
            {
                this.TestSite.Log.Add(LogEntryKind.TestError, "Client doesn's support Version 3 DYNVC.");
            }

            this.TestSite.Log.Add(LogEntryKind.Comment, "Create a dynamic virtual channel for MS-RDPEFS");
            rdpefsAdapter.ProtocolInitialize(rdpedycServer);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Send and receive efs data over DVC");
            rdpefsAdapter.EfsInitializationSequenceOverDVC();
        }
        /// <summary>
        /// Start RDP connection
        /// </summary>
        private void StartRDPConnection(bool isSoftSync = false)
        {
            #region Trigger client to connect
            //Trigger client to connect.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Triggering SUT to initiate a RDP connection to server.");
            triggerClientRDPConnect(transportProtocol, true);
            #endregion

            #region RDPBCGR Connection

            // Waiting for the transport level connection request.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting the transport layer connection request.");
            this.rdpbcgrAdapter.ExpectTransportConnection(RDPSessionType.Normal);

            //Set Server Capability with RomoteFX codec supported.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Setting Server Capability.");
            setServerCapabilitiesWithRemoteFxSupported();

            // Waiting for the RDP connection sequence.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Establishing RDP connection.");

            MULTITRANSPORT_TYPE_FLAGS flags = MULTITRANSPORT_TYPE_FLAGS.None;
            if (isSoftSync)
            {
                flags = MULTITRANSPORT_TYPE_FLAGS.SOFTSYNC_TCP_TO_UDP | MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECL;
            }
            this.rdpbcgrAdapter.EstablishRDPConnection(selectedProtocol, enMethod, enLevel, true, false, rdpServerVersion, flags, true, isSoftSync);

            if(isSoftSync)
            {
                Site.Assert.IsTrue(this.rdpbcgrAdapter.SessionContext.MultitransportTypeFlagsInMCSConnectIntialPdu.HasFlag(MULTITRANSPORT_TYPE_FLAGS.SOFTSYNC_TCP_TO_UDP),
                   "Client Should support Soft-Sync, flags: {0}",
                   this.rdpbcgrAdapter.SessionContext.MultitransportTypeFlagsInMCSConnectIntialPdu);
            }

            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server Save Session Info PDU to SUT to notify user has logged on.");
            this.rdpbcgrAdapter.ServerSaveSessionInfo(LogonNotificationType.UserLoggedOn, ErrorNotificationType_Values.LOGON_FAILED_OTHER);

            #endregion

            this.rdpedycServer = new RdpedycServer(this.rdpbcgrAdapter.ServerStack, this.rdpbcgrAdapter.SessionContext);
            rdpegfxAdapter.AttachRdpbcgrAdapter(this.rdpbcgrAdapter);
            rdpedycServer.ExchangeCapabilities(waitTime);
        }
        /// <summary>
        /// Start RDP connection
        /// </summary>
        private void StartRDPConnection()
        {
            #region Trigger client to connect

            //Trigger client to connect.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Triggering SUT to initiate a RDP connection to server.");
            triggerClientRDPConnect(transportProtocol, true);
            #endregion

            #region RDPBCGR Connection

            // Waiting for the transport level connection request.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting the transport layer connection request.");
            this.rdpbcgrAdapter.ExpectTransportConnection(RDPSessionType.Normal);

            //Set Server Capability with RomoteFX codec supported.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Setting Server RDPRFX Capability.");
            setServerCapabilitiesWithRemoteFxSupported();

            // Waiting for the RDP connection sequence.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Establishing RDP connection.");
            this.rdpbcgrAdapter.EstablishRDPConnection(selectedProtocol, enMethod, enLevel, true, false, rdpServerVersion);

            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server Save Session Info PDU to SUT to notify user has logged on.");
            this.rdpbcgrAdapter.ServerSaveSessionInfo(LogonNotificationType.UserLoggedOn, ErrorNotificationType_Values.LOGON_FAILED_OTHER);

            #endregion

            rdpedycServer = new RdpedycServer(this.rdpbcgrAdapter.ServerStack, this.rdpbcgrAdapter.SessionContext);
            rdpedycServer.ExchangeCapabilities(waitTime);
            if (notificationType == NotificationType.SurfaceManagementCommand)
            {
                this.rdpegfxAdapter = (IRdpegfxAdapter)this.TestSite.GetAdapter(typeof(IRdpegfxAdapter));
                this.rdpegfxAdapter.Reset();
                this.rdprfxAdapter = null;
                // RDPEGFX capability exchange
                RDPEGFX_CapabilityExchange();
                this.rdpedispAdapter.AttachRdpbcgrAdapter(this.rdpbcgrAdapter);
                this.rdpedispAdapter.AttachRdpegfxAdapter(rdpegfxAdapter);
            }
            else
            {
                this.rdprfxAdapter = (IRdprfxAdapter)this.TestSite.GetAdapter(typeof(IRdprfxAdapter));
                this.rdprfxAdapter.Reset();
                //Initial the RDPRFX adapter context.
                rdprfxAdapter.Accept(this.rdpbcgrAdapter.ServerStack, this.rdpbcgrAdapter.SessionContext);
                receiveAndLogClientRfxCapabilites();
                this.rdpedispAdapter.AttachRdpbcgrAdapter(this.rdpbcgrAdapter);
                this.rdpedispAdapter.AttachRdprfxAdapter(this.rdprfxAdapter);
            }
        }