예제 #1
0
        static async Task <AppStng> getAnybody_CreateIfnobody(A0DbMdl db)
        {
            var anybody = db.AppStngs.FirstOrDefault();

            if (anybody == null)
            {
                anybody = db.AppStngs.Add(new AppStng {
                    LesnTyp = LessonType.PhrasesRandm, SubLesnId = "0", CreatedAt = DateTime.Now, Id = 1, UserId = "Dflt", Note = "Auto pre-loaded [Default]."
                });
                await db.TrySaveReportAsync();
            }

            return(anybody);
        }
예제 #2
0
        async Task <AppStng> getCurUserSettings(A0DbMdl db)
        {
            var appStngUsr = db.AppStngs.FirstOrDefault(r => r.UserId == SelectUser);

            if (appStngUsr == null)
            {
                var anybody = await getAnybody_CreateIfnobody(db);

                appStngUsr = db.AppStngs.Add(new AppStng
                {
                    LesnTyp   = anybody.LesnTyp,
                    SubLesnId = anybody.SubLesnId,
                    CreatedAt = DateTime.Now,
                    UserId    = SelectUser,
                    Note      = $"Auto pre-copied from {anybody.UserId}."
                });

                await db.TrySaveReportAsync();
            }

            return(appStngUsr);
        }
예제 #3
0
        internal void DeleteSaveSsnRsltToDb(db.SessionResult sr, A0DbMdl db)
        {
            IsBusy = true;
            var now = DateTime.Now;

            try
            {
                // using (var db = A0DbMdl.GetA0DbMdlAzureDb)
                {
                    //if (Debugger.IsAttached) Debugger.Break(); // >>> DoneAt = sr.DoneAt.DateTime, //todo: ?? .AddMinutes(sr.DoneAt.OffsetMinutes)

                    var srfromdb = db.SessionResults.Find(sr.Id);
                    db.SessionResults.Remove(srfromdb);

                    var rv = db.TrySaveReportAsync(); //Trace.TraceInformation($"{rv}");

                    InfoMsg = $" Total {db.SessionResults.Count(),4} SesRslt rows. \r\n {LesnTyp} - {SubLesnId}\r\n SelectUser: '******'";
                }
            }
            catch (Exception ex) { InfoMsg = ex.Log(); }
            finally { IsBusy = false; }
        }
        async Task migrate(A0DbMdl db)
        {
            Bpr.Beep1of2();
            var obsVm = JsonFileSerializer.Load <ObsMainVM>(MainVM.MainVmJsonFile) as ObsMainVM;

            if (obsVm == null)
            {
                MessageBox.Show("No Go");
            }
            else
            {
                var srFromJsonWithNote = obsVm.SnRts.Where(r => !string.IsNullOrEmpty(r.Notes));

                try
                {
                    if (db.SessionResults.Any(r => r.Note != null && (r.Note == "zz" || r.Note.StartsWith("from fs at"))))
                    {
                        db.SessionResults.Where(r => r.Note != null && (r.Note == "zz" || r.Note.StartsWith("from fs at"))).ToList().ForEach(r => r.Note = "");
                    }

                    tbInfo.Text = $"Json: \t{obsVm.SnRts.Length} total runs incl-g {srFromJsonWithNote.Count()} with note;\r\nDB: \t{db.SessionResults.Count()} \r\n";
                    Debug.WriteLine($"::>{tbInfo.Text}");

                    await Task.Yield();

                    Bpr.BeepClk();

                    int brandNew = 0, noMatchesInDb = 0, alreadySame = 0, updated = 0;

                    foreach (var srjs in obsVm.SnRts)
                    {
                        var srdb0 = db.SessionResults.FirstOrDefault(d =>
                                                                     d.UserId == srjs.UserId &&
                                                                     d.Duration == srjs.Duration /*drn(srjs.Duration)*/ &&
                                                                     d.ExcerciseName == srjs.ExcerciseName &&
                                                                     d.PokedIn == srjs.PokedIn &&
                                                                     Math.Abs((d.DoneAt - srjs.DoneAt.DateTime.AddMinutes(srjs.DoneAt.OffsetMinutes)).TotalSeconds) < 5);
                        if (srdb0 == null)
                        {
                            db.SessionResults.Add(new SessionResult
                            {
                                DoneAt        = srjs.DoneAt.DateTime.AddMinutes(srjs.DoneAt.OffsetMinutes),
                                UserId        = srjs.UserId,
                                Duration      = srjs.Duration /*drn(srjs.Duration)*/,
                                ExcerciseName = srjs.ExcerciseName,
                                PokedIn       = srjs.PokedIn,
                                Note          = srjs.Notes
                            });
                            brandNew++;
                        }
                    }

                    try
                    {
                        foreach (var srjs in srFromJsonWithNote)
                        {
                            var srdb2 = db.SessionResults.FirstOrDefault(d => Math.Abs((d.DoneAt - srjs.DoneAt.DateTime.AddMinutes(srjs.DoneAt.OffsetMinutes)).TotalSeconds) < 5);
                            if (srdb2 == null)
                            {
                                db.SessionResults.Add(new SessionResult
                                {
                                    DoneAt        = srjs.DoneAt.DateTime.AddMinutes(srjs.DoneAt.OffsetMinutes),
                                    UserId        = srjs.UserId,
                                    Duration      = srjs.Duration /*drn(srjs.Duration)*/,
                                    ExcerciseName = srjs.ExcerciseName,
                                    PokedIn       = srjs.PokedIn,
                                    Note          = srjs.Notes
                                });
                                noMatchesInDb++;
                            }
                            else
                            {
                                if (srjs.Notes.Equals(srdb2.Note))
                                {
                                    alreadySame++;
                                }
                                else
                                {
                                    updated++;
                                    srdb2.Note = srjs.Notes;
                                }
                            }
                        }
                    }
                    catch (Exception ex) { Debug.WriteLine(ex); }


                    tbInfo.Text += $" brandNew {brandNew}, notFoundInDb {noMatchesInDb }, alreadySame {alreadySame }, updated {updated}\n";
                    Debug.WriteLine($"::>{tbInfo.Text}");

                    var rv = await db.TrySaveReportAsync();

                    tbInfo.Text += $" {rv}";
                    Bpr.Beep2of2();
                }
                catch (Exception ex) { tbEror.Text = ex.Log(); }
                finally { new DbExplorer2().Show(); }
            }
        }
예제 #5
0
 async void onDbSave(object sender, RoutedEventArgs e)
 {
     Bpr.Beep1of2(); tbInfo.Text = (await _db.TrySaveReportAsync()).report; Bpr.Beep2of2();
 }