Ejemplo n.º 1
0
        private void TransferFiles()
        {
            DateTime starttime  = DateTime.Now;
            long     totalbytes = 0;
            AsyncObservableCollection <FileItem> itemstoExport =
                new AsyncObservableCollection <FileItem>(Items.Where(x => x.IsChecked));

            dlg.MaxValue = itemstoExport.Count;
            dlg.Progress = 0;
            int          i       = 0;
            PhotoSession session = (PhotoSession)CameraDevice.AttachedPhotoSession ??
                                   ServiceProvider.Settings.DefaultSession;

            foreach (FileItem fileItem in itemstoExport)
            {
                dlg.Label       = fileItem.FileName;
                dlg.ImageSource = fileItem.Thumbnail;
                string fileName = Path.Combine(session.Folder, fileItem.FileName);
                if (File.Exists(fileName))
                {
                    fileName =
                        StaticHelper.GetUniqueFilename(
                            Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + "_", 0,
                            Path.GetExtension(fileName));
                }
                CameraDevice.TransferFile(fileItem.DeviceObject.Handle, fileName);
                // double check if file was transferred
                if (File.Exists(fileName) && delete)
                {
                    CameraDevice.DeleteObject(fileItem.DeviceObject);
                }
                totalbytes += new FileInfo(fileName).Length;
                session.AddFile(fileName);
                i++;
                dlg.Progress = i;
            }
            dlg.Hide();
            double transfersec = (DateTime.Now - starttime).TotalSeconds;

            Log.Debug(string.Format(
                          "[BENCHMARK]Total byte transferred ;{0}\nTotal seconds :{1}\nSpeed : {2} Mbyte/sec ", totalbytes,
                          transfersec, (totalbytes / transfersec / 1024 / 1024).ToString("0000.00")));
        }