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:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
13
Moonlight/Core/Extensions/ConfigurationBuilderExtensions.cs
Normal file
13
Moonlight/Core/Extensions/ConfigurationBuilderExtensions.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
37
Moonlight/Core/Extensions/EventHandlerExtensions.cs
Normal file
37
Moonlight/Core/Extensions/EventHandlerExtensions.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
26
Moonlight/Core/Extensions/ZipArchiveExtension.cs
Normal file
26
Moonlight/Core/Extensions/ZipArchiveExtension.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user