Example #1
0
        /// <summary>
        /// Deserialize items from byte array.
        /// </summary>
        /// <param name="byteArray">The byte array which contains response message.</param>
        /// <param name="currentIndex">The index special where to start.</param>
        /// <param name="lengthOfItems">The length of items.</param>
        protected override void DeserializeItemsFromByteArray(byte[] byteArray, ref int currentIndex, int lengthOfItems)
        {
            int index = currentIndex;

            this.RequestID   = BasicObject.Parse <Compact64bitInt>(byteArray, ref index);
            this.RequestType = BasicObject.Parse <Compact64bitInt>(byteArray, ref index);
            this.Status      = (byteArray[index] & 0x1) == 0x1 ? true : false;
            this.Reserved    = (byte)(byteArray[index] >> 1);
            index           += 1;

            if (index - currentIndex != lengthOfItems)
            {
                throw new ResponseParseErrorException(currentIndex, "CellSubResponse object over-parse error", null);
            }

            if (this.Status)
            {
                this.ResponseError = StreamObject.GetCurrent <ResponseError>(byteArray, ref index);
            }
            else
            {
                this.SubResponseData = SubResponseData.GetCurrentSubResponseData((int)this.RequestType.DecodedValue, byteArray, ref index);

                if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
                {
                    // Capture the requirements related response data.
                    new MsfsshttpbAdapterCapture().InvokeCaptureMethod(this.SubResponseData.GetType(), this.SubResponseData, SharedContext.Current.Site);
                }
            }

            currentIndex = index;
        }
        /// <summary>
        /// Used to return the length of this element.
        /// </summary>
        /// <param name="byteArray">A Byte array</param>
        /// <param name="startIndex">Start position</param>
        /// <returns>The element length</returns>
        public override int DeserializeDataElementDataFromByteArray(byte[] byteArray, int startIndex)
        {
            int index = startIndex;

            this.DataElementFragment = StreamObject.GetCurrent <DataElementFragment>(byteArray, ref index);
            return(index - startIndex);
        }
        /// <summary>
        /// Deserialize sub response data from byte array.
        /// </summary>
        /// <param name="byteArray">The byte array which contains sub response data.</param>
        /// <param name="currentIndex">The index special where to start.</param>
        protected override void DeserializeSubResponseDataFromByteArray(byte[] byteArray, ref int currentIndex)
        {
            int index = currentIndex;

            this.ReadAccessResponse  = StreamObject.GetCurrent <ReadAccessResponse>(byteArray, ref index);
            this.WriteAccessResponse = StreamObject.GetCurrent <WriteAccessResponse>(byteArray, ref index);

            currentIndex = index;

            using (BitReader bitReader = new BitReader(byteArray, index))
            {
                int headertype = bitReader.ReadInt32(2);
                if (headertype == 0x2)
                {
                    StreamObjectHeaderStart32bit header = new StreamObjectHeaderStart32bit();
                    header.HeaderType = headertype;
                    header.Compound   = bitReader.ReadInt32(1);
                    int type = bitReader.ReadInt32(14);
                    header.Type   = (StreamObjectTypeHeaderStart)type;
                    header.Length = bitReader.ReadInt32(15);
                    index        += 4;
                    ResponseError responseError = StreamObject.GetCurrent <ResponseError>(byteArray, ref index);
                }

                // If header type is not 16-bit Stream Object Header End
                if (headertype != 0x3)
                {
                    currentIndex = index + 2;
                }
            }
        }
