/// <summary> /// Transform the RESPONSE_MESSAGE to a byte array /// </summary> /// <param name="responseMessage">The RESPONSE_MESSAGE message</param> /// <returns>The result array</returns> public static byte[] EncodeResponseMessage(RESPONSE_MESSAGE responseMessage) { List<byte> list = new List<byte>(); list.AddRange(GetBytesFromUint32(responseMessage.TransportHeader.Size, false)); list.Add((byte)responseMessage.ResponseCode); return list.ToArray(); }
/// <summary> /// Convert the responsemessage struct defined in adapter to stack /// </summary> /// <param name="responseMessageStack">The response message of send initialInfoMeaage or segmentInfoMessage</param> /// <returns>Return the ResponseMessage type defined in adapter</returns> public static ResponseMessage ConvertFromStackForResponseMsg(RESPONSE_MESSAGE responseMessageStack) { ResponseMessage responseMessage; responseMessage.ResponseCode = ConvertFromStackForResponseCode(responseMessageStack.ResponseCode); responseMessage.TransportHeader = ConvertFromStackForTransHeader(responseMessageStack.TransportHeader); return responseMessage; }
/// <summary> /// Send Reponse Message to the client. /// </summary> /// <param name="responseMessage">The response message.</param> public void SendPackage(RESPONSE_MESSAGE responseMessage) { this.SendByte(EncodeMessage.EncodeResponseMessage(responseMessage)); if (this.logger != null) { this.logger.AddDebug("Pchc response message is sent successfully."); } }
/// <summary> /// Send the byte array of PCHC message using https transport . /// </summary> /// <param name="httpRequestPayload">The http request payload.</param> /// <returns>The pchc response message.</returns> private RESPONSE_MESSAGE SendByte(byte[] httpRequestPayload) { // Set the timeout of http. int timeout = 20000; byte[] payloadBuffer = null; HttpWebResponse httpWebResponse; this.httpClientTransport.Send(HttpVersion.Version10, null, httpRequestPayload, HttpMethod.POST, timeout); try { httpWebResponse = this.httpClientTransport.Receive(ref payloadBuffer); } catch (WebException e) { if (e.Message.Contains(HttpStatusCode.Unauthorized.ToString())) { throw new HttpStatusCode401Exception(); } else if (e.Message.ToLower().Contains("timed out".ToLower())) { throw new NoRESPONSEMESSAGEException(); } else { // Un expected exception is received. throw; } } this.httpResponseMethod = httpWebResponse.Method; this.httpResponseUri = httpWebResponse.ResponseUri; if (payloadBuffer == null) { throw new NoRESPONSEMESSAGEException(); } try { this.responseMessage = DecodeMessage.DecodeResponseMessage(payloadBuffer); } catch (ArgumentOutOfRangeException e) { throw new NoRESPONSEMESSAGEException(e.Message); } return this.responseMessage; }
/// <summary> /// Send the SEGMENT_INFO_MESSAGE request. /// </summary> /// <param name="segmentInfoMessage">The SEGMENT_INFO_MESSAGE message.</param> /// <returns>The repsonse message RESPONSE_MESSAGE from the hosted cache.</returns> public RESPONSE_MESSAGE SendSegmentInfoMessage(SEGMENT_INFO_MESSAGE segmentInfoMessage) { return this.responseMessage = this.SendByte(EncodeMessage.EncodeSegmentInfoMessage(segmentInfoMessage)); }
/// <summary> /// Send the INITIAL_OFFER_MESSAGE request. /// </summary> /// <param name="initialOfferMessage">The INITIAL_OFFER_MESSAGE message.</param> /// <returns>The repsonse message RESPONSE_MESSAGE from the hosted cache.</returns> public RESPONSE_MESSAGE SendInitialOfferMessage(INITIAL_OFFER_MESSAGE initialOfferMessage) { return this.responseMessage = this.SendByte(EncodeMessage.EncodeInitialOfferMessage(initialOfferMessage)); }
/// <summary> /// Send the BATCHED_OFFER_MESSAGE request. /// </summary> /// <param name="batchedOfferMessage">The BATCHED_OFFER_MESSAGE message.</param> /// <returns>The repsonse message RESPONSE_MESSAGE from the hosted cache.</returns> public RESPONSE_MESSAGE SendBatchedOfferMessage(BATCHED_OFFER_MESSAGE batchedOfferMessage) { List<byte> buffer = new List<byte>(); buffer.AddRange(TypeMarshal.ToBytes(batchedOfferMessage.MessageHeader)); buffer.AddRange(TypeMarshal.ToBytes(batchedOfferMessage.ConnectionInfo)); for (int i = 0; i < batchedOfferMessage.SegmentDescriptors.Length; i++) { buffer.AddRange(TypeMarshal.ToBytes(batchedOfferMessage.SegmentDescriptors[i])); } return this.responseMessage = this.SendByte(buffer.ToArray()); }