mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
Move IEntrySource to workshop
This commit is contained in:
1 parent
c1e0dadce8
commit
59fe1df40f
13 files changed
+63
-34
No files matched your search
@@ -1,5 +1,4 @@
|
||||
using Artemis.WebClient.Workshop.Handlers.UploadHandlers.Implementations;
|
||||
using DryIoc;
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
|
||||
public interface IEntrySource
|
||||
{
|
||||
|
||||
}
|
||||
@@ -4,5 +4,5 @@ namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
|
||||
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);
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
using Artemis.Core;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
|
||||
public class LayoutEntrySource : IEntrySource
|
||||
{
|
||||
public LayoutEntrySource(ArtemisLayout layout)
|
||||
{
|
||||
Layout = layout;
|
||||
}
|
||||
|
||||
public ArtemisLayout Layout { get; set; }
|
||||
public List<LayoutInfo> LayoutInfo { get; set; } = new();
|
||||
public Core.KeyboardLayoutType PhysicalLayout { get; set; }
|
||||
|
||||
private List<LayoutCustomLedDataLogicalLayout> GetLogicalLayouts()
|
||||
{
|
||||
return Layout.Leds
|
||||
.Where(l => l.LayoutCustomLedData.LogicalLayouts != null)
|
||||
.SelectMany(l => l.LayoutCustomLedData.LogicalLayouts!)
|
||||
.Where(l => !string.IsNullOrWhiteSpace(l.Name))
|
||||
.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; }
|
||||
}
|
||||
+17
-4
@@ -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
|
||||
{
|
||||
/// <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();
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
using Artemis.Core;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
|
||||
public class ProfileEntrySource : IEntrySource
|
||||
{
|
||||
public ProfileEntrySource(ProfileConfiguration profileConfiguration)
|
||||
{
|
||||
ProfileConfiguration = profileConfiguration;
|
||||
}
|
||||
|
||||
public ProfileConfiguration ProfileConfiguration { get; set; }
|
||||
}
|
||||
+4
-5
@@ -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
|
||||
}
|
||||
|
||||
/// <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");
|
||||
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user