📄 requeststate.cs
字号:
using System;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using feiyun0112.cnblogs.com.CSDNReader.Functions;
using System.Collections.Generic;
namespace feiyun0112.cnblogs.com.CSDNReader.Model
{
public class RequestState:IDisposable
{
public const int BUFFER_SIZE = 0x1000;
public byte[] BufferRead = new byte[0x1000];
public string ContentEncoding;
public RequestInfo requestInfo ;
public MemoryStream RequestData = new MemoryStream();
public Stream ResponseStream;
public StartDownloadCallback StartDownload;
public RequestCompleteCallback WebRequestComplete;
public ExceptionCallback WebRequestException;
public RequestStatePriority Priority;
public void FireRequestComplete()
{
if ((this.WebRequestComplete != null) && (this.RequestData != null))
{
byte[] dataBuffer = this.RequestData.GetBuffer();
try
{
this.WebRequestComplete(dataBuffer);
}
catch (Exception e)
{
FireRequestException(e);
}
finally
{
this.Dispose();
}
}
}
public void FireRequestException(Exception e)
{
try
{
if (this.ResponseStream != null)
{
this.ResponseStream.Close();
}
if (this.WebRequestException != null)
{
this.WebRequestException(e);
}
}
finally
{
this.Dispose();
}
}
public bool FireStartDownload()
{
if (this.StartDownload != null)
{
return this.StartDownload();
}
return true;
}
public int CompareTo(RequestState x)
{
return this.Priority - x.Priority;
}
#region IDisposable 成员
public void Dispose()
{
BufferRead = null;
if (this.requestInfo != null)
{
if (this.requestInfo.Request != null)
{
this.requestInfo.Request.Abort();
}
this.requestInfo = null;
}
if (this.RequestData != null)
{
this.RequestData.Close();
this.RequestData = null;
}
if (this.ResponseStream != null)
{
this.ResponseStream.Close();
this.ResponseStream = null;
}
}
#endregion
}
public class RequestStateComparer : IComparer<RequestState>
{
public int Compare(RequestState x, RequestState y)
{
return y.CompareTo(x);
}
}
public class RequestInfo
{
private HttpWebRequest _Request;
private string _URL, _Referer, _PostData;
private System.Text.Encoding _encoding;
public RequestInfo(string URL):this(URL, string.Empty, string.Empty, null)
{
}
public RequestInfo(string URL, string strReferer, string PostData, System.Text.Encoding encoding)
{
_Request = null;
_URL=URL;
_Referer=strReferer;
_PostData=PostData;
_encoding = encoding;
}
public HttpWebRequest Request
{
get
{
if (_Request == null)
{
_Request = WEBFunc.CreateWebRequest(_URL, _Referer, _PostData,_encoding);
}
return _Request;
}
}
public void Reset()
{
_Request = null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -