public void GenerateGeneralStatistics(BackgroundWorker bgWkr, LogRecorderInterface log) { GenerateOnlinePlayerStats(log); DateTime date = DateTime.Now; try { string filePath = String.Format("{0}\\general_{1:yyyyMMdd}.html", AppSettings.Default.setStatisticsDir, date); if (File.Exists(filePath)) { return; } using (DamDataSet ds = new DamDataSet()) { bgWkr.ReportProgress(60, "Creating general statistics..."); dataAccess.GetGeneralStatisticsTable((DamDataSet.GeneralStatisticsTableDataTable)ds.GeneralStatisticsTable); bgWkr.ReportProgress(70, "Generating general reports..."); string[] colTitles = new string[] { "Description", "Result" }; string[] colNames = new string[] { "Description", "Result" }; string title = String.Format("General Statistics - {0}", date); DataRow[] rows = ds.GeneralStatisticsTable.Select(); SaveAsHTML(filePath, title, rows, colTitles, colNames, 0, rows.Length); File.Copy(filePath, AppSettings.Default.setStatisticsDir + "\\general.html", true); } } catch (Exception ex) { log.AddLog(String.Format("Error '{0}' when calculating general statistics", ex.Message)); } }
public BannedPlayers(AppServiceInterface appServices, DamDataSet dataSet) { this.appServices = appServices; this.dataSet = dataSet; InitializeComponent(); banListBindingSource.DataSource = dataSet; TimerFilterUpdate(null, null); dataGridView1_SelectionChanged(null, null); }
private void MakeIt(object sender, DoWorkEventArgs e) { DamDataSet ds = new DamDataSet(); using (DataAccess da = new DataAccess()) { da.GetGeneralStatisticsTable((DamDataSet.GeneralStatisticsTableDataTable)ds.GeneralStatisticsTable); ds.AcceptChanges(); } e.Result = ds.GeneralStatisticsTable; }
/// <summary> /// Generate player stats in a format similar to FLStat. /// </summary> /// <param name="bgWkr"></param> /// <param name="log"></param> public void GeneratePlayerStats(BackgroundWorker bgWkr, LogRecorderInterface log) { DateTime date = DateTime.Now; try { string filePath = String.Format("{0}\\players_{1:yyyyMMdd}.html", AppSettings.Default.setStatisticsDir, date); if (File.Exists(filePath)) { return; } using (DamDataSet ds = new DamDataSet()) { dataAccess.GetCharacterList(ds.CharacterList); bgWkr.ReportProgress(75, "Generating player reports..."); //DataRow[] rows = ds.CharacterList.Select("IsDeleted = 'false'"); using (UIDataSet uds = new UIDataSet()) { foreach (DamDataSet.CharacterListRow cr in ds.CharacterList) { if (!cr.IsDeleted) { uds.StatPlayer.AddStatPlayerRow(cr.CharName, new TimeSpan(0, 0, cr.OnLineSecs), cr.Money, cr.Rank, cr.LastOnLine, cr.OnLineSecs); } } string[] colTitles = new string[] { "Name", "Rank", "Money", "Last On Line", "On Line Time" }; string[] colNames = new string[] { "Name", "Rank", "Money", "LastOnLine", "OnLineTime" }; string title = String.Format("Players - {0}", date); SaveAsHTML(filePath, title, uds.StatPlayer.Select("", "Rank DESC"), colTitles, colNames, 0, 2500); File.Copy(filePath, AppSettings.Default.setStatisticsDir + "\\players.html", true); } } } catch (Exception ex) { log.AddLog(String.Format("Error '{0}' when calculating player statistics", ex.Message)); } }
public CreateBanWindow(AppServiceInterface appServices, string accDir, string accID, DamDataSet dataSet, DamDataSet.BanListRow banRecord) { this.appServices = appServices; this.accDir = accDir; this.accID = accID; this.dataSet = dataSet; this.banRecord = banRecord; InitializeComponent(); if (banRecord != null) { richTextBox1.Text = banRecord.BanReason; dateTimePickerStartDate.Value = banRecord.BanStart.ToUniversalTime(); numericUpDownDuration.Value = (decimal)(banRecord.BanEnd - banRecord.BanEnd).TotalDays; } else { dateTimePickerStartDate.Value = DateTime.Now; numericUpDownDuration.Value = 0; } }
public HashcodeWindow(DamDataSet dataStore, FLGameData gd) { InitializeComponent(); gameDataTableBindingSource.DataSource = dataStore; this.gd = gd; }
/// <summary> /// Commit pending changes on the CharacterList, BanList, IPList and LoginID /// </summary> /// <param name="dsTable"></param> public void CommitChanges(DamDataSet dsTable, LogRecorderInterface log) { BeginTransaction(); using (SQLiteDataAdapter adpt = new SQLiteDataAdapter("SELECT * FROM CharacterList", GetConnection())) { SQLiteCommandBuilder builder = new SQLiteCommandBuilder(adpt); builder.ConflictOption = ConflictOption.OverwriteChanges; try { adpt.Update(dsTable.CharacterList); } catch (Exception e) { log.AddLog(String.Format("Error '{0}' when updating db with {1} records", e.Message, dsTable.CharacterList.Count)); } } using (SQLiteDataAdapter adpt = new SQLiteDataAdapter("SELECT * FROM BanList", GetConnection())) { try { SQLiteCommandBuilder builder = new SQLiteCommandBuilder(adpt); builder.ConflictOption = ConflictOption.OverwriteChanges; adpt.Update(dsTable.BanList); } catch (Exception e) { log.AddLog("Update of database failed: " + e.Message); } } using (SQLiteDataAdapter adpt = new SQLiteDataAdapter("SELECT * FROM IPList", GetConnection())) { try { SQLiteCommandBuilder builder = new SQLiteCommandBuilder(adpt); builder.ConflictOption = ConflictOption.OverwriteChanges; adpt.Update(dsTable.IPList); } catch (Exception e) { log.AddLog("Update of database failed: " + e.Message); } } using (SQLiteDataAdapter adpt = new SQLiteDataAdapter("SELECT * FROM LoginIDList", GetConnection())) { try { SQLiteCommandBuilder builder = new SQLiteCommandBuilder(adpt); builder.ConflictOption = ConflictOption.OverwriteChanges; adpt.Update(dsTable.LoginIDList); } catch (Exception e) { log.AddLog("Update of database failed: " + e.Message); } } using (SQLiteDataAdapter adpt = new SQLiteDataAdapter("SELECT * FROM LoginIDBanList", GetConnection())) { try { SQLiteCommandBuilder builder = new SQLiteCommandBuilder(adpt); builder.ConflictOption = ConflictOption.OverwriteChanges; adpt.Update(dsTable.LoginIDBanList); } catch (Exception e) { log.AddLog("Update of database failed: " + e.Message); } } EndTransaction(); }
/// <summary> /// Scan the historical character lists and build a list containing the time each players /// was online within the specified time period. /// </summary> /// <returns>Returns the path to an HTML file cot </returns> private UIDataSet CalcActivity(DateTime startDate, DateTime endDate, BackgroundWorker bgWkr, LogRecorderInterface log) { UIDataSet results = new UIDataSet(); try { // Keep two tables; one containing the records when they are first detected and // the other with the most recent data. DamDataSet oldestData = new DamDataSet(); DamDataSet newestData = new DamDataSet(); Dictionary <string, int> onLineTimes = new Dictionary <string, int>(); // Scan from oldest date to newest reading character lists from the database // and building the online time list. for (DateTime date = startDate.Subtract(new TimeSpan(90, 0, 0, 0)); date <= endDate; date = date.AddDays(1)) { if (bgWkr.CancellationPending) { return(null); } using (DamDataSet tds = new DamDataSet()) { if (dataAccess.GetCharacterHistory(date, tds.CharacterList)) { foreach (DamDataSet.CharacterListRow tempCharRecord in tds.CharacterList) { if (bgWkr.CancellationPending) { return(null); } // Record the oldest data. Don't update if data is already present. DamDataSet.CharacterListRow oldCharRecord = oldestData.CharacterList.FindByCharPath(tempCharRecord.CharPath); if (oldCharRecord == null) { oldestData.CharacterList.AddCharacterListRow(tempCharRecord.CharName, tempCharRecord.CharPath, tempCharRecord.Created, tempCharRecord.Updated, tempCharRecord.AccID, tempCharRecord.IsDeleted, tempCharRecord.Location, tempCharRecord.Rank, tempCharRecord.Money, tempCharRecord.Ship, tempCharRecord.AccDir, tempCharRecord.OnLineSecs, tempCharRecord.LastOnLine); } // Keep updating to find the newest record from before the startDate else if (tempCharRecord.LastOnLine < startDate) { oldCharRecord.Created = tempCharRecord.Created; oldCharRecord.Updated = tempCharRecord.Updated; oldCharRecord.IsDeleted = tempCharRecord.IsDeleted; oldCharRecord.Location = tempCharRecord.Location; oldCharRecord.Rank = tempCharRecord.Rank; oldCharRecord.Money = tempCharRecord.Money; oldCharRecord.Ship = tempCharRecord.Ship; oldCharRecord.OnLineSecs = tempCharRecord.OnLineSecs; oldCharRecord.LastOnLine = tempCharRecord.LastOnLine; } } } } } newestData = oldestData.Copy() as DamDataSet; for (DateTime date = startDate; date <= endDate; date = date.AddDays(1)) { if (bgWkr.CancellationPending) { return(null); } using (DamDataSet tds = new DamDataSet()) { if (dataAccess.GetCharacterHistory(date, tds.CharacterList)) { foreach (DamDataSet.CharacterListRow tempCharRecord in tds.CharacterList) { if (bgWkr.CancellationPending) { return(null); } // Record the newest data. Keep updating with the most recent records. // Calculate the online seconds here to deal with the situation where // a character has been deleted then re-created. DamDataSet.CharacterListRow charRecord = newestData.CharacterList.FindByCharPath(tempCharRecord.CharPath); if (charRecord == null) { charRecord = newestData.CharacterList.AddCharacterListRow(tempCharRecord.CharName, tempCharRecord.CharPath, tempCharRecord.Created, tempCharRecord.Updated, tempCharRecord.AccID, tempCharRecord.IsDeleted, tempCharRecord.Location, tempCharRecord.Rank, tempCharRecord.Money, tempCharRecord.Ship, tempCharRecord.AccDir, tempCharRecord.OnLineSecs, tempCharRecord.LastOnLine); } else { int onLineTime = tempCharRecord.OnLineSecs - charRecord.OnLineSecs; if (onLineTime < 0) { onLineTime = 0; } if (onLineTimes.ContainsKey(charRecord.CharPath)) { onLineTimes[charRecord.CharPath] += onLineTime; } else { onLineTimes[charRecord.CharPath] = onLineTime; } charRecord.Created = tempCharRecord.Created; charRecord.Updated = tempCharRecord.Updated; charRecord.IsDeleted = tempCharRecord.IsDeleted; charRecord.Location = tempCharRecord.Location; charRecord.Rank = tempCharRecord.Rank; charRecord.Money = tempCharRecord.Money; charRecord.Ship = tempCharRecord.Ship; charRecord.OnLineSecs = tempCharRecord.OnLineSecs; charRecord.LastOnLine = tempCharRecord.LastOnLine; } } } } } // Build the results data set. This data set will be used to generate individual activity reports. foreach (DamDataSet.CharacterListRow newestCharRecord in newestData.CharacterList) { if (bgWkr.CancellationPending) { return(null); } DamDataSet.CharacterListRow oldestCharRecord = oldestData.CharacterList.FindByCharPath(newestCharRecord.CharPath); if (oldestCharRecord != null) { int rankDelta = newestCharRecord.Rank - oldestCharRecord.Rank; int moneyDelta = newestCharRecord.Money - oldestCharRecord.Money; int onLineSecsDelta = 0; if (onLineTimes.ContainsKey(oldestCharRecord.CharPath)) { onLineSecsDelta = onLineTimes[oldestCharRecord.CharPath]; } results.StatPlayer.AddStatPlayerRow(newestCharRecord.CharName, new TimeSpan(0, 0, onLineSecsDelta), moneyDelta, rankDelta, newestCharRecord.LastOnLine, onLineSecsDelta); } } } catch (Exception ex) { log.AddLog(String.Format("Error '{0}' when calculating activity statistics", ex.Message)); return(null); } return(results); }