示例#1
0
        private void SaveAndFireEvent(Guid gamerId, bool suppressUpdateEvent = false)
        {
            //Ensure serialized to disk - shouldn't take more than a jiffy
            var existing = _gamers.First(f => f.Id.Equals(gamerId));
            var ser      = new ScoreSerializer <Gamer>();

            ser.SerializeObject(existing, Path.Combine(_contactDir, $"{gamerId}.xml"));
            if (!suppressUpdateEvent)
            {
                GamerUpdated?.Invoke(this, gamerId);
            }
        }
示例#2
0
        private void LoadGamers()
        {
            var di  = new DirectoryInfo(_contactDir);
            var fis = di.GetFiles("*.xml").ToList();

            if (fis.Count == 0)
            {
                return;
            }
            var ser = new ScoreSerializer <Gamer>();

            foreach (var fileInfo in fis)
            {
                var gamer = ser.DeSerializeObject(fileInfo.FullName);
                if (gamer.Games.Any())
                {
                    gamer.Games.All(f => f.IsCurrent = false);
                    gamer.BestGameId = gamer.Games.OrderByDescending(g => g.TotalScore).First().Id;
                }
                _gamers.RemoveAll(f => f.Id.Equals(gamer.Id));
                _gamers.Add(gamer);
            }
        }