Example #1
0
        /// <summary>
        /// 计算复制进度
        /// </summary>
        void copyProgress_ReportCopyProgress(object sender, ProgressInfoEventArgs e)
        {
            if (this.progressBar.InvokeRequired)
            {
                Action<object, ProgressInfoEventArgs> action = new Action<object, ProgressInfoEventArgs>(copyProgress_ReportCopyProgress);
                this.progressBar.Invoke(action, sender, e);
            }
            else
            {
                try
                {
                    stringBuilder.Clear();
                    stringBuilder.Append("[" + DateTime.Now.ToString() + "]");
                    stringBuilder.Append(" " + e.MT.ToString() + ": " + e.Name);
                    stringBuilder.Append(Environment.NewLine);
                    this.textBox1.AppendText(stringBuilder.ToString());

                    string filename = e.Name;
                    if (e.MT == MessageType.EXIST)
                    {
                        filename += " 已经存在";
                    }
                    lock (obj)
                    {
                        WriteRecord(filename, recordPath);
                        this.progressBar.Value += 1;
                        double value = this.progressBar.Value * 1.0 / count * 100;
                        this.labelInfo.Text = string.Format("{0:.00}%", value);
                    }
                }
                catch (Exception)
                {
                }
            }
        }
Example #2
0
 /// <summary>
 /// 开始复制过程,外部调用
 /// </summary>
 public void StartCopy()
 {
     if (!Directory.Exists(destFolder))
     {
         Directory.CreateDirectory(destFolder);
     }
     StringBuilder sql = new StringBuilder("select * from datainfo where 1=1 ");
     sql.Append(append);
     SqlDataReader reader = DataBaseControl.RunSqlForDataReader(sql.ToString());
     while (reader.Read())
     {
         string name = reader["name"].ToString();
         string fullpath = reader["fullpath"].ToString();
         if (!File.Exists(fullpath))
         {
             ProgressInfoEventArgs e = new ProgressInfoEventArgs(MessageType.ERR, name);
             OnReportCopyProgress(e);
             continue;
         }
         Func<string, string, ProgressInfoEventArgs> copyAction = CopyFile;
         copyAction.BeginInvoke(name, fullpath, new AsyncCallback(CopyFileCallBack), copyAction);
     }
     reader.Close();
     DataBaseControl.CloseConnection();
 }
Example #3
0
 /// <summary>
 /// 触发上报进度事件
 /// </summary>
 /// <param name="e"></param>
 private void OnReportCopyProgress(ProgressInfoEventArgs e)
 {
     EventHandler<ProgressInfoEventArgs> temp = Interlocked.CompareExchange(ref ReportCopyProgress, null, null);
     if (temp != null)
     {
         temp(this, e);
     }
 }