mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Code style - Use file scoped namespaces
Code style - Ran code cleanup
This commit is contained in:
1 parent
e68e16df4d
commit
f6090dc296
691 files changed
+37301
-38119
No files matched your search
@@ -1,92 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core
|
||||
namespace Artemis.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Provides a default implementation for models that can have a broken state
|
||||
/// </summary>
|
||||
public abstract class BreakableModel : CorePropertyChanged, IBreakableModel
|
||||
{
|
||||
private string? _brokenState;
|
||||
private Exception? _brokenStateException;
|
||||
|
||||
/// <summary>
|
||||
/// Provides a default implementation for models that can have a broken state
|
||||
/// Invokes the <see cref="BrokenStateChanged" /> event
|
||||
/// </summary>
|
||||
public abstract class BreakableModel : CorePropertyChanged, IBreakableModel
|
||||
protected virtual void OnBrokenStateChanged()
|
||||
{
|
||||
private string? _brokenState;
|
||||
private Exception? _brokenStateException;
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="BrokenStateChanged" /> event
|
||||
/// </summary>
|
||||
protected virtual void OnBrokenStateChanged()
|
||||
{
|
||||
BrokenStateChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract string BrokenDisplayName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the broken state of this breakable model, if <see langword="null" /> this model is not broken.
|
||||
/// <para>Note: If setting this manually you are also responsible for invoking <see cref="BrokenStateChanged" /></para>
|
||||
/// </summary>
|
||||
public string? BrokenState
|
||||
{
|
||||
get => _brokenState;
|
||||
set => SetAndNotify(ref _brokenState, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the exception that caused the broken state
|
||||
/// <para>Note: If setting this manually you are also responsible for invoking <see cref="BrokenStateChanged" /></para>
|
||||
/// </summary>
|
||||
public Exception? BrokenStateException
|
||||
{
|
||||
get => _brokenStateException;
|
||||
set => SetAndNotify(ref _brokenStateException, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TryOrBreak(Action action, string breakMessage)
|
||||
{
|
||||
try
|
||||
{
|
||||
action();
|
||||
ClearBrokenState(breakMessage);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
SetBrokenState(breakMessage, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetBrokenState(string state, Exception? exception)
|
||||
{
|
||||
BrokenState = state ?? throw new ArgumentNullException(nameof(state));
|
||||
BrokenStateException = exception;
|
||||
OnBrokenStateChanged();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ClearBrokenState(string state)
|
||||
{
|
||||
if (state == null) throw new ArgumentNullException(nameof(state));
|
||||
if (BrokenState == null)
|
||||
return;
|
||||
|
||||
if (BrokenState != state) return;
|
||||
BrokenState = null;
|
||||
BrokenStateException = null;
|
||||
OnBrokenStateChanged();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual IEnumerable<IBreakableModel> GetBrokenHierarchy()
|
||||
{
|
||||
if (BrokenState != null)
|
||||
yield return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler? BrokenStateChanged;
|
||||
BrokenStateChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract string BrokenDisplayName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the broken state of this breakable model, if <see langword="null" /> this model is not broken.
|
||||
/// <para>Note: If setting this manually you are also responsible for invoking <see cref="BrokenStateChanged" /></para>
|
||||
/// </summary>
|
||||
public string? BrokenState
|
||||
{
|
||||
get => _brokenState;
|
||||
set => SetAndNotify(ref _brokenState, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the exception that caused the broken state
|
||||
/// <para>Note: If setting this manually you are also responsible for invoking <see cref="BrokenStateChanged" /></para>
|
||||
/// </summary>
|
||||
public Exception? BrokenStateException
|
||||
{
|
||||
get => _brokenStateException;
|
||||
set => SetAndNotify(ref _brokenStateException, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TryOrBreak(Action action, string breakMessage)
|
||||
{
|
||||
try
|
||||
{
|
||||
action();
|
||||
ClearBrokenState(breakMessage);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
SetBrokenState(breakMessage, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetBrokenState(string state, Exception? exception)
|
||||
{
|
||||
BrokenState = state ?? throw new ArgumentNullException(nameof(state));
|
||||
BrokenStateException = exception;
|
||||
OnBrokenStateChanged();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ClearBrokenState(string state)
|
||||
{
|
||||
if (state == null) throw new ArgumentNullException(nameof(state));
|
||||
if (BrokenState == null)
|
||||
return;
|
||||
|
||||
if (BrokenState != state) return;
|
||||
BrokenState = null;
|
||||
BrokenStateException = null;
|
||||
OnBrokenStateChanged();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual IEnumerable<IBreakableModel> GetBrokenHierarchy()
|
||||
{
|
||||
if (BrokenState != null)
|
||||
yield return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler? BrokenStateChanged;
|
||||
}
|
||||
Reference in new issue
Block a user