Esempio n. 1
0
        public static Domain.Race InsertRaceMaybe(string raceName)
        {
            string location = new StackFrame().GetMethod().DeclaringType.ToString();

            _logger.OpenSection(location);

            string message = "Inserting new family '" + raceName + "'";

            _logger.Info("Asking user: '******'");

            Domain.Race returnRace = null;

            DialogResult dr = MessageBox.Show(message, "New family",
                                              MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (dr == DialogResult.Cancel)
            {
                _logger.Info("User cancelled; race will not be inserted.");
            }
            else
            {
                var insertedRace = new Domain.Race()
                {
                    Name = raceName,
                    Game = GlobalObjects.CurrentGame
                };
                _logger.Info("Inserting race...");
                _dbSession.Save(insertedRace);
                _logger.Info("Inserted race: " + insertedRace.ToString());
                returnRace = insertedRace;
            }

            _logger.CloseSection(location);
            return(returnRace);
        }
 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);
 }
Esempio n. 3
0
        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 JapaneseStudyForm(string databasePath)
        {
            _logger = GlobalObjects.Logger;

            _location = this.GetType().Name + "." + MethodBase.GetCurrentMethod().Name;
            _logger.OpenSection(_location);

            _logger.Info("Creating new DB connection");
            _dbConnection = new SQLiteConnection("Data Source = " + databasePath);
            _logger.Info("Connection created");

            InitializeComponent();
            LoadAllWords();
            UpdateLabelsOneTimeOnly();

            CreateRightClickMenus();

            _numberOfCurrentWords = Math.Min(_numberOfTotalWords, STARTING_NUMBER_OF_WORDS_LOADED);

            NextStep();
        }
        public FullDemonsListForm()
        {
            _logger = GlobalObjects.Logger;
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);
            _dbSession = GlobalObjects.DbSession;
            _logger.Info("Initializing component...");
            InitializeComponent();

            InitializeColumnsAndStuff();

            _logger.CloseSection(location);
        }
Esempio n. 6
0
        public ChooseGame()
        {
            _logger = GlobalObjects.Logger;
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);
            _dbSession = GlobalObjects.DbSession;
            _logger.Info("Initializing component...");
            InitializeComponent();

            exitWasChosen = false;

            PopulateGamesComboBox();
        }
Esempio n. 7
0
        public ChooseGameForm()
        {
            _logger = GlobalObjects.Logger;
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);
            _dbSession = GlobalObjects.DbSession;
            _logger.Info("Initializing component...");
            InitializeComponent();

            PopulateGamesComboBox();

            SetImpossibleToFuseRace();

            _logger.CloseSection(location);
        }
        private void JapaneseStudyForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            var eventLocation = this.GetType().Name + "." + MethodBase.GetCurrentMethod().Name;

            var dialogMessage = "Save before exiting?";

            if (_changesOccurred)
            {
                var result = MessageBox.Show(dialogMessage, "Save?", MessageBoxButtons.YesNoCancel);

                _logger.Info("Result is " + result);

                if (result == DialogResult.Cancel)
                {
                    e.Cancel = true;
                }
                else
                {
                    if (result == DialogResult.Yes)
                    {
                        using (var tx = _dbSession.BeginTransaction())
                        {
                            foreach (var oneWord in _wordsToStudy)
                            {
                                _dbSession.Save(oneWord);
                            }
                            tx.Commit();
                        }
                    }

                    _dbSession.Close();
                    _dbConnection.Close();

                    _logger.CloseSection(eventLocation);
                    _logger.CloseSection(_location);
                }
            }
            else
            {
                _dbSession.Close();
                _dbConnection.Close();

                _logger.CloseSection(eventLocation);
                _logger.CloseSection(_location);
            }
        }
Esempio n. 9
0
        public FusionsChartForm()
        {
            _logger = GlobalObjects.Logger;
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);
            _dbSession = GlobalObjects.DbSession;
            _logger.Info("Initializing component...");
            InitializeComponent();

            this.dgvFusions.AutoSizeRowsMode                     = DataGridViewAutoSizeRowsMode.None;
            this.dgvFusions.AllowUserToResizeRows                =
                this.dgvFusions.AllowUserToResizeColumns         =
                    this.dgvFusions.AllowUserToAddRows           =
                        this.dgvFusions.AllowUserToDeleteRows    =
                            this.dgvFusions.ColumnHeadersVisible = false;
            this.dgvFusions.RowTemplate.Height                   = 35;
            this.dgvFusions.RowTemplate.MinimumHeight            = 35;

            LoadData();

            _logger.CloseSection(location);
        }
