void saveLog(Hunt h, string logPath) { StreamWriter streamWriter = new StreamWriter(logPath); // we load the data from the database instead of from the stored dictionary so it is ordered properly SQLiteCommand comm = new SQLiteCommand(String.Format("SELECT message FROM \"{0}\"", h.GetTableName()), lootConn); SQLiteDataReader reader = comm.ExecuteReader(); while (reader.Read()) { streamWriter.WriteLine(reader["message"].ToString()); } streamWriter.Flush(); streamWriter.Close(); }
public static void InsertMessage(Hunt hunt, int stamp, int hour, int minute, string message) { ExecuteNonQuery(String.Format("INSERT INTO \"{4}\" VALUES({0}, {1}, {2}, \"{3}\");", stamp, hour, minute, message.Replace("\"", "\\\""), hunt.GetTableName())); }
public void addKillToHunt(Hunt h, Tuple<Creature, List<Tuple<Item, int>>> resultList, string t, string message, int stamp = 0, int hour = 0, int minute = 0, SQLiteTransaction transaction = null) { Creature cr = resultList.Item1; if (!h.loot.creatureLoot.ContainsKey(cr)) h.loot.creatureLoot.Add(cr, new Dictionary<Item, int>()); foreach (Tuple<Item, int> tpl in resultList.Item2) { Item item = tpl.Item1; int count = tpl.Item2; if (!h.loot.creatureLoot[cr].ContainsKey(item)) h.loot.creatureLoot[cr].Add(item, count); else h.loot.creatureLoot[cr][item] += count; } if (!h.loot.killCount.ContainsKey(cr)) h.loot.killCount.Add(cr, 1); else h.loot.killCount[cr] += 1; if (!h.loot.logMessages.ContainsKey(t)) h.loot.logMessages.Add(t, new List<string>()); h.loot.logMessages[t].Add(message); if (transaction != null) { string query = String.Format("INSERT INTO \"{4}\" VALUES({0}, {1}, {2}, \"{3}\");", stamp, hour, minute, message.Replace("\"", "\\\""), h.GetTableName()); SQLiteCommand command = new SQLiteCommand(query, lootConn); command.ExecuteNonQuery(); } }
void deleteLogMessage(Hunt h, string logMessage) { string timeStamp = logMessage.Substring(0, 5); bool found = false; lock (hunts) { if (h.loot.logMessages.ContainsKey(timeStamp)) { if (h.loot.logMessages[timeStamp].Contains(logMessage)) { h.loot.logMessages[timeStamp].Remove(logMessage); var logMessageItems = ParseLootMessage(logMessage); Creature cr = logMessageItems.Item1; if (h.loot.killCount.ContainsKey(cr)) { h.loot.killCount[cr]--; if (h.loot.killCount[cr] == 0) { h.loot.killCount.Remove(cr); } } foreach (Tuple<Item, int> tpl in logMessageItems.Item2) { if (h.loot.creatureLoot[cr].ContainsKey(tpl.Item1)) { h.loot.creatureLoot[cr][tpl.Item1] -= tpl.Item2; if (h.loot.creatureLoot[cr][tpl.Item1] <= 0) { h.loot.creatureLoot[cr].Remove(tpl.Item1); } } } found = true; } } } if (!found) return; string huntTable = h.GetTableName(); SQLiteCommand comm = new SQLiteCommand(String.Format("SELECT day,hour,minute,message FROM \"{0}\" WHERE message=\"{1}\"", huntTable, logMessage.Replace("\"", "\\\"")), lootConn); SQLiteDataReader reader = comm.ExecuteReader(); if (reader.Read()) { comm = new SQLiteCommand(String.Format("DELETE FROM \"{0}\" WHERE day={1} AND hour={2} AND minute={3} AND message=\"{4}\"", huntTable, reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2), reader["message"].ToString()), lootConn); comm.ExecuteNonQuery(); } LootChanged(); }
public static void DeleteMessagesBefore(Hunt h, int stamp, int hour, int minute) { SQLiteCommand comm = new SQLiteCommand(String.Format("DELETE FROM \"{0}\" WHERE day < {1} OR hour < {2} OR (hour == {2} AND minute < {3})", h.GetTableName(), stamp, hour, minute), lootConn); comm.ExecuteNonQuery(); }
public static bool HuntTableExists(Hunt h) { SQLiteCommand command = new SQLiteCommand(String.Format("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='{0}';", h.GetTableName()), lootConn); int value = int.Parse(command.ExecuteScalar().ToString()); return value != 0; }
private void HuntList_AttemptNewItem(object sender, EventArgs e) { Hunt h = new Hunt(); lock (hunts) { SQLiteCommand command; if (!nameExists("New Hunt")) { h.name = "New Hunt"; } else { int index = 1; while (nameExists("New Hunt " + index)) index++; h.name = "New Hunt " + index; } h.dbtableid = 1; while (true) { command = new SQLiteCommand(String.Format("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='{0}';", h.GetTableName()), lootConn); int value = int.Parse(command.ExecuteScalar().ToString()); if (value == 0) { break; } h.dbtableid++; } } resetHunt(h); h.trackAllCreatures = true; h.trackedCreatures = ""; hunts.Add(h); refreshHunts(); }
public static void DeleteHuntTable(Hunt hunt) { SQLiteCommand comm = new SQLiteCommand(String.Format("DROP TABLE IF EXISTS \"{0}\";", hunt.GetTableName()), lootConn); comm.ExecuteNonQuery(); }
public static bool HuntTableExists(Hunt h) { int value = 0; object result = ExecuteScalar(String.Format("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='{0}';", h.GetTableName())); if (result != null && int.TryParse(result.ToString(), out value)) { return(value != 0); } return(false); }
public static void DeleteMessage(Hunt hunt, string msg, SQLiteTransaction transaction) { SQLiteCommand command = new SQLiteCommand(String.Format("DELETE FROM \"{0}\" WHERE message=\"{1}\"", hunt.GetTableName(), msg.Replace("\"", "\\\"")), lootConn, transaction); command.ExecuteNonQuery(); }
public static void InsertMessage(Hunt hunt, int stamp, int hour, int minute, string message) { SQLiteCommand command = new SQLiteCommand(String.Format("INSERT INTO \"{4}\" VALUES({0}, {1}, {2}, \"{3}\");", stamp, hour, minute, message.Replace("\"", "\\\""), hunt.GetTableName()), lootConn); command.ExecuteNonQuery(); }
public static SQLiteDataReader GetHuntMessages(Hunt hunt) { SQLiteCommand command = new SQLiteCommand(String.Format("SELECT message FROM \"{0}\" ORDER BY day, hour, minute;", hunt.GetTableName()), lootConn); return(command.ExecuteReader()); }
public static void DeleteHuntTable(Hunt hunt) { ExecuteNonQuery(String.Format("DROP TABLE IF EXISTS \"{0}\";", hunt.GetTableName())); ExecuteNonQuery(String.Format("DROP TABLE IF EXISTS \"{0}\";", hunt.GetWasteTableName())); }
void initializeHunts() { //"Name#DBTableID#Track#Time#Exp#SideHunt#AggregateHunt#ClearOnStartup#Creature#Creature#..." if (!SettingsManager.settingExists("Hunts")) { SettingsManager.setSetting("Hunts", new List<string>() { "New Hunt#True#0#0#False#True" }); } hunts.Clear(); int activeHuntIndex = 0, index = 0; List<int> dbTableIds = new List<int>(); foreach (string str in SettingsManager.getSetting("Hunts")) { SQLiteCommand command; SQLiteDataReader reader; Hunt hunt = new Hunt(); string[] splits = str.Split('#'); if (splits.Length >= 7) { hunt.name = splits[0]; if (!int.TryParse(splits[1].Trim(), out hunt.dbtableid)) continue; if (dbTableIds.Contains(hunt.dbtableid)) continue; dbTableIds.Add(hunt.dbtableid); hunt.totalTime = 0; hunt.trackAllCreatures = splits[2] == "True"; double.TryParse(splits[3], NumberStyles.Any, CultureInfo.InvariantCulture, out hunt.totalTime); long.TryParse(splits[4], out hunt.totalExp); hunt.sideHunt = splits[5] == "True"; hunt.aggregateHunt = splits[6] == "True"; hunt.clearOnStartup = splits[7] == "True"; hunt.temporary = false; string massiveString = ""; for (int i = 8; i < splits.Length; i++) { if (splits[i].Length > 0) { massiveString += splits[i] + "\n"; } } hunt.trackedCreatures = massiveString; // set this hunt to the active hunt if it is the active hunt if (SettingsManager.settingExists("ActiveHunt") && SettingsManager.getSettingString("ActiveHunt") == hunt.name) activeHuntIndex = index; refreshLootCreatures(hunt); if (hunt.clearOnStartup) { resetHunt(hunt); } // create the hunt table if it does not exist command = new SQLiteCommand(String.Format("CREATE TABLE IF NOT EXISTS \"{0}\"(day INTEGER, hour INTEGER, minute INTEGER, message STRING);", hunt.GetTableName()), lootConn); command.ExecuteNonQuery(); // load the data for the hunt from the database command = new SQLiteCommand(String.Format("SELECT message FROM \"{0}\" ORDER BY day, hour, minute;", hunt.GetTableName()), lootConn); reader = command.ExecuteReader(); while (reader.Read()) { string message = reader["message"].ToString(); Tuple<Creature, List<Tuple<Item, int>>> resultList = ParseLootMessage(message); if (resultList == null) continue; string t = message.Substring(0, 5); if (!hunt.loot.logMessages.ContainsKey(t)) hunt.loot.logMessages.Add(t, new List<string>()); hunt.loot.logMessages[t].Add(message); Creature cr = resultList.Item1; if (!hunt.loot.creatureLoot.ContainsKey(cr)) hunt.loot.creatureLoot.Add(cr, new Dictionary<Item, int>()); foreach (Tuple<Item, int> tpl in resultList.Item2) { Item item = tpl.Item1; int count = tpl.Item2; if (!hunt.loot.creatureLoot[cr].ContainsKey(item)) hunt.loot.creatureLoot[cr].Add(item, count); else hunt.loot.creatureLoot[cr][item] += count; } if (!hunt.loot.killCount.ContainsKey(cr)) hunt.loot.killCount.Add(cr, 1); else hunt.loot.killCount[cr] += 1; } hunts.Add(hunt); index++; } } if (hunts.Count == 0) { Hunt h = new Hunt(); h.name = "New Hunt"; h.dbtableid = 1; hunts.Add(h); resetHunt(h); } skip_hunt_refresh = true; huntList.Items.Clear(); foreach (Hunt h in hunts) { huntList.Items.Add(h.name); } activeHunt = hunts[activeHuntIndex]; skip_hunt_refresh = false; huntList.SelectedIndex = activeHuntIndex; huntList.ItemsChanged += HuntList_ItemsChanged; huntList.ChangeTextOnly = true; huntList.AttemptDeleteItem += HuntList_AttemptDeleteItem; huntList.AttemptNewItem += HuntList_AttemptNewItem; logMessageCollection.ReadOnly = true; logMessageCollection.TextAlign = HorizontalAlignment.Left; logMessageCollection.AttemptDeleteItem += LogMessageCollection_AttemptDeleteItem; }
public static void DeleteMessagesBefore(Hunt h, int stamp, int hour, int minute) { ExecuteNonQuery(String.Format("DELETE FROM \"{0}\" WHERE day < {1} OR hour < {2} OR (hour == {2} AND minute < {3})", h.GetTableName(), stamp, hour, minute)); }
public static void DeleteMessage(Hunt hunt, string msg, SQLiteTransaction transaction) { ExecuteNonQuery(String.Format("DELETE FROM \"{0}\" WHERE message=\"{1}\"", hunt.GetTableName(), msg.Replace("\"", "\\\""))); }
public static SQLiteDataReader GetHuntMessages(Hunt hunt) { SQLiteCommand command = new SQLiteCommand(String.Format("SELECT message FROM \"{0}\" ORDER BY day, hour, minute;", hunt.GetTableName()), lootConn); return command.ExecuteReader(); }
public static void CreateHuntTable(Hunt hunt) { ExecuteNonQuery(String.Format("CREATE TABLE IF NOT EXISTS \"{0}\"(day INTEGER, hour INTEGER, minute INTEGER, message STRING);", hunt.GetTableName())); }
void clearOldLog(Hunt h, int clearMinutes = 10) { var time = DateTime.Now; int hour = time.Hour; int minute = time.Minute; while (clearMinutes > 60) { hour--; clearMinutes -= 60; } if (minute >= clearMinutes) { minute -= clearMinutes; } else { hour--; minute = 60 + (minute - clearMinutes); } int stamp = getDayStamp(); while (hour < 0) { hour += 24; stamp--; } h.loot.creatureLoot.Clear(); h.loot.killCount.Clear(); h.loot.logMessages.Clear(); h.totalExp = 0; h.totalTime = 0; foreach (string t in getLatestTimes(clearMinutes)) { if (totalExperienceResults.ContainsKey(t)) { h.totalExp += totalExperienceResults[t]; h.totalTime += 60; } } SQLiteCommand comm = new SQLiteCommand(String.Format("DELETE FROM \"{0}\" WHERE day < {1} OR hour < {2} OR (hour == {2} AND minute < {3})", h.GetTableName(), stamp, hour, minute), lootConn); comm.ExecuteNonQuery(); comm = new SQLiteCommand(String.Format("SELECT message FROM \"{0}\"", h.GetTableName()), lootConn); SQLiteDataReader reader = comm.ExecuteReader(); Dictionary<string, List<string>> logMessages = new Dictionary<string, List<string>>(); while (reader.Read()) { string line = reader["message"].ToString(); if (line.Length < 15) continue; string t = line.Substring(0, 5); if (!(isDigit(t[0]) && isDigit(t[1]) && isDigit(t[3]) && isDigit(t[4]) && t[2] == ':')) continue; //not a valid timestamp if (!logMessages.ContainsKey(t)) logMessages.Add(t, new List<string>()); logMessages[t].Add(line); } ParseLootMessages(h, logMessages, null, false, false, true); LootChanged(); }
public static void DeleteHuntTable(Hunt hunt) { ExecuteNonQuery(String.Format("DROP TABLE IF EXISTS \"{0}\";", hunt.GetTableName())); }
void resetHunt(Hunt h) { lock (hunts) { h.loot.creatureLoot.Clear(); h.loot.killCount.Clear(); h.loot.logMessages.Clear(); h.totalExp = 0; h.totalTime = 0; } string huntTable = h.GetTableName(); SQLiteCommand comm = new SQLiteCommand(String.Format("DROP TABLE IF EXISTS \"{0}\";", huntTable), lootConn); comm.ExecuteNonQuery(); comm = new SQLiteCommand(String.Format("CREATE TABLE IF NOT EXISTS \"{0}\"(day INTEGER, hour INTEGER, minute INTEGER, message STRING);", huntTable), lootConn); comm.ExecuteNonQuery(); LootChanged(); }
public static SQLiteDataReader GetHuntMessages(Hunt hunt) { return(ExecuteReaderQuery(String.Format("SELECT message FROM \"{0}\" ORDER BY day, hour, minute;", hunt.GetTableName()))); }
public static bool HuntTableExists(Hunt h) { int value = 0; object result = ExecuteScalar(String.Format("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='{0}';", h.GetTableName())); if (result != null && int.TryParse(result.ToString(), out value)) { return value != 0; } return false; }
public static bool HuntTableExists(Hunt h) { lock (lootLock) { SQLiteCommand command = new SQLiteCommand(String.Format("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='{0}';", h.GetTableName()), lootConn); int value = int.Parse(command.ExecuteScalar().ToString()); return(value != 0); } }
public static void CreateHuntTable(Hunt hunt) { ExecuteNonQuery(String.Format("CREATE TABLE IF NOT EXISTS \"{0}\"(day INTEGER, hour INTEGER, minute INTEGER, message STRING);", hunt.GetTableName())); ExecuteNonQuery(String.Format("CREATE TABLE IF NOT EXISTS \"{0}\"(itemid INTEGER, amount INTEGER);", hunt.GetWasteTableName())); }
public static void CreateHuntTable(Hunt hunt) { SQLiteCommand command = new SQLiteCommand(String.Format("CREATE TABLE IF NOT EXISTS \"{0}\"(day INTEGER, hour INTEGER, minute INTEGER, message STRING);", hunt.GetTableName()), lootConn); command.ExecuteNonQuery(); }
public static SQLiteDataReader GetHuntMessages(Hunt hunt) { return ExecuteReaderQuery(String.Format("SELECT message FROM \"{0}\" ORDER BY day, hour, minute;", hunt.GetTableName())); }