Storage - Use nullable reference types

Core - Fix build warnings
This commit is contained in:
Robert committed 2024-02-23 17:35:06 +01:00
1 parent f0e9581fe1
commit 248d4c8e18
65 files changed
+318 -159

No files matched your search

@@ -7,6 +7,9 @@ using System.Threading;
namespace Artemis.Core.Services;
/// <summary>
/// Represents a monitor that efficiently keeps track of running processes.
/// </summary>
public static partial class ProcessMonitor
{
#region Properties & Fields
@@ -15,8 +18,11 @@ public static partial class ProcessMonitor
private static Timer? _timer;
private static Dictionary<int, ProcessInfo> _processes = new();
private static readonly Dictionary<int, ProcessInfo> _processes = new();
/// <summary>
/// Gets an immutable array of the current processes.
/// </summary>
public static ImmutableArray<ProcessInfo> Processes
{
get
@@ -25,9 +31,17 @@ public static partial class ProcessMonitor
return _processes.Values.ToImmutableArray();
}
}
/// <summary>
/// Gets the date time at which the last update took place.
/// </summary>
public static DateTime LastUpdate { get; private set; }
private static TimeSpan _updateInterval = TimeSpan.FromSeconds(1);
/// <summary>
/// Gets or sets the interval at which to update the list of processes.
/// </summary>
public static TimeSpan UpdateInterval
{
get => _updateInterval;
@@ -40,6 +54,9 @@ public static partial class ProcessMonitor
}
}
/// <summary>
/// Gets a value indicating whether the monitoring has started.
/// </summary>
public static bool IsStarted
{
get
@@ -53,7 +70,14 @@ public static partial class ProcessMonitor
#region Events
/// <summary>
/// Occurs when a new process is started.
/// </summary>
public static event EventHandler<ProcessEventArgs>? ProcessStarted;
/// <summary>
/// Occurs when a process is stopped.
/// </summary>
public static event EventHandler<ProcessEventArgs>? ProcessStopped;
#endregion
@@ -69,6 +93,9 @@ public static partial class ProcessMonitor
#region Methods
/// <summary>
/// Starts monitoring processes.
/// </summary>
public static void Start()
{
lock (LOCK)
@@ -87,6 +114,9 @@ public static partial class ProcessMonitor
}
}
/// <summary>
/// Stops monitoring processes.
/// </summary>
public static void Stop()
{
lock (LOCK)
@@ -100,7 +130,7 @@ public static partial class ProcessMonitor
FreeBuffer();
}
}
/// <summary>
/// Returns whether the specified process is running
/// </summary>
@@ -111,7 +141,7 @@ public static partial class ProcessMonitor
{
if (!IsStarted || (processName == null && processLocation == null))
return false;
lock (LOCK)
{
return _processes.Values.Any(x => IsProcessRunning(x, processName, processLocation));
@@ -130,19 +160,19 @@ public static partial class ProcessMonitor
OnProcessStopped(info);
}
}
private static bool IsProcessRunning(ProcessInfo info, string? processName, string? processLocation)
{
if (processName != null && processLocation != null)
return string.Equals(info.ProcessName, processName, StringComparison.InvariantCultureIgnoreCase) &&
string.Equals(Path.GetDirectoryName(info.Executable), processLocation, StringComparison.InvariantCultureIgnoreCase);
if (processName != null)
return string.Equals(info.ProcessName, processName, StringComparison.InvariantCultureIgnoreCase);
if (processLocation != null)
return string.Equals(Path.GetDirectoryName(info.Executable), processLocation, StringComparison.InvariantCultureIgnoreCase);
return false;
}
@@ -152,7 +182,10 @@ public static partial class ProcessMonitor
{
ProcessStarted?.Invoke(null, new ProcessEventArgs(processInfo));
}
catch { /* Subscribers are idiots! */ }
catch
{
/* Subscribers are idiots! */
}
}
private static void OnProcessStopped(ProcessInfo processInfo)
@@ -161,7 +194,10 @@ public static partial class ProcessMonitor
{
ProcessStopped?.Invoke(null, new ProcessEventArgs(processInfo));
}
catch { /* Subscribers are idiots! */ }
catch
{
/* Subscribers are idiots! */
}
}
#endregion
@@ -42,6 +42,7 @@ internal class LayerBrushService : ILayerBrushService
BrushType = "SolidBrush"
});
defaultReference.Value ??= new LayerBrushReference();
defaultReference.Value.LayerBrushProviderId ??= "Artemis.Plugins.LayerBrushes.Color.ColorBrushProvider-92a9d6ba";
defaultReference.Value.BrushType ??= "SolidBrush";
return LayerBrushStore.Get(defaultReference.Value.LayerBrushProviderId, defaultReference.Value.BrushType)?.LayerBrushDescriptor;
@@ -221,7 +221,7 @@ internal class ProfileService : IProfileService
return profileConfiguration.Profile;
}
ProfileEntity profileEntity;
ProfileEntity? profileEntity;
try
{
profileEntity = _profileRepository.Get(profileConfiguration.Entity.ProfileId);
@@ -280,7 +280,7 @@ internal class ProfileService : IProfileService
{
DeactivateProfile(profileConfiguration);
ProfileEntity profileEntity = _profileRepository.Get(profileConfiguration.Entity.ProfileId);
ProfileEntity? profileEntity = _profileRepository.Get(profileConfiguration.Entity.ProfileId);
if (profileEntity == null)
return;
@@ -353,7 +353,7 @@ internal class ProfileService : IProfileService
DeactivateProfile(profileConfiguration);
SaveProfileCategory(profileConfiguration.Category);
ProfileEntity profileEntity = _profileRepository.Get(profileConfiguration.Entity.ProfileId);
ProfileEntity? profileEntity = _profileRepository.Get(profileConfiguration.Entity.ProfileId);
if (profileEntity != null)
_profileRepository.Remove(profileEntity);
@@ -100,7 +100,7 @@ public interface IWebServerService : IArtemisService
/// <summary>
/// Removes an existing Web API controller and restarts the web server
/// </summary>
/// <typeparam name="T">The type of Web API controller to remove</typeparam>
/// <param name="registration">The registration of the controller to remove.</param>
void RemoveController(WebApiControllerRegistration registration);
/// <summary>