1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +00:00

Storage - Use nullable reference types

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

View File

@ -248,8 +248,8 @@ public sealed class Layer : RenderProfileElement
typeof(PropertyGroupDescriptionAttribute)
)!;
LayerEntity.GeneralPropertyGroup ??= new PropertyGroupEntity {Identifier = generalAttribute.Identifier};
LayerEntity.TransformPropertyGroup ??= new PropertyGroupEntity {Identifier = transformAttribute.Identifier};
LayerEntity.GeneralPropertyGroup ??= new PropertyGroupEntity {Identifier = generalAttribute.Identifier!};
LayerEntity.TransformPropertyGroup ??= new PropertyGroupEntity {Identifier = transformAttribute.Identifier!};
General.Initialize(this, null, generalAttribute, LayerEntity.GeneralPropertyGroup);
Transform.Initialize(this, null, transformAttribute, LayerEntity.TransformPropertyGroup);

View File

@ -240,7 +240,8 @@ public abstract class LayerPropertyGroup : IDisposable
foreach (LayerPropertyGroup layerPropertyGroup in LayerPropertyGroups)
{
layerPropertyGroup.ApplyToEntity();
PropertyGroupEntity.PropertyGroups.Add(layerPropertyGroup.PropertyGroupEntity);
if (layerPropertyGroup.PropertyGroupEntity != null)
PropertyGroupEntity.PropertyGroups.Add(layerPropertyGroup.PropertyGroupEntity);
}
}

View File

@ -46,7 +46,7 @@ public class ArtemisDevice : CorePropertyChanged
InputIdentifiers = new List<ArtemisDeviceInputIdentifier>();
InputMappings = new Dictionary<ArtemisLed, ArtemisLed>();
Categories = new HashSet<DeviceCategory>();
LayoutSelection = new LayoutSelection {Type = DefaultLayoutProvider.LayoutType};
LayoutSelection = new LayoutSelection {Type = DefaultLayoutProvider.LAYOUT_TYPE};
RgbDevice.ColorCorrections.Clear();
RgbDevice.ColorCorrections.Add(new ScaleColorCorrection(this));
@ -75,7 +75,7 @@ public class ArtemisDevice : CorePropertyChanged
InputIdentifiers = new List<ArtemisDeviceInputIdentifier>();
InputMappings = new Dictionary<ArtemisLed, ArtemisLed>();
Categories = new HashSet<DeviceCategory>();
LayoutSelection = new LayoutSelection {Type = DefaultLayoutProvider.LayoutType};
LayoutSelection = new LayoutSelection {Type = DefaultLayoutProvider.LAYOUT_TYPE};
foreach (DeviceInputIdentifierEntity identifierEntity in DeviceEntity.InputIdentifiers)
InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(identifierEntity.InputProvider, identifierEntity.Identifier));
@ -155,6 +155,9 @@ public class ArtemisDevice : CorePropertyChanged
/// </summary>
public HashSet<DeviceCategory> Categories { get; }
/// <summary>
/// Gets the layout selection applied to this device
/// </summary>
public LayoutSelection LayoutSelection { get; }
/// <summary>

View File

@ -57,6 +57,9 @@ public class ArtemisLayout
/// </summary>
public LayoutCustomDeviceData LayoutCustomDeviceData { get; private set; } = null!;
/// <summary>
/// Gets a boolean indicating whether this layout is a default layout or not
/// </summary>
public bool IsDefaultLayout { get; private set; }
/// <summary>

View File

@ -65,7 +65,7 @@ public class LayerBrushDescriptor
BaseLayerBrush brush = (BaseLayerBrush) Provider.Plugin.Resolve(LayerBrushType);
brush.Layer = layer;
brush.Descriptor = this;
brush.LayerBrushEntity = entity ?? new LayerBrushEntity {ProviderId = Provider.Id, BrushType = LayerBrushType.FullName};
brush.LayerBrushEntity = entity ?? new LayerBrushEntity {ProviderId = Provider.Id, BrushType = LayerBrushType.FullName ?? throw new InvalidOperationException()};
brush.Initialize();
return brush;

View File

@ -231,7 +231,7 @@ public abstract class BaseLayerEffect : BreakableModel, IDisposable, IStorageMod
return;
LayerEffectEntity.ProviderId = Descriptor.Provider.Id;
LayerEffectEntity.EffectType = GetType().FullName;
LayerEffectEntity.EffectType = GetType().FullName ?? throw new InvalidOperationException();
BaseProperties?.ApplyToEntity();
LayerEffectEntity.PropertyGroup = BaseProperties?.PropertyGroupEntity;
}

