/// <summary> /// /// </summary> /// <param name="uri"></param> /// <param name="requestMethod"></param> /// <param name="bufferSize"></param> /// <param name="destinationStream"></param> /// <param name="contentLength"></param> /// <param name="isAsync"></param> /// <returns></returns> protected WebRequestContext CreateRequestContext(Uri uri, WebRequestMethod requestMethod, int bufferSize, FileStream destinationStream, long contentLength, bool isAsync = false) { var _request = CreateRequest(uri, requestMethod); var _context = new WebRequestContext(_request, requestMethod, bufferSize, destinationStream, contentLength, isAsync); return(_context); }
/// <summary> /// /// </summary> /// <param name="uri"></param> /// <param name="requestMethod"></param> /// <param name="isAsync"></param> /// <returns></returns> protected WebRequestContext CreateRequestContext(Uri uri, WebRequestMethod requestMethod, bool isAsync = false) { var _request = CreateRequest(uri, requestMethod); var _context = new WebRequestContext(_request, requestMethod, isAsync); return(_context); }
/// <summary> /// /// </summary> /// <param name="requestContext"></param> /// <returns></returns> protected virtual void HandleRequestResponseStream(WebRequestContext requestContext) { if (!requestContext.IsInError && null != requestContext.Response) { try { requestContext.RequestState = new WebRequestState(requestContext.Response.GetResponseStream()); if (!requestContext.IsAsync) { while (0 < requestContext.ReadContent()) { requestContext.WriteContent(); } return; } requestContext.BeginReadContent(new AsyncCallback(BeginReadContentCallback)); } catch (Exception ex) { requestContext.HandleThrownException(ex); RaiseFaultedEvent(requestContext); } } }
/// <summary> /// /// </summary> /// <param name="requestContext"></param> protected virtual void HandleWriteContentToRequestStream(WebRequestContext requestContext) { if (!requestContext.IsInError && null != requestContext.RequestState) { try { if (!requestContext.IsAsync) { _bytesRead = 0; _totalBytesRead = 0L; _byteBuffer = new byte[requestContext.BufferSize]; while (0 < (_bytesRead = requestContext.Content.Read(_byteBuffer, 0, _byteBuffer.Length))) { _totalBytesRead += _bytesRead; requestContext.RequestState.SourceStream.Write(_byteBuffer, 0, _bytesRead); } return; } requestContext.BeginReadContent(new AsyncCallback(BeginReadContentCallback)); } catch (Exception ex) { requestContext.HandleThrownException(ex); RaiseFaultedEvent(requestContext); } } }
/// <summary> /// /// </summary> /// <param name="uri"></param> /// <param name="requestMethod"></param> /// <param name="bufferSize"></param> /// <param name="sourceStream"></param> /// <param name="contentLength"></param> /// <returns></returns> protected WebRequestContext CreateRequestContext(Uri uri, WebRequestMethod requestMethod, int bufferSize, FileStream sourceStream, bool isAsync = false) { var _request = CreateRequest(uri, requestMethod); var _context = new WebRequestContext(_request, requestMethod, bufferSize, sourceStream, isAsync); _byteBuffer = new byte[bufferSize]; return(_context); }
/// <summary> /// /// </summary> /// <param name="requestContext"></param> void RaiseFaultedEvent(WebRequestContext requestContext) { var _argument = new WebRequestEventArgs(requestContext); if (null != Faulted) { Faulted(this, _argument); } OnFaulted(_argument); }
/// <summary> /// /// </summary> /// <param name="requestContext"></param> void RaiseWritingProgressChanged(WebRequestContext requestContext) { var _argument = new WebRequestWritingProgressChangedEventArgs(requestContext, requestContext.RequestState.TotalBytesHandled, requestContext.ContentLength); if (null != WritingProgressChanged) { WritingProgressChanged(this, _argument); } OnWritingProgressChanged(_argument); }
/// <summary> /// /// </summary> /// <param name="requestContext"></param> void RaiseReadingCompletedEvent(WebRequestContext requestContext) { var _argument = new WebRequestEventArgs(requestContext); if (null != ReadingCompleted) { ReadingCompleted(this, _argument); } OnReadingCompleted(_argument); }
/// <summary> /// /// </summary> /// <param name="requestContext"></param> void RaiseGettingComplatedEvent(WebRequestContext requestContext) { var _argument = new WebRequestEventArgs(requestContext); if (null != GettingComplated) { GettingComplated(this, _argument); } OnGettingCompleted(_argument); }
/// <summary> /// /// </summary> public void Initialize(WebRequestContext requestContext) { if (!_isInitialized) { _bytesHandled = 0; _totalBytesHandled = 0L; _byteBuffer = new byte[requestContext.BufferSize]; _isInitialized = true; } }
/// <summary> /// /// </summary> /// <param name="requestContext"></param> /// <returns></returns> protected virtual void HandleRequestResponse(WebRequestContext requestContext) { if (!requestContext.IsInError) { try { if (!requestContext.IsAsync) { requestContext.Response = requestContext.Request.GetResponse(); return; } requestContext.Request.BeginGetResponse(new AsyncCallback(BeginGetResponseCallback), requestContext); } catch (Exception ex) { requestContext.HandleThrownException(ex); RaiseFaultedEvent(requestContext); } } }
/// <summary> /// /// </summary> /// <param name="requestContext"></param> protected abstract IExternalResult GetRequestResult(WebRequestContext requestContext);
/// <summary> /// /// </summary> /// <param name="requestContext"></param> /// <param name="bytesRead"></param> /// <param name="totalBytesToRead"></param> public WebRequestReadingProgressChangedEventArgs(WebRequestContext requestContext, long bytesRead, long totalBytesToRead) : base(requestContext) { _bytesRead = bytesRead; _totalBytesToRead = totalBytesToRead; }
/// <summary> /// /// </summary> /// <param name="requestContext"></param> /// <param name="bytesWritten"></param> /// <param name="totalBytesToWrite"></param> public WebRequestWritingProgressChangedEventArgs(WebRequestContext requestContext, long bytesWritten, long totalBytesToWrite) : base(requestContext) { _bytesWritten = bytesWritten; _totalBytesToWrite = totalBytesToWrite; }
/// <summary> /// /// </summary> /// <param name="requestContext"></param> public WebRequestEventArgs(WebRequestContext requestContext) : base() { _requestContext = requestContext; }