mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Workshop Library - Finished basic implementation of installed tab
This commit is contained in:
1 parent
876465cfdb
commit
3d1e53e395
32 files changed
+407
-191
No files matched your search
@@ -48,4 +48,8 @@
|
||||
<Generator>MSBuild:GenerateGraphQLCode</Generator>
|
||||
</GraphQL>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Handlers\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,28 +0,0 @@
|
||||
using Artemis.Web.Workshop.Entities;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.DownloadHandlers;
|
||||
|
||||
public class EntryInstallResult<T>
|
||||
{
|
||||
public bool IsSuccess { get; set; }
|
||||
public string? Message { get; set; }
|
||||
public T? Result { get; set; }
|
||||
|
||||
public static EntryInstallResult<T> FromFailure(string? message)
|
||||
{
|
||||
return new EntryInstallResult<T>
|
||||
{
|
||||
IsSuccess = false,
|
||||
Message = message
|
||||
};
|
||||
}
|
||||
|
||||
public static EntryInstallResult<T> FromSuccess(T installationResult)
|
||||
{
|
||||
return new EntryInstallResult<T>
|
||||
{
|
||||
IsSuccess = true,
|
||||
Result = installationResult
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.DownloadHandlers;
|
||||
|
||||
public interface IEntryInstallationHandler
|
||||
{
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
using System.Reflection;
|
||||
using Artemis.WebClient.Workshop.DownloadHandlers;
|
||||
using Artemis.WebClient.Workshop.Extensions;
|
||||
using Artemis.WebClient.Workshop.Handlers.InstallationHandlers;
|
||||
using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
using Artemis.WebClient.Workshop.Repositories;
|
||||
using Artemis.WebClient.Workshop.Services;
|
||||
using Artemis.WebClient.Workshop.State;
|
||||
using Artemis.WebClient.Workshop.UploadHandlers;
|
||||
using DryIoc;
|
||||
using DryIoc.Microsoft.DependencyInjection;
|
||||
using IdentityModel.Client;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace Artemis.WebClient.Workshop.Handlers.InstallationHandlers;
|
||||
|
||||
public class EntryInstallResult
|
||||
{
|
||||
public bool IsSuccess { get; set; }
|
||||
public string? Message { get; set; }
|
||||
public object? Result { get; set; }
|
||||
|
||||
public static EntryInstallResult FromFailure(string? message)
|
||||
{
|
||||
return new EntryInstallResult
|
||||
{
|
||||
IsSuccess = false,
|
||||
Message = message
|
||||
};
|
||||
}
|
||||
|
||||
public static EntryInstallResult FromSuccess(object installationResult)
|
||||
{
|
||||
return new EntryInstallResult
|
||||
{
|
||||
IsSuccess = true,
|
||||
Result = installationResult
|
||||
};
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
using Artemis.WebClient.Workshop.Handlers.InstallationHandlers.Implementations;
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.Handlers.InstallationHandlers;
|
||||
|
||||
public class EntryInstallationHandlerFactory
|
||||
{
|
||||
private readonly IContainer _container;
|
||||
|
||||
public EntryInstallationHandlerFactory(IContainer container)
|
||||
{
|
||||
_container = container;
|
||||
}
|
||||
|
||||
public IEntryInstallationHandler CreateHandler(EntryType entryType)
|
||||
{
|
||||
return entryType switch
|
||||
{
|
||||
EntryType.Profile => _container.Resolve<ProfileEntryInstallationHandler>(),
|
||||
_ => throw new NotSupportedException($"EntryType '{entryType}' is not supported.")
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace Artemis.WebClient.Workshop.Handlers.InstallationHandlers;
|
||||
|
||||
public class EntryUninstallResult
|
||||
{
|
||||
public bool IsSuccess { get; set; }
|
||||
public string? Message { get; set; }
|
||||
|
||||
public static EntryUninstallResult FromFailure(string? message)
|
||||
{
|
||||
return new EntryUninstallResult
|
||||
{
|
||||
IsSuccess = false,
|
||||
Message = message
|
||||
};
|
||||
}
|
||||
|
||||
public static EntryUninstallResult FromSuccess()
|
||||
{
|
||||
return new EntryUninstallResult
|
||||
{
|
||||
IsSuccess = true
|
||||
};
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
using Artemis.WebClient.Workshop.Services;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.Handlers.InstallationHandlers;
|
||||
|
||||
public interface IEntryInstallationHandler
|
||||
{
|
||||
Task<EntryInstallResult> InstallAsync(IGetEntryById_Entry entry, Guid releaseId, Progress<StreamProgress> progress, CancellationToken cancellationToken);
|
||||
Task<EntryUninstallResult> UninstallAsync(InstalledEntry installedEntry, CancellationToken cancellationToken);
|
||||
}
|
||||
+32
-6
@@ -4,7 +4,7 @@ using Artemis.UI.Shared.Extensions;
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
using Artemis.WebClient.Workshop.Services;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.DownloadHandlers.Implementations;
|
||||
namespace Artemis.WebClient.Workshop.Handlers.InstallationHandlers.Implementations;
|
||||
|
||||
public class ProfileEntryInstallationHandler : IEntryInstallationHandler
|
||||
{
|
||||
@@ -19,7 +19,7 @@ public class ProfileEntryInstallationHandler : IEntryInstallationHandler
|
||||
_workshopService = workshopService;
|
||||
}
|
||||
|
||||
public async Task<EntryInstallResult<ProfileConfiguration>> InstallProfileAsync(IGetEntryById_Entry entry, Guid releaseId, Progress<StreamProgress> progress, CancellationToken cancellationToken)
|
||||
public async Task<EntryInstallResult> InstallAsync(IGetEntryById_Entry entry, Guid releaseId, Progress<StreamProgress> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
using MemoryStream stream = new();
|
||||
|
||||
@@ -31,7 +31,7 @@ public class ProfileEntryInstallationHandler : IEntryInstallationHandler
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return EntryInstallResult<ProfileConfiguration>.FromFailure(e.Message);
|
||||
return EntryInstallResult.FromFailure(e.Message);
|
||||
}
|
||||
|
||||
// Find existing installation to potentially replace the profile
|
||||
@@ -43,10 +43,10 @@ public class ProfileEntryInstallationHandler : IEntryInstallationHandler
|
||||
{
|
||||
ProfileConfiguration overwritten = await _profileService.OverwriteProfile(stream, existing);
|
||||
installedEntry.LocalReference = overwritten.ProfileId.ToString();
|
||||
|
||||
|
||||
// Update the release and return the profile configuration
|
||||
UpdateRelease(releaseId, installedEntry);
|
||||
return EntryInstallResult<ProfileConfiguration>.FromSuccess(overwritten);
|
||||
return EntryInstallResult.FromSuccess(overwritten);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,33 @@ public class ProfileEntryInstallationHandler : IEntryInstallationHandler
|
||||
|
||||
// Update the release and return the profile configuration
|
||||
UpdateRelease(releaseId, installedEntry);
|
||||
return EntryInstallResult<ProfileConfiguration>.FromSuccess(imported);
|
||||
return EntryInstallResult.FromSuccess(imported);
|
||||
}
|
||||
|
||||
public async Task<EntryUninstallResult> UninstallAsync(InstalledEntry installedEntry, CancellationToken cancellationToken)
|
||||
{
|
||||
if (!Guid.TryParse(installedEntry.LocalReference, out Guid profileId))
|
||||
return EntryUninstallResult.FromFailure("Local reference does not contain a GUID");
|
||||
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
// Find the profile if still there
|
||||
ProfileConfiguration? profile = _profileService.ProfileConfigurations.FirstOrDefault(c => c.ProfileId == profileId);
|
||||
if (profile != null)
|
||||
_profileService.DeleteProfile(profile);
|
||||
|
||||
// Remove the release
|
||||
_workshopService.RemoveInstalledEntry(installedEntry);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return EntryUninstallResult.FromFailure(e.Message);
|
||||
}
|
||||
|
||||
return EntryUninstallResult.FromSuccess();
|
||||
}, cancellationToken);
|
||||
}
|
||||
|
||||
private void UpdateRelease(Guid releaseId, InstalledEntry installedEntry)
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
using Artemis.WebClient.Workshop.UploadHandlers.Implementations;
|
||||
using Artemis.WebClient.Workshop.Handlers.UploadHandlers.Implementations;
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.UploadHandlers;
|
||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
|
||||
public class EntryUploadHandlerFactory
|
||||
{
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
using Artemis.Web.Workshop.Entities;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.UploadHandlers;
|
||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
|
||||
public class EntryUploadResult
|
||||
{
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.UploadHandlers;
|
||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
|
||||
public interface IEntryUploadHandler
|
||||
{
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace Artemis.WebClient.Workshop.UploadHandlers;
|
||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
|
||||
public class ImageUploadResult
|
||||
{
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.UploadHandlers.Implementations;
|
||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers.Implementations;
|
||||
|
||||
public class LayoutEntryUploadHandler : IEntryUploadHandler
|
||||
{
|
||||
+1
-2
@@ -1,12 +1,11 @@
|
||||
using System.Net.Http.Headers;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
using Artemis.Web.Workshop.Entities;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.UploadHandlers.Implementations;
|
||||
namespace Artemis.WebClient.Workshop.Handlers.UploadHandlers.Implementations;
|
||||
|
||||
public class ProfileEntryUploadHandler : IEntryUploadHandler
|
||||
{
|
||||
@@ -20,7 +20,6 @@ public class InstalledEntry
|
||||
|
||||
Author = entry.Author;
|
||||
Name = entry.Name;
|
||||
Summary = entry.Summary;
|
||||
}
|
||||
|
||||
public Guid EntryId { get; set; }
|
||||
@@ -28,7 +27,6 @@ public class InstalledEntry
|
||||
|
||||
public string Author { get; set; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Summary { get; set; } = string.Empty;
|
||||
|
||||
public Guid ReleaseId { get; set; }
|
||||
public string ReleaseVersion { get; set; } = string.Empty;
|
||||
@@ -45,7 +43,6 @@ public class InstalledEntry
|
||||
|
||||
Author = Entity.Author;
|
||||
Name = Entity.Name;
|
||||
Summary = Entity.Summary;
|
||||
|
||||
ReleaseId = Entity.ReleaseId;
|
||||
ReleaseVersion = Entity.ReleaseVersion;
|
||||
@@ -61,7 +58,6 @@ public class InstalledEntry
|
||||
|
||||
Entity.Author = Author;
|
||||
Entity.Name = Name;
|
||||
Entity.Summary = Summary;
|
||||
|
||||
Entity.ReleaseId = ReleaseId;
|
||||
Entity.ReleaseVersion = ReleaseVersion;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
using Artemis.WebClient.Workshop.UploadHandlers;
|
||||
using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.Services;
|
||||
|
||||
@@ -14,7 +14,9 @@ public interface IWorkshopService
|
||||
List<InstalledEntry> GetInstalledEntries();
|
||||
InstalledEntry? GetInstalledEntry(IGetEntryById_Entry entry);
|
||||
InstalledEntry CreateInstalledEntry(IGetEntryById_Entry entry);
|
||||
void RemoveInstalledEntry(InstalledEntry installedEntry);
|
||||
void SaveInstalledEntry(InstalledEntry entry);
|
||||
|
||||
|
||||
public record WorkshopStatus(bool IsReachable, string Message);
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using Artemis.Storage.Entities.Workshop;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using Artemis.UI.Shared.Routing;
|
||||
using Artemis.UI.Shared.Utilities;
|
||||
using Artemis.WebClient.Workshop.UploadHandlers;
|
||||
using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
|
||||
|
||||
namespace Artemis.WebClient.Workshop.Services;
|
||||
|
||||
@@ -124,6 +124,12 @@ public class WorkshopService : IWorkshopService
|
||||
return new InstalledEntry(entry);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void RemoveInstalledEntry(InstalledEntry installedEntry)
|
||||
{
|
||||
_entryRepository.Remove(installedEntry.Entity);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SaveInstalledEntry(InstalledEntry entry)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user