View File

@ -41,7 +41,7 @@ public class PluginSettings
if (_settingEntities.ContainsKey(name))
return (PluginSetting<T>) _settingEntities[name];
// Try to find in database
PluginSettingEntity settingEntity = _pluginRepository.GetSettingByNameAndGuid(name, Plugin.Guid);
PluginSettingEntity? settingEntity = _pluginRepository.GetSettingByNameAndGuid(name, Plugin.Guid);
// If not found, create a new one
if (settingEntity == null)
{

View File

@ -1,8 +1,14 @@
namespace Artemis.Core.Providers;
/// <summary>
/// Represents a layout provider that loads a layout from a custom path.
/// </summary>
public class CustomPathLayoutProvider : ILayoutProvider
{
public static string LayoutType = "CustomPath";
/// <summary>
/// The layout type of this layout provider.
/// </summary>
public const string LAYOUT_TYPE = "CustomPath";
/// <inheritdoc />
public ArtemisLayout? GetDeviceLayout(ArtemisDevice device)
@ -21,7 +27,7 @@ public class CustomPathLayoutProvider : ILayoutProvider
/// <inheritdoc />
public bool IsMatch(ArtemisDevice device)
{
return device.LayoutSelection.Type == LayoutType;
return device.LayoutSelection.Type == LAYOUT_TYPE;
}
/// <summary>
@ -31,7 +37,7 @@ public class CustomPathLayoutProvider : ILayoutProvider
/// <param name="path">The path to the custom layout.</param>
public void ConfigureDevice(ArtemisDevice device, string? path)
{
device.LayoutSelection.Type = LayoutType;
device.LayoutSelection.Type = LAYOUT_TYPE;
device.LayoutSelection.Parameter = path;
}
}

View File

@ -1,8 +1,14 @@
namespace Artemis.Core.Providers;
/// <summary>
/// Represents a layout provider that loads a layout from the plugin and falls back to a default layout.
/// </summary>
public class DefaultLayoutProvider : ILayoutProvider
{
public static string LayoutType = "Default";
/// <summary>
/// The layout type of this layout provider.
/// </summary>
public const string LAYOUT_TYPE = "Default";
/// <inheritdoc />
public ArtemisLayout? GetDeviceLayout(ArtemisDevice device)
@ -26,7 +32,7 @@ public class DefaultLayoutProvider : ILayoutProvider
/// <inheritdoc />
public bool IsMatch(ArtemisDevice device)
{
return device.LayoutSelection.Type == LayoutType;
return device.LayoutSelection.Type == LAYOUT_TYPE;
}
/// <summary>
@ -35,7 +41,7 @@ public class DefaultLayoutProvider : ILayoutProvider
/// <param name="device">The device to apply the provider to.</param>
public void ConfigureDevice(ArtemisDevice device)
{
device.LayoutSelection.Type = LayoutType;
device.LayoutSelection.Type = LAYOUT_TYPE;
device.LayoutSelection.Parameter = null;
}
}

View File

@ -12,6 +12,17 @@ public interface ILayoutProvider
/// <returns>The resulting layout if one was available; otherwise <see langword="null" />.</returns>
ArtemisLayout? GetDeviceLayout(ArtemisDevice device);
/// <summary>
/// Applies the layout to the provided device.
/// </summary>
/// <param name="device">The device to apply to.</param>
/// <param name="layout">The layout to apply.</param>
void ApplyLayout(ArtemisDevice device, ArtemisLayout layout);
/// <summary>
/// Determines whether the provided device is configured to use this layout provider.
/// </summary>
/// <param name="device">The device to check.</param>
/// <returns>A value indicating whether the provided device is configured to use this layout provider.</returns>
bool IsMatch(ArtemisDevice device);
}

View File

@ -1,8 +1,14 @@
namespace Artemis.Core.Providers;
/// <summary>
/// Represents a layout provider that does not load a layout.
/// </summary>
public class NoneLayoutProvider : ILayoutProvider
{
public static string LayoutType = "None";
/// <summary>
/// The layout type of this layout provider.
/// </summary>
public const string LAYOUT_TYPE = "None";
/// <inheritdoc />
public ArtemisLayout? GetDeviceLayout(ArtemisDevice device)
@ -19,7 +25,7 @@ public class NoneLayoutProvider : ILayoutProvider
/// <inheritdoc />
public bool IsMatch(ArtemisDevice device)
{
return device.LayoutSelection.Type == LayoutType;
return device.LayoutSelection.Type == LAYOUT_TYPE;
}
/// <summary>
@ -28,7 +34,7 @@ public class NoneLayoutProvider : ILayoutProvider
/// <param name="device">The device to apply the provider to.</param>
public void ConfigureDevice(ArtemisDevice device)
{
device.LayoutSelection.Type = LayoutType;
device.LayoutSelection.Type = LAYOUT_TYPE;
device.LayoutSelection.Parameter = null;
}
}

