using System; using System.Collections.Generic; namespace RGB.NET.Core { /// /// Represents a generic RGB-surface. /// public class RGBSurface { #region Properties & Fields private DateTime _lastUpdate; #endregion #region Events // ReSharper disable EventNeverSubscribedTo.Global /// /// Occurs when a catched exception is thrown inside the . /// public event ExceptionEventHandler Exception; /// /// Occurs when the starts updating. /// public event UpdatingEventHandler Updating; /// /// Occurs when the update is done. /// public event UpdatedEventHandler Updated; /// /// Occurs when the starts to update the . /// public event LedsUpdatingEventHandler LedsUpdating; /// /// Occurs when the updated the . /// public event LedsUpdatedEventHandler LedsUpdated; // ReSharper restore EventNeverSubscribedTo.Global #endregion #region Constructors /// /// Initializes a new instance of the class. /// public RGBSurface() { _lastUpdate = DateTime.Now; } #endregion #region EventCaller /// /// Handles the needed event-calls for an exception. /// /// The exception previously thrown. protected virtual void OnException(Exception ex) { try { Exception?.Invoke(this, new ExceptionEventArgs(ex)); } catch { // Well ... that's not my fault } } /// /// Handles the needed event-calls before updating. /// protected virtual void OnUpdating() { try { long lastUpdateTicks = _lastUpdate.Ticks; _lastUpdate = DateTime.Now; Updating?.Invoke(this, new UpdatingEventArgs((DateTime.Now.Ticks - lastUpdateTicks) / 10000000.0)); } catch { // Well ... that's not my fault } } /// /// Handles the needed event-calls after an update. /// protected virtual void OnUpdated() { try { Updated?.Invoke(this, new UpdatedEventArgs()); } catch { // Well ... that's not my fault } } /// /// Handles the needed event-calls before the are updated. /// protected virtual void OnLedsUpdating(ICollection updatingLeds) { try { LedsUpdating?.Invoke(this, new LedsUpdatingEventArgs(updatingLeds)); } catch { // Well ... that's not my fault } } /// /// Handles the needed event-calls after the are updated. /// protected virtual void OnLedsUpdated(IEnumerable updatedLeds) { try { LedsUpdated?.Invoke(this, new LedsUpdatedEventArgs(updatedLeds)); } catch { // Well ... that's not my fault } } #endregion } }