Exemple #1
0
        public void FromBytes(WspBuffer buffer)
        {
            var header = new WspMessageHeader();

            header.FromBytes(buffer);

            Header = header;

            var request = (CPMConnectIn)Request;

            var tempBuffer = new WspBuffer();

            request.ToBytes(tempBuffer);

            var requestBytes = tempBuffer.GetBytes();

            var responseBytes = buffer.GetBytes().Skip(buffer.ReadOffset).ToArray();

            bool supportVersion = false;

            if (responseBytes.Length >= 20)
            {
                if (!Enumerable.SequenceEqual(requestBytes.Skip(4).Take(16), responseBytes.Skip(4).Take(16)))
                {
                    supportVersion = true;
                }
            }

            _serverVersion = buffer.ToStruct <uint>();

            if (supportVersion)
            {
                _reserved = new byte[4];

                for (int i = 0; i < 4; i++)
                {
                    _reserved[i] = buffer.ToStruct <byte>();
                }

                dwWinVerMajor = buffer.ToStruct <uint>();

                dwWinVerMinor = buffer.ToStruct <uint>();

                dwNLSVerMajor = buffer.ToStruct <uint>();

                dwNLSVerMinor = buffer.ToStruct <uint>();
            }
            else
            {
                _reserved = buffer.GetBytes().Skip(buffer.ReadOffset).ToArray();

                dwWinVerMajor = null;

                dwWinVerMinor = null;

                dwNLSVerMajor = null;

                dwNLSVerMinor = null;
            }
        }
Exemple #2
0
        public void FromBytes(WspBuffer buffer)
        {
            var header = new WspMessageHeader();

            header.FromBytes(buffer);

            Header = header;

            _fTrueSequential = buffer.ToStruct <uint>();

            _fWorkIdUnique = buffer.ToStruct <uint>();

            int categorizationCount = 0;

            var createQueryIn = (CPMCreateQueryIn)Request;

            if (createQueryIn.CCategorizationSet.HasValue)
            {
                categorizationCount = (int)createQueryIn.CCategorizationSet.Value.count;
            }

            aCursors = new uint[categorizationCount + 1];

            for (int i = 0; i < aCursors.Length; i++)
            {
                uint cursor = buffer.ToStruct <uint>();

                aCursors[i] = cursor;
            }
        }
Exemple #3
0
        public void FromBytes(WspBuffer buffer)
        {
            var header = new WspMessageHeader();

            header.FromBytes(buffer);

            Header = header;
        }
Exemple #4
0
        private bool IsCPMDisconnectMessage(byte[] messageBlob)
        {
            var buffer = new WspBuffer(messageBlob);
            var header = new WspMessageHeader();

            header.FromBytes(buffer);

            return(header._msg == WspMessageHeader_msg_Values.CPMDisconnect);
        }
        public void FromBytes(WspBuffer buffer)
        {
            var header = new WspMessageHeader();

            header.FromBytes(buffer);

            Header = header;

            State = buffer.ToStruct <CPMCiState>();
        }
Exemple #6
0
        /// <summary>
        /// Send message to server with a given header.
        /// </summary>
        /// <param name="request">Message to be sent.</param>
        /// <param name="header">Header to be sent.</param>
        private void SendWithGivenHeader(IWspInMessage request, WspMessageHeader header)
        {
            var requestBytes = Helper.ToBytes(request);
            var headerBytes  = Helper.ToBytes(header);

            Array.Copy(headerBytes, requestBytes, headerBytes.Length);
            request.Header = header;
            lastRequest    = request;

            Sender.SendMessage(requestBytes, out lastResponseBytes);
        }
        public void FromBytes(WspBuffer buffer)
        {
            Header = buffer.ToStruct <WspMessageHeader>();

            _cbValue = buffer.ToStruct <uint>();

            _fMoreExists = buffer.ToStruct <uint>();

            _fValueExists = buffer.ToStruct <uint>();

            if (_fValueExists == 1)
            {
                vValue = buffer.ReadBytes((int)_cbValue);
            }
        }
        public void ToBytes(WspBuffer buffer)
        {
            var bodyBytes = GetBodyBytes();

            var checksum = Helper.CalculateChecksum(WspMessageHeader_msg_Values.CPMSetBindingsIn, bodyBytes);

            var header = Header;

            header._ulChecksum = checksum;

            Header = header;

            Header.ToBytes(buffer);

            buffer.AddRange(bodyBytes);
        }
