コード例 #1
0
        /// <summary>
        /// Saves the raw response to disk
        /// </summary>
        /// <param name="requestId"></param>
        /// <param name="data"></param>
        public void SaveResponse(int requestId, byte[] data)
        {
            RequestResponseBytes reqData = new RequestResponseBytes();

            reqData.AddToResponse(data);
            SaveResponse(requestId, reqData);
        }
コード例 #2
0
        /// <summary>
        /// Creates a deep copy of the request data object
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            RequestResponseBytes clone = new RequestResponseBytes();

            clone.RawRequest  = this.RawRequest.Clone() as byte[];
            clone.RawResponse = this.RawResponse.Clone() as byte[];

            return(clone);
        }
コード例 #3
0
        /// <summary>
        /// Save the raw request with the specified response
        /// </summary>
        /// <param name="requestId"></param>
        /// <param name="request"></param>
        /// <param name="response"></param>
        public void SaveRequestResponse(int requestId, byte[] request, byte[] response)
        {
            RequestResponseBytes data = new RequestResponseBytes();

            data.AddToRequest(request);
            data.AddToResponse(response);

            SaveRequest(requestId, data);
            SaveResponse(requestId, data);
        }
コード例 #4
0
        /// <summary>
        /// Commits a response to the memory cache
        /// </summary>
        /// <param name="reqHeaderId"></param>
        /// <param name="data"></param>
        private void BufferSaveResponse(int reqHeaderId, byte[] data)
        {
            ICacheable entry = RequestDataCache.Instance.GetEntry(_objectId ^ reqHeaderId);

            if (entry != null)
            {
                RequestResponseBytes reqData = entry.Reserve() as RequestResponseBytes;
                reqData.RawResponse = data;
                entry.Release();
            }
        }
コード例 #5
0
        /// <summary>
        /// Retrieves the request bytes from disk or from the memory cache
        /// </summary>
        /// <param name="requestHeaderId"></param>
        /// <returns></returns>
        public byte[] LoadRequestData(int requestHeaderId)
        {
            byte[] result = new byte[0];
            try
            {
                lock (_lockData)                 //critical section begins
                {
                    TVRequestInfo reqInfo;
                    if (_requestInfos.TryGetValue(requestHeaderId, out reqInfo) && reqInfo.RequestLength > 0)
                    {
                        //check if the request is already in the buffer
                        ICacheable           entry   = RequestDataCache.Instance.GetEntry(_objectId ^ requestHeaderId);
                        RequestResponseBytes reqData = null;
                        if (entry != null)
                        {
                            reqData = entry.Reserve() as RequestResponseBytes;
                            entry.Release();
                        }

                        if (reqData != null && reqData.RawRequest != null)
                        {
                            result = reqData.RawRequest;
                        }
                        else
                        {
                            //load request from disk
                            int  length        = reqInfo.RequestLength;
                            long startPosition = reqInfo.RequestStartPosition;
                            result = DataRead(startPosition, length);

                            //save request to buffer if is not null
                            if (result.Length != 0)
                            {
                                BufferSaveRequest(requestHeaderId, result);
                            }
                        }

                        if (reqInfo.IsEncrypted && result != null && result.Length > 0)
                        {
                            //decrypt the request
                            result = Encryptor.Decrypt(result);
                        }
                    }
                }                 //critical section ends
            }
            catch (Exception ex)
            {
                SdkSettings.Instance.Logger.Log(TraceLevel.Error, "Cannot load request data for request id: {0} . Stack trace: {1}", requestHeaderId, ex.ToString());
            }

            return(result);
        }
コード例 #6
0
        /// <summary>
        /// Commits a request to the memory cache
        /// </summary>
        /// <param name="reqHeaderId"></param>
        /// <param name="data"></param>
        private void BufferSaveRequest(int reqHeaderId, byte[] data)
        {
            if (!_cacheEnabled)
            {
                return;
            }

            ICacheable           entry = RequestDataCache.Instance.GetEntry(_objectId ^ reqHeaderId);
            RequestResponseBytes reqData;

            if (entry == null)
            {
                reqData            = new RequestResponseBytes();
                reqData.RawRequest = data;
                RequestDataCache.Instance.Add(_objectId ^ reqHeaderId, new CacheEntry(reqData));
            }
            else
            {
                reqData            = entry.Reserve() as RequestResponseBytes;
                reqData.RawRequest = data;
                entry.Release();
            }
        }
コード例 #7
0
        /// <summary>
        /// Saves response bytes to disk and caches it if tail is on
        /// </summary>
        /// <param name="requestId"></param>
        /// <param name="data">Request data object storing the response</param>
        public void SaveResponse(int requestId, RequestResponseBytes data)
        {
            if (data == null || data.RawResponse == null)
            {
                return;
            }

            bool          isResponseChanged = false;
            TVRequestInfo reqInfo           = null;

            try
            {
                lock (_lockData)                 //critical section begins
                {
                    if (_requestInfos.ContainsKey(requestId))
                    {
                        //save to memory buffer only if tail is on
                        //this is done to use minimum memory footprint since on
                        //normal load the user is viewing the requests
                        //at the beginning of the file
                        reqInfo = _requestInfos[requestId];
                        //save to disk
                        reqInfo.ResponseStartPosition = WritePosition;

                        string respStatus = null;

                        if (_tailInProgress || RequestDataCache.Instance.GetEntry(_objectId ^ requestId) != null || reqInfo.IsEncrypted)
                        {
                            byte[] rawResponse = data.RawResponse;
                            respStatus = HttpResponseInfo.GetResponseStatus(rawResponse);
                            //this takes memory but at the same time insures that the user can see the data fast during tail

                            if (reqInfo.IsEncrypted)
                            {
                                rawResponse = Encryptor.Encrypt(rawResponse);
                            }

                            BufferSaveResponse(requestId, rawResponse);
                            DataWrite(rawResponse, 0, rawResponse.Length);
                            reqInfo.ResponseLength = rawResponse.Length;
                        }
                        else
                        {
                            byte[] chunk;
                            //this saves memory and writes the chunks of data directly to disk
                            data.ResetResponseChunkPosition();
                            while ((chunk = data.ReadResponseChunk()) != null)
                            {
                                if (respStatus == null)
                                {
                                    respStatus = HttpResponseInfo.GetResponseStatus(chunk);
                                }
                                DataWrite(chunk, 0, chunk.Length);
                            }
                            reqInfo.ResponseLength = data.ResponseSize;
                        }

                        reqInfo.ResponseStatus = respStatus;
                        isResponseChanged      = true;
                    }
                }                //critical section ends

                if (isResponseChanged && ResponseChanged != null)
                {
                    ResponseChanged.Invoke(
                        new TVDataAccessorDataArgs(requestId, reqInfo));
                }
            }
            catch (Exception ex)
            {
                SdkSettings.Instance.Logger.Log(TraceLevel.Error, "Error saving response data for request id: {0} . Stack trace: {1}", requestId, ex.ToString());
            }
        }