void AddConfirmedPoster(String name) { foreach (CensusEntry e in _voteCount.Census) { if (e.Name == name) { return; } } CensusEntry ce = new CensusEntry(); ce.Name = name; ce.Alive = "Alive"; _voteCount.Census.Add(ce); }
/* * void Start() { * s += SymAgent.Censimento('\t')+"\r\n"; * * } * * string s = ""; * float last = 0; * public float step = 1; * void Update() { * if (Time.time-last>=step) { //Non tiene conto della velocità del mondo; basta che lo sappiamo noi fissando lo step. * s += SymAgent.Censimento('\t')+"\r\n"; * } * } * * void OnDestroy() { * System.IO.File.WriteAllText("Censimento.txt", s); * }*/ public Dictionary <string, CensusEntry> Census() { Dictionary <string, CensusEntry> returner = new Dictionary <string, CensusEntry>(); foreach (KeyValuePair <string, List <SymAgent> > kvp in SymAgent.All) { CensusEntry entry = new CensusEntry(kvp.Key, 0, 0); returner[kvp.Key] = entry; foreach (SymAgent a in kvp.Value) { if (a.IsAdult()) { entry.adults++; } else { entry.infants++; } } } return(returner); }
public void Setup(CensusEntry census) { all.sizeDelta = new Vector2(all.sizeDelta.x, isto.unit * (census.adults + census.infants)); infants.sizeDelta = new Vector2(all.sizeDelta.x, isto.unit * census.infants); }
public void WriteRoster(Int32 threadId, IEnumerable <CensusEntry> census) { Dictionary <String, List <CensusEntry> > roleList = new Dictionary <String, List <CensusEntry> >(); HashSet <String> subOut = new HashSet <string>(); HashSet <String> subIn = new HashSet <string>(); HashSet <String> all = new HashSet <string>(); foreach (CensusEntry ce in census) { if ((ce.Name == null) || (ce.Name == String.Empty)) { continue; } if (!roleList.ContainsKey(ce.Name)) { all.Add(ce.Name); roleList.Add(ce.Name, new List <CensusEntry> { ce }); if ((ce.Replacement != null) && (ce.Replacement != String.Empty)) { subOut.Add(ce.Name); subIn.Add(ce.Replacement); } } } HashSet <String> originals = new HashSet <string>(all.Except(subIn)); // merge subs foreach (String original in originals) { String current = roleList[original][0].Replacement; while ((current != String.Empty) && (current != null)) { if (!roleList.ContainsKey(current)) { break; } roleList[original].AddRange(roleList[current]); String next = roleList[current].Last().Replacement; roleList.Remove(current); current = next; } } Stopwatch watch = new Stopwatch(); watch.Start(); using (SqliteConnection dbWrite = new SqliteConnection(_connect)) { dbWrite.Open(); using (SqliteTransaction trans = dbWrite.BeginTransaction()) { String sqlDelete = @"DELETE FROM GameRole where (threadid = @p1);"; using (SqliteCommand cmd = new SqliteCommand(sqlDelete, dbWrite, trans)) { cmd.Parameters.Add(new SqliteParameter("@p1", threadId)); int e = cmd.ExecuteNonQuery(); } String sql = @"INSERT INTO GameRole ( threadid, deathtime) VALUES (@p1, @p2); SELECT last_insert_rowid();"; using (SqliteCommand cmd = new SqliteCommand(sql, dbWrite, trans)) { SqliteParameter pThreadId = new SqliteParameter("@p1"); cmd.Parameters.Add(pThreadId); pThreadId.Value = threadId; foreach (List <CensusEntry> role in roleList.Values) { Int32 id = -1; DateTime? deathTime = null; CensusEntry lastPlayer = role.Last(); if (lastPlayer.Alive == "Dead") { deathTime = lastPlayer.EndPostTime; } SqliteParameter pDeath = new SqliteParameter("@p2", System.Data.DbType.DateTime); pDeath.Value = deathTime; cmd.Parameters.Add(pDeath); using (SqliteDataReader r = cmd.ExecuteReader()) { if (r.Read()) { id = r.GetInt32(0); } } if (id == -1) { continue; } string sqlPlayer = @"INSERT INTO Player (roleid, posterid, starttime, endtime) VALUES(@p1, @p2, @p3, @p4);"; using (SqliteCommand cmdPlayer = new SqliteCommand(sqlPlayer, dbWrite, trans)) { SqliteParameter pRoleId = new SqliteParameter("@p1"); pRoleId.Value = id; DateTime?startTime = null; foreach (CensusEntry player in role) { SqliteParameter pPosterId = new SqliteParameter("@p2"); Int32 playerId = GetPlayerId(player.Name); if (playerId < 0) { break; } pPosterId.Value = playerId; cmdPlayer.Parameters.Add(pRoleId); cmdPlayer.Parameters.Add(pPosterId); SqliteParameter pStartTime = new SqliteParameter("@p3", System.Data.DbType.DateTime); pStartTime.Value = startTime; cmdPlayer.Parameters.Add(pStartTime); SqliteParameter pEndTime = new SqliteParameter("@p4", System.Data.DbType.DateTime); if (player.Alive != "Alive") { DateTime?endTime = null; if (player.EndPostTime != null) { endTime = player.EndPostTime.Value.ToUniversalTime(); } pEndTime.Value = endTime; startTime = endTime; } cmdPlayer.Parameters.Add(pEndTime); int e = cmdPlayer.ExecuteNonQuery(); } } } } trans.Commit(); } } watch.Stop(); //Trace.TraceInformation("after ReplacePlayerList {0}", watch.Elapsed.ToString()); }
public IEnumerable <CensusEntry> ReadRoster(Int32 threadId) { SortableBindingList <CensusEntry> census = new SortableBindingList <CensusEntry>(); String sql = @" SELECT Player.roleid, GameRole.deathtime, Player.posterid, Player.endtime, Poster.postername FROM GameRole, Player, Poster WHERE (GameRole.threadid = @p1) AND (Player.roleid = GameRole.roleid) AND (Player.posterid = Poster.posterid) ORDER BY GameRole.roleid ASC, (CASE WHEN Player.endtime IS NULL THEN 0 ELSE 1 END), Player.endtime ASC ; "; Stopwatch watch = new Stopwatch(); watch.Start(); using (SqliteConnection dbRead = new SqliteConnection(_connect)) { dbRead.Open(); using (SqliteCommand cmd = new SqliteCommand(sql, dbRead)) { cmd.Parameters.Add(new SqliteParameter("@p1", threadId)); using (SqliteDataReader r = cmd.ExecuteReader()) { Int32 currentRole = -1; String newestName = String.Empty; while (r.Read()) { CensusEntry ce = new CensusEntry(); Int32 role = r.GetInt32(0); if (currentRole == role) { ce.Alive = "Sub Out"; ce.Replacement = newestName; } else { currentRole = role; if (!r.IsDBNull(1)) { ce.EndPostTime = r.GetDateTime(1); ce.Alive = "Dead"; } } Int32 playerId = r.GetInt32(2); if (!r.IsDBNull(3)) { ce.EndPostTime = r.GetDateTime(3); } ce.Name = r.GetString(4); newestName = ce.Name; census.Add(ce); } } } } watch.Stop(); //Trace.TraceInformation("After ReadRoster {0}", watch.Elapsed.ToString()); return(census); }