Пример #1
0
 //-------------------------------------------------------------------------
 private Batches GetAppConfig()
 {
     Exception ex;
     var serializer = new SerializerHelper();
     return serializer.GetBatchesFromFile(OcrAppConfig.AppConfigFileName, out ex);
 }
Пример #2
0
        public OcrAppConfig(string appConfigFileName)
        {
            if (!File.Exists(appConfigFileName))
            {
                CreateDefaultAppConfig();
                appConfigFileName = OcrAppConfig.AppConfigFileName;
                var Message = "Error in " + appConfigFileName + " This file does not exist. Default AppConfig was created.";
                log.LogMessage(Message);
            }

            this.appConfigDateTime = File.GetLastWriteTime(appConfigFileName).ToString();

            var serializer = new SerializerHelper();
            Batches currentAppConfig = serializer.GetBatchesFromFile(appConfigFileName, out exception);
            if (currentAppConfig == null)
            {
                log.LogMessage(exception);
                var Message = "Error in " + OcrAppConfig.AppConfigFileName + ". The program will be closed";
                log.LogMessage(Message);
                exception = new Exception("Error in " + OcrAppConfig.AppConfigFileName + "\r\n" + exception.Message + "\r\nThe program will be closed");
                return;
            }

            bool active = false;
            foreach (var item in currentAppConfig.batches)
            {
                if (!item.active)
                {
                    continue;
                }
                active = true;
                useStudentId = item.useStudentId;
                recQRCode = item.recQRCode;
                InputFolder = item.inPath;
                ManualInputFolder = item.manualInPath;
                ErrorFolder = item.outPathError;
                ManualErrorFolder = item.manualErrorsFolder;
                ConfigsFolder = item.configsFolder;
                ManualConfigsFolder = item.manuaConfigsFolder;
                ArchiveFolder = item.outPathArchive;
                ManualArchiveFolder = item.manualOutPathArchive;
                NotConfidentFolder = item.outPathNotConfident;
                ManualNotConfidentFolder = item.manualOutPathNotConfident;
                SuccessFolder = item.outPathSuccess;
                OutputFolder_Success = item.outputFolder_Success;
                ManualSuccessFolder = item.manualSuccessFolder;
                ManualNextProccessingFolder = item.manualNextProccessingFolder;
                DualControl = item.dual_control_bar_codes;
                AutoRunEditorOnError = item.autoRunEditorOnError;
                if (!string.IsNullOrEmpty(item.serverName))
                    ServerName = item.serverName;
                else
                    ServerName = Environment.MachineName;

                if (!string.IsNullOrEmpty(item.updateServerName))
                    UpdateServerName = item.updateServerName;

                if (!string.IsNullOrEmpty(item.outputMode))
                    OutputMode = item.outputMode;

                if (!string.IsNullOrEmpty(item.baseTempFolder))
                {
                    BaseTempFolder = item.baseTempFolder;
                    TempFolder = Path.Combine(BaseTempFolder, "Temp\\");
                    TempFramesFolder = Path.Combine(BaseTempFolder, "TempFrames\\");
                    TempEdFolder = Path.Combine(BaseTempFolder, "TempEd\\");
                    LogsFolder = Path.Combine(BaseTempFolder, "Logs\\");
                }

                SmartResize = (item.smartResize == true) ? true : false;
                DoNotProcess = (item.doNotProcess == true) ? true : false;

                RemoveEmptyScans = (item.removeEmptyScans == true) ? true : false;

                PercentConfidentText = (item.percent_confident_text != null) ? (double)item.percent_confident_text : PercentConfidentTextDefault;
                FontName = (String.IsNullOrEmpty(item.fontName)) ? FontNameDefault : item.fontName;
                SupportedExtensions = (String.IsNullOrEmpty(item.fileMask)) ? SupportedExtensionsDefault : item.fileMask;
                MoveToNextProccessingFolderOnSheetIdentifierError = (item.moveToNextProccessingFolderOnSheetIdentifierError == true) ? true : false;

                EmptyScanDarknessPercent = (item.emptyScanDarknessPercent != null) ? (double)item.emptyScanDarknessPercent : EmptyScanDarknessPercentDefault;
                EmptyScansFolder = (String.IsNullOrEmpty(item.emptyScansPath)) ? ErrorFolder : item.emptyScansPath;

                NotSupportedSheetFolder = (String.IsNullOrEmpty(item.notSupportedSheetPath)) ? ErrorFolder : item.notSupportedSheetPath;
                NotSupportedSheets = (!String.IsNullOrEmpty(item.notSupportedSheets))
                    ? Regex.Split(item.notSupportedSheets, "\\s+").ToList() : (!String.IsNullOrEmpty(NotSupportedSheetsDefault))
                        ? Regex.Split(NotSupportedSheetsDefault, "\\s+").ToList() : new List<string>();

                OutputFileValue = new Dictionary<int, string>();
                foreach (Batches.OutputFileValue itm in item.outputFileValues)
                {
                    OutputFileValue.Add(itm.position, itm.value.ToString());
                }
                SheetIdEnum = new Dictionary<int, string>();
                if (item.sheetIdEnum != null)
                {
                    foreach (Batches.SheetIdEnum itm in item.sheetIdEnum)
                    {
                        SheetIdEnum.Add(itm.position, itm.value);
                    }
                }
                //ManualProcessingFlag = new KeyValuePair<int, string>
                //    (item.manualProcessingFlag.position, item.manualProcessingFlag.value as string);

                if (configsFolderDefault != ConfigsFolder)
                    CopyConfigsFile(ConfigsFolder);
                if (configsFolderDefault != ManualConfigsFolder)
                    CopyConfigsFile(ManualConfigsFolder);
                break;
            }
            if (!active)
            {
                exception = new Exception("Active batches not found. The program will be closed.");
                log.LogMessage(exception);
                return;
            }

            this.AutoStart = currentAppConfig.autoStart;
            this.LogLength = currentAppConfig.logLength;
        }