public static int GetSettingInteger(string key, int defaultValue)
        {
            var stringVal = ServiceHelper.GetSettingValue(key);
            int temp      = defaultValue;

            if (int.TryParse(stringVal, out temp))
            {
                return(temp);
            }
            return(defaultValue);
        }
        public static bool GetSettingBoolean(string key)
        {
            var  stringVal = ServiceHelper.GetSettingValue(key);
            bool temp      = false;

            if (bool.TryParse(stringVal, out temp))
            {
                return(temp);
            }
            return(false);
        }
        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;
            }
        }
Exemple #4
0
        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.");
            }
        }