public static void CreateOCREngine() { if (_ocrEngine != null) { _ocrEngine.Dispose(); } // Reset the OCR Engine Status _OcrEngineStatus = OcrEngineStatus.Unset; var engineTypeString = ServiceHelper.GetSettingValue(ServiceHelper.Key_Ocr_EngineType); if (string.IsNullOrEmpty(engineTypeString)) { return; } var engineType = OcrEngineType.LEAD; try { // not necessary since we set to LEAD OCR above, but here as an example. if (engineTypeString.Equals("lead", StringComparison.OrdinalIgnoreCase)) { engineType = OcrEngineType.LEAD; } else if (engineTypeString.Equals("omnipage", StringComparison.OrdinalIgnoreCase)) { engineType = OcrEngineType.OmniPage; } } catch { // Error with engine type _OcrEngineStatus = OcrEngineStatus.Error; return; } // Check for a location of the OCR Runtime var runtimeDirectory = ServiceHelper.GetSettingValue(ServiceHelper.Key_Ocr_RuntimeDirectory); runtimeDirectory = ServiceHelper.GetAbsolutePath(runtimeDirectory); if (string.IsNullOrEmpty(runtimeDirectory)) { runtimeDirectory = CheckOCRRuntimeDirectory(); } // Use LEAD OCR engine var ocrEngine = OcrEngineManager.CreateEngine(engineType, true); try { // Start it up ocrEngine.Startup(null, null, null, runtimeDirectory); _ocrEngine = ocrEngine; _OcrEngineStatus = OcrEngineStatus.Ready; } catch { ocrEngine.Dispose(); _OcrEngineStatus = OcrEngineStatus.Error; System.Diagnostics.Trace.WriteLine("The OCR Engine could not be started. This application will continue to run, but without OCR functionality."); } }
public static void InitializeService() { /* This method is called by Application_Start of the web service * We will initialize the global and static objects used through out the demos and * Each controller will be able to use these same objects. * Controller-specific initialization is performed in InitializeController */ // Set the license, initialize the cache and various objects // For the license, the TestController.Ping method is used to check the status of this // So save the values here to get them later try { SetLicense(); IsKernelExpired = RasterSupport.KernelExpired; } catch { IsKernelExpired = true; } if (!IsKernelExpired) { // The license is OK, continue try { // This setting disables disk access when creating temp files if (!GetSettingBoolean(Key_Application_AllowTempFilesFromDisk)) { RasterDefaults.TempFileMode = LeadTempFileMode.Memory; } string tempDirectory = GetSettingValue(ServiceHelper.Key_Application_TempDirectory); if (!string.IsNullOrEmpty(tempDirectory)) { tempDirectory = ServiceHelper.GetAbsolutePath(tempDirectory); RasterDefaults.TemporaryDirectory = tempDirectory; } SetMultiplatformSupport(); CreateCache(); PreCacheHelper.CreatePreCache(); SetRasterCodecsOptions(DocumentFactory.RasterCodecsTemplate, 0); LoadMimeTypesWhitelist(); if (GetSettingBoolean(Key_Document_OnlyAllowedMimeTypes)) { /* * If true, all unspecified mimeTypes are automatically considered "denied". * This effectively means that only mimeTypes in the "allowed" list are accepted. */ DocumentFactory.MimeTypes.DefaultStatus = DocumentMimeTypeStatus.Denied; } _autoUpdateHistory = GetSettingBoolean(Key_Document_AutoUpdateHistory); _returnRequestUserData = GetSettingBoolean(Key_Application_ReturnRequestUserData); } catch { // Let this pass, it is checked again in TestController.Ping } CreateOCREngine(); CreateAnnRenderingEngine(); } }