mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-15 22:56:37 +01:00
101 lines
3.4 KiB
C#
101 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using TINK.Model.Services.CopriApi.ServerUris;
|
|
|
|
namespace TINK.Model.Connector
|
|
{
|
|
/// <summary> View model managing active uri and sets of uris. </summary>
|
|
public class CopriServerUriListViewModel : INotifyPropertyChanged
|
|
{
|
|
/// <summary>
|
|
/// Object holding active uris.
|
|
/// </summary>
|
|
private CopriServerUriList m_oUris;
|
|
|
|
/// <summary>
|
|
/// Fired whenever a property changes.
|
|
/// </summary>
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
/// <summary>Maps uris to user fiendly descriptions.</summary>
|
|
private Dictionary<string, string> uriToServerText;
|
|
|
|
/// <summary>Maps user fiendly descriptions to uris.</summary>
|
|
private Dictionary<string, string> serverTextToUri;
|
|
|
|
public CopriServerUriListViewModel(CopriServerUriList p_oSource)
|
|
{
|
|
uriToServerText = new Dictionary<string, string> {
|
|
{ CopriServerUriList.TINK_DEVEL, "TINK-Konrad-devellopment" },
|
|
{ CopriServerUriList.TINK_LIVE, "TINK-Konrad-live" },
|
|
{ CopriServerUriList.SHAREE_DEVEL, "Sharee-fr01-devellopment" },
|
|
{ CopriServerUriList.SHAREE_LIVE, "Sharee-fr01-live" }
|
|
};
|
|
|
|
serverTextToUri = uriToServerText.ToDictionary(x => x.Value, x => x.Key);
|
|
|
|
m_oUris = new CopriServerUriList(p_oSource);
|
|
NextActiveUri = m_oUris.ActiveUri;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the active uri.
|
|
/// </summary>
|
|
private Uri ActiveUri
|
|
{
|
|
set
|
|
{
|
|
if (m_oUris.ActiveUri.AbsoluteUri == value.AbsoluteUri)
|
|
{
|
|
/// Nothing to do.
|
|
return;
|
|
}
|
|
|
|
m_oUris = new CopriServerUriList(m_oUris.Uris.ToArray(), value);
|
|
}
|
|
}
|
|
|
|
/// <summary> Gets the known uris. </summary>
|
|
public IList<string> ServerTextList
|
|
{
|
|
get
|
|
{
|
|
return m_oUris.Uris.Select(x => (uriToServerText.ContainsKey(x.AbsoluteUri) ? uriToServerText[x.AbsoluteUri] : x.AbsoluteUri)).OrderBy(x => x).ToList();
|
|
}
|
|
}
|
|
|
|
/// <summary> Holds the uri which will be applied after restart of app. </summary>
|
|
public Uri NextActiveUri { get; private set; }
|
|
|
|
/// <summary> Holds the uri which will be applied after restart. </summary>
|
|
public string NextActiveServerText
|
|
{
|
|
get
|
|
{
|
|
return uriToServerText.ContainsKey(NextActiveUri.AbsoluteUri) ? uriToServerText[NextActiveUri.AbsoluteUri] : NextActiveUri.AbsoluteUri;
|
|
}
|
|
|
|
set
|
|
{
|
|
NextActiveUri = new Uri(serverTextToUri.ContainsKey(value) ? serverTextToUri[value] : value);
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CorpiServerUriDescription)));
|
|
}
|
|
}
|
|
|
|
/// <summary> Holds the description of the picker.</summary>
|
|
public string CorpiServerUriDescription
|
|
{
|
|
get
|
|
{
|
|
return m_oUris.ActiveUri.AbsoluteUri == NextActiveUri.AbsoluteUri
|
|
? "Aktiver Copri- Server"
|
|
: "Copri- Server.\r\nNeustart erforderlich für Wechsel!";
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|