/// <summary> /// 下载完成调用 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { //到此则一个文件下载完毕 DownloadCompliteFileInfo = (SynFileInfo)e.UserState; if (DownloadCompliteFileInfo.FileSize != DownloadCompliteFileInfo.Size) { DownloadCompliteFileInfo.RowObject.Cells["Image"].Value = Resources.cross; DownloadCompliteFileInfo.RowObject.Cells["SynSpeed"].Value = "0%"; ECON++; this.DownloadSize = this.DownloadSize - DownloadCompliteFileInfo.FileSize; } else { this.infor.DownloadFileList.Remove(this.infor.DownloadFileList.Where(c => c.Name == DownloadCompliteFileInfo.DocName).FirstOrDefault()); DownloadCompliteFileInfo.RowObject.Cells["Image"].Value = Resources.tick; CON++; lbl_SUM.Text = string.Format("文件:{0}/{1}", CON, SUM); string path = "//File[@Name='" + DownloadCompliteFileInfo.DocName + "']"; XmlNode root = file[2].SelectSingleNode(path); if (root == null) { XmlElement subElement = localDoc.CreateElement("File"); subElement.SetAttribute("Name", DownloadCompliteFileInfo.DocName); subElement.SetAttribute("Version", DownloadCompliteFileInfo.Version); subElement.SetAttribute("Size", DownloadCompliteFileInfo.Size.ToString()); file[2].AppendChild(subElement); } else { root.Attributes[1].Value = DownloadCompliteFileInfo.Version; root.Attributes[2].Value = DownloadCompliteFileInfo.Size.ToString(); } localDoc.Save(xmlPath); } m_SynFileInfoList.Remove(DownloadCompliteFileInfo); if (m_SynFileInfoList.Count <= 0) { tr.Abort(); pb_All.Value = (int)this.DownloadSize; lbl_Size.Text = string.Format("大小:{0}/{1}", FileOperate.GetAutoSizeString(this.DownloadSize, 2), TotalSize); if (ECON != 0) { lbl_Error.Text = "文件更新失败" + ECON + "个,请尝试重新更新!\n提示:本地网络限制或访问服务器会更新失败"; lbl_Error.Visible = true; btn_OK.Text = "重新更新"; } else { CutNewFile(); CreateDesk(); CompledUpdate(); } file[0].InnerText = this.version; file[1].InnerText = this.remark; localDoc.Save(xmlPath); btn_OK.Enabled = true; } }
/// <summary> /// 下载进度条 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { SynFileInfo m_SynFileInfo = (SynFileInfo)e.UserState; m_SynFileInfo.SynProgress = e.ProgressPercentage + "%"; double secondCount = (DateTime.Now - m_SynFileInfo.LastTime).TotalSeconds; m_SynFileInfo.SynSpeed = FileOperate.GetAutoSizeString(Convert.ToDouble(e.BytesReceived / secondCount), 2) + "/s"; //更新DataGridView中相应数据显示下载进度 m_SynFileInfo.RowObject.Cells["SynProgress"].Value = m_SynFileInfo.SynProgress; //更新DataGridView中相应数据显示下载速度(总进度的平均速度) m_SynFileInfo.RowObject.Cells["SynSpeed"].Value = m_SynFileInfo.SynSpeed; }
/// <summary> /// 下载进度条 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { DownloadFileInfo = (SynFileInfo)e.UserState; DownloadFileInfo.RowObject.Cells["Image"].Value = Resources.hourglass_go; DownloadFileInfo.SynProgress = e.ProgressPercentage + "%"; DownloadFileInfo.SynSpeed = FileOperate.GetAutoSizeString(e.BytesReceived, 2); DownloadFileInfo.RowObject.Cells["SynSpeed"].Value = DownloadFileInfo.SynProgress; DownloadFileInfo.FileSize = e.TotalBytesToReceive; this.DownloadSize += ToInt(e.BytesReceived) - ToInt(DownloadFileInfo.RowObject.Cells["SynProgress"].Value); DownloadFileInfo.RowObject.Cells["SynProgress"].Value = e.BytesReceived; pb_All.Value = (int)this.DownloadSize; lbl_Size.Text = string.Format("大小:{0}/{1}", FileOperate.GetAutoSizeString(this.DownloadSize, 2), TotalSize); }
void AddBatchDownload() { try { //清空行数据 dgvDownLoad.Rows.Clear(); //添加列表(建立多个任务) List <ArrayList> arrayListList = new List <ArrayList>(); double size = 0; double Totle = 0; for (int i = 0; i < this.infor.DownloadFileList.Count; i++) { size = Convert.ToDouble(this.infor.DownloadFileList[i].Size); Totle += size; arrayListList.Add(new ArrayList() { Resources.hourglass, i, this.infor.DownloadFileList[i].Name, FileOperate.GetAutoSizeString(size, 2), "0%", "0%", size, this.infor.DownloadFileList[i].Version }); } pb_All.Value = 0; pb_All.Maximum = int.Parse(Totle.ToString()); SUM = arrayListList.Count; lbl_SUM.Text = string.Format("文件:{0}/{1}", CON, SUM); TotalSize = FileOperate.GetAutoSizeString(Totle, 2); lbl_Size.Text = string.Format("大小:{0}/{1}", 0, TotalSize); lbl_Wait.Visible = false; foreach (ArrayList arrayList in arrayListList) { int rowIndex = dgvDownLoad.Rows.Add(arrayList.ToArray()); arrayList[3] = 0; arrayList.Add(dgvDownLoad.Rows[rowIndex]); //取出列表中的行信息保存列表集合(m_SynFileInfoList)中 m_SynFileInfoList.Add(new SynFileInfo(arrayList.ToArray())); } lbl_Info.Text = string.Format("发布最新版本:{0}\n优化内容:\n{1}", this.version, this.remark); } catch (Exception ex) { MessageBox.Show(ex.Message); } }