View File

@ -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)
@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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>

View File

@ -1,12 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<PreserveCompilationContext>false</PreserveCompilationContext>
<Platforms>x64</Platforms>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LiteDB" Version="5.0.18" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project>

View File

@ -11,7 +11,7 @@ public class QueuedActionEntity
}
public Guid Id { get; set; }
public string Type { get; set; }
public string Type { get; set; } = string.Empty;
public DateTimeOffset CreatedAt { get; set; }
public Dictionary<string, object> Parameters { get; set; }

View File

@ -6,6 +6,6 @@ public class ReleaseEntity
{
public Guid Id { get; set; }
public string Version { get; set; }
public string Version { get; set; } = string.Empty;
public DateTimeOffset? InstalledAt { get; set; }
}

View File

@ -6,7 +6,7 @@ public class ScriptConfigurationEntity
{
public Guid Id { get; set; }
public string Name { get; set; }
public string ScriptingProviderId { get; set; }
public string ScriptContent { get; set; }
public string Name { get; set; } = string.Empty;
public string ScriptingProviderId { get; set; } = string.Empty;
public string? ScriptContent { get; set; }
}

View File

@ -24,6 +24,6 @@ public class PluginEntity
/// </summary>
public class PluginFeatureEntity
{
public string Type { get; set; }
public string Type { get; set; } = string.Empty;
public bool IsEnabled { get; set; }
}

View File

@ -10,6 +10,6 @@ public class PluginSettingEntity
public Guid Id { get; set; }
public Guid PluginGuid { get; set; }
public string Name { get; set; }
public string Value { get; set; }
public string Name { get; set; } = string.Empty;
public string Value { get; set; } = string.Empty;
}

View File

@ -1,8 +0,0 @@
using System.Collections.Generic;
namespace Artemis.Storage.Entities.Profile.Abstract;
public abstract class DataModelConditionPartEntity
{
public List<DataModelConditionPartEntity> Children { get; set; }
}

View File

@ -8,8 +8,8 @@ public abstract class RenderElementEntity
public Guid Id { get; set; }
public Guid ParentId { get; set; }
public List<LayerEffectEntity> LayerEffects { get; set; }
public List<LayerEffectEntity> LayerEffects { get; set; } = new();
public IConditionEntity DisplayCondition { get; set; }
public TimelineEntity Timeline { get; set; }
public IConditionEntity? DisplayCondition { get; set; }
public TimelineEntity? Timeline { get; set; }
}

View File

@ -1,5 +1,3 @@
namespace Artemis.Storage.Entities.Profile.AdaptionHints;
public interface IAdaptionHintEntity
{
}
public interface IAdaptionHintEntity;

View File

@ -2,6 +2,4 @@
namespace Artemis.Storage.Entities.Profile.Conditions;
public class AlwaysOnConditionEntity : IConditionEntity
{
}
public class AlwaysOnConditionEntity : IConditionEntity;

View File

@ -8,6 +8,6 @@ public class EventConditionEntity : IConditionEntity
public int TriggerMode { get; set; }
public int OverlapMode { get; set; }
public int ToggleOffMode { get; set; }
public DataModelPathEntity EventPath { get; set; }
public NodeScriptEntity Script { get; set; }
public DataModelPathEntity? EventPath { get; set; }
public NodeScriptEntity? Script { get; set; }
}

View File

@ -1,5 +1,3 @@
namespace Artemis.Storage.Entities.Profile.Abstract;
public interface IConditionEntity
{
}
public interface IConditionEntity;

View File

@ -2,6 +2,4 @@
namespace Artemis.Storage.Entities.Profile.Conditions;
public class PlayOnceConditionEntity : IConditionEntity
{
}
public class PlayOnceConditionEntity : IConditionEntity;

View File

@ -7,5 +7,5 @@ public class StaticConditionEntity : IConditionEntity
{
public int PlayMode { get; set; }
public int StopMode { get; set; }
public NodeScriptEntity Script { get; set; }
public NodeScriptEntity? Script { get; set; }
}

View File

@ -4,7 +4,6 @@ namespace Artemis.Storage.Entities.Profile.DataBindings;
public class DataBindingEntity
{
public string Identifier { get; set; }
public bool IsEnabled { get; set; }
public NodeScriptEntity NodeScript { get; set; }
public NodeScriptEntity? NodeScript { get; set; }
}