Exemple #9
0
        /// <summary>
        /// Expect reponse from server.
        /// </summary>
        /// <typeparam name="T">Response type.</typeparam>
        /// <param name="response">Response from server.</param>
        /// <returns>Status</returns>
        public uint ExpectMessage <T>(out T response) where T : IWspOutMessage, new()
        {
            response = new T();

            response.Request = lastRequest;

            var header = new WspMessageHeader();

            Helper.FromBytes(ref header, lastResponseBytes);

            if (header._msg != lastRequest.Header._msg)
            {
                throw new InvalidOperationException("Unexpected response from server!");
            }

            if (header._status != 0 && header._status != (uint)WspErrorCode.DB_S_ENDOFROWSET && header._status != (uint)WspErrorCode.DB_S_DIALECTIGNORED)
            {
                response.Header = header;
                return(header._status);
            }

            if (response is CPMGetRowsOut)
            {
                CPMGetRowsOut getRowsOut = response as CPMGetRowsOut;
                getRowsOut.Is64Bit        = Is64bit;
                getRowsOut.BindingRequest = bindingRequestMap[latestCPMGetRowsIn._hCursor];
            }

            var buffer = new WspBuffer(lastResponseBytes);

            response.FromBytes(buffer);

            // Update the state of client according to response.
            UpdateContext(response);

            return(0);
        }
Exemple #10
0
        public void FromBytes(WspBuffer buffer)
        {
            Header = buffer.ToStruct <WspMessageHeader>();

            _QStatus = buffer.ToStruct <QStatus_Values>();

            _cFilteredDocuments = buffer.ToStruct <uint>();

            _cDocumentsToFilter = buffer.ToStruct <uint>();

            _dwRatioFinishedDenominator = buffer.ToStruct <uint>();

            _dwRatioFinishedNumerator = buffer.ToStruct <uint>();

            _iRowBmk = buffer.ToStruct <uint>();

            _cRowsTotal = buffer.ToStruct <uint>();

            _maxRank = buffer.ToStruct <uint>();

            _cResultsFound = buffer.ToStruct <uint>();

            _whereID = buffer.ToStruct <uint>();
        }
