async Task Save() { testSpec.SpinnerSaving = true; testSpec.SaveLabel = "Wait"; testSpec.ControlsDisabled = true; testSpec.TenorWeightDisabled = true; screenA.PlayDisabled = true; screenB.PlayDisabled = true; StateHasChanged(); // Push the created test to the API in JSON format // Start by creating a BlowSetCore object, which just has the parent data BlowSet, for each of A and B // Note implicit cast from child to parent BlowSetCore blowSetCoreA = blowSetA; BlowSetCore blowSetCoreB = blowSetB; // BlowSetCore has a BlowsCore list which is empty so far // Call the LoadBlowsCore method to populate it for each of A and B blowSetCoreA.LoadBlowsCore(blowSetA); blowSetCoreB.LoadBlowsCore(blowSetB); // Next use the Serializer method of the JsonSerializer class (in the System.Text.Json namespace) to create // a Json object from the BlowSetData object for each of A and B ABTestData aBTestData = new ABTestData { ABTestSpecA = JsonSerializer.Serialize(blowSetCoreA), ABTestSpecB = JsonSerializer.Serialize(blowSetCoreB) }; // Push the Json object to the API await TJBarnesService.GetHttpClient().PostAsJsonAsync("api/abtests", aBTestData); // Refresh the contents of the Select Test dropdown aBTestsData = (await TJBarnesService.GetHttpClient() .GetFromJsonAsync <ABTestData[]>("api/abtests")).ToList(); testSpec.SpinnerSaving = false; testSpec.Saved = true; StateHasChanged(); await Task.Delay(1000); testSpec.Saved = false; testSpec.SaveLabel = "Save"; testSpec.ControlsDisabled = false; testSpec.TenorWeightDisabled = TenorWeightSelect.TenorWeightDisabled(testSpec.Stage); screenA.PlayDisabled = false; screenB.PlayDisabled = false; StateHasChanged(); }
async Task Load(int id) { // Get a test from the API ABTestData aBTestData = await TJBarnesService.GetHttpClient() .GetFromJsonAsync <ABTestData>("api/abtests/" + id.ToString()); // Use the Deserializer method of the JsonSerializer class (in the System.Text.Json namespace) to create // a BlowSetCore object for each of A and B BlowSetCore blowSetCoreA = JsonSerializer.Deserialize <BlowSetCore>(aBTestData.ABTestSpecA); BlowSetCore blowSetCoreB = JsonSerializer.Deserialize <BlowSetCore>(aBTestData.ABTestSpecB); testSpec.AHasErrors = blowSetCoreA.HasErrors; // Create a BlowSet object from the BlowSetCore object for A blowSetA = new BlowSet(blowSetCoreA.Stage, blowSetCoreA.NumRows, blowSetCoreA.TenorWeight, blowSetCoreA.ErrorType, blowSetCoreA.HasErrors); // Use an audioIdSuffix of "b" for this blowset blowSetA.LoadBlows(blowSetCoreA, "a"); blowSetA.SetUnstruck(); // Create a BlowSet object from the BlowSetCore object for B blowSetB = new BlowSet(blowSetCoreB.Stage, blowSetCoreB.NumRows, blowSetCoreB.TenorWeight, blowSetCoreB.ErrorType, blowSetCoreB.HasErrors); // Use an audioIdSuffix of "b" for this blowset blowSetB.LoadBlows(blowSetCoreB, "b"); blowSetB.SetUnstruck(); // Update drop down boxes on screen // Use BlowSetA - by definition the following properties for BlowSetA and BlowSetB will be the same testSpec.Stage = blowSetA.Stage; testSpec.TenorWeight = blowSetA.TenorWeight; testSpec.ErrorType = blowSetA.ErrorType; // Set up test spec-dependent elements of the screen object int baseGap = BaseGaps.BaseGap(testSpec.Stage, testSpec.TenorWeight, 1); testSpec.BaseGap = baseGap; // Set the timing for the animation (when not showing the bells) screenA.AnimationDuration = blowSetA.Blows.Last().GapCumulative + 1000; screenB.AnimationDuration = blowSetB.Blows.Last().GapCumulative + 1000; testSpec.ResultEntered = false; testSpec.ShowGaps = false; StateHasChanged(); }