Example #4
0
        /// <summary>
        /// Deserialize sub response data from byte array.
        /// </summary>
        /// <param name="byteArray">The byte array which contains sub response data.</param>
        /// <param name="currentIndex">The index special where to start.</param>
        protected override void DeserializeSubResponseDataFromByteArray(byte[] byteArray, ref int currentIndex)
        {
            PutChangesResponseSerialNumberReassignAll outValue;
            int index = currentIndex;

            if (StreamObject.TryGetCurrent <PutChangesResponseSerialNumberReassignAll>(byteArray, ref index, out outValue))
            {
                this.PutChangesResponseSerialNumberReassignAll = outValue;
            }

            PutChangesResponse putChangesResponse;

            if (StreamObject.TryGetCurrent <PutChangesResponse>(byteArray, ref index, out putChangesResponse))
            {
                this.PutChangesResponse = putChangesResponse;
            }

            this.Knowledge = StreamObject.GetCurrent <Knowledge>(byteArray, ref index);

            DiagnosticRequestOptionOutput diagnosticRequestOptionOutput;

            if (StreamObject.TryGetCurrent <DiagnosticRequestOptionOutput>(byteArray, ref index, out diagnosticRequestOptionOutput))
            {
                this.DiagnosticRequestOptionOutput = diagnosticRequestOptionOutput;
            }

            currentIndex = index;
        }
Example #5
0
        /// <summary>
        /// Used to de-serialize the element.
        /// </summary>
        /// <param name="byteArray">A Byte array</param>
        /// <param name="currentIndex">Start position</param>
        /// <param name="lengthOfItems">The length of the items</param>
        protected override void DeserializeItemsFromByteArray(byte[] byteArray, ref int currentIndex, int lengthOfItems)
        {
            int index = currentIndex;

            if (lengthOfItems != 0)
            {
                throw new StreamObjectParseErrorException(currentIndex, "LeafNodeObjectData", "Stream Object over-parse error", null);
            }

            this.Signature = StreamObject.GetCurrent <SignatureObject>(byteArray, ref index);
            this.DataSize  = StreamObject.GetCurrent <DataSizeObject>(byteArray, ref index);

            // Try to read StreamObjectHeaderStart to see there is data hash object or not
            StreamObjectHeaderStart streamObjectHeader;

            if ((StreamObjectHeaderStart.TryParse(byteArray, index, out streamObjectHeader)) != 0)
            {
                if (streamObjectHeader.Type == StreamObjectTypeHeaderStart.DataHashObject)
                {
                    this.DataHash = StreamObject.GetCurrent <DataHashObject>(byteArray, ref index);
                }
            }

            currentIndex = index;
        }
        /// <summary>
        /// Used to return the length of this element.
        /// </summary>
        /// <param name="byteArray">A Byte array</param>
        /// <param name="startIndex">Start position</param>
        /// <returns>The element length</returns>
        public override int DeserializeDataElementDataFromByteArray(byte[] byteArray, int startIndex)
        {
            int index = startIndex;

            this.CellManifestCurrentRevision = StreamObject.GetCurrent <CellManifestCurrentRevision>(byteArray, ref index);
            return(index - startIndex);
        }
Example #7
0
        /// <summary>
        /// Used to de-serialize data element.
        /// </summary>
        /// <param name="byteArray">Byte array</param>
        /// <param name="startIndex">Start position</param>
        /// <returns>The length of the array</returns>
        public override int DeserializeDataElementDataFromByteArray(byte[] byteArray, int startIndex)
        {
            int index = startIndex;

            this.StorageManifestSchemaGUID      = StreamObject.GetCurrent <StorageManifestSchemaGUID>(byteArray, ref index);
            this.StorageManifestRootDeclareList = new List <StorageManifestRootDeclare>();

            StreamObjectHeaderStart header;
            int headerLength = 0;

            while ((headerLength = StreamObjectHeaderStart.TryParse(byteArray, index, out header)) != 0)
            {
                if (header.Type == StreamObjectTypeHeaderStart.StorageManifestRootDeclare)
                {
                    index += headerLength;
                    this.StorageManifestRootDeclareList.Add(StreamObject.ParseStreamObject(header, byteArray, ref index) as StorageManifestRootDeclare);
                }
                else
                {
                    throw new DataElementParseErrorException(index, "Failed to parse StorageManifestDataElement, expect the inner object type StorageManifestRootDeclare, but actual type value is " + header.Type, null);
                }
            }

            return(index - startIndex);
        }
        /// <summary>
        /// Deserialize items from byte array.
        /// </summary>
        /// <param name="byteArray">The byte array which contains response message.</param>
        /// <param name="currentIndex">The index special where to start.</param>
        /// <param name="lengthOfItems">The length of items.</param>
        protected override void DeserializeItemsFromByteArray(byte[] byteArray, ref int currentIndex, int lengthOfItems)
        {
            if (lengthOfItems != 0)
            {
                throw new ResponseParseErrorException(currentIndex, "ReadAccessResponse over-parse error", null);
            }

            int index = currentIndex;

            this.ReadResponseError = StreamObject.GetCurrent <ResponseError>(byteArray, ref index);
            currentIndex           = index;
        }
