Beispiel #1
0
        private void EndBeginRequestCallback(object state, bool timedOut)
        {
            try
            {
                TcpKsiServiceAsyncResult asyncResult = (TcpKsiServiceAsyncResult)state;
                _asyncResults.Remove(asyncResult);

                if (timedOut)
                {
                    asyncResult.Error = new KsiServiceProtocolException("Request timed out.");
                }

                asyncResult.SetComplete();
            }
            catch (Exception ex)
            {
                Logger.Debug("EndBeginRequestCallback failed.", ex);
                throw;
            }
        }
        /// <summary>
        /// Finds all asyncResults matching response payloads in given PDU and marks them as completed.
        /// </summary>
        /// <param name="pduBytes">PDU bytes</param>
        /// <returns></returns>
        private bool ProcessPdu(byte[] pduBytes)
        {
            bool isPayloadFound = false;

            using (TlvReader reader = new TlvReader(new MemoryStream(pduBytes)))
            {
                // iterate over all payloads in PDU
                foreach (KsiServiceResponsePayloadInfo payloadInfo in GetResponsePayloadInfos(reader.ReadTag()))
                {
                    isPayloadFound = true;
                    bool asyncResultFound = false;

                    foreach (TcpKsiServiceAsyncResult asyncResult in GetAsyncResults(payloadInfo))
                    {
                        asyncResultFound = true;

                        if (!asyncResult.IsCompleted)
                        {
                            asyncResult.ResultStream = new MemoryStream(pduBytes);
                            Logger.Debug("Response payload received. Request type: {0}; Response payload type: {1}; (request id: {2}).", asyncResult.ServiceRequestType,
                                         payloadInfo.ResponsePayloadType, asyncResult.RequestId);
                            asyncResult.SetComplete();
                        }
                        else
                        {
                            Logger.Debug("AsyncResult already marked as Completed. Request type: {0}; Response payload type: {1}; (request id: {2}).",
                                         asyncResult.ServiceRequestType, payloadInfo.ResponsePayloadType, asyncResult.RequestId);
                        }

                        _asyncResults.Remove(asyncResult);
                    }

                    if (!asyncResultFound)
                    {
                        Logger.Warn("No request data found corresponding to the respose payload. Response info: {0}; Response TLV: {1}", payloadInfo, Base16.Encode(pduBytes));
                    }
                }
            }

            return(isPayloadFound);
        }