⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 requeststate.cs

📁 JAVA的精彩实例
💻 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 HttpWebRequest Request ;
        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);
                }
            }


        }

        public void FireRequestException(Exception e)
        {
            if (this.ResponseStream != null)
            {
                this.ResponseStream.Close();
            }
            if (this.WebRequestException != null)
            {
                this.WebRequestException(e);
            }
        }

        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.Request != null)
            {
                this.Request.Abort();
                this.Request = 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);
            
        }
    }


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -