1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Move IEntrySource to workshop

This commit is contained in:
Robert 2023-11-01 20:19:00 +01:00
parent c1e0dadce8
commit 59fe1df40f
13 changed files with 63 additions and 34 deletions

View File

@ -1,6 +0,0 @@
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Models;
public interface IEntrySource
{
}

View File

@ -5,6 +5,7 @@ using Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Layout;
using Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile; using Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile;
using Artemis.UI.Shared.Services; using Artemis.UI.Shared.Services;
using Artemis.WebClient.Workshop; using Artemis.WebClient.Workshop;
using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
using DryIoc; using DryIoc;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Models; namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Models;

View File

@ -6,7 +6,7 @@ using System.Reactive.Disposables;
using System.Reactive.Linq; using System.Reactive.Linq;
using Artemis.Core; using Artemis.Core;
using Artemis.UI.Screens.Workshop.Layout; using Artemis.UI.Screens.Workshop.Layout;
using Artemis.UI.Screens.Workshop.SubmissionWizard.Models; using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
using PropertyChanged.SourceGenerator; using PropertyChanged.SourceGenerator;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Validation.Extensions; using ReactiveUI.Validation.Extensions;
@ -40,7 +40,7 @@ public partial class LayoutInfoStepViewModel : SubmissionViewModel
_layout = layoutEntrySource.Layout; _layout = layoutEntrySource.Layout;
IsKeyboardLayout = _layout.RgbLayout.Type == RGBDeviceType.Keyboard; IsKeyboardLayout = _layout.RgbLayout.Type == RGBDeviceType.Keyboard;
PhysicalLayout = layoutEntrySource.PhysicalLayout; PhysicalLayout = layoutEntrySource.PhysicalLayout;
LayoutInfo = layoutEntrySource.LayoutInfo; LayoutInfo = new ObservableCollection<LayoutInfoViewModel>(layoutEntrySource.LayoutInfo.Select(CreateLayoutInfoViewModel));
if (!LayoutInfo.Any()) if (!LayoutInfo.Any())
ExecuteAddLayoutInfo(); ExecuteAddLayoutInfo();
@ -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() private void ExecuteAddLayoutInfo()
{ {
if (_layout == null) if (_layout == null)
@ -74,6 +85,7 @@ public partial class LayoutInfoStepViewModel : SubmissionViewModel
return; return;
layoutEntrySource.PhysicalLayout = PhysicalLayout; layoutEntrySource.PhysicalLayout = PhysicalLayout;
// layoutEntrySource.LayoutInfo = new List<LayoutInfo>(LayoutInfo.Select(i => i.ToLayoutInfo()));
if (string.IsNullOrWhiteSpace(State.Name)) if (string.IsNullOrWhiteSpace(State.Name))
State.Name = layoutEntrySource.Layout.RgbLayout.Name ?? ""; State.Name = layoutEntrySource.Layout.RgbLayout.Name ?? "";
@ -108,7 +120,6 @@ public partial class LayoutInfoStepViewModel : SubmissionViewModel
} }
State.Categories = new List<long> {8}; // Device category, yes this could change but why would it State.Categories = new List<long> {8}; // Device category, yes this could change but why would it
if (State.EntryId == null) if (State.EntryId == null)
State.ChangeScreen<SpecificationsStepViewModel>(); State.ChangeScreen<SpecificationsStepViewModel>();
else else

View File

@ -12,6 +12,7 @@ using System.Threading.Tasks;
using Artemis.UI.Screens.Workshop.SubmissionWizard.Models; using Artemis.UI.Screens.Workshop.SubmissionWizard.Models;
using Artemis.UI.Shared.Extensions; using Artemis.UI.Shared.Extensions;
using Artemis.UI.Shared.Services; using Artemis.UI.Shared.Services;
using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
using Avalonia.Media.Imaging; using Avalonia.Media.Imaging;
using Avalonia.Threading; using Avalonia.Threading;
using SkiaSharp; using SkiaSharp;

View File

@ -9,6 +9,7 @@ using Artemis.Core.Services;
using Artemis.UI.Screens.ProfileEditor.ProfileTree.Dialogs; using Artemis.UI.Screens.ProfileEditor.ProfileTree.Dialogs;
using Artemis.UI.Screens.Workshop.SubmissionWizard.Models; using Artemis.UI.Screens.Workshop.SubmissionWizard.Models;
using Artemis.UI.Shared.Services; using Artemis.UI.Shared.Services;
using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
using DynamicData; using DynamicData;
using DynamicData.Aggregation; using DynamicData.Aggregation;
using ReactiveUI; using ReactiveUI;

View File

@ -8,6 +8,7 @@ using Artemis.Core.Services;
using Artemis.UI.Extensions; using Artemis.UI.Extensions;
using Artemis.UI.Screens.Workshop.Profile; using Artemis.UI.Screens.Workshop.Profile;
using Artemis.UI.Screens.Workshop.SubmissionWizard.Models; using Artemis.UI.Screens.Workshop.SubmissionWizard.Models;
using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
using Material.Icons; using Material.Icons;
using PropertyChanged.SourceGenerator; using PropertyChanged.SourceGenerator;
using ReactiveUI; using ReactiveUI;

View File

@ -1,5 +1,4 @@
using Artemis.WebClient.Workshop.Handlers.UploadHandlers.Implementations; using DryIoc;
using DryIoc;
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers; namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;

View File

@ -0,0 +1,6 @@
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
public interface IEntrySource
{
}

View File

@ -4,5 +4,5 @@ namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
public interface IEntryUploadHandler public interface IEntryUploadHandler
{ {
Task<EntryUploadResult> CreateReleaseAsync(long entryId, object file, Progress<StreamProgress> progress, CancellationToken cancellationToken); Task<EntryUploadResult> CreateReleaseAsync(long entryId, IEntrySource entrySource, Progress<StreamProgress> progress, CancellationToken cancellationToken);
} }

View File

@ -1,10 +1,6 @@
using System.Collections.Generic; using Artemis.Core;
using System.Collections.ObjectModel;
using System.Linq;
using Artemis.Core;
using Artemis.UI.Screens.Workshop.Layout;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Models; namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
public class LayoutEntrySource : IEntrySource public class LayoutEntrySource : IEntrySource
{ {
@ -14,8 +10,8 @@ public class LayoutEntrySource : IEntrySource
} }
public ArtemisLayout Layout { get; set; } public ArtemisLayout Layout { get; set; }
public ObservableCollection<LayoutInfoViewModel> LayoutInfo { get; } = new(); public List<LayoutInfo> LayoutInfo { get; set; } = new();
public KeyboardLayoutType PhysicalLayout { get; set; } public Core.KeyboardLayoutType PhysicalLayout { get; set; }
private List<LayoutCustomLedDataLogicalLayout> GetLogicalLayouts() private List<LayoutCustomLedDataLogicalLayout> GetLogicalLayouts()
{ {
@ -27,3 +23,10 @@ public class LayoutEntrySource : IEntrySource
.ToList(); .ToList();
} }
} }
public class LayoutInfo
{
public string Vendor { get; set; } = string.Empty;
public string Model { get; set; } = string.Empty;
public Guid DeviceProviderId { get; set; }
}

View File

@ -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 class LayoutEntryUploadHandler : IEntryUploadHandler
{ {
/// <inheritdoc /> /// <inheritdoc />
public async Task<EntryUploadResult> CreateReleaseAsync(long entryId, object file, Progress<StreamProgress> progress, CancellationToken cancellationToken) public async Task<EntryUploadResult> CreateReleaseAsync(long entryId, IEntrySource entrySource, Progress<StreamProgress> 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();
} }
} }

View File

@ -1,6 +1,6 @@
using Artemis.Core; using Artemis.Core;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Models; namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
public class ProfileEntrySource : IEntrySource public class ProfileEntrySource : IEntrySource
{ {

View File

@ -1,11 +1,10 @@
using System.Net.Http.Headers; using System.Net.Http.Headers;
using Artemis.Core;
using Artemis.Core.Services; using Artemis.Core.Services;
using Artemis.UI.Shared.Utilities; using Artemis.UI.Shared.Utilities;
using Artemis.WebClient.Workshop.Entities; using Artemis.WebClient.Workshop.Entities;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers.Implementations; namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
public class ProfileEntryUploadHandler : IEntryUploadHandler public class ProfileEntryUploadHandler : IEntryUploadHandler
{ {
@ -19,12 +18,12 @@ public class ProfileEntryUploadHandler : IEntryUploadHandler
} }
/// <inheritdoc /> /// <inheritdoc />
public async Task<EntryUploadResult> CreateReleaseAsync(long entryId, object file, Progress<StreamProgress> progress, CancellationToken cancellationToken) public async Task<EntryUploadResult> CreateReleaseAsync(long entryId, IEntrySource entrySource, Progress<StreamProgress> 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"); 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 // Submit the archive
HttpClient client = _httpClientFactory.CreateClient(WorkshopConstants.WORKSHOP_CLIENT_NAME); HttpClient client = _httpClientFactory.CreateClient(WorkshopConstants.WORKSHOP_CLIENT_NAME);