Inheritance: DataDvcBasePdu
        /// <summary>
        /// Process DVC Data
        /// </summary>
        /// <param name="pdu"></param>
        private void ProcessDataPdu(DataDvcBasePdu pdu)
        {
            if (pdu is DataFirstDvcPdu)
            {
                dataFragmentManager = new DataFragmentManager();
                DataFirstDvcPdu first = (DataFirstDvcPdu)pdu;
                dataFragmentManager.AddFirstData(first.Length, first.Data);
            }
            else if (pdu is DataDvcPdu)
            {
                if (dataFragmentManager == null)
                {
                    // Single data PDU which is not fragmented.
                    if (this.Received != null)
                    {
                        this.Received(pdu.Data, this.ChannelId);
                    }
                    return;
                }
                else
                {
                    // Received a fragment.
                    dataFragmentManager.AppendData(pdu.Data);
                }
            }

            if (dataFragmentManager.Completed)
            {
                if (this.Received != null)
                {
                    this.Received(dataFragmentManager.Data, this.ChannelId);
                }
                dataFragmentManager = null;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Create the DYNVC_DATA PDU
        /// </summary>
        /// <param name="channelId">The channelId</param>
        /// <param name="data">The uncompressed data</param>
        /// <param name="channelChunkLength">The maximum number of uncompressed bytes in a single segment </param>
        /// <returns>Return the first and second PDUs in an array</returns>
        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());
        }
        /// <summary>
        /// Create the DYNVC_DATA PDU
        /// </summary>
        /// <param name="channelId">The channelId</param>
        /// <param name="data">The uncompressed data</param>
        /// <param name="channelChunkLength">The maximum number of uncompressed bytes in a single segment </param>        
        /// <returns>Return the first and second PDUs in an array</returns>
        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();
        }
        /// <summary>
        /// Process DVC Data
        /// </summary>
        /// <param name="pdu"></param>
        private void ProcessDataPdu(DataDvcBasePdu pdu)
        {
            if (pdu is DataFirstDvcPdu)
            {
                dataFragmentManager = new DataFragmentManager();
                DataFirstDvcPdu first = (DataFirstDvcPdu)pdu;
                dataFragmentManager.AddFirstData(first.Length, first.Data);
            }
            else if (pdu is DataDvcPdu)
            {
                if (dataFragmentManager == null)
                {
                    // Single data PDU which is not fragmented.
                    if (this.Received != null)
                    {
                        this.Received(pdu.Data, this.ChannelId);
                    }
                    return;
                }
                else
                {
                    // Received a fragment.
                    dataFragmentManager.AppendData(pdu.Data);
                }
            }
            else if (pdu is DataCompressedDvcPdu)
            {
                CompressFactory Compressor = new CompressFactory();
                if (dataFragmentManager == null)
                {
                    RDP_SEGMENTED_DATA segData = new RDP_SEGMENTED_DATA();
                    bool fResult = PduMarshaler.Unmarshal(pdu.Data, segData);
                    if (fResult)
                    {
                        if (segData.descriptor == DescriptorTypes.SINGLE)
                        {
                            byte[] rawData = Compressor.Decompress(segData.bulkData.data, segData.bulkData.header);
                            // Single data PDU which is not fragmented.
                            if (this.Received != null)
                            {
                                this.Received(rawData, this.ChannelId);
                            }
                            return;
                        }
                    }
                }
                else
                {
                    // Received a fragment.
                    dataFragmentManager.AppendData(pdu.Data);
                }
            }

            if (dataFragmentManager.Completed)
            {
                if (this.Received != null)
                {
                    this.Received(dataFragmentManager.Data, this.ChannelId);
                }
                dataFragmentManager = null;
            }
        }