Exemple #1
0
        private bool SaveOneFile(AutoSaveSettings settings, DateTime now, int i, List <ScannedImage> images, ISaveNotify notify, ref string firstFileSaved)
        {
            if (images.Count == 0)
            {
                return(true);
            }
            var    form    = formFactory.Create <FProgress>();
            string subPath = fileNamePlaceholders.SubstitutePlaceholders(settings.FilePath, now, true, i);

            if (settings.PromptForFilePath)
            {
                if (dialogHelper.PromptToSavePdfOrImage(subPath, out string newPath))
                {
                    subPath = fileNamePlaceholders.SubstitutePlaceholders(newPath, now, true, i);
                }
            }
            var extension = Path.GetExtension(subPath);

            if (extension != null && extension.Equals(".pdf", StringComparison.InvariantCultureIgnoreCase))
            {
                if (File.Exists(subPath))
                {
                    subPath = fileNamePlaceholders.SubstitutePlaceholders(subPath, now, true, 0, 1);
                }
                var op = operationFactory.Create <SavePdfOperation>();
                form.Operation = op;
                var ocrLanguageCode = userConfigManager.Config.EnableOcr ? userConfigManager.Config.OcrLanguageCode : null;
                if (op.Start(subPath, now, images, pdfSettingsContainer.PdfSettings, ocrLanguageCode, false))
                {
                    form.ShowDialog();
                }
                if (op.Status.Success && firstFileSaved == null)
                {
                    firstFileSaved = subPath;
                }
                if (op.Status.Success)
                {
                    notify?.PdfSaved(subPath);
                }
                return(op.Status.Success);
            }
            else
            {
                var op = operationFactory.Create <SaveImagesOperation>();
                form.Operation = op;
                if (op.Start(subPath, now, images))
                {
                    form.ShowDialog();
                }
                if (op.Status.Success && firstFileSaved == null)
                {
                    firstFileSaved = op.FirstFileSaved;
                }
                if (op.Status.Success)
                {
                    notify?.ImagesSaved(images.Count, op.FirstFileSaved);
                }
                return(op.Status.Success);
            }
        }
Exemple #2
0
 public bool Save(AutoSaveSettings settings, List <ScannedImage> images, ISaveNotify notify)
 {
     if (appConfigManager.Config.DisableAutoSave)
     {
         return(false);
     }
     try
     {
         bool     ok             = true;
         DateTime now            = DateTime.Now;
         int      i              = 0;
         string   firstFileSaved = null;
         var      scans          = SaveSeparatorHelper.SeparateScans(new[] { images }, settings.Separator).ToList();
         foreach (var imageList in scans)
         {
             if (!SaveOneFile(settings, now, i++, imageList, scans.Count == 1 ? notify : null, ref firstFileSaved))
             {
                 ok = false;
             }
         }
         if (notify != null && scans.Count > 1 && ok)
         {
             // Can't just do images.Count because that includes patch codes
             int imageCount = scans.SelectMany(x => x).Count();
             notify.ImagesSaved(imageCount, firstFileSaved);
         }
         return(ok);
     }
     catch (Exception ex)
     {
         Log.ErrorException(MiscResources.AutoSaveError, ex);
         errorOutput.DisplayError(MiscResources.AutoSaveError);
         return(false);
     }
 }
Exemple #3
0
 public bool Save(AutoSaveSettings settings, List<ScannedImage> images, ISaveNotify notify)
 {
     if (appConfigManager.Config.DisableAutoSave)
     {
         return false;
     }
     try
     {
         bool ok = true;
         DateTime now = DateTime.Now;
         int i = 0;
         string firstFileSaved = null;
         var scans = SaveSeparatorHelper.SeparateScans(new[] { images }, settings.Separator).ToList();
         foreach (var imageList in scans)
         {
             if (!SaveOneFile(settings, now, i++, imageList, scans.Count == 1 ? notify : null, ref firstFileSaved))
             {
                 ok = false;
             }
         }
         if (notify != null && scans.Count > 1 && ok)
         {
             // Can't just do images.Count because that includes patch codes
             int imageCount = scans.SelectMany(x => x).Count();
             notify.ImagesSaved(imageCount, firstFileSaved);
         }
         return ok;
     }
     catch (Exception ex)
     {
         Log.ErrorException(MiscResources.AutoSaveError, ex);
         errorOutput.DisplayError(MiscResources.AutoSaveError, ex);
         return false;
     }
 }
        public bool SaveImages(List <ScannedImage> images, ISaveNotify notify)
        {
            if (images.Any())
            {
                string savePath;

                var imageSettings = imageSettingsContainer.ImageSettings;
                if (imageSettings.SkipSavePrompt && Path.IsPathRooted(imageSettings.DefaultFileName))
                {
                    savePath = imageSettings.DefaultFileName;
                }
                else
                {
                    if (!dialogHelper.PromptToSaveImage(imageSettings.DefaultFileName, out savePath))
                    {
                        return(false);
                    }
                }

                var op           = operationFactory.Create <SaveImagesOperation>();
                var progressForm = formFactory.Create <FProgress>();
                progressForm.Operation = op;
                progressForm.Start     = () => op.Start(savePath, DateTime.Now, images);
                progressForm.ShowDialog();
                if (op.Status.Success)
                {
                    changeTracker.HasUnsavedChanges = false;
                    notify?.ImagesSaved(images.Count, op.FirstFileSaved);
                    return(true);
                }
            }
            return(false);
        }
        public async Task <bool> SaveImages(List <ScannedImage> images, ISaveNotify notify)
        {
            if (images.Any())
            {
                string savePath;

                var imageSettings = imageSettingsContainer.ImageSettings;
                if (imageSettings.SkipSavePrompt && Path.IsPathRooted(imageSettings.DefaultFileName))
                {
                    savePath = imageSettings.DefaultFileName;
                }
                else
                {
                    if (!dialogHelper.PromptToSaveImage(imageSettings.DefaultFileName, out savePath))
                    {
                        return(false);
                    }
                }

                var op          = operationFactory.Create <SaveImagesOperation>();
                var changeToken = changeTracker.State;
                if (op.Start(savePath, DateTime.Now, images))
                {
                    operationProgress.ShowProgress(op);
                }
                if (await op.Success)
                {
                    changeTracker.Saved(changeToken);
                    notify?.ImagesSaved(images.Count, op.FirstFileSaved);
                    return(true);
                }
            }
            return(false);
        }
