Ejemplo n.º 1
0
        public static bool SaveConfigData(ConfigurationBase config, MainConfigType mainConfigType, out Exception _ex)
        {
            bool result = true;

            _ex = new Exception();

            string configDataPath = GetConfigDataPath(config.Title, mainConfigType);

            if (!Directory.Exists(configDataPath))
            {
                Directory.CreateDirectory(configDataPath);
            }

            string configDataFilePath = GetConfigDataFilePath(config.Title, mainConfigType);

            switch (mainConfigType)
            {
            case MainConfigType.OMR:
                OMRConfiguration omrConfiguration = (OMRConfiguration)config;

                try
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    using (FileStream fs = new FileStream(configDataFilePath, FileMode.Create))
                    {
                        bf.Serialize(fs, omrConfiguration);
                    }
                }
                catch (Exception ex)
                {
                    _ex    = ex;
                    result = false;
                }
                break;

            case MainConfigType.BARCODE:
                OBRConfiguration obrConfiguration = (OBRConfiguration)config;

                try
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    using (FileStream fs = new FileStream(configDataFilePath, FileMode.Create))
                    {
                        bf.Serialize(fs, obrConfiguration);
                    }
                }
                catch (Exception ex)
                {
                    _ex    = ex;
                    result = false;
                }
                break;

            case MainConfigType.ICR:
                ICRConfiguration icrConfiguration = (ICRConfiguration)config;

                try
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    using (FileStream fs = new FileStream(configDataFilePath, FileMode.Create))
                    {
                        bf.Serialize(fs, icrConfiguration);
                    }
                }
                catch (Exception ex)
                {
                    _ex    = ex;
                    result = false;
                }
                break;
            }

            return(result);
        }
Ejemplo n.º 2
0
        public ProcessedDataEntry ProcessSheet(ConfigurationBase configuration, Mat sheet, Action <RectangleF, bool> OnOptionProcessed = null, string originalSheetPath = "")
        {
            OBRConfiguration obrConfiguration = (OBRConfiguration)configuration;

            RectangleF barcodeRegion = obrConfiguration.GetConfigArea.ConfigRect;

            // Configure reader
            //CiServer ciServer = Server.GetThreadServer();
            //CiBarcodePro barcodeReader = ciServer.CreateBarcodePro();
            barcodeReader.Auto1D = obrConfiguration.AutoDetect1DBarcode; // Enable automatic detection of barcode type (Slower processing)
            if (!obrConfiguration.AutoDetect1DBarcode)
            {                                                            // Select barcode types to read
                barcodeReader.Code128 = obrConfiguration.Code128;
                barcodeReader.Code93  = obrConfiguration.Code93;
                barcodeReader.Code39  = obrConfiguration.Code39;
            }
            if (obrConfiguration.CheckAll) // Limit barcode search direction (Faster processing)
            {
                barcodeReader.Horizontal = true;
                barcodeReader.Vertical   = true;
                barcodeReader.Diagonal   = true;
            }
            else
            {
                barcodeReader.Horizontal = obrConfiguration.CheckHorizontal;
                barcodeReader.Vertical   = obrConfiguration.CheckVertical;
                barcodeReader.Diagonal   = obrConfiguration.CheckDiagonal;
            }
            //barcodeReader.Algorithm = obrConfiguration.AlgorithmPreference;

            string output = "-";

            Barcode[] barcodes = null;
            using (Bitmap region = sheet.Bitmap.Clone(barcodeRegion, System.Drawing.Imaging.PixelFormat.Format8bppIndexed))
            {
                try
                {
                    barcodes = barcodeReader.Read(region);   // Read barcodes
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception: " + ex.ToString());
                }
                finally
                {
                    if (barcodeReader != null)
                    {
                        barcodeReader.Dispose();
                    }
                }  //Free image memory.
                if (barcodes.Length == 0 && obrConfiguration.SearchFullIfNull)
                {
                    using (Mat orignalSheet = CvInvoke.Imread(originalSheetPath))
                    {
                        barcodes = barcodeReader.Read(orignalSheet.Bitmap);   // Read barcodes
                    }
                }
                output = barcodes.Length > 0 ? barcodes[0].Text : "-";
            }

            return(new ProcessedDataEntry(configuration.Title, output.ToCharArray(), new ProcessedDataType[] { ProcessedDataType.NORMAL }, new byte[0, 0], barcodes));
        }