Beispiel #1
0
        public void TransferFile(FileTransfer fileTransfer)
        {
            this.executing = true;
            this.Execute();
            int    fileCount = 0;
            long   totalSize = 0;
            string fileName  = String.Empty;

            this.noneCopiedList = new List <string>();
            try
            {
                DateTime start = DateTime.Now;
                foreach (FileInfo file in fileTransfer.CopyFileList)
                {
                    if (!this.executing)
                    {
                        this.Cancel();
                        return;
                    }
                    MediaConfig mediaConfig = fileTransfer.GetMediaType(file);
                    if (mediaConfig == null)
                    {
                        continue;
                    }
                    string path = fileTransfer.GetDestinationDirectory(mediaConfig, file);
                    fileTransfer.CreateDestinationDirectory(path);
                    path += Path.DirectorySeparatorChar + file.Name;
                    FileInfo target = new FileInfo(path);
                    if (target.Exists)
                    {
                        log.Info(String.Format(Properties.Resources.NotCopiedFile, path));
                        this.noneCopiedList.Add(file.FullName);
                        continue;
                    }
                    this.lblFileName.Text = String.Format(Properties.Resources.FileNameMessage, file.FullName, file.Length / 1000000, path);
                    Refresh();
                    file.CopyTo(path);
                    fileCount++;
                    totalSize += file.Length;

                    double percentage = (double)((double)totalSize / (double)fileTransfer.TotalSize) * 100;
                    this.progressBar1.Value = (int)percentage;

                    fileName = file.FullName;
                    this.lblFileCount.Text = String.Format(Properties.Resources.FileCountMessage, fileCount, fileTransfer.FileCount);
                    this.lblProgress.Text  = String.Format(Properties.Resources.ProgressMessage,
                                                           totalSize / 1000000, fileTransfer.TotalSize / 1000000, (int)percentage, this.GetRemainTime(start, percentage));
                    Refresh();
                    Application.DoEvents();
                }
                ;
                if (this.noneCopiedList.Count > 0)
                {
                    SkippedFileList skippedFileList = new SkippedFileList();
                    skippedFileList.SetFileList(String.Join("\r\n", this.noneCopiedList));
                    skippedFileList.Show();
                }
                TimeSpan timeSpan = DateTime.Now.Subtract(start);
                this.lblFileCount.Text = String.Format(Properties.Resources.FileCountMessage, fileCount, fileTransfer.FileCount);
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message,
                                Properties.Resources.ErrorCaption,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error
                                );
                log.Error(ex.Message, ex);
                this.Init();
                this.lblFileName.Text = String.Format(Properties.Resources.FileNameMessageError, fileName);
                throw new Exception(ex.Message, ex);
            }
        }