From 59fe1df40fbe18f5efc3bc8dcc34a9bf00131d4f Mon Sep 17 00:00:00 2001 From: Robert Date: Wed, 1 Nov 2023 20:19:00 +0100 Subject: [PATCH] Move IEntrySource to workshop --- .../SubmissionWizard/Models/IEntrySource.cs | 6 ----- .../Models/SubmissionWizardState.cs | 1 + .../Steps/Layout/LayoutInfoStepViewModel.cs | 25 +++++++++++++------ .../Layout/LayoutSelectionStepViewModel.cs | 1 + .../ProfileAdaptionHintsStepViewModel.cs | 1 + .../Profile/ProfileSelectionStepViewModel.cs | 1 + .../EntryUploadHandlerFactory.cs | 3 +-- .../Handlers/UploadHandlers/IEntrySource.cs | 6 +++++ .../UploadHandlers/IEntryUploadHandler.cs | 2 +- .../Implementations}/LayoutEntrySource.cs | 19 ++++++++------ .../LayoutEntryUploadHandler.cs | 21 +++++++++++++--- .../Implementations}/ProfileEntrySource.cs | 2 +- .../ProfileEntryUploadHandler.cs | 9 +++---- 13 files changed, 63 insertions(+), 34 deletions(-) delete mode 100644 src/Artemis.UI/Screens/Workshop/SubmissionWizard/Models/IEntrySource.cs create mode 100644 src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/IEntrySource.cs rename src/{Artemis.UI/Screens/Workshop/SubmissionWizard/Models => Artemis.WebClient.Workshop/Handlers/UploadHandlers/Implementations}/LayoutEntrySource.cs (58%) rename src/{Artemis.UI/Screens/Workshop/SubmissionWizard/Models => Artemis.WebClient.Workshop/Handlers/UploadHandlers/Implementations}/ProfileEntrySource.cs (81%) diff --git a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Models/IEntrySource.cs b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Models/IEntrySource.cs deleted file mode 100644 index 1789cdc1b..000000000 --- a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Models/IEntrySource.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Models; - -public interface IEntrySource -{ - -} \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Models/SubmissionWizardState.cs b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Models/SubmissionWizardState.cs index c980a0895..9b0c79503 100644 --- a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Models/SubmissionWizardState.cs +++ b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Models/SubmissionWizardState.cs @@ -5,6 +5,7 @@ using Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Layout; using Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile; using Artemis.UI.Shared.Services; using Artemis.WebClient.Workshop; +using Artemis.WebClient.Workshop.Handlers.UploadHandlers; using DryIoc; namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Models; diff --git a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/Layout/LayoutInfoStepViewModel.cs b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/Layout/LayoutInfoStepViewModel.cs index 585e2f8b4..4b99fb802 100644 --- a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/Layout/LayoutInfoStepViewModel.cs +++ b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/Layout/LayoutInfoStepViewModel.cs @@ -6,7 +6,7 @@ using System.Reactive.Disposables; using System.Reactive.Linq; using Artemis.Core; using Artemis.UI.Screens.Workshop.Layout; -using Artemis.UI.Screens.Workshop.SubmissionWizard.Models; +using Artemis.WebClient.Workshop.Handlers.UploadHandlers; using PropertyChanged.SourceGenerator; using ReactiveUI; using ReactiveUI.Validation.Extensions; @@ -26,7 +26,7 @@ public partial class LayoutInfoStepViewModel : SubmissionViewModel public LayoutInfoStepViewModel(Func getLayoutInfoViewModel) { _getLayoutInfoViewModel = getLayoutInfoViewModel; - + GoBack = ReactiveCommand.Create(() => State.ChangeScreen()); Continue = ReactiveCommand.Create(ExecuteContinue, ValidationContext.Valid); Secondary = ReactiveCommand.Create(ExecuteAddLayoutInfo); @@ -40,11 +40,11 @@ public partial class LayoutInfoStepViewModel : SubmissionViewModel _layout = layoutEntrySource.Layout; IsKeyboardLayout = _layout.RgbLayout.Type == RGBDeviceType.Keyboard; PhysicalLayout = layoutEntrySource.PhysicalLayout; - LayoutInfo = layoutEntrySource.LayoutInfo; + LayoutInfo = new ObservableCollection(layoutEntrySource.LayoutInfo.Select(CreateLayoutInfoViewModel)); if (!LayoutInfo.Any()) ExecuteAddLayoutInfo(); - + this.ValidationRule( vm => vm.PhysicalLayout, this.WhenAnyValue(vm => vm.IsKeyboardLayout, vm => vm.PhysicalLayout, (isKeyboard, layout) => !isKeyboard || layout != KeyboardLayoutType.Unknown), @@ -58,6 +58,17 @@ public partial class LayoutInfoStepViewModel : SubmissionViewModel }); } + private LayoutInfoViewModel CreateLayoutInfoViewModel(LayoutInfo layoutInfo) + { + LayoutInfoViewModel vm = _getLayoutInfoViewModel(_layout ?? throw new InvalidOperationException()); + vm.Model = layoutInfo.Model; + vm.Vendor = layoutInfo.Vendor; + vm.DeviceProviderId = layoutInfo.DeviceProviderId; + vm.Remove = ReactiveCommand.Create(() => LayoutInfo.Remove(vm)); + + return vm; + } + private void ExecuteAddLayoutInfo() { if (_layout == null) @@ -74,8 +85,9 @@ public partial class LayoutInfoStepViewModel : SubmissionViewModel return; layoutEntrySource.PhysicalLayout = PhysicalLayout; - - if (string.IsNullOrWhiteSpace(State.Name)) + // layoutEntrySource.LayoutInfo = new List(LayoutInfo.Select(i => i.ToLayoutInfo())); + + if (string.IsNullOrWhiteSpace(State.Name)) State.Name = layoutEntrySource.Layout.RgbLayout.Name ?? ""; if (string.IsNullOrWhiteSpace(State.Summary)) { @@ -108,7 +120,6 @@ public partial class LayoutInfoStepViewModel : SubmissionViewModel } State.Categories = new List {8}; // Device category, yes this could change but why would it - if (State.EntryId == null) State.ChangeScreen(); else diff --git a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/Layout/LayoutSelectionStepViewModel.cs b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/Layout/LayoutSelectionStepViewModel.cs index 83c788e68..9dc0899a1 100644 --- a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/Layout/LayoutSelectionStepViewModel.cs +++ b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/Layout/LayoutSelectionStepViewModel.cs @@ -12,6 +12,7 @@ using System.Threading.Tasks; using Artemis.UI.Screens.Workshop.SubmissionWizard.Models; using Artemis.UI.Shared.Extensions; using Artemis.UI.Shared.Services; +using Artemis.WebClient.Workshop.Handlers.UploadHandlers; using Avalonia.Media.Imaging; using Avalonia.Threading; using SkiaSharp; diff --git a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/Profile/ProfileAdaptionHintsStepViewModel.cs b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/Profile/ProfileAdaptionHintsStepViewModel.cs index 289ad846b..0e3556a96 100644 --- a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/Profile/ProfileAdaptionHintsStepViewModel.cs +++ b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/Profile/ProfileAdaptionHintsStepViewModel.cs @@ -9,6 +9,7 @@ using Artemis.Core.Services; using Artemis.UI.Screens.ProfileEditor.ProfileTree.Dialogs; using Artemis.UI.Screens.Workshop.SubmissionWizard.Models; using Artemis.UI.Shared.Services; +using Artemis.WebClient.Workshop.Handlers.UploadHandlers; using DynamicData; using DynamicData.Aggregation; using ReactiveUI; diff --git a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/Profile/ProfileSelectionStepViewModel.cs b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/Profile/ProfileSelectionStepViewModel.cs index 5845a47d8..d52457a55 100644 --- a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/Profile/ProfileSelectionStepViewModel.cs +++ b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/Profile/ProfileSelectionStepViewModel.cs @@ -8,6 +8,7 @@ using Artemis.Core.Services; using Artemis.UI.Extensions; using Artemis.UI.Screens.Workshop.Profile; using Artemis.UI.Screens.Workshop.SubmissionWizard.Models; +using Artemis.WebClient.Workshop.Handlers.UploadHandlers; using Material.Icons; using PropertyChanged.SourceGenerator; using ReactiveUI; diff --git a/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/EntryUploadHandlerFactory.cs b/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/EntryUploadHandlerFactory.cs index 17dc5245c..809c1c16b 100644 --- a/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/EntryUploadHandlerFactory.cs +++ b/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/EntryUploadHandlerFactory.cs @@ -1,5 +1,4 @@ -using Artemis.WebClient.Workshop.Handlers.UploadHandlers.Implementations; -using DryIoc; +using DryIoc; namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers; diff --git a/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/IEntrySource.cs b/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/IEntrySource.cs new file mode 100644 index 000000000..a24c24012 --- /dev/null +++ b/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/IEntrySource.cs @@ -0,0 +1,6 @@ +namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers; + +public interface IEntrySource +{ + +} \ No newline at end of file diff --git a/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/IEntryUploadHandler.cs b/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/IEntryUploadHandler.cs index 88ff68896..b391dd963 100644 --- a/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/IEntryUploadHandler.cs +++ b/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/IEntryUploadHandler.cs @@ -4,5 +4,5 @@ namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers; public interface IEntryUploadHandler { - Task CreateReleaseAsync(long entryId, object file, Progress progress, CancellationToken cancellationToken); + Task CreateReleaseAsync(long entryId, IEntrySource entrySource, Progress progress, CancellationToken cancellationToken); } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Models/LayoutEntrySource.cs b/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/Implementations/LayoutEntrySource.cs similarity index 58% rename from src/Artemis.UI/Screens/Workshop/SubmissionWizard/Models/LayoutEntrySource.cs rename to src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/Implementations/LayoutEntrySource.cs index c795a5b6b..765fb14c0 100644 --- a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Models/LayoutEntrySource.cs +++ b/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/Implementations/LayoutEntrySource.cs @@ -1,10 +1,6 @@ -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using Artemis.Core; -using Artemis.UI.Screens.Workshop.Layout; +using Artemis.Core; -namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Models; +namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers; public class LayoutEntrySource : IEntrySource { @@ -14,8 +10,8 @@ public class LayoutEntrySource : IEntrySource } public ArtemisLayout Layout { get; set; } - public ObservableCollection LayoutInfo { get; } = new(); - public KeyboardLayoutType PhysicalLayout { get; set; } + public List LayoutInfo { get; set; } = new(); + public Core.KeyboardLayoutType PhysicalLayout { get; set; } private List GetLogicalLayouts() { @@ -26,4 +22,11 @@ public class LayoutEntrySource : IEntrySource .DistinctBy(l => l.Name) .ToList(); } +} + +public class LayoutInfo +{ + public string Vendor { get; set; } = string.Empty; + public string Model { get; set; } = string.Empty; + public Guid DeviceProviderId { get; set; } } \ No newline at end of file diff --git a/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/Implementations/LayoutEntryUploadHandler.cs b/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/Implementations/LayoutEntryUploadHandler.cs index 0b16fae3d..90f9869c5 100644 --- a/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/Implementations/LayoutEntryUploadHandler.cs +++ b/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/Implementations/LayoutEntryUploadHandler.cs @@ -1,12 +1,25 @@ -using Artemis.UI.Shared.Utilities; +using System.Xml.Serialization; +using Artemis.UI.Shared.Utilities; +using RGB.NET.Layout; -namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers.Implementations; +namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers; public class LayoutEntryUploadHandler : IEntryUploadHandler { /// - public async Task CreateReleaseAsync(long entryId, object file, Progress progress, CancellationToken cancellationToken) + public async Task CreateReleaseAsync(long entryId, IEntrySource entrySource, Progress progress, CancellationToken cancellationToken) { - throw new NotImplementedException(); + if (entrySource is not LayoutEntrySource source) + throw new InvalidOperationException("Can only create releases for layouts"); + + // Create a copy of the layout, image paths are about to be rewritten + XmlSerializer serializer = new(typeof(DeviceLayout)); + using MemoryStream ms = new(); + await using StreamWriter writer = new(ms); + serializer.Serialize(writer, source.Layout.RgbLayout); + await writer.FlushAsync(); + ms.Seek(0, SeekOrigin.Begin); + + return new EntryUploadResult(); } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Models/ProfileEntrySource.cs b/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/Implementations/ProfileEntrySource.cs similarity index 81% rename from src/Artemis.UI/Screens/Workshop/SubmissionWizard/Models/ProfileEntrySource.cs rename to src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/Implementations/ProfileEntrySource.cs index 7bd076666..739f8e28f 100644 --- a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Models/ProfileEntrySource.cs +++ b/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/Implementations/ProfileEntrySource.cs @@ -1,6 +1,6 @@ using Artemis.Core; -namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Models; +namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers; public class ProfileEntrySource : IEntrySource { diff --git a/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/Implementations/ProfileEntryUploadHandler.cs b/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/Implementations/ProfileEntryUploadHandler.cs index 4ec607d85..9466cb92e 100644 --- a/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/Implementations/ProfileEntryUploadHandler.cs +++ b/src/Artemis.WebClient.Workshop/Handlers/UploadHandlers/Implementations/ProfileEntryUploadHandler.cs @@ -1,11 +1,10 @@ using System.Net.Http.Headers; -using Artemis.Core; using Artemis.Core.Services; using Artemis.UI.Shared.Utilities; using Artemis.WebClient.Workshop.Entities; using Newtonsoft.Json; -namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers.Implementations; +namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers; public class ProfileEntryUploadHandler : IEntryUploadHandler { @@ -19,12 +18,12 @@ public class ProfileEntryUploadHandler : IEntryUploadHandler } /// - public async Task CreateReleaseAsync(long entryId, object file, Progress progress, CancellationToken cancellationToken) + public async Task CreateReleaseAsync(long entryId, IEntrySource entrySource, Progress progress, CancellationToken cancellationToken) { - if (file is not ProfileConfiguration profileConfiguration) + if (entrySource is not ProfileEntrySource source) throw new InvalidOperationException("Can only create releases for profile configurations"); - await using Stream archiveStream = await _profileService.ExportProfile(profileConfiguration); + await using Stream archiveStream = await _profileService.ExportProfile(source.ProfileConfiguration); // Submit the archive HttpClient client = _httpClientFactory.CreateClient(WorkshopConstants.WORKSHOP_CLIENT_NAME);