public string Pharse(string template, PhotoSession session, ICameraDevice device, string fileName, string tempfileName)
        {
            if (!File.Exists(tempfileName))
            {
                return("");
            }

            // load a bitmap
            PhotoUtils.WaitForFile(tempfileName);

            var file = tempfileName;

            if (Path.GetExtension(fileName).ToLower() == ".cr2" || Path.GetExtension(fileName).ToLower() == ".nef")
            {
                string dcraw_exe = Path.Combine(Settings.ApplicationFolder, "dcraw.exe");
                if (File.Exists(dcraw_exe))
                {
                    string thumb = Path.Combine(Path.GetTempPath(),
                                                Path.GetFileNameWithoutExtension(tempfileName) + ".thumb.jpg");
                    PhotoUtils.RunAndWait(dcraw_exe,
                                          string.Format(" -e -O \"{0}\" \"{1}\"", thumb, tempfileName));
                    if (File.Exists(thumb))
                    {
                        var res = GetBarcode(thumb, template);
                        File.Delete(thumb);
                        return(res);
                    }
                }
            }
            else
            {
                return(GetBarcode(tempfileName, template));
            }
            return(template);
        }
        public void Send(FileItem item, AutoExportPluginConfig configData)
        {
            try
            {
                configData.IsRedy  = false;
                configData.IsError = false;
                var conf = new SendEmailPluginViewModel(configData);

                var outfile = PhotoUtils.ReplaceExtension(Path.GetTempFileName(), Path.GetExtension(item.Name));
                outfile = AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile);

                HelpProvider.SendEmail((string.IsNullOrEmpty(conf.Message) ? "." : conf.TransformTemplate(item, conf.Message)), (string.IsNullOrEmpty(conf.Subject) ? "Your photo" : conf.TransformTemplate(item, conf.Subject)),
                                       conf.From, conf.To, outfile);

                // remove unused file
                if (outfile != item.FileName)
                {
                    PhotoUtils.WaitForFile(outfile);
                    File.Delete(outfile);
                }
            }
            catch (Exception exception)
            {
                Log.Error("Error send email file", exception);
                configData.IsError = true;
                configData.Error   = exception.Message;
            }
            configData.IsRedy = true;
        }
Beispiel #3
0
        private void Restore()
        {
            if (ServiceProvider.Settings.SelectedBitmap == null ||
                ServiceProvider.Settings.SelectedBitmap.FileItem == null)
            {
                return;
            }
            var item = ServiceProvider.Settings.SelectedBitmap.FileItem;

            if (File.Exists(item.BackupFileName))
            {
                try
                {
                    PhotoUtils.WaitForFile(item.FileName);
                    File.Copy(item.BackupFileName, item.FileName, true);
                    item.RemoveThumbs();
                    item.IsLoaded = false;
                    ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.Refresh_Image);
                }
                catch (Exception ex)
                {
                    Log.Error("Error restore", ex);
                }
            }
        }
Beispiel #4
0
        public void Send(FileItem item, AutoExportPluginConfig configData)
        {
            try
            {
                var filename = item.FileName;
                configData.IsRedy  = false;
                configData.IsError = false;
                var conf = new DropboxViewModel(configData);

                var outfile = Path.Combine(Path.GetTempPath(), Path.GetFileName(filename));
                outfile = AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile);

                conf.Upload(outfile, ServiceProvider.Settings.DefaultSession.Name);

                // remove unused file
                if (outfile != item.FileName)
                {
                    PhotoUtils.WaitForFile(outfile);
                    File.Delete(outfile);
                }
            }
            catch (Exception exception)
            {
                Log.Error("Error send dropbox file", exception);
                configData.IsError = true;
                configData.Error   = exception.Message;
            }
            configData.IsRedy = true;
        }
