Пример #1
0
 //反注册
 public void UnRegisteFileHttpDownload(uint sid)
 {
     for (int i = 0; i < _httpSessions.Count; i++)
     {
         HttpFileSession session = _httpSessions[i];
         if (session.Id == sid)
         {
             session.Stop();
             session.IsOver = true;
             break;
         }
         _httpSessions[i] = session;
     }
     Clean();
 }
Пример #2
0
        void IScheduleHandler.OnScheduleHandle(ScheduleType type, uint id)
        {
            if (_httpSessions == null || _httpSessions.Count <= 0)
            {
                return;
            }
            //
            int workCnt = 0;

            //
            for (int i = 0; i < _httpSessions.Count; i++)
            {
                HttpFileSession ss = _httpSessions[i];
                if (ss != null)
                {
                    if (ss.IsBegined)
                    {
                        workCnt++;
                        ss.Update();
                    }
                    if (workCnt <= MaxParallelCnt)
                    {
                        if (ss.IsBegined == false)
                        {
                            ss.IsBegined = true;
                            ss.Begin();
                        }
                    }
                    else
                    {
                        //等待
                    }
                }
                _httpSessions[i] = ss;
            }
            //
            Clean();
        }
Пример #3
0
        /// 注册下载文件
        public uint RegisteFileHttpDownload(string url, string filePath, HttpFileSessionDelegate handler = null)
        {
            if (string.IsNullOrEmpty(url) || (filePath == null))
            {
                JW.Common.Log.LogE("RegisteFileHttpDownload:Arg Error");
                return(0);
            }
            if ((!url.Contains("http://")) && (!url.Contains("https://")))
            {
                url = "http://" + url;
            }

            HttpFileSession hf = new HttpFileSession();

            hf.Url = url;
            hf.DownloadFilePath = filePath;
            hf.Id      = _currentId++;
            hf.Handler = handler;
            if (hf != null && (hf.IsOver == false))
            {
                _httpSessions.Add(hf);
            }
            return(hf.Id);
        }