diff --git a/Common/Phantom.Common.Data.Web/EventLog/EventLogEventType.cs b/Common/Phantom.Common.Data.Web/EventLog/EventLogEventType.cs index a82c322..9e93109 100644 --- a/Common/Phantom.Common.Data.Web/EventLog/EventLogEventType.cs +++ b/Common/Phantom.Common.Data.Web/EventLog/EventLogEventType.cs @@ -7,7 +7,7 @@ public enum EventLogEventType { InstanceStopped, InstanceBackupSucceeded, InstanceBackupSucceededWithWarnings, - InstanceBackupFailed, + InstanceBackupFailed } public static class EventLogEventTypeExtensions { @@ -18,7 +18,7 @@ public static class EventLogEventTypeExtensions { { EventLogEventType.InstanceStopped, EventLogSubjectType.Instance }, { EventLogEventType.InstanceBackupSucceeded, EventLogSubjectType.Instance }, { EventLogEventType.InstanceBackupSucceededWithWarnings, EventLogSubjectType.Instance }, - { EventLogEventType.InstanceBackupFailed, EventLogSubjectType.Instance }, + { EventLogEventType.InstanceBackupFailed, EventLogSubjectType.Instance } }; static EventLogEventTypeExtensions() { diff --git a/Common/Phantom.Common.Data.Web/Users/LogInSuccess.cs b/Common/Phantom.Common.Data.Web/Users/LogInSuccess.cs index e09cc56..172e9b5 100644 --- a/Common/Phantom.Common.Data.Web/Users/LogInSuccess.cs +++ b/Common/Phantom.Common.Data.Web/Users/LogInSuccess.cs @@ -4,7 +4,7 @@ using MemoryPack; namespace Phantom.Common.Data.Web.Users; [MemoryPackable(GenerateType.VersionTolerant)] -public sealed partial record LogInSuccess ( +public sealed partial record LogInSuccess( [property: MemoryPackOrder(0)] Guid UserGuid, [property: MemoryPackOrder(1)] PermissionSet Permissions, [property: MemoryPackOrder(2)] ImmutableArray<byte> Token diff --git a/Common/Phantom.Common.Data/AuthToken.cs b/Common/Phantom.Common.Data/AuthToken.cs index 34d6078..67a5efb 100644 --- a/Common/Phantom.Common.Data/AuthToken.cs +++ b/Common/Phantom.Common.Data/AuthToken.cs @@ -14,9 +14,7 @@ public sealed partial class AuthToken { private readonly byte[] bytes; internal AuthToken(byte[]? bytes) { - if (bytes == null) { - throw new ArgumentNullException(nameof(bytes)); - } + ArgumentNullException.ThrowIfNull(bytes); if (bytes.Length != Length) { throw new ArgumentOutOfRangeException(nameof(bytes), "Invalid token length: " + bytes.Length + ". Token length must be exactly " + Length + " bytes."); diff --git a/Controller/Phantom.Controller.Database/ApplicationDbContext.cs b/Controller/Phantom.Controller.Database/ApplicationDbContext.cs index 57b770e..f3c313a 100644 --- a/Controller/Phantom.Controller.Database/ApplicationDbContext.cs +++ b/Controller/Phantom.Controller.Database/ApplicationDbContext.cs @@ -13,18 +13,18 @@ namespace Phantom.Controller.Database; [SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Global")] public class ApplicationDbContext : DbContext { - public DbSet<UserEntity> Users { get; set; } = null!; - public DbSet<RoleEntity> Roles { get; set; } = null!; - public DbSet<PermissionEntity> Permissions { get; set; } = null!; + public DbSet<UserEntity> Users { get; init; } = null!; + public DbSet<RoleEntity> Roles { get; init; } = null!; + public DbSet<PermissionEntity> Permissions { get; init; } = null!; - public DbSet<UserRoleEntity> UserRoles { get; set; } = null!; - public DbSet<UserPermissionEntity> UserPermissions { get; set; } = null!; - public DbSet<RolePermissionEntity> RolePermissions { get; set; } = null!; + public DbSet<UserRoleEntity> UserRoles { get; init; } = null!; + public DbSet<UserPermissionEntity> UserPermissions { get; init; } = null!; + public DbSet<RolePermissionEntity> RolePermissions { get; init; } = null!; - public DbSet<AgentEntity> Agents { get; set; } = null!; - public DbSet<InstanceEntity> Instances { get; set; } = null!; - public DbSet<AuditLogEntity> AuditLog { get; set; } = null!; - public DbSet<EventLogEntity> EventLog { get; set; } = null!; + public DbSet<AgentEntity> Agents { get; init; } = null!; + public DbSet<InstanceEntity> Instances { get; init; } = null!; + public DbSet<AuditLogEntity> AuditLog { get; init; } = null!; + public DbSet<EventLogEntity> EventLog { get; init; } = null!; public AgentEntityUpsert AgentUpsert { get; } public InstanceEntityUpsert InstanceUpsert { get; } diff --git a/Controller/Phantom.Controller.Database/Entities/AgentEntity.cs b/Controller/Phantom.Controller.Database/Entities/AgentEntity.cs index 0cc5bdd..efb1e34 100644 --- a/Controller/Phantom.Controller.Database/Entities/AgentEntity.cs +++ b/Controller/Phantom.Controller.Database/Entities/AgentEntity.cs @@ -9,7 +9,7 @@ namespace Phantom.Controller.Database.Entities; [SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Global")] public sealed class AgentEntity { [Key] - public Guid AgentGuid { get; set; } + public Guid AgentGuid { get; init; } public string Name { get; set; } public ushort ProtocolVersion { get; set; } diff --git a/Controller/Phantom.Controller.Database/Entities/AuditLogEntity.cs b/Controller/Phantom.Controller.Database/Entities/AuditLogEntity.cs index 255e558..0f7db37 100644 --- a/Controller/Phantom.Controller.Database/Entities/AuditLogEntity.cs +++ b/Controller/Phantom.Controller.Database/Entities/AuditLogEntity.cs @@ -13,16 +13,16 @@ public class AuditLogEntity : IDisposable { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] [SuppressMessage("ReSharper", "UnusedMember.Global")] - public long Id { get; set; } + public long Id { get; init; } - public Guid? UserGuid { get; set; } - public DateTime UtcTime { get; set; } // Note: Converting to UTC is not best practice, but for historical records it's good enough. - public AuditLogEventType EventType { get; set; } - public AuditLogSubjectType SubjectType { get; set; } - public string SubjectId { get; set; } - public JsonDocument? Data { get; set; } + public Guid? UserGuid { get; init; } + public DateTime UtcTime { get; init; } // Note: Converting to UTC is not best practice, but for historical records it's good enough. + public AuditLogEventType EventType { get; init; } + public AuditLogSubjectType SubjectType { get; init; } + public string SubjectId { get; init; } + public JsonDocument? Data { get; init; } - public virtual UserEntity? User { get; set; } + public virtual UserEntity? User { get; init; } [SuppressMessage("ReSharper", "UnusedMember.Global")] internal AuditLogEntity() { diff --git a/Controller/Phantom.Controller.Database/Entities/EventLogEntity.cs b/Controller/Phantom.Controller.Database/Entities/EventLogEntity.cs index 361bd03..5c666ef 100644 --- a/Controller/Phantom.Controller.Database/Entities/EventLogEntity.cs +++ b/Controller/Phantom.Controller.Database/Entities/EventLogEntity.cs @@ -11,14 +11,14 @@ namespace Phantom.Controller.Database.Entities; [SuppressMessage("ReSharper", "ClassWithVirtualMembersNeverInherited.Global")] public sealed class EventLogEntity : IDisposable { [Key] - public Guid EventGuid { get; set; } + public Guid EventGuid { get; init; } - public DateTime UtcTime { get; set; } // Note: Converting to UTC is not best practice, but for historical records it's good enough. - public Guid? AgentGuid { get; set; } - public EventLogEventType EventType { get; set; } - public EventLogSubjectType SubjectType { get; set; } - public string SubjectId { get; set; } - public JsonDocument? Data { get; set; } + public DateTime UtcTime { get; init; } // Note: Converting to UTC is not best practice, but for historical records it's good enough. + public Guid? AgentGuid { get; init; } + public EventLogEventType EventType { get; init; } + public EventLogSubjectType SubjectType { get; init; } + public string SubjectId { get; init; } + public JsonDocument? Data { get; init; } [SuppressMessage("ReSharper", "UnusedMember.Global")] internal EventLogEntity() { diff --git a/Controller/Phantom.Controller.Database/Entities/InstanceEntity.cs b/Controller/Phantom.Controller.Database/Entities/InstanceEntity.cs index 6419a62..fccaf2b 100644 --- a/Controller/Phantom.Controller.Database/Entities/InstanceEntity.cs +++ b/Controller/Phantom.Controller.Database/Entities/InstanceEntity.cs @@ -11,7 +11,7 @@ namespace Phantom.Controller.Database.Entities; [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] public sealed class InstanceEntity { [Key] - public Guid InstanceGuid { get; set; } + public Guid InstanceGuid { get; init; } public Guid AgentGuid { get; set; } diff --git a/Controller/Phantom.Controller.Database/Entities/PermissionEntity.cs b/Controller/Phantom.Controller.Database/Entities/PermissionEntity.cs index 2da43eb..0422b7d 100644 --- a/Controller/Phantom.Controller.Database/Entities/PermissionEntity.cs +++ b/Controller/Phantom.Controller.Database/Entities/PermissionEntity.cs @@ -6,7 +6,7 @@ namespace Phantom.Controller.Database.Entities; [Table("Permissions", Schema = "identity")] public sealed class PermissionEntity { [Key] - public string Id { get; set; } + public string Id { get; init; } public PermissionEntity(string id) { Id = id; diff --git a/Controller/Phantom.Controller.Database/Entities/RoleEntity.cs b/Controller/Phantom.Controller.Database/Entities/RoleEntity.cs index b76c361..2d20c42 100644 --- a/Controller/Phantom.Controller.Database/Entities/RoleEntity.cs +++ b/Controller/Phantom.Controller.Database/Entities/RoleEntity.cs @@ -7,9 +7,9 @@ namespace Phantom.Controller.Database.Entities; [Table("Roles", Schema = "identity")] public sealed class RoleEntity { [Key] - public Guid RoleGuid { get; set; } + public Guid RoleGuid { get; init; } - public string Name { get; set; } + public string Name { get; init; } public RoleEntity(Guid roleGuid, string name) { RoleGuid = roleGuid; diff --git a/Controller/Phantom.Controller.Database/Entities/RolePermissionEntity.cs b/Controller/Phantom.Controller.Database/Entities/RolePermissionEntity.cs index 72be1bb..4dfdb04 100644 --- a/Controller/Phantom.Controller.Database/Entities/RolePermissionEntity.cs +++ b/Controller/Phantom.Controller.Database/Entities/RolePermissionEntity.cs @@ -4,8 +4,8 @@ namespace Phantom.Controller.Database.Entities; [Table("RolePermissions", Schema = "identity")] public sealed class RolePermissionEntity { - public Guid RoleGuid { get; set; } - public string PermissionId { get; set; } + public Guid RoleGuid { get; init; } + public string PermissionId { get; init; } public RolePermissionEntity(Guid roleGuid, string permissionId) { RoleGuid = roleGuid; diff --git a/Controller/Phantom.Controller.Database/Entities/UserEntity.cs b/Controller/Phantom.Controller.Database/Entities/UserEntity.cs index da4b72c..7f90058 100644 --- a/Controller/Phantom.Controller.Database/Entities/UserEntity.cs +++ b/Controller/Phantom.Controller.Database/Entities/UserEntity.cs @@ -7,9 +7,9 @@ namespace Phantom.Controller.Database.Entities; [Table("Users", Schema = "identity")] public sealed class UserEntity { [Key] - public Guid UserGuid { get; set; } + public Guid UserGuid { get; init; } - public string Name { get; set; } + public string Name { get; init; } public string PasswordHash { get; set; } public UserEntity(Guid userGuid, string name, string passwordHash) { diff --git a/Controller/Phantom.Controller.Database/Entities/UserPermissionEntity.cs b/Controller/Phantom.Controller.Database/Entities/UserPermissionEntity.cs index 332b66f..2515f21 100644 --- a/Controller/Phantom.Controller.Database/Entities/UserPermissionEntity.cs +++ b/Controller/Phantom.Controller.Database/Entities/UserPermissionEntity.cs @@ -4,8 +4,8 @@ namespace Phantom.Controller.Database.Entities; [Table("UserPermissions", Schema = "identity")] public sealed class UserPermissionEntity { - public Guid UserGuid { get; set; } - public string PermissionId { get; set; } + public Guid UserGuid { get; init; } + public string PermissionId { get; init; } public UserPermissionEntity(Guid userGuid, string permissionId) { UserGuid = userGuid; diff --git a/Controller/Phantom.Controller.Database/Entities/UserRoleEntity.cs b/Controller/Phantom.Controller.Database/Entities/UserRoleEntity.cs index 5d20d05..3168936 100644 --- a/Controller/Phantom.Controller.Database/Entities/UserRoleEntity.cs +++ b/Controller/Phantom.Controller.Database/Entities/UserRoleEntity.cs @@ -4,11 +4,11 @@ namespace Phantom.Controller.Database.Entities; [Table("UserRoles", Schema = "identity")] public sealed class UserRoleEntity { - public Guid UserGuid { get; set; } - public Guid RoleGuid { get; set; } + public Guid UserGuid { get; init; } + public Guid RoleGuid { get; init; } - public UserEntity User { get; set; } - public RoleEntity Role { get; set; } + public UserEntity User { get; init; } + public RoleEntity Role { get; init; } public UserRoleEntity(Guid userGuid, Guid roleGuid) { UserGuid = userGuid; diff --git a/Controller/Phantom.Controller.Services/Rpc/AgentMessageHandlerActor.cs b/Controller/Phantom.Controller.Services/Rpc/AgentMessageHandlerActor.cs index e4d2a8f..19225c3 100644 --- a/Controller/Phantom.Controller.Services/Rpc/AgentMessageHandlerActor.cs +++ b/Controller/Phantom.Controller.Services/Rpc/AgentMessageHandlerActor.cs @@ -1,5 +1,4 @@ -using Akka.Actor; -using Phantom.Common.Data.Replies; +using Phantom.Common.Data.Replies; using Phantom.Common.Messages.Agent; using Phantom.Common.Messages.Agent.BiDirectional; using Phantom.Common.Messages.Agent.ToAgent; @@ -19,8 +18,6 @@ sealed class AgentMessageHandlerActor : ReceiveActor<IMessageToController> { return Props<IMessageToController>.Create(() => new AgentMessageHandlerActor(init), new ActorConfiguration { SupervisorStrategy = SupervisorStrategies.Resume }); } - public IStash Stash { get; set; } = null!; - private readonly Guid agentGuid; private readonly RpcConnectionToClient<IMessageToAgent> connection; private readonly AgentRegistrationHandler agentRegistrationHandler; diff --git a/Utils/Phantom.Utils.Actor/Mailbox/UnboundedJumpAheadMailbox.cs b/Utils/Phantom.Utils.Actor/Mailbox/UnboundedJumpAheadMailbox.cs index bc2d2f3..58bc8a4 100644 --- a/Utils/Phantom.Utils.Actor/Mailbox/UnboundedJumpAheadMailbox.cs +++ b/Utils/Phantom.Utils.Actor/Mailbox/UnboundedJumpAheadMailbox.cs @@ -1,10 +1,12 @@ -using Akka.Actor; +using System.Diagnostics.CodeAnalysis; +using Akka.Actor; using Akka.Configuration; using Akka.Dispatch; using Akka.Dispatch.MessageQueues; namespace Phantom.Utils.Actor.Mailbox; +[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] public sealed class UnboundedJumpAheadMailbox : MailboxType, IProducesMessageQueue<UnboundedJumpAheadMessageQueue> { public const string Name = "unbounded-jump-ahead-mailbox"; diff --git a/Utils/Phantom.Utils.Rpc/Runtime/RpcConnectionToClient.cs b/Utils/Phantom.Utils.Rpc/Runtime/RpcConnectionToClient.cs index 788c6a0..6223d8c 100644 --- a/Utils/Phantom.Utils.Rpc/Runtime/RpcConnectionToClient.cs +++ b/Utils/Phantom.Utils.Rpc/Runtime/RpcConnectionToClient.cs @@ -9,7 +9,7 @@ public sealed class RpcConnectionToClient<TMessageBase> : RpcConnection<TMessage private readonly uint routingId; internal event EventHandler<RpcClientConnectionClosedEventArgs>? Closed; - public bool IsClosed { get; private set; } + private bool isClosed; internal RpcConnectionToClient(ServerSocket socket, uint routingId, MessageRegistry<TMessageBase> messageRegistry, MessageReplyTracker replyTracker) : base(messageRegistry, replyTracker) { this.socket = socket; @@ -24,8 +24,8 @@ public sealed class RpcConnectionToClient<TMessageBase> : RpcConnection<TMessage bool hasClosed = false; lock (this) { - if (!IsClosed) { - IsClosed = true; + if (!isClosed) { + isClosed = true; hasClosed = true; } } diff --git a/Utils/Phantom.Utils.Tests/Runtime/EnvironmentVariablesTests.cs b/Utils/Phantom.Utils.Tests/Runtime/EnvironmentVariablesTests.cs index 0242e72..9011ee1 100644 --- a/Utils/Phantom.Utils.Tests/Runtime/EnvironmentVariablesTests.cs +++ b/Utils/Phantom.Utils.Tests/Runtime/EnvironmentVariablesTests.cs @@ -12,7 +12,7 @@ public class EnvironmentVariablesTests { private readonly HashSet<string> createdVariables = new (); private static void Discard<T>(T value) { - var _ = value; + _ = value; } private string CreateVariable(string value) { diff --git a/Utils/Phantom.Utils/Collections/EnumerableExtensions.cs b/Utils/Phantom.Utils/Collections/EnumerableExtensions.cs index 9407074..b31eae3 100644 --- a/Utils/Phantom.Utils/Collections/EnumerableExtensions.cs +++ b/Utils/Phantom.Utils/Collections/EnumerableExtensions.cs @@ -1,18 +1,8 @@ using System.Collections.Immutable; -using System.Diagnostics.CodeAnalysis; namespace Phantom.Utils.Collections; public static class EnumerableExtensions { - [SuppressMessage("ReSharper", "LoopCanBeConvertedToQuery")] - public static IEnumerable<TSource> WhereNotNull<TSource>(this IEnumerable<TSource?> items) { - foreach (var item in items) { - if (item is not null) { - yield return item; - } - } - } - public static async Task<ImmutableArray<TSource>> ToImmutableArrayAsync<TSource>(this IAsyncEnumerable<TSource> source, CancellationToken cancellationToken = default) { var builder = ImmutableArray.CreateBuilder<TSource>(); diff --git a/Utils/Phantom.Utils/Collections/TableData.cs b/Utils/Phantom.Utils/Collections/TableData.cs index 42ac5af..5a2c924 100644 --- a/Utils/Phantom.Utils/Collections/TableData.cs +++ b/Utils/Phantom.Utils/Collections/TableData.cs @@ -5,7 +5,7 @@ using System.Diagnostics.CodeAnalysis; namespace Phantom.Utils.Collections; public sealed class TableData<TRow, TKey> : IReadOnlyList<TRow>, IReadOnlyDictionary<TKey, TRow> where TRow : notnull where TKey : notnull { - private readonly List<TRow> rowList = new(); + private readonly List<TRow> rowList = new (); private readonly Dictionary<TKey, TRow> rowDictionary = new (); public TRow this[int index] => rowList[index]; diff --git a/Utils/Phantom.Utils/Tasks/Result.cs b/Utils/Phantom.Utils/Tasks/Result.cs index 4988ef4..4345dd8 100644 --- a/Utils/Phantom.Utils/Tasks/Result.cs +++ b/Utils/Phantom.Utils/Tasks/Result.cs @@ -1,4 +1,6 @@ -namespace Phantom.Utils.Tasks; +using System.Diagnostics.CodeAnalysis; + +namespace Phantom.Utils.Tasks; public abstract record Result<TValue, TError> { private Result() {} @@ -42,7 +44,7 @@ public abstract record Result<TError> { return new Fail(error); } - public static implicit operator Result<TError>(Result.OkType _) { + public static implicit operator Result<TError>([SuppressMessage("ReSharper", "UnusedParameter.Global")] Result.OkType _) { return new Ok(); } diff --git a/Utils/Phantom.Utils/Threading/ThreadSafeLinkedList.cs b/Utils/Phantom.Utils/Threading/ThreadSafeLinkedList.cs deleted file mode 100644 index 21ab03f..0000000 --- a/Utils/Phantom.Utils/Threading/ThreadSafeLinkedList.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace Phantom.Utils.Threading; - -public sealed class ThreadSafeLinkedList<T> : IDisposable { - private readonly LinkedList<T> list = new (); - private readonly SemaphoreSlim semaphore = new (1, 1); - - public async Task Add(T item, bool toFront, CancellationToken cancellationToken) { - await semaphore.WaitAsync(cancellationToken); - try { - if (toFront) { - list.AddFirst(item); - } - else { - list.AddLast(item); - } - } finally { - semaphore.Release(); - } - } - - public async Task<T?> TryTakeFromFront(CancellationToken cancellationToken) { - await semaphore.WaitAsync(cancellationToken); - try { - var firstNode = list.First; - if (firstNode == null) { - return default; - } - - list.RemoveFirst(); - return firstNode.Value; - } finally { - semaphore.Release(); - } - } - - public void Dispose() { - semaphore.Dispose(); - } -} diff --git a/Utils/Phantom.Utils/Threading/ThreadSafeStructRef.cs b/Utils/Phantom.Utils/Threading/ThreadSafeStructRef.cs deleted file mode 100644 index 406ad6f..0000000 --- a/Utils/Phantom.Utils/Threading/ThreadSafeStructRef.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace Phantom.Utils.Threading; - -public sealed class ThreadSafeStructRef<T> : IDisposable where T : struct { - private T? value; - private readonly SemaphoreSlim semaphore = new (1, 1); - - public async Task<T?> Get(CancellationToken cancellationToken) { - await semaphore.WaitAsync(cancellationToken); - try { - return value; - } finally { - semaphore.Release(); - } - } - - public async Task Set(T? value, CancellationToken cancellationToken) { - await semaphore.WaitAsync(cancellationToken); - try { - this.value = value; - } finally { - semaphore.Release(); - } - } - - public void Dispose() { - semaphore.Dispose(); - } -}