Beispiel #5
0
        public string Pharse(string template, PhotoSession session, ICameraDevice device, string fileName, string tempfileName)
        {
            if (!File.Exists(tempfileName))
            {
                return("");
            }

            IBarcodeReader reader = new BarcodeReader()
            {
                AutoRotate  = true,
                TryInverted = true,
                Options     = new DecodingOptions {
                    TryHarder = true
                }
            };

            // load a bitmap
            PhotoUtils.WaitForFile(tempfileName);
            using (var barcodeBitmap = (Bitmap)Bitmap.FromFile(tempfileName))
            {
                // detect and decode the barcode inside the bitmap
                var result = reader.Decode(barcodeBitmap);
                // do something with the result
                if (result != null)
                {
                    return(result.Text);
                }
            }
            return(template);
        }
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            var item = ServiceProvider.Settings.SelectedBitmap.FileItem;

            if (ServiceProvider.Settings.SelectedBitmap.FileItem == null)
            {
                return;
            }
            //bool fullres = e.Argument is bool && (bool) e.Argument ||LayoutViewModel.ZoomFit
            //bool fullres = !LayoutViewModel.ZoomFit;
            bool fullres = e.Argument is bool && (bool)e.Argument;

            if ((!File.Exists(item.LargeThumb) && item.IsJpg && File.Exists(item.FileName)))
            {
                try
                {
                    PhotoUtils.WaitForFile(item.FileName);
                    ServiceProvider.Settings.SelectedBitmap.DisplayImage = (WriteableBitmap)BitmapLoader.Instance.LoadImage(item.FileName, BitmapLoader.LargeThumbSize,
                                                                                                                            0);
                }
                catch (Exception ex)
                {
                    Log.Error("Unable to load fast preview", ex);
                }
            }

            ServiceProvider.Settings.ImageLoading = fullres ||
                                                    !ServiceProvider.Settings.SelectedBitmap.FileItem.IsLoaded;
            if (ServiceProvider.Settings.SelectedBitmap.FileItem.Loading)
            {
                while (ServiceProvider.Settings.SelectedBitmap.FileItem.Loading)
                {
                    Thread.Sleep(10);
                }
            }
            else
            {
                BitmapLoader.Instance.GenerateCache(ServiceProvider.Settings.SelectedBitmap.FileItem);
            }
            if (!ServiceProvider.Settings.SelectedBitmap.FileItem.HaveHistogramReady())
            {
                ServiceProvider.QueueManager.Add(new QueueItemFileItem
                {
                    FileItem = ServiceProvider.Settings.SelectedBitmap.FileItem,
                    Generate = QueueType.Histogram
                });
            }

            ServiceProvider.Settings.SelectedBitmap.DisplayImage =
                BitmapLoader.Instance.LoadImage(ServiceProvider.Settings.SelectedBitmap.FileItem, fullres);
            BitmapLoader.Instance.SetData(ServiceProvider.Settings.SelectedBitmap,
                                          ServiceProvider.Settings.SelectedBitmap.FileItem);
            BitmapLoader.Highlight(ServiceProvider.Settings.SelectedBitmap,
                                   ServiceProvider.Settings.HighlightUnderExp,
                                   ServiceProvider.Settings.HighlightOverExp);
            ServiceProvider.Settings.SelectedBitmap.FullResLoaded = fullres;
            ServiceProvider.Settings.ImageLoading = false;
            GC.Collect();
            Dispatcher.BeginInvoke(new Action(OnImageLoaded));
        }
Beispiel #7
0
        public void Send(FileItem item, AutoExportPluginConfig configData)
        {
            try
            {
                configData.IsRedy  = false;
                configData.IsError = false;
                var conf = new FacebookPluginViewModel(configData, false);

                var outfile = PhotoUtils.ReplaceExtension(Path.GetTempFileName(), Path.GetExtension(item.Name));
                outfile = AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile);

                conf.UploadFile(outfile, item.Name);

                // remove unused file
                if (outfile != item.FileName)
                {
                    PhotoUtils.WaitForFile(outfile);
                    File.Delete(outfile);
                }
            }
            catch (Exception exception)
            {
                Log.Error("Error send facebook file", exception);
                configData.IsError = true;
                configData.Error   = exception.Message;
            }
            configData.IsRedy = true;
        }