Exemple #6
0
        private async Task <(bool, string)> SaveOneFile(AutoSaveSettings settings, DateTime now, int i, List <ScannedImage> images, ISaveNotify notify)
        {
            if (images.Count == 0)
            {
                return(true, null);
            }
            string subPath = fileNamePlaceholders.SubstitutePlaceholders(settings.FilePath, now, true, i);

            if (settings.PromptForFilePath)
            {
                if (dialogHelper.PromptToSavePdfOrImage(subPath, out string newPath))
                {
                    subPath = fileNamePlaceholders.SubstitutePlaceholders(newPath, now, true, i);
                }
                else
                {
                    return(false, null);
                }
            }
            var extension = Path.GetExtension(subPath);

            if (extension != null && extension.Equals(".pdf", StringComparison.InvariantCultureIgnoreCase))
            {
                if (File.Exists(subPath))
                {
                    subPath = fileNamePlaceholders.SubstitutePlaceholders(subPath, now, true, 0, 1);
                }
                var op = operationFactory.Create <SavePdfOperation>();
                if (op.Start(subPath, now, images, pdfSettingsContainer.PdfSettings, ocrManager.DefaultParams, false, null))
                {
                    operationProgress.ShowProgress(op);
                }
                bool success = await op.Success;
                if (success)
                {
                    notify?.PdfSaved(subPath);
                }
                return(success, subPath);
            }
            else
            {
                var op = operationFactory.Create <SaveImagesOperation>();
                if (op.Start(subPath, now, images))
                {
                    operationProgress.ShowProgress(op);
                }
                bool success = await op.Success;
                if (success)
                {
                    notify?.ImagesSaved(images.Count, op.FirstFileSaved);
                }
                return(success, subPath);
            }
        }
Exemple #7
0
 private bool SaveOneFile(AutoSaveSettings settings, DateTime now, int i, List<ScannedImage> images, ISaveNotify notify, ref string firstFileSaved)
 {
     if (images.Count == 0)
     {
         return true;
     }
     var form = formFactory.Create<FProgress>();
     var subPath = fileNamePlaceholders.SubstitutePlaceholders(settings.FilePath, now, true, i);
     var extension = Path.GetExtension(subPath);
     if (extension != null && extension.Equals(".pdf", StringComparison.InvariantCultureIgnoreCase))
     {
         if (File.Exists(subPath))
         {
             subPath = fileNamePlaceholders.SubstitutePlaceholders(subPath, now, true, 0, 1);
         }
         var op = operationFactory.Create<SavePdfOperation>();
         form.Operation = op;
         var ocrLanguageCode = userConfigManager.Config.EnableOcr ? userConfigManager.Config.OcrLanguageCode : null;
         if (op.Start(subPath, now, images, pdfSettingsContainer.PdfSettings, ocrLanguageCode, false))
         {
             form.ShowDialog();
         }
         if (op.Status.Success && firstFileSaved == null)
         {
             firstFileSaved = subPath;
         }
         if (op.Status.Success && notify != null)
         {
             notify.PdfSaved(subPath);
         }
         return op.Status.Success;
     }
     else
     {
         var op = operationFactory.Create<SaveImagesOperation>();
         form.Operation = op;
         if (op.Start(subPath, now, images))
         {
             form.ShowDialog();
         }
         if (op.Status.Success && firstFileSaved == null)
         {
             firstFileSaved = op.FirstFileSaved;
         }
         if (op.Status.Success && notify != null)
         {
             notify.ImagesSaved(images.Count, op.FirstFileSaved);
         }
         return op.Status.Success;
     }
 }