public VotingModeTimeConfig this[VotingMode mode] { get { return((VotingModeTimeConfig)BaseGet(mode)); } }
public VotingModeTimeConfig this[VotingMode mode] { get { return (VotingModeTimeConfig)BaseGet(mode); } }
public TimeSpan GetVotingModeStartTime(VotingMode mode) { var modeTime = VotingModeTimes.FirstOrDefault(item => item.mode == mode); if (modeTime != null) { return(TimeSpan.FromHours(modeTime.hour) + TimeSpan.FromMinutes(modeTime.minute)); } throw new ApplicationException("Не найдено время начала режима голосования " + mode); }
public TimeSpan GetTimeToModeStart(VotingMode mode) { var now = LocalTimeNow; var nowTime = now - now.Date; var timeToStart = GetVotingModeStartTime(mode) - nowTime; return(timeToStart < TimeSpan.Zero ? TimeSpan.Zero : timeToStart); }
public bool IsVotingModeValidForBlank(Blank blank, VotingMode votingMode) { if (votingMode == VotingMode.Test) { return(true); } return(blank.Sections .Select(electionNum => GetElectionByNum(electionNum)) .SelectMany(election => election.VotingModes) .Any(mode => mode == votingMode)); }
public ModeTime GetModeTime(VotingMode mode) { var modeTimeConfig = this[mode]; var time = (modeTimeConfig == null ? TimeSpan.Zero : modeTimeConfig.Time); return new ModeTime { mode = mode, hour = time.Hours, minute = time.Minutes }; }
public override void RestoreState(object state) { var arr = (object[])state; SetSourceDataInternal( null, (SourceDataFileDescriptor)arr[SOURCE_DATA_FILE_DESCRIPTOR_STATEINDEX], (SourceDataChangesCache)arr[SOURCE_DATA_CHANGES_CACHE_STATEINDEX], (bool)arr[IS_SOURCE_DATA_CORRECT_STATEINDEX]); _currentVotingMode = (VotingMode)arr[CURRENT_VOTING_MODE_STATEINDEX]; }
public ModeTime GetModeTime(VotingMode mode) { var modeTimeConfig = this[mode]; var time = (modeTimeConfig == null ? TimeSpan.Zero : modeTimeConfig.Time); return(new ModeTime { mode = mode, hour = time.Hours, minute = time.Minutes }); }
public VoteKey(BlankType? type, VotingMode? mode, int? scannerSerial, string candidate, string election, string blankId) { BlankType = type; VotingMode = mode; ScannerSerialNumber = scannerSerial; CandidateId = candidate; ElectionNum = election; BlankId = blankId; }
public VotingMode GetNextVotingMode(VotingMode mode) { if (mode == VotingMode.Test) { return(VotingModes[0]); } for (int i = 0; i < VotingModes.Length - 1; i++) { if (VotingModes[i] == mode) { return(VotingModes[i + 1]); } } return(VotingMode.Results); }
public VotingMode GetPreviousVotingMode(VotingMode mode) { if (mode == VotingMode.Results) { return(VotingModes[VotingModes.Length - 1]); } for (var i = VotingModes.Length - 1; i > 0; i--) { if (VotingModes[i] == mode) { return(VotingModes[i - 1]); } } return(VotingMode.Test); }
private void SetCurrentVotingMode(VotingMode newVotingMode) { var args = new VotingModeChangedEventArgs( _currentVotingMode, newVotingMode, _votingResultManager.VotingResults.VotesCount( new VoteKey { VotingMode = _currentVotingMode })); _currentVotingMode = newVotingMode; if (newVotingMode > VotingMode.Test) { _votingResultManager.VotingResults.ClearTestData(); } VotingModeChanged.RaiseEvent(this, args); }
public bool IsVotingModeTime(VotingMode mode) { for (var i = 0; i < VotingModeTimes.Length; ++i) { var modeTime = VotingModeTimes[i]; if (modeTime.mode != mode) { continue; } var nextModeTime = ++i < VotingModeTimes.Length ? VotingModeTimes[i] : ModeTime.MaxValue; var now = LocalTimeNow; var nowTotalMinutes = now.Hour * 60 + now.Minute; return(modeTime.TotalMinutes <= nowTotalMinutes && nowTotalMinutes < nextModeTime.TotalMinutes); } return(false); }
public bool IsVotingModeExpired(VotingMode mode) { for (var i = 0; i < VotingModeTimes.Length; ++i) { var mt = VotingModeTimes[i]; if (mt.mode == mode) { if (++i == VotingModeTimes.Length) { return(false); } mt = VotingModeTimes[i]; } else if (mt.mode < mode) { continue; } var now = LocalTimeNow; return(mt.hour * 60 + mt.minute <= now.Hour * 60 + now.Minute); } return(false); }
/// <summary> /// Sends a request to the clients /// </summary> /// <param name="request">Name of the request</param> /// <param name="voteOptions">Vote options that should be sent</param> private void Request(string request, List <IVoteOption> voteOptions) { var msg = new OverlayMessage(); msg.request = request; msg.voteOptions = voteOptions.ConvertAll(_ => new OverlayVoteOption(_)).ToArray(); msg.retainInitialVotes = config.RetainInitialVotes; var strVotingMode = VotingMode.Lookup(config.VotingMode); if (strVotingMode != null) { msg.votingMode = strVotingMode; } else { logger.Error($"could not find voting mode {config.VotingMode} in dictionary"); msg.votingMode = "UNKNOWN_VOTING_MODE"; } // Count total votes msg.totalVotes = 0; voteOptions.ForEach(_ => msg.totalVotes += _.Votes); // Send the message to all clients Broadcast(JsonConvert.SerializeObject(msg)); }
public TimeSpan GetVotingModeStartTime(VotingMode mode) { var modeTime = VotingModeTimes.FirstOrDefault(item => item.mode == mode); if (modeTime != null) return TimeSpan.FromHours(modeTime.hour) + TimeSpan.FromMinutes(modeTime.minute); throw new ApplicationException("Не найдено время начала режима голосования " + mode); }
public TimeSpan GetTimeToModeStart(VotingMode mode) { var now = LocalTimeNow; var nowTime = now - now.Date; var timeToStart = GetVotingModeStartTime(mode) - nowTime; return timeToStart < TimeSpan.Zero ? TimeSpan.Zero : timeToStart; }
public VotingMode GetPreviousVotingMode(VotingMode mode) { if (mode == VotingMode.Results) { return VotingModes[VotingModes.Length - 1]; } for (var i = VotingModes.Length - 1; i > 0; i--) { if (VotingModes[i] == mode) { return VotingModes[i - 1]; } } return VotingMode.Test; }
public VotingMode GetNextVotingMode(VotingMode mode) { if (mode == VotingMode.Test) { return VotingModes[0]; } for (int i = 0; i < VotingModes.Length - 1; i++) { if (VotingModes[i] == mode) { return VotingModes[i + 1]; } } return VotingMode.Results; }
public void RunRecognition(int lineWidth) { Logger.LogVerbose(Message.Common_DebugCall); if (_ocr == null) return; _recognitionPerformNow = true; _recognitionStartVotingMode = _electionManager.CurrentVotingMode; _scannedLinesCount = 0; _reverseCommandWasSent = false; SetOcrDpi(); if (File.Exists(OcrLogFilePath)) { try { _ocr.EnableLogging(null); File.Delete(OcrLogFilePath); } catch (Exception ex) { Logger.LogWarning(Message.RecognizerOcrLogDeletingError, ex); } } _ocr.EnableLogging(_config.Ocr.LoggingEnabled.Enabled ? OcrLogFilePath : null); Logger.LogVerbose(Message.RecognizerOCRRunRecognizeCall); _ocr.RunRecognize(_scannerManager.WorkBufferTop, _scannerManager.WorkBufferBottom, lineWidth, lineWidth, 0, 0); Logger.LogVerbose(Message.RecognizerOCRRunRecognizeReturn); }
public bool IsVotingModeValidForBlank(Blank blank, VotingMode votingMode) { if (votingMode == VotingMode.Test) return true; return blank.Sections .Select(electionNum => GetElectionByNum(electionNum)) .SelectMany(election => election.VotingModes) .Any(mode => mode == votingMode); }
public override void RestoreState(object state) { var arr = (object[]) state; SetSourceDataInternal( null, (SourceDataFileDescriptor) arr[SOURCE_DATA_FILE_DESCRIPTOR_STATEINDEX], (SourceDataChangesCache) arr[SOURCE_DATA_CHANGES_CACHE_STATEINDEX], (bool) arr[IS_SOURCE_DATA_CORRECT_STATEINDEX]); _currentVotingMode = (VotingMode) arr[CURRENT_VOTING_MODE_STATEINDEX]; }
protected override void ResetStateInternal() { SetSourceDataInternal(null, null, new SourceDataChangesCache(), false); _currentVotingMode = VotingMode.None; }
private void SetCurrentVotingMode(VotingMode newVotingMode) { var args = new VotingModeChangedEventArgs( _currentVotingMode, newVotingMode, _votingResultManager.VotingResults.VotesCount( new VoteKey { VotingMode = _currentVotingMode })); _currentVotingMode = newVotingMode; if (newVotingMode > VotingMode.Test) _votingResultManager.VotingResults.ClearTestData(); VotingModeChanged.RaiseEvent(this, args); }
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; }
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 bool IsVotingModeExpired(VotingMode mode) { for (var i = 0; i < VotingModeTimes.Length; ++i) { var mt = VotingModeTimes[i]; if (mt.mode == mode) { if (++i == VotingModeTimes.Length) return false; mt = VotingModeTimes[i]; } else if (mt.mode < mode) { continue; } var now = LocalTimeNow; return mt.hour * 60 + mt.minute <= now.Hour * 60 + now.Minute; } return false; }
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(); }
public bool IsVotingModeTime(VotingMode mode) { for (var i = 0; i < VotingModeTimes.Length; ++i) { var modeTime = VotingModeTimes[i]; if (modeTime.mode != mode) continue; var nextModeTime = ++i < VotingModeTimes.Length ? VotingModeTimes[i] : ModeTime.MaxValue; var now = LocalTimeNow; var nowTotalMinutes = now.Hour * 60 + now.Minute; return modeTime.TotalMinutes <= nowTotalMinutes && nowTotalMinutes < nextModeTime.TotalMinutes; } return false; }
public bool VotingModeExists(VotingMode eMode) { return Elections.Any(election => election.VotingModes.Any(votingMode => votingMode == eMode)); }
public static string GetModeNames(VotingMode[] modes) { var sb = new StringBuilder(); foreach (var mode in modes) { switch (mode) { case VotingMode.Main: sb.Append("Стационарный"); break; case VotingMode.Portable: sb.Append("Переносной"); break; default: sb.Append(mode); break; } sb.Append(", "); } if (sb.Length > 0) sb.Length -= 2; return sb.ToString(); }
public bool VotingModeExists(VotingMode eMode) { return(Elections.Any(election => election.VotingModes.Any(votingMode => votingMode == eMode))); }
public VotingModeChangedEventArgs(VotingMode oldMode, VotingMode newMode, int bulletinCount) { OldMode = oldMode; NewMode = newMode; BulletinCount = bulletinCount; }
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(); }