Exemple #1
0
        private bool DownloadAndSaveDocument(PDFApi pdfApi, ImageApi imageApi, string fileId, int workerNumber, OperationsWorkflow.SaveOperationType saveOperationType, object saveOperationConfiguration, ProgressDelegate downloadOperationStartEventHandler, string inputFileAbsolutePath, out string downloadedDocumentFileName)
        {
            downloadedDocumentFileName = Path.GetTempFileName();

            using (FileStream outputFileStream = new FileStream(downloadedDocumentFileName, FileMode.Open))
            {
                try
                {
                    if (saveOperationType == OperationsWorkflow.SaveOperationType.SavePDF)
                    {
                        PassportPDFRequestsUtilities.DownloadPDF(pdfApi, new PdfSaveDocumentParameters(fileId), workerNumber, inputFileAbsolutePath, outputFileStream, downloadOperationStartEventHandler);
                    }
                    else if (saveOperationType == OperationsWorkflow.SaveOperationType.SaveImageAsPDFMRC)
                    {
                        PassportPDFRequestsUtilities.DownloadImageAsPDFMRC(imageApi, PassportPDFParametersUtilities.GetImageSaveAsPDFMRCParameters((ImageSaveAsPDFMRCActionConfiguration)saveOperationConfiguration, fileId),
                                                                           workerNumber, inputFileAbsolutePath, outputFileStream, downloadOperationStartEventHandler);
                    }

                    return(true);
                }
                catch (Exception ex)
                {
                    OnError(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_output_file_download_failure", FrameworkGlobals.ApplicationLanguage), inputFileAbsolutePath, additionalMessage: ex.Message));
                    return(false);
                }
            }
        }
Exemple #2
0
        private void UpdatePassportInfo(PassportInfo updatedPassportInfo)
        {
            FrameworkGlobals.PassportInfo = updatedPassportInfo;
            string updatedPassportStatus = LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("label_remaining_tokens", FrameworkGlobals.ApplicationLanguage), remainingTokens: updatedPassportInfo.RemainingTokens);

            PassportStatus = updatedPassportStatus;
        }
Exemple #3
0
 public void LoadPassportInfo(PassportInfo passportInfo)
 {
     tbPassportInfoPassportId.Text   = passportInfo.PassportNumber;
     tbPassportStatus.Text           = FrameworkGlobals.MessagesLocalizer.GetString(passportInfo.IsActive ? "passport_status_active" : "passport_status_inactive", FrameworkGlobals.ApplicationLanguage);
     tbPassportSubscriptionDate.Text = passportInfo.SubscriptionDate.ToString();
     tbUsedTokens.Text = LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("passport_status_remaining_tokens", FrameworkGlobals.ApplicationLanguage), remainingTokens: passportInfo.RemainingTokens, usedTokens: passportInfo.TokensUsed);
 }