View File

@ -2,7 +2,7 @@
public class DataModelPathEntity
{
public string Path { get; set; }
public string DataModelId { get; set; }
public string Type { get; set; }
public string Path { get; set; } = string.Empty;
public string? DataModelId { get; set; }
public string? Type { get; set; }
}

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using Artemis.Storage.Entities.Profile.Abstract;
using LiteDB;
@ -7,18 +6,13 @@ namespace Artemis.Storage.Entities.Profile;
public class FolderEntity : RenderElementEntity
{
public FolderEntity()
{
LayerEffects = new List<LayerEffectEntity>();
}
public int Order { get; set; }
public string Name { get; set; }
public string? Name { get; set; }
public bool IsExpanded { get; set; }
public bool Suspended { get; set; }
[BsonRef("ProfileEntity")]
public ProfileEntity Profile { get; set; }
public ProfileEntity Profile { get; set; } = null!;
public Guid ProfileId { get; set; }
}

View File

@ -6,6 +6,6 @@ public class KeyframeEntity
{
public TimeSpan Position { get; set; }
public int Timeline { get; set; }
public string Value { get; set; }
public string Value { get; set; } = string.Empty;
public int EasingFunction { get; set; }
}

View File

@ -2,8 +2,8 @@
public class LayerBrushEntity
{
public string ProviderId { get; set; }
public string BrushType { get; set; }
public string ProviderId { get; set; } = string.Empty;
public string BrushType { get; set; } = string.Empty;
public PropertyGroupEntity PropertyGroup { get; set; }
public PropertyGroupEntity? PropertyGroup { get; set; }
}

View File

@ -2,11 +2,11 @@
public class LayerEffectEntity
{
public string ProviderId { get; set; }
public string EffectType { get; set; }
public string Name { get; set; }
public string ProviderId { get; set; } = string.Empty;
public string EffectType { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public bool HasBeenRenamed { get; set; }
public int Order { get; set; }
public PropertyGroupEntity PropertyGroup { get; set; }
public PropertyGroupEntity? PropertyGroup { get; set; }
}

View File

@ -12,22 +12,21 @@ public class LayerEntity : RenderElementEntity
{
Leds = new List<LedEntity>();
AdaptionHints = new List<IAdaptionHintEntity>();
LayerEffects = new List<LayerEffectEntity>();
}
public int Order { get; set; }
public string Name { get; set; }
public string? Name { get; set; }
public bool Suspended { get; set; }
public List<LedEntity> Leds { get; set; }
public List<IAdaptionHintEntity> AdaptionHints { get; set; }
public PropertyGroupEntity GeneralPropertyGroup { get; set; }
public PropertyGroupEntity TransformPropertyGroup { get; set; }
public LayerBrushEntity LayerBrush { get; set; }
public PropertyGroupEntity? GeneralPropertyGroup { get; set; }
public PropertyGroupEntity? TransformPropertyGroup { get; set; }
public LayerBrushEntity? LayerBrush { get; set; }
[BsonRef("ProfileEntity")]
public ProfileEntity Profile { get; set; }
public ProfileEntity Profile { get; set; } = null!;
public Guid ProfileId { get; set; }
}

View File

@ -5,8 +5,8 @@ namespace Artemis.Storage.Entities.Profile;
public class LedEntity
{
public string LedName { get; set; }
public string DeviceIdentifier { get; set; }
public string LedName { get; set; } = string.Empty;
public string DeviceIdentifier { get; set; } = string.Empty;
public int? PhysicalLayout { get; set; }
@ -14,7 +14,7 @@ public class LedEntity
private sealed class LedEntityEqualityComparer : IEqualityComparer<LedEntity>
{
public bool Equals(LedEntity x, LedEntity y)
public bool Equals(LedEntity? x, LedEntity? y)
{
if (ReferenceEquals(x, y))
return true;

View File

@ -20,12 +20,12 @@ public class NodeConnectionEntity
TargetPinId = nodeConnectionEntity.TargetPinId;
}
public string SourceType { get; set; }
public string SourceType { get; set; } = string.Empty;
public Guid SourceNode { get; set; }
public Guid TargetNode { get; set; }
public int SourcePinCollectionId { get; set; }
public int SourcePinId { get; set; }
public string TargetType { get; set; }
public string TargetType { get; set; } = string.Empty;
public int TargetPinCollectionId { get; set; }
public int TargetPinId { get; set; }
}

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
@ -28,15 +28,15 @@ public class NodeEntity
}
public Guid Id { get; set; }
public string Type { get; set; }
public string Type { get; set; } = string.Empty;
public Guid PluginId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public bool IsExitNode { get; set; }
public double X { get; set; }
public double Y { get; set; }
public string Storage { get; set; }
public string Storage { get; set; } = string.Empty;
public List<NodePinCollectionEntity> PinCollections { get; set; }
}

