public static void SetMultiplatformSupport() { try { // Set the optional multi-platform support // Refer to https://www.leadtools.com/help/leadtools/v20/dh/to/leadtools-drawing-engine-and-multi-platform-consideration.html // Get the current options DrawEngineOptions options = DrawEngine.GetOptions(); var drawEngineTypeString = ServiceHelper.GetSettingValue(ServiceHelper.Key_Application_DrawEngineType); if (!string.IsNullOrEmpty(drawEngineTypeString)) { options.EngineType = (DrawEngineType)Enum.Parse(typeof(DrawEngineType), drawEngineTypeString, true); } var shadowFontModeString = ServiceHelper.GetSettingValue(ServiceHelper.Key_Application_ShadowFontMode); if (!string.IsNullOrEmpty(shadowFontModeString)) { options.ShadowFontMode = (DrawShadowFontMode)Enum.Parse(typeof(DrawShadowFontMode), shadowFontModeString, true); } DrawEngine.SetOptions(options); // Set the shadow fonts directory string shadowFontsDirectory = GetSettingValue(ServiceHelper.Key_Application_ShadowFontsDirectory); shadowFontsDirectory = ServiceHelper.GetAbsolutePath(shadowFontsDirectory); if (!string.IsNullOrEmpty(shadowFontsDirectory)) { if (Directory.Exists(shadowFontsDirectory)) { // Set the shadow fonts RasterDefaults.SetResourceDirectory(LEADResourceDirectory.Fonts, shadowFontsDirectory); } else { throw new InvalidOperationException(string.Format("Unable to set shadow fonts because the file {0} does not exist or is not a directory.", shadowFontsDirectory)); } } _multiplatformSupportStatus = "Ready"; } catch { _multiplatformSupportStatus = "Error"; throw; } }
public static void CreatePreCache() { // check first, so not everyone here will get caught by the lock if (_preCache != null) { return; } var preCacheDirectory = ServiceHelper.GetSettingValue(ServiceHelper.Key_PreCache_Directory); if (string.IsNullOrEmpty(preCacheDirectory)) { preCacheDirectory = ServiceHelper.Default_PreCache_Directory; } preCacheDirectory = ServiceHelper.GetAbsolutePath(preCacheDirectory); if (string.IsNullOrEmpty(preCacheDirectory)) { // No setting, pre-caching is disabled return; } try { var cache = new FileCache(); cache.CacheDirectory = preCacheDirectory; if (!Directory.Exists(preCacheDirectory)) { Directory.CreateDirectory(preCacheDirectory); } // Choose how we want to serialize the data. We choose JSON for human-readability. cache.DataSerializationMode = CacheSerializationMode.Json; cache.PolicySerializationMode = CacheSerializationMode.Json; _preCache = cache; } catch (Exception e) { throw new InvalidOperationException("Could not create pre-cache", e); } }
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(); } }