Esempio n. 1
0
 public void CopyFrom(SavedGameInfo gi)
 {
     Id        = gi.Id;
     LastSaved = gi.LastSaved;
     Fen       = gi.Fen;
     Comment   = gi.Comment;
 }
Esempio n. 2
0
 public static BsonDocument ToBsonDoc(this SavedGameInfo gameInfo)
 {
     return(new BsonDocument {
         { "id", gameInfo.Id },
         { "date", gameInfo.LastSaved.Value.ToString("dd-MM-yyyy HH:mm:ss") },
         { "fen", gameInfo.Fen },
         { "comment", gameInfo.Comment }
     });
 }
Esempio n. 3
0
        private void AddGame(SavedGameInfo gameInfo)
        {
            var users = PersistanceManager.GetCollection();

            var x = users.UpdateOneAsync(
                Builders <BsonDocument> .Filter.Eq("name", Name),
                Builders <BsonDocument> .Update.Push("savedGames", gameInfo.ToBsonDoc())
                ).Result;

            SavedGames.Add(gameInfo);
        }
Esempio n. 4
0
 public void SaveGame(SavedGameInfo gameInfo)
 {
     if (SavedGames.Any(g => g.Id == gameInfo.Id))
     {
         UpdateGame(gameInfo);
     }
     else
     {
         AddGame(gameInfo);
     }
 }
Esempio n. 5
0
        public void DeleteGame(SavedGameInfo gameInfo)
        {
            var users = PersistanceManager.GetCollection();

            var x = users.UpdateOneAsync(
                Builders <BsonDocument> .Filter.Eq("name", Name),
                Builders <BsonDocument> .Update.Pull("savedGames", new BsonDocument {
                { "id", gameInfo.Id }
            })
                ).Result;

            SavedGames.RemoveAll(g => g.Id == gameInfo.Id);
        }
Esempio n. 6
0
        private static List <SavedGameInfo> GetSavedGames(BsonDocument userBson)
        {
            var savedGames          = new List <SavedGameInfo>();
            var savedGamesBson      = userBson.Elements.First(e => e.Name == "savedGames");
            var savedGamesBsonArray = savedGamesBson.Value.AsBsonArray;

            foreach (var savedGameBson in savedGamesBsonArray)
            {
                var gameInfo = new SavedGameInfo
                {
                    Id        = savedGameBson["id"].AsString,
                    Comment   = savedGameBson["comment"].AsString,
                    Fen       = savedGameBson["fen"].AsString,
                    LastSaved = DateTime.Parse(savedGameBson["date"].AsString)
                };
                savedGames.Add(gameInfo);
            }
            return(savedGames);
        }
Esempio n. 7
0
 private void UpdateGame(SavedGameInfo gameInfo)
 {
     DeleteGame(gameInfo);
     AddGame(gameInfo);
 }