View File

@ -10,8 +10,8 @@ public class NodeScriptEntity
Connections = new List<NodeConnectionEntity>();
}
public string Name { get; set; }
public string Description { get; set; }
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public List<NodeEntity> Nodes { get; set; }
public List<NodeConnectionEntity> Connections { get; set; }

View File

@ -7,7 +7,7 @@ public class ProfileCategoryEntity
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Name { get; set; } = string.Empty;
public bool IsCollapsed { get; set; }
public bool IsSuspended { get; set; }
public int Order { get; set; }

View File

@ -5,8 +5,8 @@ namespace Artemis.Storage.Entities.Profile;
public class ProfileConfigurationEntity
{
public string Name { get; set; }
public string MaterialIcon { get; set; }
public string Name { get; set; } = string.Empty;
public string? MaterialIcon { get; set; }
public Guid FileIconId { get; set; }
public int IconType { get; set; }
public bool IconFill { get; set; }
@ -14,13 +14,13 @@ public class ProfileConfigurationEntity
public bool IsSuspended { get; set; }
public int ActivationBehaviour { get; set; }
public NodeScriptEntity ActivationCondition { get; set; }
public NodeScriptEntity? ActivationCondition { get; set; }
public int HotkeyMode { get; set; }
public ProfileConfigurationHotkeyEntity EnableHotkey { get; set; }
public ProfileConfigurationHotkeyEntity DisableHotkey { get; set; }
public ProfileConfigurationHotkeyEntity? EnableHotkey { get; set; }
public ProfileConfigurationHotkeyEntity? DisableHotkey { get; set; }
public string ModuleId { get; set; }
public string? ModuleId { get; set; }
public Guid ProfileCategoryId { get; set; }
public Guid ProfileId { get; set; }

View File

@ -16,7 +16,7 @@ public class ProfileEntity
public Guid Id { get; set; }
public string Name { get; set; }
public string Name { get; set; } = string.Empty;
public bool IsFreshImport { get; set; }
public List<FolderEntity> Folders { get; set; }
@ -28,7 +28,7 @@ public class ProfileEntity
Guid oldGuid = Id;
Id = guid;
FolderEntity rootFolder = Folders.FirstOrDefault(f => f.ParentId == oldGuid);
FolderEntity? rootFolder = Folders.FirstOrDefault(f => f.ParentId == oldGuid);
if (rootFolder != null)
rootFolder.ParentId = Id;
}

View File

@ -5,10 +5,10 @@ namespace Artemis.Storage.Entities.Profile;
public class PropertyEntity
{
public string Identifier { get; set; }
public string Value { get; set; }
public string Identifier { get; set; } = string.Empty;
public string Value { get; set; } = string.Empty;
public bool KeyframesEnabled { get; set; }
public DataBindingEntity DataBinding { get; set; }
public DataBindingEntity? DataBinding { get; set; }
public List<KeyframeEntity> KeyframeEntities { get; set; } = new();
}

View File

@ -4,7 +4,7 @@ namespace Artemis.Storage.Entities.Profile;
public class PropertyGroupEntity
{
public string Identifier { get; set; }
public string Identifier { get; set; } = string.Empty;
public List<PropertyEntity> Properties { get; set; } = new();
public List<PropertyGroupEntity> PropertyGroups { get; set; } = new();
}

View File

@ -11,8 +11,8 @@ public class DeviceEntity
Categories = new List<int>();
}
public string Id { get; set; }
public string DeviceProvider { get; set; }
public string Id { get; set; } = string.Empty;
public string DeviceProvider { get; set; } = string.Empty;
public float X { get; set; }
public float Y { get; set; }
public float Rotation { get; set; }
@ -24,9 +24,9 @@ public class DeviceEntity
public bool IsEnabled { get; set; }
public int PhysicalLayout { get; set; }
public string LogicalLayout { get; set; }
public string LayoutType { get; set; }
public string LayoutParameter { get; set; }
public string? LogicalLayout { get; set; }
public string? LayoutType { get; set; }
public string? LayoutParameter { get; set; }
public List<DeviceInputIdentifierEntity> InputIdentifiers { get; set; }
public List<InputMappingEntity> InputMappings { get; set; }
@ -41,6 +41,6 @@ public class InputMappingEntity
public class DeviceInputIdentifierEntity
{
public string InputProvider { get; set; }
public object Identifier { get; set; }
public string InputProvider { get; set; } = string.Empty;
public object Identifier { get; set; } = string.Empty;
}

