mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-15 22:56:37 +01:00
85 lines
2.6 KiB
C#
85 lines
2.6 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> Gets the known uris text, i.e. binds to picker ItemsSource. </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 active uri, i.e. binds to picker SelectedItem. </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, i.e. binds to label Text.</summary>
|
|
public string CorpiServerUriDescription
|
|
{
|
|
get
|
|
{
|
|
return m_oUris.ActiveUri.AbsoluteUri == NextActiveUri.AbsoluteUri
|
|
? "Aktiver Copri- Server"
|
|
: "Copri- Server.\r\nNeustart erforderlich für Wechsel!";
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|