Exemple #4
0
        public static string GetMessageFromException(Exception exception, string fileName)
        {
            StringBuilder errorMessage = new StringBuilder();

            errorMessage.Append("(" + FrameworkGlobals.MessagesLocalizer.GetString("label_client_exception", FrameworkGlobals.ApplicationLanguage) + ") ");

            if (exception.GetType() == typeof(ApiException))
            {
                ApiException apiException = (ApiException)exception;

                if (apiException.ErrorCode != null)
                {
                    errorMessage.Append(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_server_returned_http_error", FrameworkGlobals.ApplicationLanguage), fileName: fileName, httpCode: (int?)apiException.ErrorCode));
                }
                else
                {
                    errorMessage.Append(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_reaching_remote_server_failure", FrameworkGlobals.ApplicationLanguage), fileName: fileName));
                }
            }
            else
            {
                errorMessage.Append(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_unexpected_error", FrameworkGlobals.ApplicationLanguage), fileName: fileName, additionalMessage: exception.Message));
            }

            return(errorMessage.ToString());
        }
Exemple #5
0
        protected override void OnFileOperationsCompletion(FileOperationsResult fileOperationsResult)
        {
            base.OnFileOperationsCompletion(fileOperationsResult);

            UpdateReductionStats(fileOperationsResult.InputFileSize, fileOperationsResult.OutputFileSize, fileOperationsResult.ConvertedToPDF);

            string operationsCompletionMessage = LogMessagesUtils.GetFileReductionOperationsCompletionText(fileOperationsResult);

            if (FrameworkGlobals.ApplicationConfiguration.TimestampLogs)
            {
                operationsCompletionMessage = LogMessagesUtils.TimeStampLogMessage(operationsCompletionMessage);
            }

            _view.NotifyOperationCompletion(operationsCompletionMessage);

            if (FrameworkGlobals.ApplicationConfiguration.ExportLogs && !string.IsNullOrEmpty(FrameworkGlobals.ApplicationConfiguration.LogsPath))
            {
                FrameworkGlobals.LogsManager.LogMessage(operationsCompletionMessage);
            }

            if (!fileOperationsResult.ConvertedToPDF)
            {
                ((IPDFReducerCloudMainView)_view).NotifyReductionRatioChange(100 - _operationsStats.ReductionRatio);
            }
        }
Exemple #6
0
        public static bool TryFetchAvailableOCRLanguagesFromPassportPDF(out string[] availableLanguages, IWin32Window owner = null)
        {
            using (frmFetchingInfoFromServer fetchWindow = new frmFetchingInfoFromServer())
            {
                fetchWindow._passportPdfRequestWorker.RunWorkerAsync(BackgroundOperationType.FetchOCRSupportedLanguages);
                fetchWindow.SetFormFetchingMessageAndShowUntilWorkCompletion(owner, FrameworkGlobals.MessagesLocalizer.GetString("message_fetching_ocr_languages", FrameworkGlobals.ApplicationLanguage));

                if (fetchWindow._apiCallException != null)
                {
                    // An exception occured when calling the API
                    DialogUtilities.ShowErrorMessage(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_fetching_ocr_languages_failure", FrameworkGlobals.ApplicationLanguage),
                                                                                                           additionalMessage: fetchWindow._apiCallException.Message), FrameworkGlobals.MessagesLocalizer.GetString("caption_error", FrameworkGlobals.ApplicationLanguage));
                    availableLanguages = null;
                    return(false);
                }
                else
                {
                    if (fetchWindow._getAvailableOCRLanguagesResponse.Error == null)
                    {
                        availableLanguages = fetchWindow._getAvailableOCRLanguagesResponse.Value.ToArray();
                        return(true);
                    }
                    else
                    {
                        DialogUtilities.ShowErrorMessage(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_fetching_ocr_languages_failure", FrameworkGlobals.ApplicationLanguage),
                                                                                                               additionalMessage: PassportPDFErrorUtilities.GetMessageFromResultCode(fetchWindow._getAvailableOCRLanguagesResponse.Error.ResultCode)), FrameworkGlobals.MessagesLocalizer.GetString("caption_error", FrameworkGlobals.ApplicationLanguage));
                        availableLanguages = null;
                        return(false);
                    }
                }
            }
        }
 private void NotifyViewOfWorkersCreation(int workerCount)
 {
     for (int workerNumber = 1; workerNumber <= workerCount; workerNumber++)
     {
         _view.AddWorker(workerNumber);
         _view.NotifyWorkerProgress(workerNumber, LogMessagesUtils.GetWorkerIdleStateText());
     }
 }
 private void LoadLocales(string newVersionNumber, string productName)
 {
     this.Text                            = PassportPDF.Tools.WinForm.Globals.LabelsLocalizer.GetString("label_frmNewVersionAvailable", FrameworkGlobals.ApplicationLanguage);
     btIgnoreUpdate.Text                  = PassportPDF.Tools.WinForm.Globals.LabelsLocalizer.GetString("label_btIgnoreUpdate", FrameworkGlobals.ApplicationLanguage);
     btUpdateNow.Text                     = PassportPDF.Tools.WinForm.Globals.LabelsLocalizer.GetString("label_btUpdateNow", FrameworkGlobals.ApplicationLanguage);
     txtNewVersionAvailable.Text          = LogMessagesUtils.ReplaceMessageSequencesAndReferences(Globals.LabelsLocalizer.GetString("label_txtNewVersionAvailable", FrameworkGlobals.ApplicationLanguage), applicationName: productName, appVersionNumber: newVersionNumber);
     chkAutomaticallycheckForUpdates.Text = PassportPDF.Tools.WinForm.Globals.LabelsLocalizer.GetString("label_chkAutomaticallyCheckForUpdates", FrameworkGlobals.ApplicationLanguage);
 }
 private void OnRemainingTokensNumberUpdated(long remainingTokens)
 {
     if (FrameworkGlobals.PassportInfo.RemainingTokens > remainingTokens)
     {
         FrameworkGlobals.PassportInfo.RemainingTokens = remainingTokens;
         string updatedPassportStatus = FrameworkGlobals.MessagesLocalizer.GetString("label_remaining_tokens", FrameworkGlobals.ApplicationLanguage);
         _view.PassportStatus = LogMessagesUtils.ReplaceMessageSequencesAndReferences(updatedPassportStatus, remainingTokens: remainingTokens);
     }
 }
        protected virtual void OnOperationsCompletion()
        {
            _stopwatch.Stop();
            _operationsStatus = OperationsStatus.Idle;

            if (FrameworkGlobals.LogsManager.Error != null)
            {
                _view.NotifyOperationError(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_logs_exportation_failure", FrameworkGlobals.ApplicationConfiguration.Language), additionalMessage: FrameworkGlobals.LogsManager.Error.Message));
            }
        }
Exemple #11
0
        private bool HandleOutputFileProduction(FileToProcess fileToProcess, string fileId, int workerNumber, OperationsWorkflow.SaveOperationType saveOperationType, object saveOperationConfiguration, PDFApi pdfApi, ImageApi imageApi, FileProductionRules fileProductionRules, WorkflowProcessingResult workflowProcessingResult, bool fileSizeReductionIsIntended, bool inputIsPDF, long inputFileSize, string outputFileAbsolutePath)
        {
            if (!DownloadAndSaveDocument(pdfApi, imageApi, fileId, workerNumber, saveOperationType, saveOperationConfiguration, DownloadOperationStartEventHandler, fileToProcess.FileAbsolutePath, out string downloadedDocumentFileName))
            {
                return(false);
            }

            bool keepProducedFile = MustProducedFileBeKept(workflowProcessingResult, fileSizeReductionIsIntended, inputIsPDF, inputFileSize, FileUtils.GetFileSize(downloadedDocumentFileName));
            bool outputIsInput    = FileUtils.AreSamePath(fileToProcess.FileAbsolutePath, outputFileAbsolutePath);

            if (keepProducedFile)
            {
                if (fileProductionRules.DeleteOriginalFileOnSuccess && !outputIsInput)
                {
                    try
                    {
                        FileUtils.DeleteFile(fileToProcess.FileAbsolutePath);
                    }
                    catch (Exception exception)
                    {
                        OnWarning(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_original_file_deletion_failure", FrameworkGlobals.ApplicationLanguage), fileName: fileToProcess.FileAbsolutePath, additionalMessage: exception.Message));
                    }
                }

                FileUtils.MoveFile(downloadedDocumentFileName, outputFileAbsolutePath);
                File.SetCreationTime(outputFileAbsolutePath, File.GetCreationTime(fileToProcess.FileAbsolutePath));
            }
            else
            {
                if (!outputIsInput)
                {
                    FileUtils.CopyFile(fileToProcess.FileAbsolutePath, outputFileAbsolutePath);
                }

                if (fileSizeReductionIsIntended)
                {
                    // Inform file size reduction failure
                    workflowProcessingResult.WarningMessages.Add(LogMessagesUtils.GetWarningStatustext(new ReduceWarningInfo()
                    {
                        WarningCode = ReduceWarningCode.FileSizeReductionFailure
                    }, fileToProcess.FileAbsolutePath));
                }

                FileUtils.DeleteFile(downloadedDocumentFileName);
            }


            if (fileProductionRules.KeepWriteAndAccessTime)
            {
                FileUtils.SetOriginalLastAccessTime(fileToProcess.FileAbsolutePath, outputFileAbsolutePath);
            }

            return(true);
        }
Exemple #12
0
        protected override void OnFileOperationsCompletion(FileOperationsResult fileOperationsResult)
        {
            base.OnFileOperationsCompletion(fileOperationsResult);

            string operationsCompletionMessage = LogMessagesUtils.TimeStampLogMessage(LogMessagesUtils.GetGenericFileOperationsCompletionText(fileOperationsResult));

            _view.NotifyOperationCompletion(operationsCompletionMessage);

            if (FrameworkGlobals.ApplicationConfiguration.ExportLogs && !string.IsNullOrEmpty(FrameworkGlobals.ApplicationConfiguration.LogsPath))
            {
                FrameworkGlobals.LogsManager.LogMessage(operationsCompletionMessage);
            }
        }
Exemple #13
0
        private PdfReduceResponse HandleReducePDF(PDFApi pdfApiInstance, PDFReduceActionConfiguration actionConfiguration, FileToProcess fileToProcess, string fileID, int workerNumber, List <string> warnings)
        {
            PdfReduceParameters reduceParameters = PassportPDFParametersUtilities.GetReduceParameters(actionConfiguration, fileID);
            PdfReduceResponse   reduceResponse   = PassportPDFRequestsUtilities.SendReduceRequest(pdfApiInstance, reduceParameters, workerNumber, fileToProcess.FileAbsolutePath, FileOperationStartEventHandler);

            if (reduceResponse.WarningsInfo != null)
            {
                foreach (ReduceWarningInfo warning in reduceResponse.WarningsInfo)
                {
                    warnings.Add(LogMessagesUtils.GetWarningStatustext(warning, fileToProcess.FileAbsolutePath));
                }
            }

            return(reduceResponse);
        }
        private void OnOperationWarning(string warningMessage)
        {
            if (FrameworkGlobals.ApplicationConfiguration.TimestampLogs)
            {
                warningMessage = LogMessagesUtils.TimeStampLogMessage(warningMessage);
            }

            _view.NotifyOperationWarning(warningMessage);

            if (FrameworkGlobals.ApplicationConfiguration.ExportLogs && !string.IsNullOrEmpty(FrameworkGlobals.ApplicationConfiguration.LogsPath))
            {
                // Update logs file
                FrameworkGlobals.LogsManager.LogMessage(warningMessage);
            }
        }
Exemple #15
0
 private bool CheckInputFileSizeValidity(float inputFileSize, string inputFileAbsolutePath)
 {
     if (inputFileSize == 0)
     {
         OnError(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_empty_file", FrameworkGlobals.ApplicationLanguage), fileName: inputFileAbsolutePath));
         return(false);
     }
     else if (inputFileSize > FrameworkGlobals.PassportPDFConfiguration.MaxAllowedContentLength)
     {
         OnError(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_input_file_too_large", FrameworkGlobals.ApplicationLanguage), fileName: inputFileAbsolutePath, inputSize: FrameworkGlobals.PassportPDFConfiguration.MaxAllowedContentLength));
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemple #16
0
        private void checkForLastUpdateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bool?newVersionAvailable = frmFetchingInfoFromServer.IsNewVersionAvailable(_controller.AppInfo.AppID, _controller.AppInfo.AppVersion, out string latestVersionNumber);

            if (newVersionAvailable == true)
            {
                _controller.OnAppUpdateAvailable(latestVersionNumber);
            }
            else if (newVersionAvailable == false)
            {
                ShowInformationMessage(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_already_up_to_date", FrameworkGlobals.ApplicationLanguage), applicationName: _controller.AppInfo.ProductName), FrameworkGlobals.MessagesLocalizer.GetString("caption_information", FrameworkGlobals.ApplicationLanguage));
            }
            else
            {
                ShowErrorMessage(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_failed_to_retrieve_latest_version", FrameworkGlobals.ApplicationLanguage), applicationName: _controller.AppInfo.ProductName), FrameworkGlobals.MessagesLocalizer.GetString("caption_error", FrameworkGlobals.ApplicationLanguage));
            }
        }
        private bool EnsurePassportRegistrationAndRetrievePassportInfo()
        {
            if (!LicensingUtilities.IsPassportKeyRegistered(_appInfo.AppID) || // No passport number found in registry
                !frmFetchingInfoFromServer.TryFetchPassportInfoFromPassportPDF(LicensingUtilities.GetRegisterPassportId(_appInfo.AppID), out PassportInfo passportInfo, _view.WindowInstance) || // Server failed to be reached
                passportInfo == null)    // No passport corresponding to the passport number could be fetched
            {
                if ((passportInfo = frmRegisterPassport.PromptPassportRegistration(_view.WindowInstance, _appInfo.AppID)) == null)
                {
                    return(false);
                }
            }

            FrameworkGlobals.PassportInfo = passportInfo;
            _view.PassportStatus          = LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("label_remaining_tokens", FrameworkGlobals.ApplicationLanguage), remainingTokens: passportInfo.RemainingTokens);

            return(true);
        }
        private void OnFileOperationError(string errorMessage)
        {
            _operationsStats.UnsuccessfullyProcessedFileCount += 1;
            _operationsStats.ProcessedFileCount += 1;
            _view.ProcessedFileCount             = _operationsStats.ProcessedFileCount;

            if (FrameworkGlobals.ApplicationConfiguration.TimestampLogs)
            {
                errorMessage = LogMessagesUtils.TimeStampLogMessage(errorMessage);
            }

            _view.NotifyOperationError(errorMessage);

            if (FrameworkGlobals.ApplicationConfiguration.ExportLogs && !string.IsNullOrEmpty(FrameworkGlobals.ApplicationConfiguration.LogsPath))
            {
                // Update logs file
                FrameworkGlobals.LogsManager.LogMessage(errorMessage);
            }
        }
        public static string GetErrorMessageFromReduceErrorInfo(ReduceErrorInfo reduceErrorInfo)
        {
            switch (reduceErrorInfo.ErrorCode)
            {
            case ReduceErrorCode.OK: return(PassportPDFResultCodesMessagesLocalizer.GetString("reduceErrorCode_OK", FrameworkGlobals.ApplicationLanguage));

            case ReduceErrorCode.GetPageImagesCount: return(LogMessagesUtils.ReplaceMessageSequencesAndReferences(PassportPDFResultCodesMessagesLocalizer.GetString("reduceErrorCode_GetPageImagesCount", FrameworkGlobals.ApplicationLanguage), pageNumber: reduceErrorInfo.PageNumber));

            case ReduceErrorCode.MRCPostOperationsFailure: return(LogMessagesUtils.ReplaceMessageSequencesAndReferences(PassportPDFResultCodesMessagesLocalizer.GetString("reduceErrorCode_MRCPostOperationsFailure", FrameworkGlobals.ApplicationLanguage), pageNumber: reduceErrorInfo.PageNumber));

            case ReduceErrorCode.PageConversionFailure: return(LogMessagesUtils.ReplaceMessageSequencesAndReferences(PassportPDFResultCodesMessagesLocalizer.GetString("reduceErrorCode_PageConversionFailure", FrameworkGlobals.ApplicationLanguage), pageNumber: reduceErrorInfo.PageNumber));

            case ReduceErrorCode.DocumentEncrypted: return(PassportPDFResultCodesMessagesLocalizer.GetString("reduceErrorCode_DocumentEncrypted", FrameworkGlobals.ApplicationLanguage));

            case ReduceErrorCode.UnexpectedError: return(PassportPDFResultCodesMessagesLocalizer.GetString("reduceErrorCode_UnexpectedError", FrameworkGlobals.ApplicationLanguage));

            default: return("Unknown reduce error");    //here for forward compatibility purpose.
            }
        }
Exemple #20
0
        protected override void OnOperationsCompletion()
        {
            base.OnOperationsCompletion();

            string workCompletionMessage = LogMessagesUtils.GetGenericWorkCompletionMessage(_operationsStats.ProcessedFileCount, _operationsStats.SuccesfullyProcessedFileCount,
                                                                                            _operationsStats.UnsuccessfullyProcessedFileCount, ParsingUtils.GetElapsedTimeString(_stopwatch.Elapsed.Hours, _stopwatch.Elapsed.Minutes, _stopwatch.Elapsed.Seconds, _stopwatch.Elapsed.Milliseconds / 10));

            _view.NotifyOperationsResult(workCompletionMessage);

            if (!_appInfo.AutoRun)
            {
                _view.ShowInformationMessage(workCompletionMessage, FrameworkGlobals.MessagesLocalizer.GetString("processTerminated", FrameworkGlobals.ApplicationConfiguration.Language));
                _view.UnlockView();
            }
            else
            {
                Console.Write(workCompletionMessage);
                _view.ExitApplication();
            }
        }
Exemple #21
0
        public static bool FetchConfigurationFromPassportPDF(string appId, IWin32Window owner = null)
        {
            using (frmFetchingInfoFromServer fetchWindow = new frmFetchingInfoFromServer())
            {
                fetchWindow._appId = appId;
                fetchWindow._passportPdfRequestWorker.RunWorkerAsync(BackgroundOperationType.FetchConfiguration);
                fetchWindow.SetFormFetchingMessageAndShowUntilWorkCompletion(owner, FrameworkGlobals.MessagesLocalizer.GetString("message_fetching_configuration", FrameworkGlobals.ApplicationLanguage));

                if (fetchWindow._apiCallException != null)
                {
                    // An exception occured when calling the API
                    DialogUtilities.ShowErrorMessage(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_configuration_fetching_failure", FrameworkGlobals.ApplicationLanguage),
                                                                                                           additionalMessage: fetchWindow._apiCallException.Message), FrameworkGlobals.MessagesLocalizer.GetString("caption_error", FrameworkGlobals.ApplicationLanguage));
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
Exemple #22
0
        protected override void OnOperationsCompletion()
        {
            base.OnOperationsCompletion();

            string elapsedTime = ParsingUtils.GetElapsedTimeString(_stopwatch.Elapsed);

            _view.NotifyOperationsResult(LogMessagesUtils.GetReductionWorkCompletionText(_operationsStats.ProcessedFileCount, _operationsStats.SuccesfullyProcessedFileCount, _operationsStats.UnsuccessfullyProcessedFileCount, _operationsStats.TotalInputSize, _operationsStats.TotalOutputSize, elapsedTime));

            string detailedWorkCompletionMessage = LogMessagesUtils.GetDetailedReductionWorkCompletionText(_operationsStats.ProcessedFileCount, _operationsStats.SuccesfullyProcessedFileCount, _operationsStats.UnsuccessfullyProcessedFileCount, _operationsStats.FileConvertedToPDFCount, _operationsStats.TotalInputSize, _operationsStats.TotalOutputSize, elapsedTime);

            if (!_appInfo.AutoRun)
            {
                _view.ShowInformationMessage(detailedWorkCompletionMessage, FrameworkGlobals.MessagesLocalizer.GetString("processTerminated", FrameworkGlobals.ApplicationLanguage));
                _view.UnlockView();
            }
            else
            {
                Console.Write(detailedWorkCompletionMessage);
                _view.ExitApplication();
            }
        }
 private void OnDownloadStart(int workerNumber, string fileName, int retries)
 {
     _view.NotifyWorkerProgress(workerNumber, LogMessagesUtils.GetFileDownloadingStartText(fileName, retries));
 }
 private void OnFileProcessingChunkProgress(int workerNumber, string fileName, string pageRange, int pageCount, int retries)
 {
     _view.NotifyWorkerProgress(workerNumber, LogMessagesUtils.GetFileChunkProcessingProgressText(fileName, pageRange, pageCount, retries));
 }
 private void OnWorkerWorkPause(int workerNumber)
 {
     _view.NotifyWorkerProgress(workerNumber, LogMessagesUtils.GetWorkerIdleStateText());
 }
Exemple #26
0
        private WorkflowProcessingResult ProcessWorkflow(PDFApi pdfApiInstance, ImageApi imageApiInstance, OperationsWorkflow workflow, FileToProcess fileToProcess, int workerNumber)
        {
            List <string> warningMessages = new List <string>();
            bool          contentRemoved  = false;
            bool          versionChanged  = false;
            bool          linearized      = false;
            string        fileID          = null;

            foreach (Operation operation in workflow.OperationsToBePerformed)
            {
                Error           actionError     = null;
                ReduceErrorInfo reduceErrorInfo = null;
                long            remainingTokens = 0;

                if (_cancellationPending)
                {
                    return(null);
                }

                switch (operation.Type)
                {
                case Operation.OperationType.LoadPDF:
                    PdfVersion outputVersion = (PdfVersion)operation.Parameters;
                    PdfLoadDocumentResponse loadDocumentResponse = HandleLoadPDF(pdfApiInstance, outputVersion, fileToProcess, workerNumber);
                    if (loadDocumentResponse == null)
                    {
                        OnError(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_invalid_response_received", FrameworkGlobals.ApplicationLanguage), actionName: "Load"));
                        return(null);
                    }
                    remainingTokens = loadDocumentResponse.RemainingTokens;
                    actionError     = loadDocumentResponse.Error;
                    fileID          = loadDocumentResponse.FileId;
                    break;

                case Operation.OperationType.LoadImage:
                    ImageLoadResponse imageLoadResponse = HandleLoadImage(imageApiInstance, fileToProcess, workerNumber);
                    if (imageLoadResponse == null)
                    {
                        OnError(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_invalid_response_received", FrameworkGlobals.ApplicationLanguage), actionName: "Load"));
                        return(null);
                    }
                    remainingTokens = imageLoadResponse.RemainingTokens;
                    actionError     = imageLoadResponse.Error;
                    fileID          = imageLoadResponse.FileId;
                    break;

                case Operation.OperationType.ReducePDF:
                    PDFReduceActionConfiguration reduceActionConfiguration = (PDFReduceActionConfiguration)operation.Parameters;
                    PdfReduceResponse            reduceResponse            = HandleReducePDF(pdfApiInstance, reduceActionConfiguration, fileToProcess, fileID, workerNumber, warningMessages);
                    if (reduceResponse == null)
                    {
                        OnError(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_invalid_response_received", FrameworkGlobals.ApplicationLanguage), actionName: "Reduce"));
                        return(null);
                    }
                    remainingTokens = reduceResponse.RemainingTokens;
                    contentRemoved  = reduceResponse.ContentRemoved;
                    versionChanged  = reduceResponse.VersionChanged;
                    actionError     = reduceResponse.Error;
                    reduceErrorInfo = reduceResponse.ErrorInfo;
                    linearized      = reduceActionConfiguration.FastWebView;
                    break;

                case Operation.OperationType.OCRPDF:
                    PDFOCRActionConfiguration ocrActionConfiguration = (PDFOCRActionConfiguration)operation.Parameters;
                    PdfOCRResponse            ocrResponse            = HandleOCRPDF(pdfApiInstance, ocrActionConfiguration, fileToProcess, fileID, workerNumber);
                    if (ocrResponse == null)
                    {
                        OnError(LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("message_invalid_response_received", FrameworkGlobals.ApplicationLanguage), actionName: "OCR"));
                        return(null);
                    }
                    remainingTokens = ocrResponse.RemainingTokens;
                    actionError     = ocrResponse.Error;
                    break;
                }

                if (actionError != null)
                {
                    string errorMessage = reduceErrorInfo != null && reduceErrorInfo.ErrorCode != ReduceErrorCode.OK ? ErrorManager.GetMessageFromReduceActionError(reduceErrorInfo, fileToProcess.FileAbsolutePath) : ErrorManager.GetMessageFromPassportPDFError(actionError, operation.Type, fileToProcess.FileAbsolutePath);
                    OnError(errorMessage);
                    return(null);
                }
                else
                {
                    RemainingTokensUpdateEventHandler.Invoke(remainingTokens);
                }
            }


            return(new WorkflowProcessingResult(contentRemoved, versionChanged, linearized, fileID, warningMessages));
        }
 private void OnFileOperationsStart(int workerNumber, string fileName, int retries)
 {
     _view.NotifyWorkerProgress(workerNumber, LogMessagesUtils.GetFileOperationsStartText(fileName, retries));
 }
Exemple #28
0
 private void LoadLocales(string productName)
 {
     Text             = Globals.LabelsLocalizer.GetString("label_frmUpdateInProgress", FrameworkGlobals.ApplicationLanguage);
     txtUpdating.Text = LogMessagesUtils.ReplaceMessageSequencesAndReferences(Globals.LabelsLocalizer.GetString("label_txtUpdating", FrameworkGlobals.ApplicationLanguage), applicationName: productName);
 }
 public void OnLanguageChangeRequested(string language)
 {
     FrameworkGlobals.ApplicationConfiguration.Language = language;
     _view.ChangeLanguage(language);
     _view.PassportStatus = LogMessagesUtils.ReplaceMessageSequencesAndReferences(FrameworkGlobals.MessagesLocalizer.GetString("label_remaining_tokens", FrameworkGlobals.ApplicationLanguage), remainingTokens: FrameworkGlobals.PassportInfo.RemainingTokens);
 }