예제 #1
0
 private void Initialize()
 {
     string[] files = Directory.GetFiles(Executor.BookPath, "*.json");
     foreach (string file in files)
     {
         Line line = SerializeHelpers.Deserialize <Line>(File.ReadAllText(file));
         if (line != null)
         {
             this._lines.Add(line);
         }
     }
 }
예제 #2
0
        public Task <bool> AddLine(double amount, DateTime dateTime, string accountName, string description, string category)
        {
            Line line = new Line()
            {
                Id          = this.GetNewId(),
                AccountName = accountName,
                Amount      = amount,
                Category    = category,
                DateTime    = dateTime,
                Description = description
            };

            this._lines.Add(line);
            string json = SerializeHelpers.Serialize <Line>(line);

            File.WriteAllText(Path.Combine(Executor.BookPath, string.Format("{0}.json", line.Id)), json);

            return(Task.FromResult(true));
        }
예제 #3
0
        /// <summary>
        /// Fetches user's characters from the database to be selected from in the character select screen
        /// </summary>
        public void ShowCharList()
        {
            var stopwatch = new System.Diagnostics.Stopwatch();

            Log.Verbose("Showing Character List");
            if (!IsLoggedIn)
            {
                TriggerEvent("UI.Notification", "~r~Error~s~ Not logged in.");
                return;
            }

            try {
                NUIModels.PlayerCharacters characterList = new NUIModels.PlayerCharacters();
                stopwatch.Start();
                using (var conn = DBManager.GetConnection()) {
                    using (var cmd = conn.GetCommand()) {
                        // Fetch all characters belonging on the logged in user
                        cmd.CommandText = "SELECT `CharID`, `FirstName`, `LastName`, DATE_FORMAT( `DOB`, '%m/%d/%Y' ) AS `DOB`, `Gender`, `IsPolice`, `IsEMS`, `IsFireman`, `IsFirstSpawn`, `CharacterCompensation` FROM `Characters` WHERE `UserID`=@UserID AND `IsActive`=1";
                        cmd.Prepare();
                        cmd.Parameters.AddWithValue("@UserID", UserID);

                        using (var res = cmd.ExecuteReader()) {
                            while (res.Read())
                            {
                                characterList.Characters.Add(new NUIModels.PlayerCharacter(res));
                            }
                        }
                    }
                }
                stopwatch.Stop();
                Log.Verbose($"Database fetch complete - Elapsed ms: {stopwatch.ElapsedMilliseconds}");
                Log.Verbose("Returning character list");
                stopwatch.Restart();
                TriggerEvent("Session.CharList", SerializeHelpers.SerializeObject(characterList));
                stopwatch.Stop();
                Log.Verbose($"Triggered Char List, elapsed ms: {stopwatch.ElapsedMilliseconds}");
            }
            catch (Exception ex) {
                Log.Error(ex.Message);
            }
        }