Esempio n. 10
0
        public MainForm()
        {
            _logger = GlobalObjects.Logger;
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);
            _dbSession = GlobalObjects.DbSession;
            _logger.Info("Initializing component...");
            InitializeComponent();

            GlobalObjects.MainForm    = this;
            GlobalObjects.CurrentGame = null;

            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

            // ShowPartyDemonsForm();
            ShowFusionsChartForm();
            ShowFullDemonsListForm();
            ShowPartyFusionsForm();

            ShowChooseGameForm();

            _logger.CloseSection(location);
        }
Esempio n. 11
0
        public void LoadData()
        {
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);

            RemoveHandlers();

            var game = GlobalObjects.CurrentGame;

            this.dgvPartyFusions.Enabled = (game != null);
            if (game == null)
            {
                _logger.Info("No data to load; no game is chosen.");
                this.dgvPartyFusions.Rows.Clear();
            }
            else
            {
                _logger.Info("Game '" + game.Name + "' chosen; will load fusions for demons.");
                this.dgvPartyFusions.Rows.Clear();
                var demonsForFusions = GlobalObjects.CurrentGame.Races.SelectMany(x => x.Demons).
                                       Where(y => y.UseInFusionCalculatorBoolean).ToList();

                for (int i = 0; i < demonsForFusions.Count; i++)
                {
                    for (int j = i + 1; j < demonsForFusions.Count; j++)
                    {
                        if (j < demonsForFusions.Count)
                        {
                            _logger.Info("First demon for fusion: " + demonsForFusions[i].ToString());
                            _logger.Info("Second demon for fusion: " + demonsForFusions[j].ToString());

                            _logger.Info("Checking if this fusion was already calculated...");
                            var strSql =
                                " SELECT IdDemon3 FROM CalculatedFusions cf" +
                                " WHERE (cf.IdDemon1 = " + demonsForFusions[i].Id +
                                " AND cf.IdDemon2 = " + demonsForFusions[j].Id + ")" +
                                " OR (cf.IdDemon2 = " + demonsForFusions[i].Id +
                                " AND cf.IdDemon1 = " + demonsForFusions[j].Id + ")";
                            _logger.Info("Query: '" + strSql + "'");

                            var existingFusions = _dbSession.CreateSQLQuery(strSql)
                                                  .AddScalar("IdDemon3", NHibernateUtil.Int32).List();

                            FusionObject oneFusionObject;
                            if (existingFusions.Count > 0)
                            {
                                var DemonResult = _dbSession.Get <Domain.Demon>(Convert.ToInt32(existingFusions[0]));
                                oneFusionObject = new FusionObject
                                                      (demonsForFusions[i], demonsForFusions[j], DemonResult);
                            }
                            else
                            {
                                var oneFusion = _dbSession.CreateCriteria <Domain.Fusion>().List <Domain.Fusion>()
                                                .Where(x =>
                                                       (x.IdRace1 == demonsForFusions[i].Race.Id &&
                                                        x.IdRace2 == demonsForFusions[j].Race.Id) ||
                                                       (x.IdRace2 == demonsForFusions[i].Race.Id &&
                                                        x.IdRace1 == demonsForFusions[j].Race.Id))
                                                .SingleOrDefault();
                                oneFusionObject = new FusionObject
                                                      (demonsForFusions[i], demonsForFusions[j], oneFusion);

                                if (oneFusionObject.Demon3 != null)
                                {
                                    var strSqlUpdate =
                                        " INSERT INTO CalculatedFusions (IdDemon1, IdDemon2, IdDemon3)" +
                                        " VALUES (" + oneFusionObject.Demon1.Id + ", " + oneFusionObject.Demon2.Id + ", " +
                                        oneFusionObject.Demon3.Id + ")";
                                    _dbSession.CreateSQLQuery(strSqlUpdate).ExecuteUpdate();
                                }
                            }

                            this.dgvPartyFusions.Rows.Add(this.CreateRow(oneFusionObject));

                            var formattedRow = this.dgvPartyFusions.Rows[this.dgvPartyFusions.Rows.Count - 1];

                            ChangeCellColorsBasedOnParty(oneFusionObject.Demon1,
                                                         new DataGridViewCell[] {
                                formattedRow.Cells[(int)MyDataGridColumns.colLevel1],
                                formattedRow.Cells[(int)MyDataGridColumns.colRace1],
                                formattedRow.Cells[(int)MyDataGridColumns.colName1]
                            });

                            ChangeCellColorsBasedOnParty(oneFusionObject.Demon2,
                                                         new DataGridViewCell[] {
                                formattedRow.Cells[(int)MyDataGridColumns.colLevel2],
                                formattedRow.Cells[(int)MyDataGridColumns.colRace2],
                                formattedRow.Cells[(int)MyDataGridColumns.colName2]
                            });

                            ChangeCellColorsBasedOnParty(oneFusionObject.Demon3,
                                                         new DataGridViewCell[] {
                                formattedRow.Cells[(int)MyDataGridColumns.colLevel3],
                                formattedRow.Cells[(int)MyDataGridColumns.colRace3],
                                formattedRow.Cells[(int)MyDataGridColumns.colName3]
                            });
                        }
                    }
                }
                ReorderTable();
            }
            this.dgvPartyFusions.ClearSelection();
            _logger.Info("Adding complete.");
            AddHandlers();
            _logger.CloseSection(location);
        }
