async Task F8_() { Bpr.BeepClk(); IsReady = false; await Task.Delay(9); using (var db = new A0DbContext()) { db.FileDetails.RemoveRange(db.FileDetails); SaveRpt += Environment.NewLine + db.GetDbChangesReport(); } IsReady = true; }
protected override async Task ClosingVM() { Bpr.BeepClk(); if (_cancelClosing = IsInSsn) // if in session: finish it and cancel closing and show results. { await finishTheSession(); return; } //redundant: SaveToDb_SettingsMostly(); <== redundant Jun 2019 Opcty = 0; IsInSsn = true; // just to show responciveness MainVis = Visibility.Hidden; refreshUiSynch(); await refreshUi(); await Task.Run(() => SoundPlayer.PlayByeByeSound()); await base.ClosingVM(); }
async Task FA_() { Bpr.BeepClk(); IsReady = false; await DeleteAllDupesAutoAndManual_F10(); IsReady = true; }
async Task F7_() { IsReady = false; Bpr.BeepClk(); await UpdateDBfromFS(9); IsReady = true; }
async Task F6_() { IsReady = false; Bpr.BeepClk(); await Task.Delay(9); IsReady = true; }
async Task F3_() { IsReady = false; Bpr.BeepClk(); await findDupesInDbAndDeleteThemFromFS_SUSPENDED(CurrentFolder, -1, "DoubleFolder", -2, MinFileSize); IsReady = true; }
async Task F1_() { IsReady = false; Bpr.BeepClk(); await Task.Delay(9); await fastSyncFStoDbSansHashing_Folder(CurrentFolder, true); IsReady = true; }
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(); } } }
async Task finishTheSession() { var sw = Stopwatch.StartNew(); try { IsInSsn = false; //todo: why so slow in reflecting in the UI??? await Task.Yield(); Bpr.BeepClk(); if (!_swMain.IsRunning || _swMain.ElapsedTicks == 0) // if has not been started yet. { return; } _swMain.Stop(); if (PupilInput.Length == 0) { return; } if (PupilInput.Trim().Length < LessonLen - 3) { #if !DEBUG synth.SpeakAsyncCancelAll(); await synth.SpeakAsync($"Does not count: Too short!"); #endif return; } if (!IsCorrect) { synth.SpeakAsyncCancelAll(); synth.SpeakFaF($"Does not count: Mistyped! Always finish typing till the last letter. Pressing Escape button ruins/discards the lesson."); return; } var prevRcrdCpm = RcrdCpm; var thisResult = new dbMdl.SessionResult { Duration = _swMain.Elapsed, ExcerciseName = DashName, PokedIn = PupilInput.Length, UserId = SelectUser, Note = $"{Environment.MachineName.Substring(0, 2).ToLower()}{Environment.MachineName.Substring(Environment.MachineName.Length - 1)}", DoneAt = DateTime.Now }; if (thisResult.CpM < .333 * prevRcrdCpm) { synth.SpeakAsyncCancelAll(); synth.SpeakFaF($"Does not count: Very-very-very- V. E. R. Y. slow!"); return; } //var pb = new PromptBuilder(); for (int i = 0; i < 10; i++) { pb.AppendText($"{1 + i} mississippi ", i % 2 > 0 ? PromptEmphasis.Strong : PromptEmphasis.Reduced); } synth.SpeakFaF(pb); // synth.SpeakFaF("The end. Storing the results... 1 mississippi 2 mississippi 3 mississippi 4 mississippi 5 mississippi 6 mississippi 7 mississippi 8 mississippi 9 mississippi 10 mississippi 11 mississippi 12 mississippi 13 mississippi 14 mississippi 15 mississippi 16 mississippi 17 mississippi 18 mississippi 19 "); await Task.Delay(3333); var swStoring = Stopwatch.StartNew(); if (thisResult.CpM > prevRcrdCpm) { thisResult.IsRecord = true; } using (var db = dbMdl.A0DbMdl.GetA0DbMdlAzureDb) { //2019-12/ _chartUC.LoadDataToChart(CurUserCurExcrsRsltLst.OrderByDescending(r => r.DoneAt).Take(10).ToList()); //2019-12/ await Task.Delay(50); synth.SpeakAsyncCancelAll(); await synth.SpeakAsync("adding"); /**/ db.SessionResults.Add(SelectSnRt = thisResult); /**/ // synth.SpeakAsyncCancelAll(); await synth.Speak("added"); synth.SpeakAsyncCancelAll(); await synth.SpeakAsync("seting"); /**/ await updateSettings(db); /**/ // synth.SpeakAsyncCancelAll(); await synth.Speak("setingsed"); synth.SpeakAsyncCancelAll(); await synth.SpeakAsync("saving"); /**/ await db.TrySaveReportAsync(); /**/ // synth.SpeakAsyncCancelAll(); await synth.Speak("saved"); synth.SpeakAsyncCancelAll(); await synth.SpeakAsync("loading"); /**/ loadListsFromDB(DashName, SelectUser, db); /**/ // synth.SpeakAsyncCancelAll(); await synth.Speak("loaded"); synth.SpeakAsyncCancelAll(); await synth.SpeakAsync("todoing"); /**/ await updateDoneTodo(SelectUser, synth, db); /**/ // synth.SpeakAsyncCancelAll(); await synth.Speak("todoed"); synth.SpeakAsyncCancelAll(); await synth.SpeakAsync("charting"); /**/ _chartUC.LoadDataToChart(CurUserCurExcrsRsltLst.OrderByDescending(r => r.DoneAt).Take(10).ToList()); /**/ // synth.SpeakAsyncCancelAll(); await synth.Speak("charted"); } synth.SpeakAsyncCancelAll(); await synth.SpeakAsync($"took {swStoring.Elapsed.TotalSeconds:N0} seconds."); IsFocusedPI = false; IsFocusedSB = true; IsFocusedSB = false; IsFocusedSB = true; //Task.Run(() => { if (thisResult.CpM > prevRcrdCpm) { SoundPlayer.PlaySessionFinish_Good(); synth.SpeakAsyncCancelAll(); await synth.SpeakAsync($"Wow! Congratulations! That is actually a record! {thisResult.CpM - prevRcrdCpm} characters per minute faster or {100 * (thisResult.CpM - prevRcrdCpm) / prevRcrdCpm} percent improvement!"); } else { //Jun 2019: too old: SoundPlayer.PlaySessionFinish_Baad(); synth.SpeakAsyncCancelAll(); await synth.SpeakAsync($"{thisResult.CpM}"); if (TodoToday > 0) { var t1 = ( thisResult.CpM > .99 * prevRcrdCpm ? $"OMG! That was really-really R-E-A-L-L-Y close. I am so excited! New record is coming up!" : thisResult.CpM > .98 * prevRcrdCpm ? $"OMG! That was really REALLY close. New record is coming." : thisResult.CpM > .97 * prevRcrdCpm ? $"Oh my god! That was awesome!" : thisResult.CpM > .96 * prevRcrdCpm ? $"Oh my god! That was amazing - almost a brand new record!" : thisResult.CpM > .95 * prevRcrdCpm ? $"Brilliant!" : thisResult.CpM > .94 * prevRcrdCpm ? $"Perfect! Almost ..." : thisResult.CpM > .93 * prevRcrdCpm ? $"Well done! Keep it up! " : thisResult.CpM > .92 * prevRcrdCpm ? $"Fantastic! " : thisResult.CpM > .91 * prevRcrdCpm ? $"Exciting!" : thisResult.CpM > .90 * prevRcrdCpm ? $"Looks promising..." : thisResult.CpM > .89 * prevRcrdCpm ? $"Looking pretty." : thisResult.CpM > .88 * prevRcrdCpm ? $"Looking good..." : thisResult.CpM > .87 * prevRcrdCpm ? $"Even nicer!" : thisResult.CpM > .86 * prevRcrdCpm ? $"N. I. C. E. Nice!" : thisResult.CpM > .85 * prevRcrdCpm ? $"Getting there..." : thisResult.CpM > .84 * prevRcrdCpm ? $"Nice! But could be nicer..." : thisResult.CpM > .83 * prevRcrdCpm ? $"Well executed!" : thisResult.CpM > .82 * prevRcrdCpm ? $"Well done!" : thisResult.CpM > .81 * prevRcrdCpm ? $"Better-ish!" : thisResult.CpM > .80 * prevRcrdCpm ? $"Better!" : thisResult.CpM > .69 * prevRcrdCpm ? $"Take a deep breath, and - double the effort!" : thisResult.CpM > .78 * prevRcrdCpm ? $"Not bad!" : thisResult.CpM > .77 * prevRcrdCpm ? $"Good! But needs improvement..." : thisResult.CpM > .76 * prevRcrdCpm ? $"Good! But could be better..." : thisResult.CpM > .75 * prevRcrdCpm ? $"Good! But could be much better..." : thisResult.CpM > .74 * prevRcrdCpm ? $"Good! But could be much-much better..." : thisResult.CpM > .73 * prevRcrdCpm ? $"Remember: making an effort is all what counts." : thisResult.CpM > .72 * prevRcrdCpm ? $"Good! But not good..." : thisResult.CpM > .71 * prevRcrdCpm ? $"Try to make an effort! " : thisResult.CpM > .70 * prevRcrdCpm ? $"Try a tiny bit harder! " : thisResult.CpM > .69 * prevRcrdCpm ? $"A deep breath, and - buckle up!" : thisResult.CpM > .68 * prevRcrdCpm ? $"Kind of getting there..." : thisResult.CpM > .67 * prevRcrdCpm ? $"Still too slow..." : thisResult.CpM > .66 * prevRcrdCpm ? $"Kind of slow..." : thisResult.CpM > .65 * prevRcrdCpm ? $"Kind of sluggish..." : thisResult.CpM > .64 * prevRcrdCpm ? $"That was a snail pace, if you ask me." : thisResult.CpM > .63 * prevRcrdCpm ? $"Warm up or not, but move it, will you!" : thisResult.CpM > .62 * prevRcrdCpm ? $"Warm up or not, but it must be faster!" : thisResult.CpM > .61 * prevRcrdCpm ? $"I'll take it as a joke." : thisResult.CpM > .60 * prevRcrdCpm ? $"I'll take it as a warm up." : thisResult.CpM > .59 * prevRcrdCpm ? $"Hey you! Be serious!" : thisResult.CpM > .58 * prevRcrdCpm ? $"That was not even interesting..." : thisResult.CpM > .57 * prevRcrdCpm ? $"Is anybody awake up there?" : thisResult.CpM > .56 * prevRcrdCpm ? $"You typed faster a year ago." : thisResult.CpM > .55 * prevRcrdCpm ? $"Hey you! Wake up already!" : thisResult.CpM > .54 * prevRcrdCpm ? $"You typed faster when you were 3." : thisResult.CpM > .53 * prevRcrdCpm ? $"Hello-o-o-o-o!" : thisResult.CpM > .52 * prevRcrdCpm ? $"That was just silly!" : thisResult.CpM > .51 * prevRcrdCpm ? $"Remember: slower than this does not count." : thisResult.CpM > .50 * prevRcrdCpm ? $"Just barely made it: a bit slower - and it would not count. " : thisResult.CpM > .47 * prevRcrdCpm ? $"Za-ra-za." : thisResult.CpM > .45 * prevRcrdCpm ? $"AFAIK, Your grandpa types faster." : thisResult.CpM > .40 * prevRcrdCpm ? $"Your grandma types faster." : thisResult.CpM > .33 * prevRcrdCpm ? $"OK, monkey, I will count in this disgracefully slow run this time, but you'd better do not repeat such a horrible performance. " : $"This message never played, right? Are you kidding me! This is too slow and is not counted."); synth.SpeakAsyncCancelAll(); await synth.SpeakAsync($"{t1} {DoneToday} down; {TodoToday} to go."); return; } } runTreatIfAny(); Trace.WriteLineIf(ExnLogr.AppTraceLevelCfg.TraceWarning, $"{DateTime.Now:yy.MM.dd-HH:mm:ss.f} +{(DateTime.Now - App.StartedAt):mm\\:ss\\.ff} *** finishTheSession() done in {sw.Elapsed.TotalSeconds:N1} sec."); }//);//.ContinueWith(_ => onF1_UpdateCpmRecord(), TaskScheduler.FromCurrentSynchronizationContext()); } finally { } }