private void UpdateDemonFusionsGrid() { try { this.dgvFusions.Rows.Clear(); foreach (Domain.FusionDemon oneFusion in GlobalObjects.CurrentGame.FusionDemons) { var demonFusionRow = new Object[12]; demonFusionRow[DGV_DEMONFUSION_COL_ID] = oneFusion.Id; demonFusionRow[DGV_DEMONFUSION_COL_LEVEL1] = oneFusion.Demon1.Level; demonFusionRow[DGV_DEMONFUSION_COL_RACE1] = oneFusion.Demon1.Race.Name; demonFusionRow[DGV_DEMONFUSION_COL_NAME1] = oneFusion.Demon1.Name; demonFusionRow[DGV_DEMONFUSION_COL_LEVEL2] = oneFusion.Demon2.Level; demonFusionRow[DGV_DEMONFUSION_COL_RACE2] = oneFusion.Demon2.Race.Name; demonFusionRow[DGV_DEMONFUSION_COL_NAME2] = oneFusion.Demon2.Name; demonFusionRow[DGV_DEMONFUSION_COL_LEVEL3] = oneFusion.Demon3 != null?oneFusion.Demon3.Level.ToString() : oneFusion.Level3 != null?oneFusion.Level3.ToString() + "+" : ""; demonFusionRow[DGV_DEMONFUSION_COL_RACE3] = oneFusion.Demon3 != null?oneFusion.Demon3.Race.Name.ToString() : oneFusion.Race3 != null ? oneFusion.Race3.Name : ""; demonFusionRow[DGV_DEMONFUSION_COL_NAME3] = oneFusion.Demon3 != null ? oneFusion.Demon3.Name : oneFusion.Race3 != null ? "?" : ""; var rowIndex = this.dgvFusions.Rows.Add(demonFusionRow); if (!oneFusion.Demon1.IsFused || !oneFusion.Demon2.IsFused) { this.dgvFusions.Rows[rowIndex].Visible = false; } UpdateFusionRowDisplay(this.dgvFusions.Rows[rowIndex], oneFusion.Demon1, oneFusion.Demon2, oneFusion.Demon3); } if (this.dgvFusions.Rows.Count > 0) { this.dgvFusions.Sort(this.dgvFusions_Level1, ListSortDirection.Ascending); this.dgvFusions.Sort(this.dgvFusions_Level3, ListSortDirection.Ascending); } } catch (Exception ex) { MessageBox.Show(_logger.Error(ex)); } }
private void AttemptToLogAllTypes(FeatherLogger logger) { logger.Error(TEST_ERROR_STRING); logger.Warn(TEST_WARN_STRING); logger.Sql(TEST_SQL_STRING); logger.Info(TEST_INFO_STRING); logger.Extreme(TEST_EXTREME_STRING); }
private static FeatherLogger CreateFeatherLogger() { try { string location = new StackFrame().GetMethod().DeclaringType.ToString(); var returnLogger = new FeatherLogger( //FeatherLogger.TRACE_LEVEL_INFO, FeatherLogger.TRACE_LEVEL_ERROR, @"D:\Logger\Yatagarasu", "Yatagarasu", true, "xml"); return(returnLogger); } catch (Exception ex) { _logger.Error(ex); throw; } }
public bool ImportFile(string databasePath, string filePath) { string location = this.GetType().Name + "." + MethodBase.GetCurrentMethod().Name; _logger.OpenSection(location); var allText = File.ReadAllText(filePath); try { using (var dbConnection = new SQLiteConnection("Data Source = " + databasePath)) { dbConnection.Open(); using (var dbSession = NHibernateHelper.GetCustomSession(dbConnection)) { var allLines = allText.Replace("\r\n", "\r").Split('\r'); ParseAllLines(allLines); using (var transaction = dbSession.BeginTransaction()) { foreach (var oneSource in SourcesToInsert) { _logger.Info("Saving source in database '" + oneSource.Text + "'..."); dbSession.Save(oneSource); _logger.Info("Saved."); } transaction.Commit(); } dbSession.Close(); } dbConnection.Close(); } } catch (Exception ex) { _logger.Error(ex); _logger.CloseSection(location); return(false); } _logger.CloseSection(location); return(true); }
public void GivenAFeatherLogger_IfLogModeIsLogDump_ThenFileIsCreatedOnlyAfterDump() { var logger = new FeatherLogger( logMode: FeatherLoggerLogMode.LogDump, traceLevel: FeatherLoggerTraceLevel.Error, folderName: null, filename: "log", hasTimestampInFilename: false, extension: _loggerFileExtension); logger.Error("123456"); Assert.IsFalse(File.Exists(_testFolder + @"\log." + _loggerFileExtension), "File shouldn't exist before dump"); logger.FinishLogging(); Assert.IsTrue(File.Exists(_testFolder + @"\log." + _loggerFileExtension), "File should exist after dump"); var loggedText = File.ReadAllText(_testFolder + @"\log." + _loggerFileExtension); Assert.IsTrue(loggedText.Contains("123456")); }
private void NextStep() { UpdateEveryStepLabels(); CurrentStep = DetermineNextStep(); switch (CurrentStep) { case Step.Question: CurrentWord = GetOneWord(CurrentWord); DisplayOneQuestionWord(CurrentWord); break; case Step.Answer: DisplayOneAnswerWord(CurrentWord); break; default: var ex = new Exception("Invalid step '" + CurrentStep + "'. Aborting all the things"); _logger.Error(ex); throw ex; } }
private void btnNewGame_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(this.tbGameName.Text)) { MessageBox.Show("Please enter a game name."); } else { var gameName = this.tbGameName.Text; var gameAlreadyExists = _dbSession.CreateCriteria <Domain.Game>().List <Domain.Game>() .Where(x => x.Name == gameName).ToList().Count > 0; if (gameAlreadyExists) { MessageBox.Show("This game already exists."); } else { try { using (var transaction = _dbSession.BeginTransaction()) { chosenGame = new Domain.Game(gameName); _dbSession.Save(chosenGame); transaction.Commit(); } MessageBox.Show("Game '" + chosenGame.Name + "' created.");; this.Hide(); } catch (Exception ex) { _logger.Error(ex); throw; } } } }
private void dgvPartyFusions_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (_cellChanged) { string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name; _logger.OpenSection(location); _logger.Info("Called with row index " + e.RowIndex + ", column index = " + e.ColumnIndex); var currentRow = this.dgvPartyFusions.Rows[e.RowIndex]; Domain.Demon rowDemon = null; Domain.Demon databaseDemon = null; bool insertedNewDemon = false; // THIS CODE IS COPIED FROM THE DEMONS LIST FORM // FIXME: REFACTOR / DO SOMETHING BETTER using (var transaction = _dbSession.BeginTransaction()) { rowDemon = GetDemonFromDataGridViewRow(currentRow, true); if (rowDemon != null) { databaseDemon = rowDemon; bool insertDemon = true; bool insertFusion = true; if (rowDemon.Id == null) { // ID is null but maybe the demon is already in the DB. Look in the database _logger.Info("Looking in database if this demon already exists..."); databaseDemon = _dbSession.CreateCriteria <Domain.Race>().List <Domain.Race>(). SelectMany(x => x.Demons).Where(y => y.Name == rowDemon.Name).FirstOrDefault(); if (databaseDemon != null) { _logger.Info("Found demon ID " + databaseDemon.Id + "."); if (databaseDemon.Equals(rowDemon)) { _logger.Info("Demons are exactly the same; no need to update DB."); } } else { insertDemon = true; databaseDemon = rowDemon; } } if (insertDemon) { _logger.Info("Inserting new demon..."); // TODO: UPDATING _logger.Info("Row demon is " + rowDemon.ToString() + ". " + (databaseDemon.Id == null ? "Inserting..." : "Updating...")); if (databaseDemon.Id == null) { _dbSession.Save(databaseDemon); // insert insertedNewDemon = true; } _logger.Info("Demon saved (for now; need to commit)."); } if (insertFusion) { _logger.Info("Inserting new fusion..."); Domain.Fusion f = new Domain.Fusion( (Domain.Race)currentRow.Cells[(int)MyDataGridColumns.colRaceObject1].Value, (Domain.Race)currentRow.Cells[(int)MyDataGridColumns.colRaceObject2].Value, databaseDemon.Race); _dbSession.Save(f); _logger.Info("Fusion saved (for now; need to commit)."); } if (insertDemon || insertFusion) { try { _logger.Info("Committing..."); transaction.Commit(); _logger.Info("Transaction complete."); LoadData(); } catch (Exception ex) { _logger.Error(ex); MessageBox.Show("ERROR: " + ex.Message + ex.InnerException == null ? "" : "\r\n" + ex.InnerException.Message); } } } } // using (var transaction = _dbSession.BeginTransaction()) var numberOfDemonsForFusions = _dbSession.CreateCriteria <Domain.Race>().List <Domain.Race>(). SelectMany(x => x.Demons).Where(y => y.UseInFusionCalculatorBoolean).ToList(); if (numberOfDemonsForFusions.Count == 2) { GlobalObjects.MainForm.ForceUpdateFusions(); } if (insertedNewDemon) { RemoveHandlers(); currentRow.Cells[(int)MyDataGridColumns.colId3].Value = databaseDemon.Id; AddHandlers(); } // END OF COPIED CODE // FIXME: REFACTOR / DO SOMETHING BETTER _logger.CloseSection(location); } }