2023-02-22 14:03:35 +01:00
|
|
|
using System;
|
2021-05-13 20:03:07 +02:00
|
|
|
|
|
|
|
namespace TINK.Settings
|
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
/// <summary> Holds polling parameters.</summary>
|
|
|
|
public sealed class PollingParameters : IEquatable<PollingParameters>
|
|
|
|
{
|
|
|
|
/// <summary> Holds default polling parameters. </summary>
|
|
|
|
public static PollingParameters Default { get; } = new PollingParameters(
|
2023-02-22 14:03:35 +01:00
|
|
|
new TimeSpan(0, 0, 0, 60 /*secs*/, 0), // Default polling interval. Was 10 secs up to 3.0.357.
|
2022-09-06 16:08:19 +02:00
|
|
|
true);
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
/// <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);
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
/// <summary> Constructs a polling parameter object. </summary>
|
2023-04-19 12:14:14 +02:00
|
|
|
/// <param name="period">Polling period.</param>
|
2023-02-22 14:03:35 +01:00
|
|
|
/// <param name="activated">True if polling is activated.</param>
|
2023-04-19 12:14:14 +02:00
|
|
|
public PollingParameters(TimeSpan period, bool activated)
|
2022-09-06 16:08:19 +02:00
|
|
|
{
|
2023-04-19 12:14:14 +02:00
|
|
|
Periode = period; // Can not be null because is a struct.
|
2023-02-22 14:03:35 +01:00
|
|
|
IsActivated = activated;
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2023-04-19 12:14:14 +02:00
|
|
|
/// <summary>Holds the polling period.</summary>
|
2022-09-06 16:08:19 +02:00
|
|
|
public TimeSpan Periode { get; }
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
/// <summary> Holds value whether polling is activated or not.</summary>
|
|
|
|
public bool IsActivated { get; }
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
/// <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;
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
/// <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;
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
return this == l_oParameters;
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
/// <summary> Gets the has code of object.</summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public override int GetHashCode()
|
|
|
|
{
|
|
|
|
return Periode.GetHashCode() ^ IsActivated.GetHashCode();
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
/// <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].";
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
/// <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;
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
if (p_oSource is null ^ p_oTarget is null)
|
|
|
|
{
|
|
|
|
// Only one object is null.
|
|
|
|
return false;
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
return p_oSource.Periode == p_oTarget.Periode
|
|
|
|
&& p_oSource.IsActivated == p_oTarget.IsActivated;
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
/// <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;
|
|
|
|
}
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
}
|