Exemple #11
0
        public void FromBytes(WspBuffer buffer)
        {
            var header = new WspMessageHeader();

            var initialReadOffset = buffer.ReadOffset;

            header.FromBytes(buffer);
            Header = header;

            // Do not parse message body if the status in header is not success.
            if (header._status != (uint)WspErrorCode.SUCCESS && header._status != (uint)WspErrorCode.DB_S_ENDOFROWSET && header._status != (uint)WspErrorCode.DB_S_DIALECTIGNORED)
            {
                return;
            }

            _cRowsReturned = buffer.ToStruct <uint>();

            eType = buffer.ToStruct <RowSeekType>();

            _chapt = buffer.ToStruct <uint>();

            switch (eType)
            {
            case RowSeekType.eRowSeekNone:
                SeekDescription = null;
                break;

            case RowSeekType.eRowSeekNext:
                SeekDescription = buffer.ToStruct <CRowSeekNext>();
                break;

            case RowSeekType.eRowSeekAt:
                SeekDescription = buffer.ToStruct <CRowSeekAt>();
                break;

            case RowSeekType.eRowSeekAtRatio:
                SeekDescription = buffer.ToStruct <CRowSeekAtRatio>();
                break;

            case RowSeekType.eRowSeekByBookmark:
                var tempSeekDescription = new CRowSeekByBookmark();
                tempSeekDescription.FromBytes(buffer);
                SeekDescription = tempSeekDescription;
                break;
            }

            int rowStartIndex = initialReadOffset + (int)((CPMGetRowsIn)Request)._cbReserved;
            int paddingSize   = rowStartIndex - buffer.ReadOffset;

            paddingRows = buffer.ReadBytes(paddingSize);

            rowStartIndex = buffer.ReadOffset;
            Rows          = new Row[_cRowsReturned];
            uint cColumns = BindingRequest.cColumns;

            for (int i = 0; i < _cRowsReturned; i++)
            {
                Rows[i].Columns = new Column[cColumns];

                for (int j = 0; j < cColumns; j++)
                {
                    if (BindingRequest.aColumns[j].StatusOffset != null)
                    {
                        Rows[i].Columns[j].Status = (StoreStatus)buffer.Peek <byte>(rowStartIndex + BindingRequest.aColumns[j].StatusOffset.Value);
                    }

                    if (BindingRequest.aColumns[j].LengthOffset != null)
                    {
                        Rows[i].Columns[j].Length = buffer.Peek <byte>(rowStartIndex + BindingRequest.aColumns[j].LengthOffset.Value);
                    }

                    if (BindingRequest.aColumns[j].ValueOffset != null)
                    {
                        int valueOffset = rowStartIndex + BindingRequest.aColumns[j].ValueOffset.Value;

                        if (BindingRequest.aColumns[j].vType == CBaseStorageVariant_vType_Values.VT_VARIANT)
                        {
                            Rows[i].Columns[j].RowVariant         = new CTableVariant();
                            Rows[i].Columns[j].RowVariant.Is64bit = this.Is64Bit;
                            WspBuffer rowVariantBuffer = new WspBuffer(buffer.ReadBytesFromOffset(valueOffset, BindingRequest.aColumns[j].ValueSize.Value));
                            Rows[i].Columns[j].RowVariant.FromBytes(rowVariantBuffer);

                            if (Rows[i].Columns[j].RowVariant.vType == CBaseStorageVariant_vType_Values.VT_LPWSTR)
                            {
                                int dataOffset = GetRealOffset(Rows[i].Columns[j].RowVariant.Offset);
                                Rows[i].Columns[j].Data = ReadValueByType(Rows[i].Columns[j].RowVariant.vType, dataOffset, buffer);
                            }
                            else if (Rows[i].Columns[j].RowVariant.vType.HasFlag(CBaseStorageVariant_vType_Values.VT_VECTOR))
                            {
                                var baseVType   = Rows[i].Columns[j].RowVariant.vType ^ CBaseStorageVariant_vType_Values.VT_VECTOR;
                                var vectorCount = Rows[i].Columns[j].RowVariant.Count;
                                if (baseVType == CBaseStorageVariant_vType_Values.VT_LPWSTR)
                                {
                                    var startOffset = GetRealOffset(Rows[i].Columns[j].RowVariant.Offset);
                                    var items       = new List <string>();
                                    for (var idx = 0; idx < vectorCount; idx++)
                                    {
                                        WspBuffer offsetBuffer;
                                        int       itemOffset;
                                        if (Is64Bit)
                                        {
                                            offsetBuffer = new WspBuffer(buffer.ReadBytesFromOffset(startOffset + idx * 8, 8));
                                            itemOffset   = GetRealOffset(offsetBuffer.ToStruct <long>());
                                        }
                                        else
                                        {
                                            offsetBuffer = new WspBuffer(buffer.ReadBytesFromOffset(startOffset + idx * 4, 4));
                                            itemOffset   = GetRealOffset(offsetBuffer.ToStruct <int>());
                                        }

                                        var item = ReadValueByType(CBaseStorageVariant_vType_Values.VT_LPWSTR, itemOffset, buffer) as string;
                                        items.Add(item);
                                    }

                                    Rows[i].Columns[j].Data = items.ToArray();
                                }
                                else if (baseVType == CBaseStorageVariant_vType_Values.VT_FILETIME)
                                {
                                    var startOffset = GetRealOffset(Rows[i].Columns[j].RowVariant.Offset);
                                    var items       = new List <object>();
                                    for (var idx = 0; idx < vectorCount; idx++)
                                    {
                                        var item = ReadValueByType(CBaseStorageVariant_vType_Values.VT_FILETIME, startOffset, buffer);
                                        startOffset += 8; // VT_FILETIME is a 64-bit value
                                        items.Add(item);
                                    }

                                    Rows[i].Columns[j].Data = items.ToArray();
                                }
                                else
                                {
                                    throw new NotImplementedException();
                                }
                            }
                            else
                            {
                                // If the type is not a string, the offset field saves the actual data.
                                Rows[i].Columns[j].Data = ReadValueByType(Rows[i].Columns[j].RowVariant.vType, 8, rowVariantBuffer);
                            }
                        }
                        else
                        {
                            Rows[i].Columns[j].Data = ReadValueByType(BindingRequest.aColumns[j].vType, valueOffset, buffer);
                        }
                    }
                }

                rowStartIndex += (int)((CPMGetRowsIn)Request)._cbRowWidth;
            }
        }
        public void FromBytes(WspBuffer buffer)
        {
            Header = buffer.ToStruct <WspMessageHeader>();

            _QStatus = buffer.ToStruct <QStatus_Values>();
        }
Exemple #13
0
        public void FromBytes(WspBuffer buffer)
        {
            Header = buffer.ToStruct <WspMessageHeader>();

            _cCursorsRemaining = buffer.ToStruct <uint>();
        }