Esempio n. 12
0
        public void LoadData()
        {
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);

            RemoveHandlers();

            var game = GlobalObjects.CurrentGame;

            this.dgvDemons.Enabled = (game != null);
            if (game == null)
            {
                _logger.Info("No data to load; no game is chosen.");
                this.dgvDemons.Rows.Clear();
            }
            else
            {
                _logger.Info("Game '" + game.Name + "' chosen; will load list of demons for use in fusion calculator.");
                var allDemons =
                    GlobalObjects.CurrentGame.Races
                    .SelectMany(x => x.Demons)
                    .Where(y => y.UseInFusionCalculator > 0)
                    .OrderBy(y => y.Level).ThenBy(z => z.Race.Id)
                    .ToList();
                _maxDemonId = allDemons.Select(x => x.Id).Max().GetValueOrDefault();
                foreach (Domain.Demon d in allDemons)
                {
                    _logger.Info("Loaded this demon: " + d.ToString());
                    this.dgvDemons.Rows.Add(CreateRow(d));
                }
                _logger.Info("Data load complete. Adding event handlers...");
                AddHandlers();
                SetDataGridViewReadOnlyPropertyAndColors();
                _logger.Info("Adding complete.");
            }

            _logger.CloseSection(location);
        }
Esempio n. 13
0
        public void LoadData()
        {
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);

            RemoveHandlers();

            var game = GlobalObjects.CurrentGame;

            this.dgvFusions.Enabled = (game != null);
            if (game == null)
            {
                _logger.Info("No data to load; no game is chosen.");
                this.dgvFusions.Rows.Clear();
            }
            else
            {
                _logger.Info("Game '" + game.Name + "' chosen; will load list of fusions.");

                var currentGameRaces   = game.Races.ToList();
                var currentGameRaceIds = currentGameRaces.Select(x => x.Id).ToList();
                var allFusions         =
                    _dbSession.CreateCriteria <Domain.Fusion>().List <Domain.Fusion>()
                    .Where(x => currentGameRaceIds.Contains(x.IdRace1))
                    .OrderBy(y => y.IdRace1)
                    .ThenBy(z => z.IdRace2).ToList();

                AddOneColumn(null);
                foreach (var oneRace in currentGameRaces)
                {
                    AddOneColumn(oneRace);
                }

                // first row
                object[] oneRow = new object[currentGameRaces.Count + 1];
                oneRow[0] = " ";
                for (int i = 0; i < currentGameRaces.Count; i++)
                {
                    oneRow[i + 1] = currentGameRaces[i].Name;
                }

                // race tag on every cell of the first row except the first one
                this.dgvFusions.Rows.Add(oneRow);
                for (int i = 0; i < currentGameRaces.Count; i++)
                {
                    this.dgvFusions.Rows[0].Cells[i + 1].Tag = currentGameRaces[i];
                }

                // following rows
                DataGridViewRow oneDgvr;
                foreach (var oneRace in currentGameRaces)
                {
                    oneDgvr = new DataGridViewRow();
                    oneDgvr.Cells.Add(new DataGridViewTextBoxCell()
                    {
                        Value = oneRace.Name,
                        Tag   = oneRace
                    });
                    foreach (var anotherRace in currentGameRaces)
                    {
                        int?idRaceResult =
                            allFusions.Where(x =>
                                             x.IdRace1 == oneRace.Id &&
                                             x.IdRace2 == anotherRace.Id)
                            .Select(y => y.IdRace3).FirstOrDefault();
                        if (idRaceResult == null)
                        {
                            idRaceResult =
                                allFusions.Where(x =>
                                                 x.IdRace2 == oneRace.Id &&
                                                 x.IdRace1 == anotherRace.Id)
                                .Select(y => y.IdRace3).FirstOrDefault();
                        }
                        Domain.Race raceResult =
                            (idRaceResult == null ? null :
                             _dbSession.Get <Domain.Race>(idRaceResult.GetValueOrDefault()));

                        oneDgvr.Cells.Add(new DataGridViewTextBoxCell()
                        {
                            Value = (raceResult == null ? null : raceResult.Name),
                            Tag   = raceResult
                        });
                    }
                    this.dgvFusions.Rows.Add(oneDgvr);
                }

                foreach (DataGridViewCell oneCell in this.dgvFusions.Rows[0].Cells)
                {
                    oneCell.ReadOnly = true;
                    oneCell.Style    = GlobalObjects.GetDefaultDgvcStyle(FONT_SIZE, false);
                }

                foreach (DataGridViewRow aRow in this.dgvFusions.Rows)
                {
                    aRow.Cells[0].ReadOnly = true;
                    aRow.Cells[0].Style    = GlobalObjects.GetDefaultDgvcStyle(FONT_SIZE, false);
                }

                AddHandlers();
                _logger.Info("Adding complete.");

                SetFormats();
            }
            _logger.CloseSection(location);
        }