Beispiel #8
0
        public bool Execute(FileItem item, AutoExportPluginConfig configData)
        {
            configData.IsRedy  = false;
            configData.IsError = false;
            var filename = item.FileName;
            var conf     = new TransformPluginViewModel(configData);
            var outfile  = Path.GetTempFileName();

            outfile = PhotoUtils.ReplaceExtension(outfile, Path.GetExtension(filename));
            outfile = AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile);
            if (conf.CreateNew)
            {
                string newFile = Path.Combine(Path.GetDirectoryName(filename),
                                              Path.GetFileNameWithoutExtension(filename) + "_transformed" + ".jpg");
                newFile = PhotoUtils.GetNextFileName(newFile);

                File.Copy(outfile, newFile, true);

                if (ServiceProvider.Settings.DefaultSession.GetFile(newFile) == null)
                {
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        FileItem im    = new FileItem(newFile);
                        im.Transformed = true;
                        var i          = ServiceProvider.Settings.DefaultSession.Files.IndexOf(item);
                        if (ServiceProvider.Settings.DefaultSession.Files.Count - 1 == i)
                        {
                            ServiceProvider.Settings.DefaultSession.Files.Add(im);
                        }
                        else
                        {
                            ServiceProvider.Settings.DefaultSession.Files.Insert(i + 1, im);
                        }
                    }));
                }
            }
            else
            {
                // wait for file to be not locked
                PhotoUtils.WaitForFile(filename);
                File.Copy(outfile, filename, true);
                item.IsLoaded = false;
                item.RemoveThumbs();
                item.Transformed = true;
            }
            // remove unused file
            if (outfile != item.FileName)
            {
                PhotoUtils.WaitForFile(outfile);
                File.Delete(outfile);
            }
            configData.IsRedy = true;
            return(true);
        }
Beispiel #9
0
        private void Print(FileItem item, AutoExportPluginConfig configData)
        {
            try
            {
                PrintDialog dlg = new PrintDialog();
                configData.IsRedy  = false;
                configData.IsError = false;
                var conf    = new PrintPluginViewModel(configData);
                var outfile = Path.Combine(Path.GetTempPath(), Path.GetFileName(item.FileName));

                outfile = AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile);

                System.Printing.PrintCapabilities capabilities = dlg.PrintQueue.GetPrintCapabilities(dlg.PrintTicket);
                var PageWidth  = (int)capabilities.PageImageableArea.ExtentWidth;
                var PageHeight = (int)capabilities.PageImageableArea.ExtentHeight;

                var panel = new StackPanel
                {
                    Margin = new Thickness(conf.Margin),
                };

                var image = new Image
                {
                    Source  = BitmapLoader.Instance.LoadImage(outfile, PageWidth > PageHeight ? PageWidth : PageHeight, conf.Rotate ? 90 : 0),
                    Width   = PageWidth,
                    Height  = PageHeight,
                    Stretch = Stretch.Uniform,
                };


                panel.Children.Add(image);
                panel.UpdateLayout();
                panel.Measure(new Size(PageWidth, PageHeight));
                panel.Arrange(new Rect(new Point(0, 0), panel.DesiredSize));
                panel.UpdateLayout();
                dlg.PrintVisual(panel, item.Name);
                image.Source = null;
                panel.Children.Clear();
                // remove unused file
                if (outfile != item.FileName)
                {
                    PhotoUtils.WaitForFile(outfile);
                    File.Delete(outfile);
                }
            }
            catch (Exception exception)
            {
                Log.Error("Error print file", exception);
                configData.IsError = true;
                configData.Error   = exception.Message;
            }

            configData.IsRedy = true;
        }
        private void Send(FileItem item, AutoExportPluginConfig configData)
        {
            try
            {
                configData.IsRedy  = false;
                configData.IsError = false;
                var conf = new FtpPluginViewModel(configData);

                var outfile = PhotoUtils.ReplaceExtension(Path.GetTempFileName(), Path.GetExtension(item.Name));
                outfile = AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile);

                using (FtpClient conn = new FtpClient())
                {
                    conn.Host = conf.Server;
                    if (conf.Port > 0)
                    {
                        conn.Port = conf.Port;
                    }

                    conn.Credentials = new NetworkCredential(conf.User, conf.Pass);
                    if (!string.IsNullOrWhiteSpace(conf.ServerPath))
                    {
                        conn.SetWorkingDirectory(conf.ServerPath);
                    }
                    using (Stream ostream = conn.OpenWrite(item.Name))
                    {
                        try
                        {
                            var data = File.ReadAllBytes(outfile);
                            ostream.Write(data, 0, data.Length);
                        }
                        finally
                        {
                            ostream.Close();
                        }
                    }
                }
                // remove unused file
                if (outfile != item.FileName)
                {
                    PhotoUtils.WaitForFile(outfile);
                    File.Delete(outfile);
                }
            }
            catch (Exception exception)
            {
                Log.Error("Error senf ftp file", exception);
                configData.IsError = true;
                configData.Error   = exception.Message;
            }
            configData.IsRedy = true;
        }