View File

@ -10,13 +10,12 @@ public class EntryEntity
public long EntryId { get; set; }
public int EntryType { get; set; }
public string Author { get; set; }
public string Author { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public string Summary { get; set; } = string.Empty;
public long ReleaseId { get; set; }
public string ReleaseVersion { get; set; }
public string ReleaseVersion { get; set; } = string.Empty;
public DateTimeOffset InstalledAt { get; set; }
public Dictionary<string,object> Metadata { get; set; }
public Dictionary<string,object>? Metadata { get; set; }
}

View File

@ -0,0 +1,11 @@
using LiteDB;
using Newtonsoft.Json.Linq;
namespace Artemis.Storage.Migrations;
internal interface IProfileMigration
{
int Version { get; }
void Migrate(JObject profileJson);
void Migrate(BsonDocument profileBson);
}

View File

@ -0,0 +1,97 @@
using LiteDB;
using Newtonsoft.Json.Linq;
namespace Artemis.Storage.Migrations.Profile;
/// <summary>
/// Migrates nodes to be provider-based.
/// This requires giving them a ProviderId and updating the their namespaces to match the namespace of the new plugin.
/// </summary>
internal class M0001NodeProviders : IProfileMigration
{
/// <inheritdoc />
public int Version => 1;
/// <inheritdoc />
public void Migrate(JObject profileJson)
{
JArray? folders = (JArray?) profileJson["Folders"]?["$values"];
JArray? layers = (JArray?) profileJson["Layers"]?["$values"];
if (folders != null)
{
foreach (JToken folder in folders)
{
MigrateProfileElement(folder);
}
}
if (layers != null)
{
foreach (JToken layer in layers)
{
MigrateProfileElement(layer);
MigratePropertyGroup(layer["GeneralPropertyGroup"]);
MigratePropertyGroup(layer["TransformPropertyGroup"]);
MigratePropertyGroup(layer["LayerBrush"]?["PropertyGroup"]);
}
}
}
/// <inheritdoc />
public void Migrate(BsonDocument profileBson)
{
throw new System.NotImplementedException();
}
private void MigrateProfileElement(JToken profileElement)
{
JArray? layerEffects = (JArray?) profileElement["LayerEffects"]?["$values"];
if (layerEffects != null)
{
foreach (JToken layerEffect in layerEffects)
MigratePropertyGroup(layerEffect["PropertyGroup"]);
}
JToken? displayCondition = profileElement["DisplayCondition"];
if (displayCondition != null)
MigrateNodeScript(displayCondition["Script"]);
}
private void MigratePropertyGroup(JToken? propertyGroup)
{
if (propertyGroup == null || !propertyGroup.HasValues)
return;
JArray? properties = (JArray?) propertyGroup["Properties"]?["$values"];
JArray? propertyGroups = (JArray?) propertyGroup["PropertyGroups"]?["$values"];
if (properties != null)
{
foreach (JToken property in properties)
MigrateNodeScript(property["DataBinding"]?["NodeScript"]);
}
if (propertyGroups != null)
{
foreach (JToken childPropertyGroup in propertyGroups)
MigratePropertyGroup(childPropertyGroup);
}
}
private void MigrateNodeScript(JToken? nodeScript)
{
if (nodeScript == null || !nodeScript.HasValues)
return;
JArray? nodes = (JArray?) nodeScript["Nodes"]?["$values"];
if (nodes == null)
return;
foreach (JToken node in nodes)
{
node["Type"] = node["Type"]?.Value<string>()?.Replace("Artemis.VisualScripting.Nodes", "Artemis.Plugins.Nodes.General.Nodes");
node["ProviderId"] = "Artemis.Plugins.Nodes.General.GeneralNodesProvider-d9e1ee78";
}
}
}

View File

