コード例 #1
0
        public static ImageLoadResponse SendLoadImageMultipartRequest(ImageApi apiInstance, int workerNumber, string inputFilePath, string fileName, Stream fileStream, ContentEncoding contentEncoding, OperationsManager.ProgressDelegate uploadOperationStartEventHandler)
        {
            Exception e       = null;
            int       pausems = 5000;

            for (int i = 0; i < FrameworkGlobals.MAX_RETRYING_REQUESTS; i++)
            {
                uploadOperationStartEventHandler.Invoke(workerNumber, inputFilePath, i);
                try
                {
                    fileStream.Seek(0, SeekOrigin.Begin);

                    ImageLoadResponse response = apiInstance.ImageLoadMultipart(fileStream,
                                                                                new LoadImageParameters()
                    {
                        ContentEncoding = contentEncoding,
                        FileName        = fileName
                    });

                    return(response);
                }
                catch (Exception ex)
                {
                    if (i < FrameworkGlobals.MAX_RETRYING_REQUESTS - 1)
                    {
                        Thread.Sleep(pausems); //marking a pause in case of cnx temporarily out and to avoid overhead.
                        pausems += 2000;
                    }
                    else
                    {//last iteration
                        e = ex;
                    }
                }
            }

            throw e;
        }
コード例 #2
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));
        }