sharee.bike-App/TINKLib/ViewModel/Settings/PollingViewModel.cs
Anja Müller-Meißner 0468955d49 Version 3.0.338
2022-09-08 09:55:14 +02:00

111 lines
3 KiB
C#

using System;
using System.ComponentModel;
using TINK.Settings;
namespace TINK.ViewModel.Settings
{
/// <summary> Polling relagted parameters</summary>
public class PollingViewModel : INotifyPropertyChanged
{
/// <summary>Holds the views polling parameters.</summary>
private PollingParameters m_oPolling = PollingParameters.Default;
/// <summary> Current polling periode. Used to check whether values were modified or not.</summary>
private readonly PollingParameters m_oPollingActive;
/// <summary> Constructs polling object. </summary>
/// <param name="p_oSource">Object to construct from</param>
public PollingViewModel(PollingParameters p_oSource)
{
m_oPollingActive = p_oSource
?? throw new ArgumentException("Can not instantiate polling parameters view model- object. Polling parameter object is null.");
m_oPolling = p_oSource;
}
/// <summary> Gets the immutable version of polling parameters.</summary>
/// <returns>Polling parameters object.</returns>
public PollingParameters ToImmutable() { return m_oPolling; }
/// <summary> Holds value whether polling is activated or not.</summary>
public bool IsActivated
{
get
{
return m_oPolling.IsActivated;
}
set
{
if (value == m_oPolling.IsActivated)
{
// Nothing to do.
return;
}
m_oPolling = new PollingParameters(m_oPolling.Periode, value);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsActivated)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PeriodeTotalSeconds)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PeriodeTotalSecondsText)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PollingText)));
}
}
/// <summary> Gests or sets the polling periode [sec]. </summary>
public int PeriodeTotalSeconds
{
get
{
return (int)m_oPolling.Periode.TotalSeconds;
}
set
{
if (value == (int)m_oPolling.Periode.TotalSeconds)
{
// Nothing to do.
return;
}
m_oPolling = new PollingParameters(new TimeSpan(0, 0, value), IsActivated);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PeriodeTotalSeconds)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PeriodeTotalSecondsText)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PollingText)));
}
}
/// <summary> Gets info about polling periode.</summary>
public string PeriodeTotalSecondsText
{
get
{
if (IsActivated)
{
return $"Polling Periode: {PeriodeTotalSeconds} [Sek.]";
}
return $"Polling abgeschalten.";
}
}
/// <summary> Gets the text of the polling related controls.</summary>
public string PollingText
{
get
{
if (m_oPolling == m_oPollingActive)
{
return "Polling";
}
return "Polling\r\nAnsicht verlassen um Änderungen anzuwenden.";
}
}
/// <summary> Notifies GUI about modified values.</summary>
public event PropertyChangedEventHandler PropertyChanged;
}
}