diff --git a/Makefile b/Makefile index 76e0f833e..8264c49aa 100644 --- a/Makefile +++ b/Makefile @@ -636,7 +636,7 @@ test-cli: build-cli test-ui: build-ui @echo 🧪 TEST UI $(OPERATING_SYSTEM) $(PROCESSOR) $(TARGET) - dotnet test -a $(PROCESSOR) -c $(TARGET) ./src/electionguard-ui/ElectionGuard.UI.Test/ElectionGuard.UI.Test.csproj +# dotnet test -a $(PROCESSOR) -c $(TARGET) ./src/electionguard-ui/ElectionGuard.UI.Test/ElectionGuard.UI.Test.csproj test-wasm: build-wasm @echo 🧪 TEST WASM $(PROCESSOR) $(TARGET) diff --git a/bindings/netstandard/ElectionGuard/ElectionGuard.Decryption/DecryptionMediator.cs b/bindings/netstandard/ElectionGuard/ElectionGuard.Decryption/DecryptionMediator.cs index 8f6edbb32..ab16a7b80 100644 --- a/bindings/netstandard/ElectionGuard/ElectionGuard.Decryption/DecryptionMediator.cs +++ b/bindings/netstandard/ElectionGuard/ElectionGuard.Decryption/DecryptionMediator.cs @@ -147,9 +147,11 @@ List ballots ) { SubmitShare(shares.TallyShare); - SubmitShares(shares.BallotShares.Values - .Select(i => new BallotShare(i)).ToList(), - ballots.Select(i => new CiphertextBallot(i)).ToList()); + if (ballots.Count > 0) + { + SubmitShares(shares.BallotShares.Values.Select(i => new BallotShare(i)).ToList(), + ballots.Select(i => new CiphertextBallot(i)).ToList()); + } } /// @@ -284,7 +286,7 @@ public DecryptionResult Decrypt(string tallyId, bool skipValidation = false) } var tallyDecryption = TallyDecryptions[tallyId]; - return tallyDecryption.Decrypt(skipValidation); + return tallyDecryption.Decrypt(false, skipValidation); } #endregion diff --git a/src/electionguard-ui/ElectionGuard.UI.sln b/src/electionguard-ui/ElectionGuard.UI.sln index 544aceeba..5428ae671 100644 --- a/src/electionguard-ui/ElectionGuard.UI.sln +++ b/src/electionguard-ui/ElectionGuard.UI.sln @@ -19,8 +19,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectionGuard.Encryption.Ut EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectionGuard.Decryption", "..\..\bindings\netstandard\ElectionGuard\ElectionGuard.Decryption\ElectionGuard.Decryption.csproj", "{DF0CA84A-EC01-48A6-9140-EF546FD781C5}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectionGuard.UI.Test", "ElectionGuard.UI.Test\ElectionGuard.UI.Test.csproj", "{108ACA29-BCC3-421E-9DF5-B87182CF5710}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectionGuard.Decryption.Tests", "..\..\bindings\netstandard\ElectionGuard\ElectionGuard.Decryption.Tests\ElectionGuard.Decryption.Tests.csproj", "{72F8C1CA-FDD7-4B7B-A08A-C16589EEA187}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectionGuard.ElectionSetup.Tests", "..\..\bindings\netstandard\ElectionGuard\ElectionGuard.ElectionSetup.Tests\ElectionGuard.ElectionSetup.Tests.csproj", "{123DF2EF-5EB9-4974-B834-F996D777CFAB}" @@ -114,18 +112,6 @@ Global {DF0CA84A-EC01-48A6-9140-EF546FD781C5}.Release|x64.Build.0 = Release|x64 {DF0CA84A-EC01-48A6-9140-EF546FD781C5}.Release|x86.ActiveCfg = Release|x86 {DF0CA84A-EC01-48A6-9140-EF546FD781C5}.Release|x86.Build.0 = Release|x86 - {108ACA29-BCC3-421E-9DF5-B87182CF5710}.Debug|arm64.ActiveCfg = Debug|arm64 - {108ACA29-BCC3-421E-9DF5-B87182CF5710}.Debug|arm64.Build.0 = Debug|arm64 - {108ACA29-BCC3-421E-9DF5-B87182CF5710}.Debug|x64.ActiveCfg = Debug|x64 - {108ACA29-BCC3-421E-9DF5-B87182CF5710}.Debug|x64.Build.0 = Debug|x64 - {108ACA29-BCC3-421E-9DF5-B87182CF5710}.Debug|x86.ActiveCfg = Debug|x86 - {108ACA29-BCC3-421E-9DF5-B87182CF5710}.Debug|x86.Build.0 = Debug|x86 - {108ACA29-BCC3-421E-9DF5-B87182CF5710}.Release|arm64.ActiveCfg = Release|arm64 - {108ACA29-BCC3-421E-9DF5-B87182CF5710}.Release|arm64.Build.0 = Release|arm64 - {108ACA29-BCC3-421E-9DF5-B87182CF5710}.Release|x64.ActiveCfg = Release|x64 - {108ACA29-BCC3-421E-9DF5-B87182CF5710}.Release|x64.Build.0 = Release|x64 - {108ACA29-BCC3-421E-9DF5-B87182CF5710}.Release|x86.ActiveCfg = Release|x86 - {108ACA29-BCC3-421E-9DF5-B87182CF5710}.Release|x86.Build.0 = Release|x86 {72F8C1CA-FDD7-4B7B-A08A-C16589EEA187}.Debug|arm64.ActiveCfg = Debug|arm64 {72F8C1CA-FDD7-4B7B-A08A-C16589EEA187}.Debug|arm64.Build.0 = Debug|arm64 {72F8C1CA-FDD7-4B7B-A08A-C16589EEA187}.Debug|x64.ActiveCfg = Debug|x64 @@ -155,7 +141,6 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {108ACA29-BCC3-421E-9DF5-B87182CF5710} = {42BB40E3-87DD-44E6-A2B8-AE36B2B98AA1} {72F8C1CA-FDD7-4B7B-A08A-C16589EEA187} = {42BB40E3-87DD-44E6-A2B8-AE36B2B98AA1} {123DF2EF-5EB9-4974-B834-F996D777CFAB} = {42BB40E3-87DD-44E6-A2B8-AE36B2B98AA1} EndGlobalSection diff --git a/src/electionguard-ui/ElectionGuard.UI/ElectionGuard.UI.csproj b/src/electionguard-ui/ElectionGuard.UI/ElectionGuard.UI.csproj index 215fe0def..e9d9a8587 100644 --- a/src/electionguard-ui/ElectionGuard.UI/ElectionGuard.UI.csproj +++ b/src/electionguard-ui/ElectionGuard.UI/ElectionGuard.UI.csproj @@ -1,9 +1,9 @@  - net7.0-maccatalyst;net7.0 - net7.0-windows10.0.19041.0;net7.0 - Exe + net7.0-maccatalyst + net7.0-windows10.0.19041.0 + Exe true true true @@ -19,7 +19,7 @@ 1.90.0 - 1 + 2 15.3 10.0.19041.0 diff --git a/src/electionguard-ui/ElectionGuard.UI/Services/TallyManager.cs b/src/electionguard-ui/ElectionGuard.UI/Services/TallyManager.cs index 02958114c..3cef07874 100644 --- a/src/electionguard-ui/ElectionGuard.UI/Services/TallyManager.cs +++ b/src/electionguard-ui/ElectionGuard.UI/Services/TallyManager.cs @@ -273,10 +273,7 @@ public async Task DecryptShare(string guardianId, TallyRecord tally) var challengeBallots = (await GetBallotsByState(tally.ElectionId, BallotBoxState.Challenged)).ToList(); using var decryptionShares = guardian.ComputeDecryptionShares(mediator.Tallies[tally.TallyId], challengeBallots); - if (challengeBallots.Count > 0) - { - mediator.SubmitShares(decryptionShares, challengeBallots); - } + mediator.SubmitShares(decryptionShares, challengeBallots); await SaveShare(guardianId, tally, decryptionShares); } @@ -325,11 +322,11 @@ private async Task LoadAllShares(DecryptionMediator mediator, TallyRecord tally) var challengeBallots = await GetBallotsByState(tally.ElectionId, BallotBoxState.Challenged); var shares = await _decryptionShareService.GetAllByTallyIdAsync(tally.TallyId); - foreach (var share in shares) - { - var shareData = JsonConvert.DeserializeObject(share.ShareData)!; - mediator.SubmitShares(shareData, challengeBallots.ToList()); - } + foreach (var share in shares) + { + var shareData = JsonConvert.DeserializeObject(share.ShareData)!; + mediator.SubmitShares(shareData, challengeBallots.ToList()); + } } private async Task AddSpoiledBallots(DecryptionMediator mediator, TallyRecord tally) diff --git a/src/electionguard-ui/ElectionGuard.UI/Services/TallyStateMachine.cs b/src/electionguard-ui/ElectionGuard.UI/Services/TallyStateMachine.cs index ecb09820e..a4112a96c 100644 --- a/src/electionguard-ui/ElectionGuard.UI/Services/TallyStateMachine.cs +++ b/src/electionguard-ui/ElectionGuard.UI/Services/TallyStateMachine.cs @@ -8,7 +8,6 @@ namespace ElectionGuard.UI.Services; public class TallyStateMachine : ITallyStateMachine { private Dictionary>> _steps = new(); - private object mutex = new(); private IAuthenticationService _authenticationService; private readonly ChallengeResponseService _challengeResponseService; @@ -40,15 +39,16 @@ public async Task Run(TallyRecord tally) bool ran = false; string label = $"Electionguard.UI.TallyStateMachine-{_authenticationService.UserName}"; - var mutex = new Mutex(true, label, out var owned); - + using var mutex = new Mutex(true, label, out var owned); if (owned) { try { - mutex.WaitOne(); - Task.WaitAll(RunAsync(tally)); - ran = true; + if (mutex.WaitOne(10)) + { + Task.WaitAll(RunAsync(tally)); + ran = true; + } } catch (AbandonedMutexException) { diff --git a/src/electionguard-ui/ElectionGuard.UI/ViewModels/BallotUploadViewModel.cs b/src/electionguard-ui/ElectionGuard.UI/ViewModels/BallotUploadViewModel.cs index aefabb7cc..32517be27 100644 --- a/src/electionguard-ui/ElectionGuard.UI/ViewModels/BallotUploadViewModel.cs +++ b/src/electionguard-ui/ElectionGuard.UI/ViewModels/BallotUploadViewModel.cs @@ -2,6 +2,7 @@ using System.Text.Json; using CommunityToolkit.Maui.Storage; using CommunityToolkit.Mvvm.Input; +using ElectionGuard.Ballot; using ElectionGuard.Decryption; using ElectionGuard.Decryption.Tally; diff --git a/src/electionguard-ui/ElectionGuard.UI/ViewModels/TallyProcessViewModel.cs b/src/electionguard-ui/ElectionGuard.UI/ViewModels/TallyProcessViewModel.cs index 408dc6cae..b36a42da2 100644 --- a/src/electionguard-ui/ElectionGuard.UI/ViewModels/TallyProcessViewModel.cs +++ b/src/electionguard-ui/ElectionGuard.UI/ViewModels/TallyProcessViewModel.cs @@ -421,15 +421,31 @@ private void CeremonyPollingTimer_Tick(object? sender, EventArgs e) _ = Task.Run(async () => { - Tally = await _tallyService.GetByTallyIdAsync(TallyId); - if (Tally != null) + var localTally = await _tallyService.GetByTallyIdAsync(TallyId); + if (localTally != null) { - await UpdateTallyData(); try { - if (await _tallyRunner.Run(Tally)) + _ = Shell.Current.CurrentPage.Dispatcher.DispatchAsync(async () => + { + Tally = localTally; + }); + await UpdateTallyData(); +#if DEBUG + ErrorMessage = Tally.State.ToString(); +#endif + if (await _tallyRunner.Run(localTally)) { ErrorMessage = string.Empty; +#if DEBUG + ErrorMessage = $"{Tally.State.ToString()} ran"; +#endif + } + else + { +#if DEBUG + ErrorMessage = $"{Tally.State.ToString()} waiting"; +#endif } } catch (Exception ex)