Microsoft.Protocols.TestTools.StackSdk.RemoteDesktop.Rdpedyc.PduBuilder.CreateDataPdu C# (CSharp) Méthode

CreateDataPdu() public méthode

Create the DYNVC_DATA PDU
public CreateDataPdu ( uint channelId, byte data, int channelChunkLength ) : Microsoft.Protocols.TestTools.StackSdk.RemoteDesktop.Rdpedyc.DataDvcBasePdu[]
channelId uint The channelId
data byte The uncompressed data
channelChunkLength int The maximum number of uncompressed bytes in a single segment
Résultat Microsoft.Protocols.TestTools.StackSdk.RemoteDesktop.Rdpedyc.DataDvcBasePdu[]
        public DataDvcBasePdu[] CreateDataPdu(uint channelId, byte[] data, int channelChunkLength)
        {
            DataFirstDvcPdu first = new DataFirstDvcPdu(channelId, (uint)data.Length, null);
            DataDvcPdu other = new DataDvcPdu(channelId, null);

            int firstNonDataSize = first.GetNonDataSize();
            int otherNonDataSize = other.GetNonDataSize();

            if (data.Length <= channelChunkLength - otherNonDataSize)
            {
                other.Data = data;
                return new DataDvcBasePdu[] { other };
            }

            // TODO: need to test for the following code
            byte[] buf = new byte[channelChunkLength - firstNonDataSize];
            MemoryStream ms = new MemoryStream(data);
            List<DataDvcBasePdu> pdus = new List<DataDvcBasePdu>();

            if (channelChunkLength - firstNonDataSize != ms.Read(buf, 0, channelChunkLength - firstNonDataSize))
            {
                DynamicVCException.Throw("Cannot create correct data PDUs.");
            }
            first.Data = buf;
            pdus.Add(first);

            buf = new byte[channelChunkLength - otherNonDataSize];
            // TODO: Check this logic
            int readLen = 0;
            readLen = ms.Read(buf, 0, channelChunkLength - otherNonDataSize);
            while (readLen == channelChunkLength - otherNonDataSize)
            {
                pdus.Add(new DataDvcPdu(channelId, buf));
                buf = new byte[channelChunkLength - otherNonDataSize];
                readLen = ms.Read(buf, 0, channelChunkLength - otherNonDataSize);
            }

            if (readLen > 0)
            {
                byte[] newBuf = new byte[readLen];
                Array.Copy(buf, newBuf, readLen);
                pdus.Add(new DataDvcPdu(channelId, newBuf));
            }

            return pdus.ToArray();
        }

Usage Example

        /// <summary>
        /// Send data using this DVC
        /// </summary>
        /// <param name="data"></param>
        public void Send(byte[] data)
        {
            DataDvcBasePdu[] dataPdus = pduBuilder.CreateDataPdu(channelId, data, MAX_CHUNK_LEN);

            if (dataPdus != null)
            {
                foreach (DataDvcBasePdu pdu in dataPdus)
                {
                    transport.Send(pdu);
                }
            }
        }
All Usage Examples Of Microsoft.Protocols.TestTools.StackSdk.RemoteDesktop.Rdpedyc.PduBuilder::CreateDataPdu