public async Task <IActionResult> Edit(int id, [Bind("Id,Name,StartDate,EndDate,DistrictId,CreateBy")] ElectionInfo electionInfo) { if (id != electionInfo.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(electionInfo); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ElectionInfoExists(electionInfo.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CreateBy"] = new SelectList(_context.Admin, "Id", "UserName", electionInfo.CreateBy); ViewData["DistrictId"] = new SelectList(_context.District, "Id", "Name", electionInfo.DistrictId); return(View(electionInfo)); }
void ReadTurbo(String url) { Int32 _threadId = Misc.TidFromURL(url); ThreadReader t = _forum.Reader(); Action <Action> invoker = a => a(); _count = new ElectionInfo(invoker, t, _db, _forum.ForumURL, url, _forum.PostsPerPage, false, Language.English, "3.8.7"); _count.CheckThread(() => { Console.WriteLine("{0} posts", _count.LastPost); Post p = _db.GetPost(_threadId, 1); ReadPost(p, "OP"); Console.WriteLine("{0} writes... {1}", p.Poster.Name, p.Title); var posts = _db.GetPosts(_threadId, p.Poster.Name); Console.WriteLine("{0} has {1} posts.", p.Poster.Name, posts.Count()); foreach (Post post in posts) { switch (post.Title) { case "Mod: Lynch result": { ReadPost(post, "Lynch"); } break; case "Mod: It is day!": { ReadPost(post, "Day"); } break; case "Mod: Game Over": { ReadPost(post, "End"); } break; case "Vote Count": { ReadPost(post, "VoteCount"); } break; default: { } break; } } }); }
public void UpdateSeats(ElectionInfo info) { int cnt = info.GetAllTickets(); this.Seats = new int[info.PartiesCount]; for (int i = 0; i < info.PartiesCount; i++) { this.Seats[i] = GetSeatCount(info.TicketCounter[i], ref cnt); } this.FixSeatCount(); #region old codes ////int allTickets = Politics.cPartyTickets + Politics.gPartyTickets + Politics.sPartyTickets + Politics.lPartyTickets + Politics.nPartyTickets; //int cnt = Politics.GetAllTicket(); //if (cnt != 0) { // Politics.cPartySeats = (ushort)(99 * Politics.cPartyTickets / cnt); // Politics.gPartySeats = (ushort)(99 * Politics.gPartyTickets / cnt); // Politics.sPartySeats = (ushort)(99 * Politics.sPartyTickets / cnt); // Politics.lPartySeats = (ushort)(99 * Politics.lPartyTickets / cnt); // Politics.nPartySeats = (ushort)(99 * Politics.nPartyTickets / cnt); //} else { // Politics.cPartySeats = 0; // Politics.gPartySeats = 0; // Politics.sPartySeats = 0; // Politics.lPartySeats = 0; // Politics.nPartySeats = 0; //} //Politics.cPartyTickets = 0; //Politics.gPartyTickets = 0; //Politics.sPartyTickets = 0; //Politics.lPartyTickets = 0; //Politics.nPartyTickets = 0; ////allTickets = Politics.cPartySeats + Politics.gPartySeats + Politics.sPartySeats + Politics.lPartySeats + Politics.nPartySeats; //cnt = Politics.GetAllSeatCount(); //if (cnt < 99) { // System.Random rand = new System.Random(); // switch (rand.Next(5)) { // case 0: // Politics.cPartySeats += (ushort)(99 - cnt); break; // case 1: // Politics.gPartySeats += (ushort)(99 - cnt); break; // case 2: // Politics.sPartySeats += (ushort)(99 - cnt); break; // case 3: // Politics.lPartySeats += (ushort)(99 - cnt); break; // case 4: // Politics.nPartySeats += (ushort)(99 - cnt); break; // } //} #endregion }
private void UnbindFromGame() { txtLastPost.DataBindings.Clear(); udStartPost.DataBindings.Clear(); txtEndPost.DataBindings.Clear(); dtEndTime.DataBindings.Clear(); dtStartTime.DataBindings.Clear(); if (_voteCount != null) { _voteCount.PropertyChanged -= _voteCount_PropertyChanged; _voteCount = null; } }
public async Task <IActionResult> Create([Bind("Id,Name,StartDate,EndDate,DistrictId,CreateBy")] ElectionInfo electionInfo) { if (ModelState.IsValid) { _context.Add(electionInfo); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CreateBy"] = new SelectList(_context.Admin, "Id", "UserName", electionInfo.CreateBy); ViewData["DistrictId"] = new SelectList(_context.District, "Id", "Name", electionInfo.DistrictId); return(View(electionInfo)); }
public void Setup() { String url = "forumserver.twoplustwo.com"; String vbVersion = "3.8.7"; String lobby = "59/puzzles-other-games/"; POG.Forum.Language _language = Language.English; Action <Action> invoker = (x) => x(); String dbPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\pog\"; System.IO.Directory.CreateDirectory(dbPath); String dbName = String.Format("{0}posts.{1}.sqlite", dbPath, url); PogSqlite _db = new PogSqlite(); _db.Connect(dbName); var _forum = new VBulletinForum(invoker, url, vbVersion, Language.English, lobby, "", ""); var reader = _forum.Reader(); _count = new ElectionInfo(invoker, reader, _db, _forum.ForumURL, url, _forum.PostsPerPage, true, _language, "3.8.7"); }
private void BindToNewGame(String url) { url = Utils.Misc.NormalizeUrl(url); ThreadReader t = _forum.Reader(); _voteCount = new ElectionInfo(_synchronousInvoker, t, _db, _forum.ForumURL, url, _forum.PostsPerPage, true, _language, _forum.VBVersion); _voteCount.PropertyChanged += new PropertyChangedEventHandler(_voteCount_PropertyChanged); _voteCount.Turbo = _turbo; _moderator = new Moderator(_synchronousInvoker, _voteCount, _forum); txtLastPost.DataBindings.Clear(); udStartPost.DataBindings.Clear(); txtEndPost.DataBindings.Clear(); dtEndTime.DataBindings.Clear(); dtStartTime.DataBindings.Clear(); txtLastPost.DataBindings.Add("Text", _voteCount, "LastPost", false, DataSourceUpdateMode.OnPropertyChanged); udStartPost.DataBindings.Add("Text", _voteCount, "StartPost", false, DataSourceUpdateMode.OnPropertyChanged); txtEndPost.DataBindings.Add("Text", _voteCount, "EndPost", false, DataSourceUpdateMode.OnPropertyChanged); _voteCount.ChangeDay(_day); _voteCount.Refresh(); EnableButtons(false); _voteCount.CheckThread(() => { EnableButtons(true); }); }
private ClusterDescription ProcessReplicaSetChange(ClusterDescription clusterDescription, ServerDescriptionChangedEventArgs args, List <IClusterableServer> newServers) { if (!args.NewServerDescription.Type.IsReplicaSetMember()) { return(RemoveServer(clusterDescription, args.NewServerDescription.EndPoint, string.Format("Server is a {0}, not a replica set member.", args.NewServerDescription.Type))); } if (args.NewServerDescription.Type == ServerType.ReplicaSetGhost) { return(clusterDescription.WithServerDescription(args.NewServerDescription)); } if (_replicaSetName == null) { _replicaSetName = args.NewServerDescription.ReplicaSetConfig.Name; } if (_replicaSetName != args.NewServerDescription.ReplicaSetConfig.Name) { return(RemoveServer(clusterDescription, args.NewServerDescription.EndPoint, string.Format("Server was a member of the '{0}' replica set, but should be '{1}'.", args.NewServerDescription.ReplicaSetConfig.Name, _replicaSetName))); } clusterDescription = clusterDescription.WithServerDescription(args.NewServerDescription); clusterDescription = EnsureServers(clusterDescription, args.NewServerDescription, newServers); if (args.NewServerDescription.CanonicalEndPoint != null && !EndPointHelper.Equals(args.NewServerDescription.CanonicalEndPoint, args.NewServerDescription.EndPoint)) { return(RemoveServer(clusterDescription, args.NewServerDescription.EndPoint, "CanonicalEndPoint is different than seed list EndPoint.")); } if (args.NewServerDescription.Type == ServerType.ReplicaSetPrimary) { if (args.NewServerDescription.ReplicaSetConfig.Version != null) { bool isCurrentPrimaryStale = true; if (_maxElectionInfo != null) { isCurrentPrimaryStale = _maxElectionInfo.IsStale(args.NewServerDescription.ReplicaSetConfig.Version.Value, args.NewServerDescription.ElectionId); var isReportedPrimaryStale = _maxElectionInfo.IsFresher( args.NewServerDescription.ReplicaSetConfig.Version.Value, args.NewServerDescription.ElectionId); if (isReportedPrimaryStale && args.NewServerDescription.ElectionId != null) { // we only invalidate the "newly" reported stale primary if electionId was used. lock (_serversLock) { var server = _servers.SingleOrDefault(x => EndPointHelper.Equals(args.NewServerDescription.EndPoint, x.EndPoint)); server.Invalidate(); _sdamInformationEventHandler?.Invoke(new SdamInformationEvent(() => string.Format( @"Invalidating server: Setting ServerType to ""Unknown"" for {0} because it " + @"claimed to be the replica set primary for replica set ""{1}"" but sent a " + @"(setVersion, electionId) tuple of ({2}, {3}) that was less than than the " + @"largest tuple seen, (maxSetVersion, maxElectionId), of ({4}, {5}).", args.NewServerDescription.EndPoint, args.NewServerDescription.ReplicaSetConfig.Name, args.NewServerDescription.ReplicaSetConfig.Version, args.NewServerDescription.ElectionId, _maxElectionInfo.SetVersion, _maxElectionInfo.ElectionId))); return(clusterDescription.WithServerDescription( new ServerDescription(server.ServerId, server.EndPoint))); } } } if (isCurrentPrimaryStale) { if (_maxElectionInfo == null) { _sdamInformationEventHandler?.Invoke(new SdamInformationEvent(() => string.Format( @"Initializing (maxSetVersion, maxElectionId): Saving tuple " + @"(setVersion, electionId) of ({0}, {1}) as (maxSetVersion, maxElectionId) for " + @"replica set ""{2}"" because replica set primary {3} sent ({0}, {1}), the first " + @"(setVersion, electionId) tuple ever seen for replica set ""{4}"".", args.NewServerDescription.ReplicaSetConfig.Version, args.NewServerDescription.ElectionId, args.NewServerDescription.ReplicaSetConfig.Name, args.NewServerDescription.EndPoint, args.NewServerDescription.ReplicaSetConfig.Name))); } else { if (_maxElectionInfo.SetVersion < args.NewServerDescription.ReplicaSetConfig.Version.Value) { _sdamInformationEventHandler?.Invoke(new SdamInformationEvent(() => string.Format( @"Updating stale setVersion: Updating the current " + @"(maxSetVersion, maxElectionId) tuple from ({0}, {1}) to ({2}, {3}) for " + @"replica set ""{4}"" because replica set primary {5} sent ({6}, {7})—a larger " + @"(setVersion, electionId) tuple then the saved tuple, ({0}, {1}).", _maxElectionInfo.SetVersion, _maxElectionInfo.ElectionId, args.NewServerDescription.ReplicaSetConfig.Version, args.NewServerDescription.ElectionId, args.NewServerDescription.ReplicaSetConfig.Name, args.NewServerDescription.EndPoint, args.NewServerDescription.ReplicaSetConfig.Version, args.NewServerDescription.ElectionId))); } else // current primary is stale & setVersion is not stale ⇒ the electionId must be stale { _sdamInformationEventHandler?.Invoke(new SdamInformationEvent(() => string.Format( @"Updating stale electionId: Updating the current " + @"(maxSetVersion, maxElectionId) tuple from ({0}, {1}) to ({2}, {3}) for " + @"replica set ""{4}"" because replica set primary {5} sent ({6}, {7})—" + @"a larger (setVersion, electionId) tuple than the saved tuple, ({0}, {1}).", _maxElectionInfo.SetVersion, _maxElectionInfo.ElectionId, args.NewServerDescription.ReplicaSetConfig.Version, args.NewServerDescription.ElectionId, args.NewServerDescription.ReplicaSetConfig.Name, args.NewServerDescription.EndPoint, args.NewServerDescription.ReplicaSetConfig.Version, args.NewServerDescription.ElectionId))); } } _maxElectionInfo = new ElectionInfo( args.NewServerDescription.ReplicaSetConfig.Version.Value, args.NewServerDescription.ElectionId); } } var currentPrimaryEndPoints = clusterDescription.Servers .Where(x => x.Type == ServerType.ReplicaSetPrimary) .Where(x => !EndPointHelper.Equals(x.EndPoint, args.NewServerDescription.EndPoint)) .Select(x => x.EndPoint) .ToList(); if (currentPrimaryEndPoints.Count > 0) { lock (_serversLock) { var currentPrimaries = _servers.Where(x => EndPointHelper.Contains(currentPrimaryEndPoints, x.EndPoint)); foreach (var currentPrimary in currentPrimaries) { // kick off the server to invalidate itself currentPrimary.Invalidate(); // set it to disconnected in the cluster clusterDescription = clusterDescription.WithServerDescription( new ServerDescription(currentPrimary.ServerId, currentPrimary.EndPoint)); } } } } return(clusterDescription); }
private ClusterDescription ProcessReplicaSetChange(ClusterDescription clusterDescription, ServerDescriptionChangedEventArgs args, List <IClusterableServer> newServers) { if (!args.NewServerDescription.Type.IsReplicaSetMember()) { return(RemoveServer(clusterDescription, args.NewServerDescription.EndPoint, string.Format("Server is a {0}, not a replica set member.", args.NewServerDescription.Type))); } if (args.NewServerDescription.Type == ServerType.ReplicaSetGhost) { return(clusterDescription.WithServerDescription(args.NewServerDescription)); } if (_replicaSetName == null) { _replicaSetName = args.NewServerDescription.ReplicaSetConfig.Name; } if (_replicaSetName != args.NewServerDescription.ReplicaSetConfig.Name) { return(RemoveServer(clusterDescription, args.NewServerDescription.EndPoint, string.Format("Server was a member of the '{0}' replica set, but should be '{1}'.", args.NewServerDescription.ReplicaSetConfig.Name, _replicaSetName))); } clusterDescription = clusterDescription.WithServerDescription(args.NewServerDescription); clusterDescription = EnsureServers(clusterDescription, args.NewServerDescription, newServers); if (args.NewServerDescription.CanonicalEndPoint != null && !EndPointHelper.Equals(args.NewServerDescription.CanonicalEndPoint, args.NewServerDescription.EndPoint)) { return(RemoveServer(clusterDescription, args.NewServerDescription.EndPoint, "CanonicalEndPoint is different than seed list EndPoint.")); } if (args.NewServerDescription.Type == ServerType.ReplicaSetPrimary) { if (args.NewServerDescription.ReplicaSetConfig.Version != null) { bool isCurrentPrimaryStale = true; if (_maxElectionInfo != null) { isCurrentPrimaryStale = _maxElectionInfo.IsStale(args.NewServerDescription.ReplicaSetConfig.Version.Value, args.NewServerDescription.ElectionId); var isReportedPrimaryStale = !isCurrentPrimaryStale; if (isReportedPrimaryStale && args.NewServerDescription.ElectionId != null) { // we only invalidate the "newly" reported stale primary if electionId was used. lock (_serversLock) { var server = _servers.SingleOrDefault(x => EndPointHelper.Equals(args.NewServerDescription.EndPoint, x.EndPoint)); server.Invalidate(); return(clusterDescription.WithServerDescription( new ServerDescription(server.ServerId, server.EndPoint))); } } } if (isCurrentPrimaryStale) { _maxElectionInfo = new ElectionInfo( args.NewServerDescription.ReplicaSetConfig.Version.Value, args.NewServerDescription.ElectionId); } } var currentPrimaryEndPoints = clusterDescription.Servers .Where(x => x.Type == ServerType.ReplicaSetPrimary) .Where(x => !EndPointHelper.Equals(x.EndPoint, args.NewServerDescription.EndPoint)) .Select(x => x.EndPoint) .ToList(); if (currentPrimaryEndPoints.Count > 0) { lock (_serversLock) { var currentPrimaries = _servers.Where(x => EndPointHelper.Contains(currentPrimaryEndPoints, x.EndPoint)); foreach (var currentPrimary in currentPrimaries) { // kick off the server to invalidate itself currentPrimary.Invalidate(); // set it to disconnected in the cluster clusterDescription = clusterDescription.WithServerDescription( new ServerDescription(currentPrimary.ServerId, currentPrimary.EndPoint)); } } } } return(clusterDescription); }
private ClusterDescription ProcessReplicaSetChange(ClusterDescription clusterDescription, ServerDescriptionChangedEventArgs args, List<IClusterableServer> newServers) { if (!args.NewServerDescription.Type.IsReplicaSetMember()) { return RemoveServer(clusterDescription, args.NewServerDescription.EndPoint, string.Format("Server is a {0}, not a replica set member.", args.NewServerDescription.Type)); } if (args.NewServerDescription.Type == ServerType.ReplicaSetGhost) { return clusterDescription.WithServerDescription(args.NewServerDescription); } if (_replicaSetName == null) { _replicaSetName = args.NewServerDescription.ReplicaSetConfig.Name; } if (_replicaSetName != args.NewServerDescription.ReplicaSetConfig.Name) { return RemoveServer(clusterDescription, args.NewServerDescription.EndPoint, string.Format("Server was a member of the '{0}' replica set, but should be '{1}'.", args.NewServerDescription.ReplicaSetConfig.Name, _replicaSetName)); } clusterDescription = clusterDescription.WithServerDescription(args.NewServerDescription); clusterDescription = EnsureServers(clusterDescription, args.NewServerDescription, newServers); if (args.NewServerDescription.CanonicalEndPoint != null && !EndPointHelper.Equals(args.NewServerDescription.CanonicalEndPoint, args.NewServerDescription.EndPoint)) { return RemoveServer(clusterDescription, args.NewServerDescription.EndPoint, "CanonicalEndPoint is different than seed list EndPoint."); } if (args.NewServerDescription.Type == ServerType.ReplicaSetPrimary) { if (args.NewServerDescription.ReplicaSetConfig.Version != null) { bool isCurrentPrimaryStale = true; if (_maxElectionInfo != null) { isCurrentPrimaryStale = _maxElectionInfo.IsStale(args.NewServerDescription.ReplicaSetConfig.Version.Value, args.NewServerDescription.ElectionId); var isReportedPrimaryStale = !isCurrentPrimaryStale; if (isReportedPrimaryStale && args.NewServerDescription.ElectionId != null) { // we only invalidate the "newly" reported stale primary if electionId was used. lock (_serversLock) { var server = _servers.SingleOrDefault(x => EndPointHelper.Equals(args.NewServerDescription.EndPoint, x.EndPoint)); server.Invalidate(); return clusterDescription.WithServerDescription( new ServerDescription(server.ServerId, server.EndPoint)); } } } if (isCurrentPrimaryStale) { _maxElectionInfo = new ElectionInfo( args.NewServerDescription.ReplicaSetConfig.Version.Value, args.NewServerDescription.ElectionId); } } var currentPrimaryEndPoints = clusterDescription.Servers .Where(x => x.Type == ServerType.ReplicaSetPrimary) .Where(x => !EndPointHelper.Equals(x.EndPoint, args.NewServerDescription.EndPoint)) .Select(x => x.EndPoint) .ToList(); if (currentPrimaryEndPoints.Count > 0) { lock (_serversLock) { var currentPrimaries = _servers.Where(x => EndPointHelper.Contains(currentPrimaryEndPoints, x.EndPoint)); foreach (var currentPrimary in currentPrimaries) { // kick off the server to invalidate itself currentPrimary.Invalidate(); // set it to disconnected in the cluster clusterDescription = clusterDescription.WithServerDescription( new ServerDescription(currentPrimary.ServerId, currentPrimary.EndPoint)); } } } } return clusterDescription; }
public static void NextElection() { CurrentElectionInfo = new ElectionInfo(Parties); }