@ -12,9 +12,9 @@ public class M0021GradientNodes : IStorageMigration
{
private void MigrateDataBinding(PropertyEntity property)
{
NodeScriptEntity script = property.DataBinding.NodeScript;
NodeEntity exitNode = script.Nodes.FirstOrDefault(s => s.IsExitNode);
if (exitNode == null)
NodeScriptEntity? script = property.DataBinding?.NodeScript;
NodeEntity? exitNode = script?.Nodes.FirstOrDefault(s => s.IsExitNode);
if (script == null || exitNode == null)
return;
// Create a new node at the same position of the exit node
@ -59,8 +59,11 @@ public class M0021GradientNodes : IStorageMigration
exitNode.Y += 30;
}
private void MigrateDataBinding(PropertyGroupEntity propertyGroup)
private void MigrateDataBinding(PropertyGroupEntity? propertyGroup)
{
if (propertyGroup == null)
return;
foreach (PropertyGroupEntity propertyGroupPropertyGroup in propertyGroup.PropertyGroups)
MigrateDataBinding(propertyGroupPropertyGroup);
@ -80,7 +83,7 @@ public class M0021GradientNodes : IStorageMigration
foreach (ProfileEntity profileEntity in profiles)
{
foreach (LayerEntity layer in profileEntity.Layers.Where(le => le.LayerBrush != null))
MigrateDataBinding(layer.LayerBrush.PropertyGroup);
MigrateDataBinding(layer.LayerBrush?.PropertyGroup);
repository.Update(profileEntity);
}

View File

@ -10,7 +10,7 @@ namespace Artemis.Storage.Migrations;
public class M0022TransitionNodes : IStorageMigration
{
private void MigrateNodeScript(NodeScriptEntity nodeScript)
private void MigrateNodeScript(NodeScriptEntity? nodeScript)
{
if (nodeScript == null)
return;
@ -28,7 +28,7 @@ public class M0022TransitionNodes : IStorageMigration
}
}
private void MigratePropertyGroup(PropertyGroupEntity propertyGroup)
private void MigratePropertyGroup(PropertyGroupEntity? propertyGroup)
{
if (propertyGroup == null)
return;
@ -39,7 +39,7 @@ public class M0022TransitionNodes : IStorageMigration
MigrateNodeScript(property.DataBinding?.NodeScript);
}
private void MigrateDisplayCondition(IConditionEntity conditionEntity)
private void MigrateDisplayCondition(IConditionEntity? conditionEntity)
{
if (conditionEntity is EventConditionEntity eventConditionEntity)
MigrateNodeScript(eventConditionEntity.Script);
@ -70,14 +70,14 @@ public class M0022TransitionNodes : IStorageMigration
MigratePropertyGroup(layer.GeneralPropertyGroup);
MigratePropertyGroup(layer.TransformPropertyGroup);
foreach (LayerEffectEntity layerEffectEntity in layer.LayerEffects)
MigratePropertyGroup(layerEffectEntity?.PropertyGroup);
MigratePropertyGroup(layerEffectEntity.PropertyGroup);
MigrateDisplayCondition(layer.DisplayCondition);
}
foreach (FolderEntity folder in profileEntity.Folders)
{
foreach (LayerEffectEntity folderLayerEffect in folder.LayerEffects)
MigratePropertyGroup(folderLayerEffect?.PropertyGroup);
MigratePropertyGroup(folderLayerEffect.PropertyGroup);
MigrateDisplayCondition(folder.DisplayCondition);
}

View File

@ -25,7 +25,7 @@ internal class DeviceRepository : IDeviceRepository
_repository.Delete<DeviceEntity>(deviceEntity.Id);
}
public DeviceEntity Get(string id)
public DeviceEntity? Get(string id)
{
return _repository.FirstOrDefault<DeviceEntity>(s => s.Id == id);
}

View File

@ -27,12 +27,12 @@ internal class EntryRepository : IEntryRepository
_repository.Delete<EntryEntity>(entryEntity.Id);
}
public EntryEntity Get(Guid id)
public EntryEntity? Get(Guid id)
{
return _repository.FirstOrDefault<EntryEntity>(s => s.Id == id);
}
public EntryEntity GetByEntryId(long entryId)
public EntryEntity? GetByEntryId(long entryId)
{
return _repository.FirstOrDefault<EntryEntity>(s => s.EntryId == entryId);
}

View File