Esempio n. 14
0
        public void ChooseGame(Domain.Game game)
        {
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);
            _logger.Info("Called with game = " + (game == null ? "(null)" : game.Name));

            if (game == GlobalObjects.CurrentGame)
            {
                _logger.Info("Game is same as current game, nothing to do.");
            }
            else
            {
                GlobalObjects.CurrentGame = game;

                string text = FORM_NAME + (game == null ? "" : " - " + game.Name);
                _logger.Info("Setting form text to '" + text + "'");
                this.Text = text;

                if (_fullDemonsListForm != null)
                {
                    _fullDemonsListForm.LoadData();
                }
                if (_partyDemonsListForm != null)
                {
                    _partyDemonsListForm.LoadData();
                }
                if (_fusionsForm != null)
                {
                    _fusionsForm.LoadData();
                }
                if (_partyFusionsVerticalForm != null)
                {
                    _partyFusionsVerticalForm.LoadData();
                }
            }

            _logger.CloseSection(location);
        }
Esempio n. 15
0
        private void dgvDemons_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            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.dgvDemons.Rows[e.RowIndex];

            int numberOfNonNullColumns =
                (currentRow.Cells[DGV_DEMON_COL_LEVEL].Value == null ? 0 : 1) +
                (currentRow.Cells[DGV_DEMON_COL_RACE].Value == null ? 0 : 1) +
                (currentRow.Cells[DGV_DEMON_COL_NAME].Value == null ? 0 : 1);

            var oldValue = currentRow.Cells[e.ColumnIndex].Value;

            if (oldValue != null)
            {
                oldValue = oldValue.ToString();
            }
            var newValue = e.FormattedValue;

            if (newValue != null)
            {
                newValue = newValue.ToString();
            }
            _logger.Info("oldValue = " + (oldValue == null ? "(null)" : "'" + oldValue.ToString() + "'"));
            _logger.Info("newValue = " + (newValue == null ? "(null)" : "'" + newValue.ToString() + "'"));

            _logger.Info("numberOfNonNullColumns = " + numberOfNonNullColumns);

            _cellDemonChanged = (numberOfNonNullColumns >= 2 && oldValue != newValue);

            _logger.Info("Cell changed set to " + _cellDemonChanged);
            _logger.CloseSection(location);
        }
Esempio n. 16
0
        public void LoadData()
        {
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);

            RemoveHandlers();

            var game = GlobalObjects.CurrentGame;

            this.dgvDemons.Enabled = (game != null);
            if (game == null)
            {
                _logger.Info("No data to load; no game is chosen.");
                this.dgvDemons.Rows.Clear();
            }
            else
            {
                _logger.Info("Game '" + game.Name + "' chosen; will load list of demons.");
                var allDemons = GlobalObjects.CurrentGame.Races.SelectMany(x => x.Demons).
                                OrderBy(y => y.Level).ThenBy(z => z.Race.Id).ToList();
                foreach (Domain.Demon d in allDemons)
                {
                    _logger.Info("Loaded this demon: " + d.ToString());
                    this.dgvDemons.Rows.Add(CreateRow(d));
                }
                _logger.Info("Data load complete. Adding event handlers...");
                AddHandlers();
                _logger.Info("Adding complete.");
            }
            _logger.CloseSection(location);
        }