コード例 #1
0
 /// <summary>
 /// Create new KSI service response parser.
 /// </summary>
 /// <param name="pduVersion">PDU version</param>
 /// <param name="requestType">Request type of the response to be parsed</param>
 /// <param name="macAlgorithm">MAC calculation algorithm</param>
 /// <param name="macKey">MAC calculation key</param>
 public KsiServiceResponseParser(PduVersion pduVersion, KsiServiceRequestType requestType, HashAlgorithm macAlgorithm, byte[] macKey)
 {
     _pduVersion   = pduVersion;
     _requestType  = requestType;
     _macAlgorithm = macAlgorithm;
     _macKey       = macKey;
 }
コード例 #2
0
        /// <summary>
        /// Begin TCP request
        /// </summary>
        /// <param name="requestType"></param>
        /// <param name="data">request bytes</param>
        /// <param name="requestId">request id</param>
        /// <param name="callback">callback when request is finished</param>
        /// <param name="asyncState">async state object</param>
        /// <returns></returns>
        protected IAsyncResult BeginRequest(KsiServiceRequestType requestType, byte[] data, ulong requestId, AsyncCallback callback, object asyncState)
        {
            if (_isDisposed)
            {
                throw new KsiServiceProtocolException("TCP KSI service protocol is disposed.");
            }

            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            TcpKsiServiceAsyncResult asyncResult = new TcpKsiServiceAsyncResult(requestType, data, requestId, callback, asyncState);

            Logger.Debug("Begin TCP request (request id: {0}).", asyncResult.RequestId);

            // Wait until retrying, disposing or error throwing is in progress
            lock (_syncObject)
            {
                _asyncResults.Add(requestId, asyncResult);
            }

            if (_socket == null)
            {
                CreateSocketAndConnect();
            }

            // Before starting sending request check that other request (possibly failed) haven't finished and disposed the async result.
            if (!asyncResult.IsDisposed)
            {
                ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, EndBeginRequestCallback, asyncResult, _requestTimeOut, true);

                BeginSend(asyncResult);
            }

            return(asyncResult);
        }
コード例 #3
0
 /// <summary>
 /// Create TCP KSI service async result instance
 /// </summary>
 /// <param name="serviceRequestType">Service request type</param>
 /// <param name="postData">Posted bytes</param>
 /// <param name="requestId">Request ID</param>
 /// <param name="callback">callback when TCP request is finished</param>
 /// <param name="asyncState">callback async state object</param>
 public TcpKsiServiceAsyncResult(KsiServiceRequestType serviceRequestType, byte[] postData, ulong requestId, AsyncCallback callback, object asyncState)
     : base(postData, requestId, callback, asyncState)
 {
     ServiceRequestType = serviceRequestType;
 }