mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-05 10:36:30 +01:00
100 lines
3.8 KiB
C#
100 lines
3.8 KiB
C#
using System;
|
|
|
|
namespace TINK.Settings
|
|
{
|
|
/// <summary> Holds polling parameters.</summary>
|
|
public sealed class PollingParameters : IEquatable<PollingParameters>
|
|
{
|
|
/// <summary> Holds default polling parameters. </summary>
|
|
public static PollingParameters Default { get; } = new PollingParameters(
|
|
new TimeSpan(0, 0, 0, 10 /*secs*/, 0),// Default polling interval.
|
|
true);
|
|
|
|
/// <summary> Holds polling parameters which represent polling off (empty polling object). </summary>
|
|
public static PollingParameters NoPolling { get; } = new PollingParameters(
|
|
TimeSpan.MaxValue,// Very long intervall which should never be used because polling IsActivated property is set to false.
|
|
false);
|
|
|
|
/// <summary> Constructs a polling parameter object. </summary>
|
|
/// <param name="p_oPeriode">Polling periode.</param>
|
|
/// <param name="p_bIsActivated">True if polling is activated.</param>
|
|
public PollingParameters(TimeSpan p_oPeriode, bool p_bIsActivated)
|
|
{
|
|
Periode = p_oPeriode; // Can not be null because is a struct.
|
|
IsActivated = p_bIsActivated;
|
|
}
|
|
|
|
/// <summary>Holds the polling periode.</summary>
|
|
public TimeSpan Periode { get; }
|
|
|
|
/// <summary> Holds value whether polling is activated or not.</summary>
|
|
public bool IsActivated { get; }
|
|
|
|
/// <summary> Checks equallity.</summary>
|
|
/// <param name="other">Object to compare with.</param>
|
|
/// <returns>True if objects are equal.</returns>
|
|
public bool Equals(PollingParameters other)
|
|
{
|
|
return this == other;
|
|
}
|
|
|
|
/// <summary> Checks equallity.</summary>
|
|
/// <param name="obj">Object to compare with.</param>
|
|
/// <returns>True if objects are equal.</returns>
|
|
public override bool Equals(object obj)
|
|
{
|
|
var l_oParameters = obj as PollingParameters;
|
|
if (l_oParameters == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return this == l_oParameters;
|
|
}
|
|
|
|
/// <summary> Gets the has code of object.</summary>
|
|
/// <returns></returns>
|
|
public override int GetHashCode()
|
|
{
|
|
return Periode.GetHashCode() ^ IsActivated.GetHashCode();
|
|
}
|
|
|
|
/// <summary> Gets the string representation of the object.</summary>
|
|
/// <returns></returns>
|
|
public override string ToString()
|
|
{
|
|
return $"Polling is on={IsActivated}, polling interval={Periode.TotalSeconds}[sec].";
|
|
}
|
|
|
|
/// <summary>Defines equality of thwo polling parameter objects.</summary>
|
|
/// <param name="p_oSource">First object to compare.</param>
|
|
/// <param name="p_oTarget">Second object to compare.</param>
|
|
/// <returns>True if objects are equal</returns>
|
|
public static bool operator ==(PollingParameters p_oSource, PollingParameters p_oTarget)
|
|
{
|
|
if (p_oSource is null && p_oTarget is null)
|
|
{
|
|
// Both object are null
|
|
return true;
|
|
}
|
|
|
|
if (p_oSource is null ^ p_oTarget is null)
|
|
{
|
|
// Only one object is null.
|
|
return false;
|
|
}
|
|
|
|
return p_oSource.Periode == p_oTarget.Periode
|
|
&& p_oSource.IsActivated == p_oTarget.IsActivated;
|
|
}
|
|
|
|
/// <summary>Defines equality of thwo polling parameter objects.</summary>
|
|
/// <param name="p_oSource">First object to compare.</param>
|
|
/// <param name="p_oTarget">Second object to compare.</param>
|
|
/// <returns>True if objects are equal</returns>
|
|
public static bool operator !=(PollingParameters p_oSource, PollingParameters p_oTarget)
|
|
{
|
|
return (p_oSource == p_oTarget) == false;
|
|
}
|
|
}
|
|
}
|