Beispiel #11
0
        private void ImgViewGrid_MouseDown(object sender, MouseButtonEventArgs e)
        {
            //SelectedImage.Imagepath = ImageLIstBox.
            Image clickedOnItem = (Image)GetParentDependencyObjectFromVisualTree((DependencyObject)e.MouseDevice.DirectlyOver, typeof(Image));

            if (clickedOnItem != null)
            {
                __Pathupdate         = PathUpdate.getInstance();
                __Pathupdate.PathImg = ((ImageDetails)clickedOnItem.DataContext).Path_Orginal;                                   //clickedOnItem.Source.ToString();
                ServiceProvider.Settings.EditImageByte = DSLR_Tool_PC.StaticClass.ConvertImageToByteArray(__Pathupdate.PathImg); //.Substring(8)) ;// ; //converterDemo(clickedOnItem);
                PhotoUtils.WaitForFile(__Pathupdate.PathImg);
                ServiceProvider.Settings.SelectedBitmap.DisplayEditImage = (WriteableBitmap)BitmapLoader.Instance.LoadImage(__Pathupdate.PathImg, BitmapLoader.LargeThumbSize, 0);

                //PhotoEditModel.GetInstance().ImagePath = Pathupdate.PathImg.Substring(8);
                PhotoEditModel.GetInstance().ImageData = ServiceProvider.Settings.EditImageByte;
                StaticClass.ImageListBoxSelectedItem = (ImageDetails)clickedOnItem.DataContext;

                EditBottomControl.getInstance().CallMouseClick(sender, e);
            }
        }
