Beispiel #1
0
        //public event doSendMsg;
        //public dlgSendMsg doSendMsg = null;
        private void download(string path, string dir, string filename, int id = 0)
        {
            try
            {
                DownMsg msg = new DownMsg();
                msg.Id  = id;
                msg.Tag = 0;
                doSendMsg(msg);
                FileDownloader loader = new FileDownloader(path, dir, filename, ThreadNum);
                loader.data.Clear();
                msg.Tag    = DownStatus.Start;
                msg.Length = (int)loader.getFileSize();;
                doSendMsg(msg);
                DownloadProgressListener linstenter = new DownloadProgressListener(msg);
                linstenter.doSendMsg = new DownloadProgressListener.dlgSendMsg(doSendMsg);
                loader.download(linstenter);
            }
            catch (Exception ex)
            {
                DownMsg msg = new DownMsg();
                msg.Id         = id;
                msg.Length     = 0;
                msg.Tag        = DownStatus.Error;
                msg.ErrMessage = ex.Message;
                doSendMsg(msg);

                Console.WriteLine(ex.Message);
            }
        }
Beispiel #2
0
 private void Change(DownMsg msg)
 {
     if (msg.Tag == DownStatus.Error || msg.Tag == DownStatus.End)
     {
         StartDown(1);
     }
 }
        public void OnDownloadSize(long size)
        {
            if (downMsg == null)
            {
                DownMsg downMsg = new DownMsg();
            }


            //下载速度
            if (downMsg.Size == 0)
            {
                downMsg.Speed = size;
            }
            else
            {
                downMsg.Speed = size - downMsg.Size;
            }
            if (downMsg.Speed == 0)
            {
                downMsg.Surplus     = -1;
                downMsg.SurplusInfo = "未知";
            }
            else
            {
                downMsg.Surplus = ((downMsg.Length - downMsg.Size) / downMsg.Speed);
            }
            downMsg.Size = size; //下载总量

            if (size == downMsg.Length)
            {
                //下载完成
                downMsg.Tag         = DownStatus.End;
                downMsg.SpeedInfo   = "0 K";
                downMsg.SurplusInfo = "已完成";
            }
            else
            {
                //下载中
                downMsg.Tag = DownStatus.DownLoad;
            }


            if (doSendMsg != null)
            {
                doSendMsg(downMsg);                   //通知具体调用者下载进度
            }
        }
 public DownloadProgressListener(DownMsg downmsg)
 {
     this.downMsg = downmsg;
     //this.id = id;
     //this.Length = Length;
 }