Example #9
0
        /// <summary>
        /// Deserialize items from byte array.
        /// </summary>
        /// <param name="byteArray">The byte array which contains response message.</param>
        /// <param name="currentIndex">The index special where to start.</param>
        /// <param name="lengthOfItems">The length of items.</param>
        protected override void DeserializeItemsFromByteArray(byte[] byteArray, ref int currentIndex, int lengthOfItems)
        {
            int index = currentIndex;

            if (lengthOfItems != 16)
            {
                throw new StreamObjectParseErrorException(currentIndex, "ResponseError", "Stream object over-parse error", null);
            }

            byte[] guidarray = new byte[16];
            Array.Copy(byteArray, index, guidarray, 0, 16);
            this.ErrorTypeGUID = new Guid(guidarray);
            index += 16;

            switch (this.ErrorTypeGUID.ToString().ToUpper(CultureInfo.CurrentCulture))
            {
            case CellErrorGuid:
                this.ErrorData = StreamObject.GetCurrent <CellError>(byteArray, ref index);
                break;

            case ProtocolErrorGuid:
                this.ErrorData = StreamObject.GetCurrent <ProtocolError>(byteArray, ref index);
                break;

            case Win32ErrorGuid:
                this.ErrorData = StreamObject.GetCurrent <Win32Error>(byteArray, ref index);
                break;

            case HresultErrorGuid:
                this.ErrorData = StreamObject.GetCurrent <HRESULTError>(byteArray, ref index);
                break;

            default:
                throw new StreamObjectParseErrorException(index - 16, "ResponseError", "Failed to extract the error Guid value, the value" + this.ErrorTypeGUID + "is not defined", null);
            }

            ErrorStringSupplementalInfo errorInfo;

            if (StreamObject.TryGetCurrent <ErrorStringSupplementalInfo>(byteArray, ref index, out errorInfo))
            {
                this.ErrorStringSupplementalInfo = errorInfo;
            }

            ResponseError chainedError;

            if (StreamObject.TryGetCurrent <ResponseError>(byteArray, ref index, out chainedError))
            {
                this.ChainedError = chainedError;
            }

            currentIndex = index;
        }