Beispiel #12
0
        public void Send(FileItem item, AutoExportPluginConfig configData)
        {
            try
            {
                var filename = item.FileName;
                configData.IsRedy  = false;
                configData.IsError = false;
                var conf = new SendEmailPluginViewModel(configData);

                var outfile = Path.Combine(Path.GetTempPath(), Path.GetFileName(filename));
                outfile = AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile);

                var client  = new MailgunClient("digicamcontrol.mailgun.org", "key-6n75wci5cpuz74vsxfcwfkf-t8v74g82", 3);
                var message = new MailMessage(conf.From, conf.To)
                {
                    Subject    = (string.IsNullOrEmpty(conf.Subject) ? "Your photo":conf.TransformTemplate(item, conf.Subject)),
                    Body       = (string.IsNullOrEmpty(conf.Message) ? "." : conf.TransformTemplate(item, conf.Message)),
                    IsBodyHtml = true
                };
                message.Attachments.Add(new Attachment(outfile));

                client.SendMail(message);
                message.Dispose();

                // remove unused file
                if (outfile != item.FileName)
                {
                    PhotoUtils.WaitForFile(outfile);
                    File.Delete(outfile);
                }
            }
            catch (Exception exception)
            {
                Log.Error("Error send facebook file", exception);
                configData.IsError = true;
                configData.Error   = exception.Message;
            }
            configData.IsRedy = true;
        }
        public bool Execute(FileItem item, AutoExportPluginConfig configData)
        {
            configData.IsRedy  = false;
            configData.IsError = false;
            var filename = item.FileName;
            var conf     = new TransformPluginViewModel(configData);


            var outfile = Path.GetTempFileName();
            var tp      = ServiceProvider.PluginManager.GetImageTransformPlugin(conf.TransformPlugin);

            if (tp != null)
            {
                tp.Execute(item, outfile, configData.ConfigData);
            }
            // wait for file to be not locked
            PhotoUtils.WaitForFile(filename);
            File.Copy(outfile, filename, true);
            File.Delete(outfile);
            item.IsLoaded = false;
            item.RemoveThumbs();
            configData.IsRedy = true;
            return(true);
        }
        public bool Execute(FileItem item, AutoExportPluginConfig configData)
        {
            configData.IsRedy  = false;
            configData.IsError = false;
            var filename = item.FileName;

            var outfile = Path.GetTempFileName();

            AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile);
            // wait for file to be not locked
            PhotoUtils.WaitForFile(filename);
            File.Copy(outfile, filename, true);
            File.Delete(outfile);
            item.IsLoaded = false;
            item.RemoveThumbs();
            // remove unused file
            if (outfile != item.FileName)
            {
                PhotoUtils.WaitForFile(outfile);
                File.Delete(outfile);
            }
            configData.IsRedy = true;
            return(true);
        }