@ -7,7 +7,7 @@ public interface IDeviceRepository : IRepository
{
void Add(DeviceEntity deviceEntity);
void Remove(DeviceEntity deviceEntity);
DeviceEntity Get(string id);
DeviceEntity? Get(string id);
List<DeviceEntity> GetAll();
void Save(DeviceEntity deviceEntity);
void Save(IEnumerable<DeviceEntity> deviceEntities);

View File

@ -8,8 +8,8 @@ public interface IEntryRepository : IRepository
{
void Add(EntryEntity entryEntity);
void Remove(EntryEntity entryEntity);
EntryEntity Get(Guid id);
EntryEntity GetByEntryId(long entryId);
EntryEntity? Get(Guid id);
EntryEntity? GetByEntryId(long entryId);
List<EntryEntity> GetAll();
void Save(EntryEntity entryEntity);
void Save(IEnumerable<EntryEntity> entryEntities);

View File

@ -6,12 +6,12 @@ namespace Artemis.Storage.Repositories.Interfaces;
public interface IPluginRepository : IRepository
{
void AddPlugin(PluginEntity pluginEntity);
PluginEntity GetPluginByGuid(Guid pluginGuid);
PluginEntity? GetPluginByGuid(Guid pluginGuid);
void SavePlugin(PluginEntity pluginEntity);
void AddSetting(PluginSettingEntity pluginSettingEntity);
PluginSettingEntity GetSettingByGuid(Guid pluginGuid);
PluginSettingEntity GetSettingByNameAndGuid(string name, Guid pluginGuid);
PluginSettingEntity? GetSettingByGuid(Guid pluginGuid);
PluginSettingEntity? GetSettingByNameAndGuid(string name, Guid pluginGuid);
void SaveSetting(PluginSettingEntity pluginSettingEntity);
void RemoveSettings(Guid pluginGuid);
}

View File

@ -10,8 +10,8 @@ public interface IProfileCategoryRepository : IRepository
void Add(ProfileCategoryEntity profileCategoryEntity);
void Remove(ProfileCategoryEntity profileCategoryEntity);
List<ProfileCategoryEntity> GetAll();
ProfileCategoryEntity Get(Guid id);
Stream GetProfileIconStream(Guid id);
ProfileCategoryEntity? Get(Guid id);
Stream? GetProfileIconStream(Guid id);
void SaveProfileIconStream(ProfileConfigurationEntity profileConfigurationEntity, Stream stream);
ProfileCategoryEntity IsUnique(string name, Guid? id);
void Save(ProfileCategoryEntity profileCategoryEntity);

View File

@ -9,6 +9,6 @@ public interface IProfileRepository : IRepository
void Add(ProfileEntity profileEntity);
void Remove(ProfileEntity profileEntity);
List<ProfileEntity> GetAll();
ProfileEntity Get(Guid id);
ProfileEntity? Get(Guid id);
void Save(ProfileEntity profileEntity);
}

View File

@ -1,5 +1,3 @@
namespace Artemis.Storage.Repositories.Interfaces;
public interface IRepository
{
}
public interface IRepository;

View File

@ -21,7 +21,7 @@ internal class PluginRepository : IPluginRepository
_repository.Insert(pluginEntity);
}
public PluginEntity GetPluginByGuid(Guid pluginGuid)
public PluginEntity? GetPluginByGuid(Guid pluginGuid)
{
return _repository.FirstOrDefault<PluginEntity>(p => p.Id == pluginGuid);
}
@ -37,12 +37,12 @@ internal class PluginRepository : IPluginRepository
_repository.Insert(pluginSettingEntity);
}
public PluginSettingEntity GetSettingByGuid(Guid pluginGuid)
public PluginSettingEntity? GetSettingByGuid(Guid pluginGuid)
{
return _repository.FirstOrDefault<PluginSettingEntity>(p => p.PluginGuid == pluginGuid);
}
public PluginSettingEntity GetSettingByNameAndGuid(string name, Guid pluginGuid)
public PluginSettingEntity? GetSettingByNameAndGuid(string name, Guid pluginGuid)
{
return _repository.FirstOrDefault<PluginSettingEntity>(p => p.Name == name && p.PluginGuid == pluginGuid);
}

View File

@ -34,7 +34,7 @@ internal class ProfileCategoryRepository : IProfileCategoryRepository
return _repository.Query<ProfileCategoryEntity>().ToList();
}
public ProfileCategoryEntity Get(Guid id)
public ProfileCategoryEntity? Get(Guid id)
{
return _repository.FirstOrDefault<ProfileCategoryEntity>(p => p.Id == id);
}
@ -52,7 +52,7 @@ internal class ProfileCategoryRepository : IProfileCategoryRepository
_repository.Upsert(profileCategoryEntity);
}
public Stream GetProfileIconStream(Guid id)
public Stream? GetProfileIconStream(Guid id)
{
if (!_profileIcons.Exists(id))
return null;

View File

@ -31,7 +31,7 @@ internal class ProfileRepository : IProfileRepository
return _repository.Query<ProfileEntity>().ToList();
}
public ProfileEntity Get(Guid id)
public ProfileEntity? Get(Guid id)
{
return _repository.FirstOrDefault<ProfileEntity>(p => p.Id == id);
}