public void Open() { lock (s_sync) { Id = GenerateId(); _closed = false; _closedEvent.Reset(); ReceivingAllowed = true; VotingResult = null; _error = null; ErrorSpecified.Reset(); DropResult = DropResult.Timeout; GCSettings.LatencyMode = GCLatencyMode.LowLatency; } }
private void CloseSheetProcessingSession(VotingResult votingResult, DropResult dropResult) { lock (s_sheetProcessingSessionSync) { if (_sheetProcessingSession.Closed) { Logger.LogVerbose(Message.ScannerManagerTryToCloseAlreadyClosedSheetProcessingSession, _sheetProcessingSession.Id); return; } Logger.LogVerbose(Message.ScannerManagerCloseSheetProcessingSession, _sheetProcessingSession.Id); _sheetProcessingSession.VotingResult = votingResult; _sheetProcessingSession.DropResult = dropResult; CoreApplication.Instance.LoggerEnabled = true; Logger.LogVerbose( Message.ScannerManagerSheetProcessed, () => new object[] { _sheetProcessingSession.VotingResult.ToString(), _sheetProcessingSession.DropResult }); _sheetProcessingSession.Close(); StartRollTextMachine(); SheetProcessed.RaiseEvent(this, new SheetEventArgs(_sheetProcessingSession)); } }
private void ScannerManager_SheetProcessed(object sender, SheetEventArgs e) { _lastVotingResult = e.SheetProcessingSession.VotingResult; _lastError = e.SheetProcessingSession.Error; _lastDropResult = e.SheetProcessingSession.DropResult; _lastSheetType = e.SheetProcessingSession.SheetType; _sheetProcessed.GetAccess(this); _sheetProcessed.Set(); }
public void Reset() { lock (s_sync) { Id = GenerateId(); _closed = true; _closedEvent.Set(); ReceivingAllowed = true; VotingResult = null; _error = null; ErrorSpecified.Reset(); DropResult = DropResult.Timeout; } }
private void AddVotingResult(RecognitionResult recResult) { try { var votingResult = new VotingResult( recResult.BlankType, recResult.BulletinNumber, recResult.StampNumber, recResult.BadBulletinReason.ToString(), recResult.BadStampReason, recResult.Marks, recResult.SectionsValidity); _votingResultManager.AddVotingResult( votingResult, _recognitionStartVotingMode, _scannerManager.IntSerialNumber); } catch (Exception ex) { Logger.LogError(Message.RecognizerAddVotingResultError, ex); } }
private RecognitionResult RecognitionResultAnalisys(int recResultCode) { PollResult pollRes; // результат распознавания int[][] sectionsMarks = null; // массив отметок по всем секциям бланка bool[] sectionsValidity = null; // признаки корректности секций бюллетеня var recLogAddInfoSb = new StringBuilder(); // доп. информация для записи в файл журнала распознавания var stampResult = StampResult.YES; // результат распознавания печати var stampNumber = ""; // Наиболее вероятный номер печати (полутон) var stampAlternatives = new string[4]; // Альтернативы цифр номера печати по позициям (полутон) if (recResultCode >= 0) { #region формирование массива меток sectionsMarks = new int[_ocr.Results.Count][]; sectionsValidity = new bool[_ocr.Results.Count]; for (var sectionIndex = 0; sectionIndex < _ocr.Results.Count; sectionIndex++) { var electionNum = _electionManager.SourceData.Blanks[_ocr.BulletinNumber].Sections[sectionIndex]; var currentElection = _electionManager.SourceData.GetElectionByNum(electionNum); sectionsValidity[sectionIndex] = false; pollRes = _ocr.Results[sectionIndex]; var currentMarks = new int[pollRes.Count]; var activeMarksCount = pollRes.Count; var noneAboveActive = false; for (var squareIndex = 0; squareIndex < pollRes.Count; squareIndex++) { currentMarks[squareIndex] = pollRes[squareIndex]; var currentCandidate = currentElection.Candidates[currentMarks[squareIndex]]; if (currentCandidate.Disabled) { activeMarksCount--; } else { if (currentCandidate.NoneAbove) { noneAboveActive = true; } } } sectionsMarks[sectionIndex] = currentMarks; sectionsValidity[sectionIndex] = activeMarksCount > 0 && activeMarksCount <= currentElection.MaxMarks; if (noneAboveActive) sectionsValidity[sectionIndex] = (activeMarksCount == 1); recLogAddInfoSb.AppendFormat("E{0},", sectionIndex); foreach (var squareNum in sectionsMarks[sectionIndex]) { recLogAddInfoSb.Append(squareNum); recLogAddInfoSb.Append(','); } } #endregion #region вычисление результата распознавания печати if (_config.Ocr.Stamp.TestLevel != StampTestLevel.None) { if (_config.Ocr.Stamp.TestLevel == StampTestLevel.Halftone) { stampResult = Ocr.Ocr.IsStampOKGray(ref stampNumber, ref stampAlternatives); Logger.LogVerbose(Message.RecognizerHalftoneStamp, stampResult, stampNumber); } else { stampNumber = "0"; stampResult = _ocr.StampResult; Logger.LogVerbose(Message.RecognizerBinaryStamp, stampResult); } } #endregion } var recResult = CreateRecognitionResult(recResultCode, sectionsMarks, sectionsValidity, stampResult, stampNumber, stampAlternatives); LastRecognitionResult = recResult; WriteRecognitionResultToLog(recResult, stampResult, stampNumber, recLogAddInfoSb.ToString()); if (recResult.BlankType != BlankType.Bad && recResult.BlankType != BlankType.BadMode) { AddVotingResult(recResult); } else { var votingResult = new VotingResult( recResult.BlankType, recResult.BulletinNumber, recResult.StampNumber, recResult.BadBulletinReason.ToString(), recResult.BadStampReason, recResult.Marks, recResult.SectionsValidity); _votingResultManager.SetLastVotingResult(votingResult); } SaveLastImage(recResult.ImageFilePrefix, recResult.ImageSavingType, null); return recResult; }
private List<KeyValuePair<VoteKey, bool>> GetVoteKeysForAdding( VotingResult votingResult, VotingMode votingMode, int scannerSerialNumber) { Logger.LogVerbose(Message.Common_DebugCall); var keys = new List<KeyValuePair<VoteKey, bool>>(); var sourceData = _electionManager.SourceData; var blank = (0 <= votingResult.BulletinNumber && votingResult.BulletinNumber < sourceData.Blanks.Length) ? sourceData.Blanks[votingResult.BulletinNumber] : null; var bulletinVote = new VoteKey { ScannerSerialNumber = scannerSerialNumber, VotingMode = votingMode, BlankId = (blank != null ? blank.Id : votingResult.BulletinNumber.ToString()), BlankType = votingResult.BlankType, }; if (bulletinVote.BlankType == BlankType.Valid) { if (votingResult.SectionsMarks == null || votingResult.SectionsValidity == null) { bulletinVote.BlankType = BlankType.NoMarks; } else { var invalid = true; for (var sectionIndex = 0; sectionIndex <= votingResult.SectionsMarks.GetUpperBound(0); sectionIndex++) { if (votingResult.SectionsValidity[sectionIndex] && votingResult.SectionsMarks[sectionIndex] != null && votingResult.SectionsMarks[sectionIndex].Length > 0) { invalid = false; break; } } if (invalid) bulletinVote.BlankType = BlankType.NoMarks; } } if (bulletinVote.BlankType == BlankType.Valid) { bool isBulletinAdded = false; for (var sectionIndex = 0; sectionIndex <= votingResult.SectionsMarks.GetUpperBound(0); sectionIndex++) { if (!votingResult.SectionsValidity[sectionIndex]) continue; for (var markIndex = 0; markIndex < votingResult.SectionsMarks[sectionIndex].Length; markIndex++) { VoteKey candidateVote; if (!isBulletinAdded && markIndex == 0) { candidateVote = bulletinVote; isBulletinAdded = true; } else candidateVote = new VoteKey { ScannerSerialNumber = scannerSerialNumber, BlankId = blank.Id, VotingMode = votingMode }; candidateVote.ElectionNum = blank.Sections[sectionIndex]; candidateVote.CandidateId = sourceData.GetElectionByNum(blank.Sections[sectionIndex]). Candidates[votingResult.SectionsMarks[sectionIndex][markIndex]].Id; keys.Add(new KeyValuePair<VoteKey, bool>(candidateVote, false)); } } } else { keys.Add(new KeyValuePair<VoteKey, bool>(bulletinVote, false)); } return keys; }
public void SetLastVotingResult(VotingResult votingResult) { lock (s_votingResultSync) { LastVotingResult = votingResult; } }
public void AddVotingResult( VotingResult votingResult, VotingMode votingMode, int scannerSerialNumber) { Logger.LogVerbose(Message.Common_DebugCall); lock (s_votingResultSync) { SetLastVotingResult(votingResult); List<KeyValuePair<VoteKey, bool>> voteKeysForAdding = null; while (true) { try { if (voteKeysForAdding == null) voteKeysForAdding = GetVoteKeysForAdding(LastVotingResult, votingMode, scannerSerialNumber); for (var keyIndex = 0; keyIndex < voteKeysForAdding.Count; keyIndex++) { var item = voteKeysForAdding[keyIndex]; if (item.Value) continue; var votesCount = 0; try { votesCount = VotingResults.VotesCount(item.Key); VotingResults.AddVote(item.Key); } catch (ThreadAbortException) { Logger.LogWarning(Message.VotingResult_AddVotingResultAbort); Thread.ResetAbort(); } catch (Exception ex) { Logger.LogError(Message.VotingResult_AddVotingResultError, ex); } finally { if (VotingResults.VotesCount(item.Key) != votesCount + 1) keyIndex--; else voteKeysForAdding[keyIndex] = new KeyValuePair<VoteKey, bool>(item.Key, true); } } break; } catch (ThreadAbortException) { Logger.LogWarning(Message.VotingResult_AddVotingResultAbort); Thread.ResetAbort(); } catch (Exception ex) { Logger.LogError(Message.VotingResult_AddVotingResultError, ex); } } } RaiseStateChanged(); }