Beispiel #15
0
        /// <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;
                var extension = Path.GetExtension(eventArgs.FileName);

                // the capture is for live view preview
                if (LiveViewManager.PreviewRequest.ContainsKey(eventArgs.CameraDevice) &&
                    LiveViewManager.PreviewRequest[eventArgs.CameraDevice])
                {
                    LiveViewManager.PreviewRequest[eventArgs.CameraDevice] = false;
                    var file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + extension);
                    eventArgs.CameraDevice.TransferFile(eventArgs.Handle, file);
                    eventArgs.CameraDevice.IsBusy           = false;
                    eventArgs.CameraDevice.TransferProgress = 0;
                    eventArgs.CameraDevice.ReleaseResurce(eventArgs.Handle);
                    LiveViewManager.Preview[eventArgs.CameraDevice] = file;
                    LiveViewManager.OnPreviewCaptured(eventArgs.CameraDevice, file);
                    return;
                }

                CameraProperty property = eventArgs.CameraDevice.LoadProperties();
                PhotoSession   session  = (PhotoSession)eventArgs.CameraDevice.AttachedPhotoSession ??
                                          ServiceProvider.Settings.DefaultSession;
                StaticHelper.Instance.SystemMessage = "";


                if (!eventArgs.CameraDevice.CaptureInSdRam || PhotoUtils.IsMovie(eventArgs.FileName))
                {
                    if (property.NoDownload)
                    {
                        eventArgs.CameraDevice.IsBusy = false;
                        eventArgs.CameraDevice.ReleaseResurce(eventArgs.Handle);
                        return;
                    }
                    if (extension != null && (session.DownloadOnlyJpg && extension.ToLower() != ".jpg"))
                    {
                        eventArgs.CameraDevice.IsBusy = false;
                        eventArgs.CameraDevice.ReleaseResurce(eventArgs.Handle);
                        return;
                    }
                }

                StaticHelper.Instance.SystemMessage = TranslationStrings.MsgPhotoTransferBegin;

                string tempFile = Path.GetTempFileName();

                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }

                Stopwatch stopWatch = new Stopwatch();
                // transfer file from camera to temporary folder
                // in this way if the session folder is used as hot folder will prevent write errors
                stopWatch.Start();
                if (!eventArgs.CameraDevice.CaptureInSdRam && session.DownloadThumbOnly)
                {
                    eventArgs.CameraDevice.TransferFileThumb(eventArgs.Handle, tempFile);
                }
                else
                {
                    eventArgs.CameraDevice.TransferFile(eventArgs.Handle, tempFile);
                }
                eventArgs.CameraDevice.TransferProgress = 0;
                eventArgs.CameraDevice.IsBusy           = false;
                stopWatch.Stop();
                string strTransfer = "Transfer time : " + stopWatch.Elapsed.TotalSeconds.ToString("##.###") + " Speed :" +
                                     Math.Round(
                    new System.IO.FileInfo(tempFile).Length / 1024.0 / 1024 /
                    stopWatch.Elapsed.TotalSeconds, 2) + " Mb/s";
                Log.Debug(strTransfer);

                string fileName = "";
                if (!session.UseOriginalFilename || eventArgs.CameraDevice.CaptureInSdRam)
                {
                    fileName =
                        session.GetNextFileName(eventArgs.FileName, eventArgs.CameraDevice, tempFile);
                }
                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))
                {
                    PhotoUtils.WaitForFile(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 (session.AskSavePath)
                {
                    SaveFileDialog dialog = new SaveFileDialog();
                    dialog.Filter           = "All files|*.*";
                    dialog.Title            = "Save captured photo";
                    dialog.FileName         = fileName;
                    dialog.InitialDirectory = Path.GetDirectoryName(fileName);
                    if (dialog.ShowDialog() == true)
                    {
                        fileName = dialog.FileName;
                    }
                    else
                    {
                        eventArgs.CameraDevice.IsBusy = false;
                        if (File.Exists(tempFile))
                        {
                            File.Delete(tempFile);
                        }
                        return;
                    }
                }

                if (!Directory.Exists(Path.GetDirectoryName(fileName)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(fileName));
                }


                string backupfile = null;
                if (session.BackUp)
                {
                    backupfile = session.CopyBackUp(tempFile, fileName);
                    if (string.IsNullOrEmpty(backupfile))
                    {
                        StaticHelper.Instance.SystemMessage = "Unable to save the backup";
                    }
                }

                // execute plugins which are executed before transfer
                if (ServiceProvider.Settings.DefaultSession.AutoExportPluginConfigs.Count((x) => !x.RunAfterTransfer) > 0)
                {
                    FileItem tempitem = new FileItem(tempFile);
                    tempitem.Name           = Path.GetFileName(fileName);
                    tempitem.BackupFileName = backupfile;
                    tempitem.Series         = session.Series;
                    tempitem.AddTemplates(eventArgs.CameraDevice, session);
                    ExecuteAutoexportPlugins(eventArgs.CameraDevice, tempitem, false);
                }


                if ((!eventArgs.CameraDevice.CaptureInSdRam || PhotoUtils.IsMovie(fileName)) && session.DeleteFileAfterTransfer)
                {
                    eventArgs.CameraDevice.DeleteObject(new DeviceObject()
                    {
                        Handle = eventArgs.Handle
                    });
                }

                File.Copy(tempFile, fileName);

                if (File.Exists(tempFile))
                {
                    PhotoUtils.WaitForFile(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
                {
                    try
                    {
                        _selectedItem = session.GetNewFileItem(fileName);
                        _selectedItem.BackupFileName = backupfile;
                        _selectedItem.Series         = session.Series;
                        // _selectedItem.Transformed = tempitem.Transformed;
                        _selectedItem.AddTemplates(eventArgs.CameraDevice, session);
                        ServiceProvider.Database.Add(new DbFile(_selectedItem, eventArgs.CameraDevice.SerialNumber, eventArgs.CameraDevice.DisplayName, session.Name));
                    }
                    catch (Exception ex)
                    {
                    }
                }));

                // execute plugins which are executed after transfer
                ExecuteAutoexportPlugins(eventArgs.CameraDevice, _selectedItem, true);

                Dispatcher.Invoke(() =>
                {
                    _selectedItem.RemoveThumbs();
                    session.Add(_selectedItem);
                    ServiceProvider.OnFileTransfered(_selectedItem);
                });


                if (ServiceProvider.Settings.MinimizeToTrayIcon && !IsVisible && !ServiceProvider.Settings.HideTrayNotifications)
                {
                    MyNotifyIcon.HideBalloonTip();
                    MyNotifyIcon.ShowBalloonTip("Photo transfered", fileName, BalloonIcon.Info);
                }

                ServiceProvider.DeviceManager.LastCapturedImage[eventArgs.CameraDevice] = 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 ((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 + " " + strTransfer;

                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();
                }
                eventArgs.CameraDevice.ReleaseResurce(eventArgs.Handle);

                //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);
                }

                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();
        }
        /// <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 = "";

                var extension = Path.GetExtension(eventArgs.FileName);

                if (!eventArgs.CameraDevice.CaptureInSdRam || (extension != null && extension.ToLower() == ".mov"))
                {
                    if (property.NoDownload)
                    {
                        eventArgs.CameraDevice.IsBusy = false;
                        return;
                    }
                    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);
                }

                if (!eventArgs.CameraDevice.CaptureInSdRam && session.DownloadThumbOnly)
                {
                    eventArgs.CameraDevice.TransferFileThumb(eventArgs.Handle, tempFile);
                }
                else
                {
                    eventArgs.CameraDevice.TransferFile(eventArgs.Handle, tempFile);
                }

                string fileName = "";
                if (!session.UseOriginalFilename || eventArgs.CameraDevice.CaptureInSdRam)
                {
                    fileName =
                        session.GetNextFileName(eventArgs.FileName, eventArgs.CameraDevice, tempFile);
                }
                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))
                {
                    PhotoUtils.WaitForFile(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 (session.AskSavePath)
                {
                    SaveFileDialog dialog = new SaveFileDialog();
                    dialog.Filter           = "All files|*.*";
                    dialog.Title            = "Save captured photo";
                    dialog.FileName         = fileName;
                    dialog.InitialDirectory = Path.GetDirectoryName(fileName);
                    if (dialog.ShowDialog() == true)
                    {
                        fileName = dialog.FileName;
                    }
                    else
                    {
                        eventArgs.CameraDevice.IsBusy = false;
                        if (File.Exists(tempFile))
                        {
                            File.Delete(tempFile);
                        }
                        return;
                    }
                }

                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 (!eventArgs.CameraDevice.CaptureInSdRam && session.DeleteFileAfterTransfer)
                {
                    eventArgs.CameraDevice.DeleteObject(new DeviceObject()
                    {
                        Handle = eventArgs.Handle
                    });
                }


                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
                {
                    try
                    {
                        _selectedItem = session.GetNewFileItem(fileName);
                        _selectedItem.BackupFileName = backupfile;
                        _selectedItem.Series         = session.Series;
                        _selectedItem.AddTemplates(eventArgs.CameraDevice, session);
                        ServiceProvider.Database.Add(new DbFile(_selectedItem, eventArgs.CameraDevice.SerialNumber, eventArgs.CameraDevice.DisplayName, session.Name));
                    }
                    catch (Exception ex)
                    {
                    }
                }));

                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);
                        Log.Debug("AutoexportPlugin executed " + plugin.Type);
                    }
                    catch (Exception ex)
                    {
                        plugin.IsError = true;
                        plugin.Error   = ex.Message;
                        plugin.IsRedy  = true;
                        Log.Error("Error to apply plugin", ex);
                    }
                }

                Dispatcher.Invoke(() =>
                {
                    _selectedItem.RemoveThumbs();
                    session.Add(_selectedItem);
                    ServiceProvider.OnFileTransfered(_selectedItem);
                });

                if (ServiceProvider.Settings.MinimizeToTrayIcon && !IsVisible && !ServiceProvider.Settings.HideTrayNotifications)
                {
                    MyNotifyIcon.HideBalloonTip();
                    MyNotifyIcon.ShowBalloonTip("Photo transfered", fileName, BalloonIcon.Info);
                }

                ServiceProvider.DeviceManager.LastCapturedImage[eventArgs.CameraDevice] = 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 ((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 btn_set_Click(object sender, RoutedEventArgs e)
 {
     btn_set.IsEnabled = false;
     try
     {
         string filename = ServiceProvider.Settings.SelectedBitmap.FileItem.FileName;
         Exiv2Helper.SaveComment(filename, ServiceProvider.Settings.SelectedBitmap.Comment);
         if (
             ServiceProvider.Settings.SelectedBitmap.FileItem.FileInfo.ExifTags.ContainName(
                 "Iptc.Application2.Caption"))
         {
             ServiceProvider.Settings.SelectedBitmap.FileItem.FileInfo.ExifTags["Iptc.Application2.Caption"] =
                 ServiceProvider.Settings.SelectedBitmap.Comment;
         }
         else
         {
             ServiceProvider.Settings.SelectedBitmap.FileItem.FileInfo.ExifTags.Add(new ValuePair()
             {
                 Name =
                     "Iptc.Application2.Caption",
                 Value =
                     ServiceProvider.
                     Settings.
                     SelectedBitmap.
                     Comment
             });
         }
         ServiceProvider.Settings.SelectedBitmap.FileItem.SaveInfo();
         if (chk_tags.IsChecked == true)
         {
             Exiv2Helper.DelKeyword(filename);
             if (!string.IsNullOrEmpty(ServiceProvider.Settings.DefaultSession.SelectedTag1.Value))
             {
                 Exiv2Helper.AddKeyword(filename, ServiceProvider.Settings.DefaultSession.SelectedTag1.Value);
             }
             if (!string.IsNullOrEmpty(ServiceProvider.Settings.DefaultSession.SelectedTag2.Value))
             {
                 Exiv2Helper.AddKeyword(filename, ServiceProvider.Settings.DefaultSession.SelectedTag2.Value);
             }
             if (!string.IsNullOrEmpty(ServiceProvider.Settings.DefaultSession.SelectedTag3.Value))
             {
                 Exiv2Helper.AddKeyword(filename, ServiceProvider.Settings.DefaultSession.SelectedTag3.Value);
             }
             if (!string.IsNullOrEmpty(ServiceProvider.Settings.DefaultSession.SelectedTag4.Value))
             {
                 Exiv2Helper.AddKeyword(filename, ServiceProvider.Settings.DefaultSession.SelectedTag4.Value);
             }
         }
         if (Path.GetFileNameWithoutExtension(filename) !=
             ServiceProvider.Settings.SelectedBitmap.FileName)
         {
             try
             {
                 string newfilename = Path.Combine(Path.GetDirectoryName(filename),
                                                   ServiceProvider.Settings.SelectedBitmap.FileName +
                                                   Path.GetExtension(filename));
                 PhotoUtils.WaitForFile(filename);
                 File.Move(filename, newfilename);
                 ServiceProvider.Settings.SelectedBitmap.FileItem.SetFile(newfilename);
             }
             catch (Exception exception)
             {
                 MessageBox.Show("Error rename file" + exception.Message);
                 Log.Error("Error rename file", exception);
             }
         }
         btn_set.IsEnabled = true;
     }
     catch (Exception exception)
     {
         Log.Error("Error set property ", exception);
         MessageBox.Show("Error set property !" + exception.Message);
     }
 }