mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Core - Corrected disposable pattern usage
Core - Further nullable refactoring..
This commit is contained in:
1 parent
27e25f22ed
commit
b185b28645
38 files changed
+429
-162
No files matched your search
@@ -7,9 +7,9 @@ namespace Artemis.Core
|
||||
public class DataBinding<TLayerProperty, TProperty> : IDataBinding
|
||||
{
|
||||
private TProperty _currentValue = default!;
|
||||
private TProperty _previousValue = default!;
|
||||
private bool _disposed;
|
||||
private TimeSpan _easingProgress;
|
||||
private TProperty _previousValue = default!;
|
||||
|
||||
internal DataBinding(DataBindingRegistration<TLayerProperty, TProperty> dataBindingRegistration)
|
||||
{
|
||||
@@ -98,6 +98,24 @@ namespace Artemis.Core
|
||||
return Registration?.PropertyExpression.ReturnType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the smoothing progress of the data binding
|
||||
/// </summary>
|
||||
/// <param name="delta">The delta to apply during update</param>
|
||||
public void UpdateWithDelta(TimeSpan delta)
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("DataBinding");
|
||||
|
||||
// Data bindings cannot go back in time like brushes
|
||||
if (delta < TimeSpan.Zero)
|
||||
delta = TimeSpan.Zero;
|
||||
|
||||
_easingProgress = _easingProgress.Add(delta);
|
||||
if (_easingProgress > EasingTime)
|
||||
_easingProgress = EasingTime;
|
||||
}
|
||||
|
||||
private void ResetEasing(TProperty value)
|
||||
{
|
||||
_previousValue = GetInterpolatedValue();
|
||||
@@ -143,24 +161,6 @@ namespace Artemis.Core
|
||||
UpdateWithDelta(timeline.Delta);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the smoothing progress of the data binding
|
||||
/// </summary>
|
||||
/// <param name="delta">The delta to apply during update</param>
|
||||
public void UpdateWithDelta(TimeSpan delta)
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("DataBinding");
|
||||
|
||||
// Data bindings cannot go back in time like brushes
|
||||
if (delta < TimeSpan.Zero)
|
||||
delta = TimeSpan.Zero;
|
||||
|
||||
_easingProgress = _easingProgress.Add(delta);
|
||||
if (_easingProgress > EasingTime)
|
||||
_easingProgress = EasingTime;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Apply()
|
||||
{
|
||||
@@ -175,16 +175,36 @@ namespace Artemis.Core
|
||||
Converter.ApplyValue(value);
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <summary>
|
||||
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">
|
||||
/// <see langword="true" /> to release both managed and unmanaged resources;
|
||||
/// <see langword="false" /> to release only unmanaged resources.
|
||||
/// </param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
if (Registration != null)
|
||||
Registration.DataBinding = null;
|
||||
DataBindingMode?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
if (Registration != null)
|
||||
Registration.DataBinding = null;
|
||||
DataBindingMode?.Dispose();
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Mode management
|
||||
|
||||
/// <summary>
|
||||
@@ -255,7 +275,7 @@ namespace Artemis.Core
|
||||
LayerProperty.Entity.DataBindingEntities.Add(Entity);
|
||||
|
||||
// Don't save an invalid state
|
||||
if (Registration != null)
|
||||
if (Registration != null)
|
||||
Entity.TargetExpression = Registration.PropertyExpression.ToString();
|
||||
|
||||
Entity.EasingTime = EasingTime;
|
||||
|
||||
+20
-4
@@ -43,13 +43,29 @@ namespace Artemis.Core
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <summary>
|
||||
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">
|
||||
/// <see langword="true" /> to release both managed and unmanaged resources;
|
||||
/// <see langword="false" /> to release only unmanaged resources.
|
||||
/// </param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
foreach (DataBindingCondition<TLayerProperty, TProperty> dataBindingCondition in Conditions)
|
||||
dataBindingCondition.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
foreach (DataBindingCondition<TLayerProperty, TProperty> dataBindingCondition in Conditions)
|
||||
dataBindingCondition.Dispose();
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
+22
-3
@@ -92,12 +92,31 @@ namespace Artemis.Core
|
||||
Order = Entity.Order;
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <summary>
|
||||
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">
|
||||
/// <see langword="true" /> to release both managed and unmanaged resources;
|
||||
/// <see langword="false" /> to release only unmanaged resources.
|
||||
/// </param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_disposed = true;
|
||||
ConditionalDataBinding.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
Condition.Dispose();
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -270,17 +270,37 @@ namespace Artemis.Core
|
||||
// Parameter is done during initialize
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <summary>
|
||||
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">
|
||||
/// <see langword="true" /> to release both managed and unmanaged resources;
|
||||
/// <see langword="false" /> to release only unmanaged resources.
|
||||
/// </param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
DataBindingModifierTypeStore.DataBindingModifierAdded -= DataBindingModifierTypeStoreOnDataBindingModifierAdded;
|
||||
DataBindingModifierTypeStore.DataBindingModifierRemoved -= DataBindingModifierTypeStoreOnDataBindingModifierRemoved;
|
||||
|
||||
ParameterPath?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
DataBindingModifierTypeStore.DataBindingModifierAdded -= DataBindingModifierTypeStoreOnDataBindingModifierAdded;
|
||||
DataBindingModifierTypeStore.DataBindingModifierRemoved -= DataBindingModifierTypeStoreOnDataBindingModifierRemoved;
|
||||
|
||||
ParameterPath?.Dispose();
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event handlers
|
||||
|
||||
private void DataBindingModifierTypeStoreOnDataBindingModifierAdded(object? sender, DataBindingModifierTypeStoreEvent e)
|
||||
|
||||
@@ -54,15 +54,31 @@ namespace Artemis.Core
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <summary>
|
||||
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">
|
||||
/// <see langword="true" /> to release both managed and unmanaged resources;
|
||||
/// <see langword="false" /> to release only unmanaged resources.
|
||||
/// </param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
foreach (DataBindingModifier<TLayerProperty, TProperty> dataBindingModifier in Modifiers)
|
||||
dataBindingModifier.Dispose();
|
||||
|
||||
SourcePath?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
foreach (DataBindingModifier<TLayerProperty, TProperty> dataBindingModifier in Modifiers)
|
||||
dataBindingModifier.Dispose();
|
||||
|
||||
SourcePath?.Dispose();
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -247,15 +247,31 @@ namespace Artemis.Core
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <summary>
|
||||
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">
|
||||
/// <see langword="true" /> to release both managed and unmanaged resources;
|
||||
/// <see langword="false" /> to release only unmanaged resources.
|
||||
/// </param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
|
||||
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
|
||||
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
|
||||
|
||||
Invalidate();
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -250,19 +250,35 @@ namespace Artemis.Core
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <summary>
|
||||
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">
|
||||
/// <see langword="true" /> to release both managed and unmanaged resources;
|
||||
/// <see langword="false" /> to release only unmanaged resources.
|
||||
/// </param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (_dynamicDataModel != null)
|
||||
{
|
||||
_dynamicDataModel.DynamicDataModelAdded -= DynamicDataModelOnDynamicDataModelAdded;
|
||||
_dynamicDataModel.DynamicDataModelRemoved -= DynamicDataModelOnDynamicDataModelRemoved;
|
||||
}
|
||||
|
||||
Type = DataModelPathSegmentType.Invalid;
|
||||
|
||||
_accessorLambda = null;
|
||||
Accessor = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
if (_dynamicDataModel != null)
|
||||
{
|
||||
_dynamicDataModel.DynamicDataModelAdded -= DynamicDataModelOnDynamicDataModelAdded;
|
||||
_dynamicDataModel.DynamicDataModelRemoved -= DynamicDataModelOnDynamicDataModelRemoved;
|
||||
}
|
||||
|
||||
Type = DataModelPathSegmentType.Invalid;
|
||||
|
||||
_accessorLambda = null;
|
||||
Accessor = null;
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Artemis.Core
|
||||
// Cant define generic types as nullable ¯\_(ツ)_/¯
|
||||
CurrentValue = default!;
|
||||
DefaultValue = default!;
|
||||
|
||||
|
||||
_baseValue = default!;
|
||||
_keyframes = new List<LayerPropertyKeyframe<T>>();
|
||||
}
|
||||
@@ -61,15 +61,35 @@ namespace Artemis.Core
|
||||
OnUpdated();
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <summary>
|
||||
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">
|
||||
/// <see langword="true" /> to release both managed and unmanaged resources;
|
||||
/// <see langword="false" /> to release only unmanaged resources.
|
||||
/// </param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
foreach (IDataBinding dataBinding in _dataBindings)
|
||||
dataBinding.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
foreach (IDataBinding dataBinding in _dataBindings)
|
||||
dataBinding.Dispose();
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Hierarchy
|
||||
|
||||
private bool _isHidden;
|
||||
|
||||
@@ -263,16 +263,32 @@ namespace Artemis.Core
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <summary>
|
||||
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">
|
||||
/// <see langword="true" /> to release both managed and unmanaged resources;
|
||||
/// <see langword="false" /> to release only unmanaged resources.
|
||||
/// </param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_disposed = true;
|
||||
DisableProperties();
|
||||
|
||||
foreach (ILayerProperty layerProperty in _layerProperties)
|
||||
layerProperty.Dispose();
|
||||
foreach (LayerPropertyGroup layerPropertyGroup in _layerPropertyGroups)
|
||||
layerPropertyGroup.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_disposed = true;
|
||||
DisableProperties();
|
||||
|
||||
foreach (ILayerProperty layerProperty in _layerProperties)
|
||||
layerProperty.Dispose();
|
||||
foreach (LayerPropertyGroup layerPropertyGroup in _layerPropertyGroups)
|
||||
layerPropertyGroup.Dispose();
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Artemis.Core
|
||||
public sealed class Profile : ProfileElement
|
||||
{
|
||||
private bool _isActivated;
|
||||
private readonly object _lock = new object();
|
||||
|
||||
internal Profile(ProfileModule module, string name)
|
||||
{
|
||||
@@ -64,7 +65,7 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public override void Update(double deltaTime)
|
||||
{
|
||||
lock (this)
|
||||
lock (_lock)
|
||||
{
|
||||
if (Disposed)
|
||||
throw new ObjectDisposedException("Profile");
|
||||
@@ -79,7 +80,7 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public override void Render(SKCanvas canvas)
|
||||
{
|
||||
lock (this)
|
||||
lock (_lock)
|
||||
{
|
||||
if (Disposed)
|
||||
throw new ObjectDisposedException("Profile");
|
||||
@@ -182,7 +183,7 @@ namespace Artemis.Core
|
||||
|
||||
internal void Activate(ArtemisSurface surface)
|
||||
{
|
||||
lock (this)
|
||||
lock (_lock)
|
||||
{
|
||||
if (Disposed)
|
||||
throw new ObjectDisposedException("Profile");
|
||||
|
||||
@@ -287,7 +287,7 @@ namespace Artemis.Core
|
||||
OnLayerEffectsUpdated();
|
||||
}
|
||||
|
||||
private void LayerEffectStoreOnLayerEffectRemoved(object sender, LayerEffectStoreEvent e)
|
||||
private void LayerEffectStoreOnLayerEffectRemoved(object? sender, LayerEffectStoreEvent e)
|
||||
{
|
||||
// If effects provided by the plugin are on the element, replace them with placeholders
|
||||
List<BaseLayerEffect> pluginEffects = LayerEffectsList.Where(ef => ef.Descriptor.Provider != null &&
|
||||
@@ -303,7 +303,7 @@ namespace Artemis.Core
|
||||
}
|
||||
}
|
||||
|
||||
private void LayerEffectStoreOnLayerEffectAdded(object sender, LayerEffectStoreEvent e)
|
||||
private void LayerEffectStoreOnLayerEffectAdded(object? sender, LayerEffectStoreEvent e)
|
||||
{
|
||||
if (RenderElementEntity.LayerEffects.Any(ef => ef.ProviderId == e.Registration.PluginFeature.Id))
|
||||
ActivateEffects();
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace Artemis.Core
|
||||
public class Timeline : CorePropertyChanged, IStorageModel
|
||||
{
|
||||
private const int MaxExtraTimelines = 15;
|
||||
private readonly object _lock = new object();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="Timeline" /> class
|
||||
@@ -19,9 +20,10 @@ namespace Artemis.Core
|
||||
public Timeline()
|
||||
{
|
||||
Entity = new TimelineEntity();
|
||||
_extraTimelines = new List<Timeline>();
|
||||
MainSegmentLength = TimeSpan.FromSeconds(5);
|
||||
|
||||
_extraTimelines = new List<Timeline>();
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
@@ -35,6 +37,7 @@ namespace Artemis.Core
|
||||
|
||||
private Timeline(Timeline parent)
|
||||
{
|
||||
Entity = new TimelineEntity();
|
||||
Parent = parent;
|
||||
StartSegmentLength = Parent.StartSegmentLength;
|
||||
MainSegmentLength = Parent.MainSegmentLength;
|
||||
@@ -303,7 +306,7 @@ namespace Artemis.Core
|
||||
/// <param name="stickToMainSegment">Whether to stick to the main segment, wrapping around if needed</param>
|
||||
public void Update(TimeSpan delta, bool stickToMainSegment)
|
||||
{
|
||||
lock (this)
|
||||
lock (_lock)
|
||||
{
|
||||
Delta += delta;
|
||||
Position += delta;
|
||||
@@ -330,7 +333,7 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public void JumpToStart()
|
||||
{
|
||||
lock (this)
|
||||
lock (_lock)
|
||||
{
|
||||
if (Position == TimeSpan.Zero)
|
||||
return;
|
||||
@@ -345,7 +348,7 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public void JumpToEndSegment()
|
||||
{
|
||||
lock (this)
|
||||
lock (_lock)
|
||||
{
|
||||
if (Position >= EndSegmentStartPosition)
|
||||
return;
|
||||
@@ -360,7 +363,7 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public void JumpToEnd()
|
||||
{
|
||||
lock (this)
|
||||
lock (_lock)
|
||||
{
|
||||
if (Position >= EndSegmentEndPosition)
|
||||
return;
|
||||
@@ -377,7 +380,7 @@ namespace Artemis.Core
|
||||
/// <param name="stickToMainSegment">Whether to stick to the main segment, wrapping around if needed</param>
|
||||
public void Override(TimeSpan position, bool stickToMainSegment)
|
||||
{
|
||||
lock (this)
|
||||
lock (_lock)
|
||||
{
|
||||
Delta += position - Position;
|
||||
Position = position;
|
||||
@@ -395,7 +398,7 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public void ClearDelta()
|
||||
{
|
||||
lock (this)
|
||||
lock (_lock)
|
||||
{
|
||||
Delta = TimeSpan.Zero;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user