After the first try literally gave me a head ace, there is the second try with a better way of structuring it and not divinding so much core components in individual features. Still not done though

This commit is contained in:
Marcel Baumgartner
2024-01-25 21:40:23 +01:00
parent bb53f1c40a
commit 63b2b40227
228 changed files with 1143 additions and 1049 deletions

View File

@@ -0,0 +1,20 @@
using Moonlight.Core.Models.Enums;
namespace Moonlight.Core.Extensions.Attributes;
public class RequirePermissionAttribute : Attribute
{
public int PermissionInteger = 0;
public RequirePermissionAttribute(){}
public RequirePermissionAttribute(int perms)
{
PermissionInteger = perms;
}
public RequirePermissionAttribute(Permission permission)
{
PermissionInteger = (int)permission;
}
}

View File

@@ -0,0 +1,8 @@
namespace Moonlight.Core.Extensions.Attributes;
public class SelectorAttribute : Attribute
{
public string SelectorProp { get; set; } = "";
public string DisplayProp { get; set; } = "";
public bool UseDropdown { get; set; } = false;
}

View File

@@ -0,0 +1,13 @@
using System.Text;
namespace Moonlight.Core.Extensions;
public static class ConfigurationBuilderExtensions
{
public static IConfigurationBuilder AddJsonString(this IConfigurationBuilder configurationBuilder, string json)
{
var bytes = Encoding.UTF8.GetBytes(json);
var stream = new MemoryStream(bytes);
return configurationBuilder.AddJsonStream(stream);
}
}

View File

@@ -0,0 +1,37 @@
namespace Moonlight.Core.Extensions;
public static class EventHandlerExtensions
{
public static async Task InvokeAsync(this EventHandler handler)
{
var tasks = handler
.GetInvocationList()
.Select(x => new Task(() => x.DynamicInvoke(null, null)))
.ToArray();
foreach (var task in tasks)
{
task.Start();
}
await Task.WhenAll(tasks);
}
public static async Task InvokeAsync<T>(this EventHandler<T>? handler, T? data = default(T))
{
if(handler == null)
return;
var tasks = handler
.GetInvocationList()
.Select(x => new Task(() => x.DynamicInvoke(null, data)))
.ToArray();
foreach (var task in tasks)
{
task.Start();
}
await Task.WhenAll(tasks);
}
}

View File

@@ -0,0 +1,26 @@
using System.IO.Compression;
using System.Text;
namespace Moonlight.Core.Extensions;
public static class ZipArchiveExtension
{
public static async Task AddFromText(this ZipArchive archive, string entryName, string content)
{
using var memoryStream = new MemoryStream();
await memoryStream.WriteAsync(Encoding.UTF8.GetBytes(content));
await memoryStream.FlushAsync();
await archive.AddFromStream(entryName, memoryStream);
}
public static async Task AddFromStream(this ZipArchive archive, string entryName, Stream dataStream)
{
var entry = archive.CreateEntry(entryName, CompressionLevel.Fastest);
await using var stream = entry.Open();
dataStream.Position = 0;
await dataStream.CopyToAsync(stream);
await stream.FlushAsync();
}
}