Example #10
0
        /// <summary>
        /// Used to de-serialize the element.
        /// </summary>
        /// <param name="byteArray">A Byte array</param>
        /// <param name="currentIndex">Start position</param>
        /// <param name="lengthOfItems">The length of the items</param>
        protected override void DeserializeItemsFromByteArray(byte[] byteArray, ref int currentIndex, int lengthOfItems)
        {
            int index = currentIndex;

            if (lengthOfItems != 0)
            {
                throw new StreamObjectParseErrorException(currentIndex, "IntermediateNodeObject", "Stream Object over-parse error", null);
            }

            this.Signature = StreamObject.GetCurrent <SignatureObject>(byteArray, ref index);
            this.DataSize  = StreamObject.GetCurrent <DataSizeObject>(byteArray, ref index);

            currentIndex = index;
        }
        /// <summary>
        /// Used to return the length of this element.
        /// </summary>
        /// <param name="byteArray">A Byte array</param>
        /// <param name="startIndex">Start position</param>
        /// <returns>The length of the element</returns>
        public override int DeserializeDataElementDataFromByteArray(byte[] byteArray, int startIndex)
        {
            int index = startIndex;

            DataElementHash dataElementHash;

            if (StreamObject.TryGetCurrent <DataElementHash>(byteArray, ref index, out dataElementHash))
            {
                this.DataElementHash = dataElementHash;
            }

            this.ObjectGroupDeclarations = StreamObject.GetCurrent <ObjectGroupDeclarations>(byteArray, ref index);

            ObjectGroupMetadataDeclarations objectMetadataDeclaration = new ObjectGroupMetadataDeclarations();

            if (StreamObject.TryGetCurrent <ObjectGroupMetadataDeclarations>(byteArray, ref index, out objectMetadataDeclaration))
            {
                this.ObjectMetadataDeclaration = objectMetadataDeclaration;
            }

            this.ObjectGroupData = StreamObject.GetCurrent <ObjectGroupData>(byteArray, ref index);

            return(index - startIndex);
        }
        /// <summary>
        /// Deserialize response from byte array.
        /// </summary>
        /// <param name="byteArray">Server returned message.</param>
        /// <param name="startIndex">The index special where start.</param>
        /// <returns>The instance of CellResponse.</returns>
        public static FsshttpbResponse DeserializeResponseFromByteArray(byte[] byteArray, int startIndex)
        {
            int index = startIndex;

            FsshttpbResponse response = new FsshttpbResponse();

            response.ProtocolVersion = LittleEndianBitConverter.ToUInt16(byteArray, index);
            index += 2;

            response.MinimumVersion = LittleEndianBitConverter.ToUInt16(byteArray, index);
            index += 2;

            response.Signature = LittleEndianBitConverter.ToUInt64(byteArray, index);
            index += 8;

            int length = 0;
            StreamObjectHeaderStart streamObjectHeader;

            if ((length = StreamObjectHeaderStart.TryParse(byteArray, index, out streamObjectHeader)) == 0)
            {
                throw new ResponseParseErrorException(index, "Failed to parse the response header", null);
            }

            if (!(streamObjectHeader is StreamObjectHeaderStart32bit))
            {
                throw new ResponseParseErrorException(index, "Unexpected 16-bit response stream object header, expect 32-bit stream object header for Response", null);
            }

            if (streamObjectHeader.Type != StreamObjectTypeHeaderStart.FsshttpbResponse)
            {
                throw new ResponseParseErrorException(index, "Failed to extract the response header type, unexpected value " + streamObjectHeader.Type, null);
            }

            if (streamObjectHeader.Length != 1)
            {
                throw new ResponseParseErrorException(index, "Response object over-parse error", null);
            }

            index += length;
            response.ResponseStart = streamObjectHeader as StreamObjectHeaderStart32bit;

            response.Status   = (byteArray[index] & 0x1) == 0x1 ? true : false;
            response.Reserved = (byte)(byteArray[index] >> 1);
            index            += 1;

            try
            {
                if (response.Status)
                {
                    response.ResponseError      = StreamObject.GetCurrent <ResponseError>(byteArray, ref index);
                    response.DataElementPackage = null;
                    response.CellSubResponses   = null;
                }
                else
                {
                    DataElementPackage package;
                    if (StreamObject.TryGetCurrent <DataElementPackage>(byteArray, ref index, out package))
                    {
                        response.DataElementPackage = package;
                    }

                    response.CellSubResponses = new List <FsshttpbSubResponse>();
                    FsshttpbSubResponse subResponse;
                    while (StreamObject.TryGetCurrent <FsshttpbSubResponse>(byteArray, ref index, out subResponse))
                    {
                        response.CellSubResponses.Add(subResponse);
                    }
                }

                response.ResponseEnd = BasicObject.Parse <StreamObjectHeaderEnd16bit>(byteArray, ref index);
            }
            catch (StreamObjectParseErrorException streamObjectException)
            {
                throw new ResponseParseErrorException(index, streamObjectException);
            }
            catch (DataElementParseErrorException dataElementException)
            {
                throw new ResponseParseErrorException(index, dataElementException);
            }
            catch (KnowledgeParseErrorException knowledgeException)
            {
                throw new ResponseParseErrorException(index, knowledgeException);
            }

            if (index != byteArray.Length)
            {
                throw new ResponseParseErrorException(index, "Failed to pass the whole response, not reach the end of the byte array", null);
            }

            return(response);
        }