public void Synchronize()
 {
     try
     {
         Pull();
         Push();
         SyncSuccess?.Invoke(this, null);
     }
     catch (Exception e)
     {
         if (AppState.State.Instance.Challenges == null)
         {
             var oldChallenges = LoadChallengesFromFiles(Directory.GetFiles(_challengesDir).Skip(1).ToArray());
             AppState.State.Instance.Challenges = new List <Challenge>(oldChallenges);
         }
         SyncFail?.Invoke(this, e);
     }
 }
Beispiel #2
0
        public (CommandStatus, Event[], string, Notification[]) Process(IMessage msg, IMessageContextModel ctx, string version)
        {
            var model = ctx as SyncContextModel;

            var events0 = Sync_flashcards(model).ToArray();
            var events1 = Sync_config(model);

            return(Calculate_success_stats(), events0.Concat(events1).ToArray(), "", new Notification[0]);


            SyncSuccess Calculate_success_stats()
            {
                var stats = new SyncSuccess {
                    Added   = events0.Count(e => e is NewCardEncountered),
                    Changed = events0.Count(e => e is CardWasChanged),
                    Missing = events0.Count(e => e is CardFoundMissing),
                };

                stats.TotalCount = model.Flashcards.Count + stats.Added - stats.Missing;
                return(stats);
            }
        }