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"))); }
void PhotoCaptured(object o) { PhotoCapturedEventArgs eventArgs = o as PhotoCapturedEventArgs; if (eventArgs == null) { return; } try { Log.Debug("Photo transfer begin."); eventArgs.CameraDevice.IsBusy = true; CameraProperty property = eventArgs.CameraDevice.LoadProperties(); PhotoSession session = (PhotoSession)eventArgs.CameraDevice.AttachedPhotoSession ?? ServiceProvider.Settings.DefaultSession; StaticHelper.Instance.SystemMessage = ""; if (!eventArgs.CameraDevice.CaptureInSdRam) { if (property.NoDownload) { eventArgs.CameraDevice.IsBusy = false; return; } var extension = Path.GetExtension(eventArgs.FileName); if (extension != null && (session.DownloadOnlyJpg && extension.ToLower() != ".jpg")) { eventArgs.CameraDevice.IsBusy = false; return; } } StaticHelper.Instance.SystemMessage = TranslationStrings.MsgPhotoTransferBegin; string fileName = ""; if (!session.UseOriginalFilename || eventArgs.CameraDevice.CaptureInSdRam) { fileName = session.GetNextFileName(Path.GetExtension(eventArgs.FileName), eventArgs.CameraDevice); } else { fileName = Path.Combine(session.Folder, eventArgs.FileName); if (File.Exists(fileName) && !session.AllowOverWrite) { fileName = StaticHelper.GetUniqueFilename( Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + "_", 0, Path.GetExtension(fileName)); } } if (session.AllowOverWrite && File.Exists(fileName)) { File.Delete(fileName); } if (!Directory.Exists(Path.GetDirectoryName(fileName))) { Directory.CreateDirectory(Path.GetDirectoryName(fileName)); } Log.Debug("Transfer started :" + fileName); //DateTime startTIme = DateTime.Now; eventArgs.CameraDevice.TransferFile(eventArgs.Handle, fileName); //Log.Debug("Transfer done :" + fileName); //Log.Debug("[BENCHMARK]Speed :" + // (new FileInfo(fileName).Length / (DateTime.Now - startTIme).TotalSeconds / 1024 / 1024).ToString("0000.00")); //Log.Debug("[BENCHMARK]Transfer time :" + ((DateTime.Now - startTIme).TotalSeconds).ToString("0000.000")); // write comment and tags directly in transferred file if (ServiceProvider.Settings.DefaultSession.WriteComment) { if (!string.IsNullOrEmpty(ServiceProvider.Settings.DefaultSession.Comment)) { Exiv2Helper.SaveComment(fileName, ServiceProvider.Settings.DefaultSession.Comment); } if (ServiceProvider.Settings.DefaultSession.SelectedTag1 != null && !string.IsNullOrEmpty(ServiceProvider.Settings.DefaultSession.SelectedTag1.Value)) { Exiv2Helper.AddKeyword(fileName, ServiceProvider.Settings.DefaultSession.SelectedTag1.Value); } if (ServiceProvider.Settings.DefaultSession.SelectedTag2 != null && !string.IsNullOrEmpty(ServiceProvider.Settings.DefaultSession.SelectedTag2.Value)) { Exiv2Helper.AddKeyword(fileName, ServiceProvider.Settings.DefaultSession.SelectedTag2.Value); } if (ServiceProvider.Settings.DefaultSession.SelectedTag3 != null && !string.IsNullOrEmpty(ServiceProvider.Settings.DefaultSession.SelectedTag3.Value)) { Exiv2Helper.AddKeyword(fileName, ServiceProvider.Settings.DefaultSession.SelectedTag3.Value); } if (ServiceProvider.Settings.DefaultSession.SelectedTag4 != null && !string.IsNullOrEmpty(ServiceProvider.Settings.DefaultSession.SelectedTag4.Value)) { Exiv2Helper.AddKeyword(fileName, ServiceProvider.Settings.DefaultSession.SelectedTag4.Value); } } _selectedItem = session.AddFile(fileName); //select the new file only when the multiple camera support isn't used to prevent high CPU usage on raw files if (ServiceProvider.Settings.AutoPreview && !ServiceProvider.WindowsManager.Get(typeof(MultipleCameraWnd)).IsVisible&& !ServiceProvider.Settings.UseExternalViewer) { if ((Path.GetExtension(fileName).ToLower() == ".jpg" && ServiceProvider.Settings.AutoPreviewJpgOnly) || !ServiceProvider.Settings.AutoPreviewJpgOnly) { if (ServiceProvider.Settings.DelayImageLoading && (DateTime.Now - _lastLoadTime).TotalSeconds < 4) { _selectiontimer.Stop(); _selectiontimer.Start(); } else { ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.Select_Image, _selectedItem); } } } _lastLoadTime = DateTime.Now; //ServiceProvider.Settings.Save(session); StaticHelper.Instance.SystemMessage = TranslationStrings.MsgPhotoTransferDone; eventArgs.CameraDevice.IsBusy = false; //show fullscreen only when the multiple camera support isn't used if (ServiceProvider.Settings.Preview && !ServiceProvider.WindowsManager.Get(typeof(MultipleCameraWnd)).IsVisible&& !ServiceProvider.Settings.UseExternalViewer) { ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.FullScreenWnd_ShowTimed); } if (ServiceProvider.Settings.UseExternalViewer && File.Exists(ServiceProvider.Settings.ExternalViewerPath)) { string arg = ServiceProvider.Settings.ExternalViewerArgs; arg = arg.Contains("%1") ? arg.Replace("%1", fileName) : arg + " " + fileName; PhotoUtils.Run(ServiceProvider.Settings.ExternalViewerPath, arg, ProcessWindowStyle.Normal); } if (ServiceProvider.Settings.PlaySound) { PhotoUtils.PlayCaptureSound(); } } catch (Exception ex) { eventArgs.CameraDevice.IsBusy = false; StaticHelper.Instance.SystemMessage = string.Format(TranslationStrings.MsgPhotoTransferError, ex.Message); Log.Error("Transfer error !", ex); } Log.Debug("Photo transfer done."); // not indicated to be used GC.Collect(); //GC.WaitForPendingFinalizers(); }
private void TransferFiles() { DateTime starttime = DateTime.Now; long totalbytes = 0; bool somethingwrong = false; AsyncObservableCollection <FileItem> itemstoExport = new AsyncObservableCollection <FileItem>(Items.Where(x => x.IsChecked)); dlg.MaxValue = itemstoExport.Count; dlg.Progress = 0; int i = 0; foreach (FileItem fileItem in itemstoExport) { if (fileItem.ItemType == FileItemType.Missing) { continue; } if (!fileItem.IsChecked) { continue; } dlg.Label = fileItem.FileName; dlg.ImageSource = fileItem.Thumbnail; PhotoSession session = (PhotoSession)fileItem.Device.AttachedPhotoSession ?? ServiceProvider.Settings.DefaultSession; string fileName = ""; if (!session.UseOriginalFilename) { fileName = session.GetNextFileName(Path.GetExtension(fileItem.FileName), fileItem.Device); } else { fileName = Path.Combine(session.Folder, fileItem.FileName); if (File.Exists(fileName)) { fileName = StaticHelper.GetUniqueFilename( Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + "_", 0, Path.GetExtension(fileName)); } } string dir = Path.GetDirectoryName(fileName); if (dir != null && !Directory.Exists(dir)) { Directory.CreateDirectory(dir); } try { fileItem.Device.TransferFile(fileItem.DeviceObject.Handle, fileName); } catch (Exception exception) { somethingwrong = true; Log.Error("Transfer error", exception); } // double check if file was transferred if (File.Exists(fileName)) { if (delete) { fileItem.Device.DeleteObject(fileItem.DeviceObject); } } else { somethingwrong = true; } if (!File.Exists(fileName)) { MessageBox.Show("Unable download file. Aborting!"); break; } totalbytes += new FileInfo(fileName).Length; FileItem item1 = fileItem; Dispatcher.Invoke(new Action(delegate { var item = session.AddFile(fileName); item.CameraSerial = item1.Device.SerialNumber; item.OriginalName = item1.FileName; })); i++; dlg.Progress = i; } Log.Debug("File transfer done"); if (format) { dlg.MaxValue = ServiceProvider.DeviceManager.ConnectedDevices.Count; dlg.Progress = 0; int ii = 0; if (!somethingwrong) { foreach (ICameraDevice connectedDevice in ServiceProvider.DeviceManager.ConnectedDevices) { try { dlg.Label = connectedDevice.DisplayName; ii++; dlg.Progress = ii; Log.Debug("Start format"); Log.Debug(connectedDevice.PortName); connectedDevice.FormatStorage(null); Thread.Sleep(200); Log.Debug("Format done"); } catch (Exception exception) { Log.Error("Unable to format device ", exception); } } } else { Log.Debug("File transfer failed, format aborted!"); StaticHelper.Instance.SystemMessage = "File transfer failed, format aborted!"; } } dlg.Hide(); double transfersec = (DateTime.Now - starttime).TotalSeconds; Log.Debug(string.Format("[BENCHMARK]Total byte transferred ;{0} Total seconds :{1} Speed : {2} Mbyte/sec ", totalbytes, transfersec, (totalbytes / transfersec / 1024 / 1024).ToString("0000.00"))); ServiceProvider.Settings.Save(); ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.DownloadPhotosWnd_Hide); }
void PhotoCaptured(object o) { PhotoCapturedEventArgs eventArgs = o as PhotoCapturedEventArgs; if (eventArgs == null) { return; } if (!BarcodeVerified) { ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.Select_Image, new FileItem("")); ShowWarning("Invalid Barcode; Image not transfered!"); return; } try { Log.Debug("Photo transfer begin."); eventArgs.CameraDevice.IsBusy = true; CameraProperty property = ServiceProvider.Settings.CameraProperties.Get(eventArgs.CameraDevice); PhotoSession session = (PhotoSession)eventArgs.CameraDevice.AttachedPhotoSession ?? ServiceProvider.Settings.DefaultSession; StaticHelper.Instance.SystemMessage = ""; if (!eventArgs.CameraDevice.CaptureInSdRam) { if (property.NoDownload) { eventArgs.CameraDevice.IsBusy = false; return; } var extension = Path.GetExtension(eventArgs.FileName); if (extension != null && (session.DownloadOnlyJpg && extension.ToLower() != ".jpg")) { eventArgs.CameraDevice.IsBusy = false; return; } } StaticHelper.Instance.SystemMessage = TranslationStrings.MsgPhotoTransferBegin; string fileName = ""; if (!session.UseOriginalFilename || eventArgs.CameraDevice.CaptureInSdRam) { fileName = session.GetNextFileName(Path.GetExtension(eventArgs.FileName), eventArgs.CameraDevice); } else { fileName = Path.Combine(session.Folder, eventArgs.FileName); if (File.Exists(fileName)) { fileName = StaticHelper.GetUniqueFilename( Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + "_", 0, Path.GetExtension(fileName)); } } if (!Directory.Exists(Path.GetDirectoryName(fileName))) { Directory.CreateDirectory(Path.GetDirectoryName(fileName)); } var tmpFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), Settings.AppName, "Cache", Path.GetFileName(fileName)); if (!Directory.Exists(Path.GetDirectoryName(tmpFileName))) { Directory.CreateDirectory(Path.GetDirectoryName(tmpFileName)); } Log.Debug("Transfer started :" + tmpFileName); DateTime startTIme = DateTime.Now; eventArgs.CameraDevice.TransferFile(eventArgs.Handle, tmpFileName); Log.Debug("Transfer done :" + tmpFileName); Log.Debug("[BENCHMARK]Speed :" + (new System.IO.FileInfo(tmpFileName).Length / (DateTime.Now - startTIme).TotalSeconds / 1024 / 1024).ToString("0000.00")); Log.Debug("[BENCHMARK]Transfer time :" + ((DateTime.Now - startTIme).TotalSeconds).ToString("0000.000")); //select the new file only when the multiple camera support isn't used to prevent high CPU usage on raw files if (ServiceProvider.Settings.AutoPreview && !ServiceProvider.WindowsManager.Get(typeof(MultipleCameraWnd)).IsVisible&& !ServiceProvider.Settings.UseExternalViewer) { var fileItem = session.AddFile(tmpFileName); fileItem.DestinationFilename = fileName; ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.Select_Image, fileItem); } else { System.IO.File.Move(tmpFileName, fileName); session.AddFile(fileName); } //ServiceProvider.Settings.Save(session); StaticHelper.Instance.SystemMessage = TranslationStrings.MsgPhotoTransferDone; BarcodeUsed = true; eventArgs.CameraDevice.IsBusy = false; //show fullscreen only when the multiple camera support isn't used if (ServiceProvider.Settings.Preview && !ServiceProvider.WindowsManager.Get(typeof(MultipleCameraWnd)).IsVisible&& !ServiceProvider.Settings.UseExternalViewer) { ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.FullScreenWnd_ShowTimed); } if (ServiceProvider.Settings.UseExternalViewer && File.Exists(ServiceProvider.Settings.ExternalViewerPath)) { string arg = ServiceProvider.Settings.ExternalViewerArgs; arg = arg.Contains("%1") ? arg.Replace("%1", fileName) : arg + " " + fileName; PhotoUtils.Run(ServiceProvider.Settings.ExternalViewerPath, arg, ProcessWindowStyle.Normal); } if (ServiceProvider.Settings.PlaySound) { PhotoUtils.PlayCaptureSound(); } } catch (Exception ex) { eventArgs.CameraDevice.IsBusy = false; StaticHelper.Instance.SystemMessage = string.Format(TranslationStrings.MsgPhotoTransferError, ex.Message); Log.Error("Transfer error !", ex); } Log.Debug("Photo transfer done."); // not indicated to be used GC.Collect(); //GC.WaitForPendingFinalizers(); }
/// <summary> /// Photoes the captured. /// </summary> /// <param name="o">The o.</param> private void PhotoCaptured(object o) { PhotoCapturedEventArgs eventArgs = o as PhotoCapturedEventArgs; if (eventArgs == null) { return; } try { Log.Debug("Photo transfer begin."); eventArgs.CameraDevice.IsBusy = true; CameraProperty property = eventArgs.CameraDevice.LoadProperties(); PhotoSession session = (PhotoSession)eventArgs.CameraDevice.AttachedPhotoSession ?? ServiceProvider.Settings.DefaultSession; StaticHelper.Instance.SystemMessage = ""; if (!eventArgs.CameraDevice.CaptureInSdRam) { if (property.NoDownload) { eventArgs.CameraDevice.IsBusy = false; return; } var extension = Path.GetExtension(eventArgs.FileName); if (extension != null && (session.DownloadOnlyJpg && extension.ToLower() != ".jpg")) { eventArgs.CameraDevice.IsBusy = false; return; } } StaticHelper.Instance.SystemMessage = TranslationStrings.MsgPhotoTransferBegin; string tempFile = Path.GetTempFileName(); if (File.Exists(tempFile)) { File.Delete(tempFile); } eventArgs.CameraDevice.TransferFile(eventArgs.Handle, tempFile); string fileName = ""; if (!session.UseOriginalFilename || eventArgs.CameraDevice.CaptureInSdRam) { fileName = session.GetNextFileName(eventArgs.FileName, eventArgs.CameraDevice); } else { fileName = Path.Combine(session.Folder, eventArgs.FileName); if (File.Exists(fileName) && !session.AllowOverWrite) { fileName = StaticHelper.GetUniqueFilename( Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + "_", 0, Path.GetExtension(fileName)); } } if (session.AllowOverWrite && File.Exists(fileName)) { File.Delete(fileName); } // make lower case extension if (session.LowerCaseExtension && !string.IsNullOrEmpty(Path.GetExtension(fileName))) { fileName = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + Path.GetExtension(fileName).ToLower()); } if (!Directory.Exists(Path.GetDirectoryName(fileName))) { Directory.CreateDirectory(Path.GetDirectoryName(fileName)); } File.Copy(tempFile, fileName); string backupfile = null; if (session.BackUp) { backupfile = session.CopyBackUp(tempFile, fileName); if (string.IsNullOrEmpty(backupfile)) { StaticHelper.Instance.SystemMessage = "Unable to save the backup"; } } if (File.Exists(tempFile)) { File.Delete(tempFile); } if (session.WriteComment) { if (!string.IsNullOrEmpty(session.Comment)) { Exiv2Helper.SaveComment(fileName, session.Comment); } if (session.SelectedTag1 != null && !string.IsNullOrEmpty(session.SelectedTag1.Value)) { Exiv2Helper.AddKeyword(fileName, session.SelectedTag1.Value); } if (session.SelectedTag2 != null && !string.IsNullOrEmpty(session.SelectedTag2.Value)) { Exiv2Helper.AddKeyword(fileName, session.SelectedTag2.Value); } if (session.SelectedTag3 != null && !string.IsNullOrEmpty(session.SelectedTag3.Value)) { Exiv2Helper.AddKeyword(fileName, session.SelectedTag3.Value); } if (session.SelectedTag4 != null && !string.IsNullOrEmpty(session.SelectedTag4.Value)) { Exiv2Helper.AddKeyword(fileName, session.SelectedTag4.Value); } } if (session.ExternalData != null) { session.ExternalData.FileName = fileName; } // prevent crash og GUI when item count updated Dispatcher.Invoke(new Action(delegate { _selectedItem = session.AddFile(fileName); _selectedItem.BackupFileName = backupfile; _selectedItem.Series = session.Series; _selectedItem.AddTemplates(eventArgs.CameraDevice, session); })); foreach (AutoExportPluginConfig plugin in ServiceProvider.Settings.DefaultSession.AutoExportPluginConfigs) { if (!plugin.IsEnabled) { continue; } var pl = ServiceProvider.PluginManager.GetAutoExportPlugin(plugin.Type); try { pl.Execute(_selectedItem, plugin); ServiceProvider.Analytics.PluginExecute(plugin.Type); } catch (Exception ex) { plugin.IsError = true; plugin.Error = ex.Message; plugin.IsRedy = true; Log.Error("Error to apply plugin", ex); } } if (ServiceProvider.Settings.MinimizeToTrayIcon && !IsVisible) { MyNotifyIcon.HideBalloonTip(); MyNotifyIcon.ShowBalloonTip("Photo transfered", fileName, BalloonIcon.Info); } //select the new file only when the multiple camera support isn't used to prevent high CPU usage on raw files if (ServiceProvider.Settings.AutoPreview && !ServiceProvider.WindowsManager.Get(typeof(MultipleCameraWnd)).IsVisible&& !ServiceProvider.Settings.UseExternalViewer) { if ((Path.GetExtension(fileName).ToLower() == ".jpg" && ServiceProvider.Settings.AutoPreviewJpgOnly) || !ServiceProvider.Settings.AutoPreviewJpgOnly) { if (ServiceProvider.Settings.DelayImageLoading && (DateTime.Now - _lastLoadTime).TotalSeconds < 4) { _selectiontimer.Stop(); _selectiontimer.Start(); } else { ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.Select_Image, _selectedItem); } } } _lastLoadTime = DateTime.Now; //ServiceProvider.Settings.Save(session); StaticHelper.Instance.SystemMessage = TranslationStrings.MsgPhotoTransferDone; eventArgs.CameraDevice.IsBusy = false; //show fullscreen only when the multiple camera support isn't used if (ServiceProvider.Settings.Preview && !ServiceProvider.WindowsManager.Get(typeof(MultipleCameraWnd)).IsVisible&& !ServiceProvider.Settings.UseExternalViewer) { ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.FullScreenWnd_ShowTimed); } if (ServiceProvider.Settings.UseExternalViewer && File.Exists(ServiceProvider.Settings.ExternalViewerPath)) { string arg = ServiceProvider.Settings.ExternalViewerArgs; arg = arg.Contains("%1") ? arg.Replace("%1", fileName) : arg + " " + fileName; PhotoUtils.Run(ServiceProvider.Settings.ExternalViewerPath, arg, ProcessWindowStyle.Normal); } if (ServiceProvider.Settings.PlaySound) { PhotoUtils.PlayCaptureSound(); } Log.Debug("Photo transfer done."); } catch (Exception ex) { eventArgs.CameraDevice.IsBusy = false; StaticHelper.Instance.SystemMessage = TranslationStrings.MsgPhotoTransferError + " " + ex.Message; Log.Error("Transfer error !", ex); } // not indicated to be used GC.Collect(); //GC.WaitForPendingFinalizers(); }
private void PhotoCaptured(object o) { PhotoSession session = ServiceProvider.Settings.DefaultSession; // Save recent barcode and prefix. ServiceProvider.Settings.Save(ServiceProvider.Settings.DefaultSession); ServiceProvider.Settings.Save(); ServiceProvider.Settings.DefaultSession.Files.Clear(); GC.Collect(); if (!BarcodeVerified) { ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.Select_Image, new FileItem("")); ShowWarning("Invalid Barcode; Image not transfered!"); return; } PhotoCapturedEventArgs eventArgs = o as PhotoCapturedEventArgs; if (eventArgs == null) { return; } try { Log.Debug("Photo transfer begin."); eventArgs.CameraDevice.IsBusy = true; CameraProperty property = ServiceProvider.Settings.CameraProperties.Get(eventArgs.CameraDevice); if (!eventArgs.CameraDevice.CaptureInSdRam) { if (property.NoDownload) { eventArgs.CameraDevice.IsBusy = false; return; } var extension = Path.GetExtension(eventArgs.FileName); if (extension != null && (session.DownloadOnlyJpg && extension.ToLower() != ".jpg")) { eventArgs.CameraDevice.IsBusy = false; return; } } string fileName = ""; if (!session.UseOriginalFilename || eventArgs.CameraDevice.CaptureInSdRam) { fileName = session.GetNextFileName(Path.GetExtension(eventArgs.FileName), eventArgs.CameraDevice); } else { fileName = Path.Combine(session.Folder, eventArgs.FileName); } if (File.Exists(fileName)) { fileName = StaticHelper.GetUniqueFilename( Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + "_", 0, Path.GetExtension(fileName)); } if (!Directory.Exists(Path.GetDirectoryName(fileName))) { Directory.CreateDirectory(Path.GetDirectoryName(fileName)); } var tmpFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), Settings.AppName, "Cache", Path.GetFileName(fileName)); Log.Debug("Transfer started :" + tmpFileName); DateTime startTIme = DateTime.Now; eventArgs.CameraDevice.TransferFile(eventArgs.Handle, tmpFileName); Log.Debug("Transfer done :" + tmpFileName); Log.Debug("[BENCHMARK]Speed :" + (new System.IO.FileInfo(tmpFileName).Length / (DateTime.Now - startTIme).TotalSeconds / 1024 / 1024).ToString("0000.00")); Log.Debug("[BENCHMARK]Transfer time :" + ((DateTime.Now - startTIme).TotalSeconds).ToString("0000.000")); var fileItem = session.AddFile(tmpFileName); fileItem.DestinationFilename = fileName; ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.Select_Image, fileItem); if (!session.RetainCameraCopy && BarcodeVerified) { var Cam = ServiceProvider.DeviceManager.SelectedCameraDevice; var imgFile = Cam.GetObjects(null).Where(t => (uint)(t.Handle) == (uint)(eventArgs.Handle)).SingleOrDefault(); if (imgFile != null) { FileItem delFileItem = new FileItem(imgFile, Cam); delFileItem.Device.DeleteObject(delFileItem.DeviceObject); } } BarcodeUsed = true; eventArgs.CameraDevice.IsBusy = false; if (ServiceProvider.Settings.PlaySound) { PhotoUtils.PlayCaptureSound(); } } catch (Exception exception) { eventArgs.CameraDevice.IsBusy = false; //MessageBox.Show("Error downloading photo from camera :\n" + exception.ToString()); Log.Error("Error downloading photo from camera :\n" + exception.ToString()); } Log.Debug("Photo transfer done."); GC.Collect(); }