Code updated to 3.0.238

This commit is contained in:
Oliver Hauff 2021-06-26 20:57:55 +02:00
parent 3302d80678
commit 9c6a1fa92b
257 changed files with 7763 additions and 2861 deletions

View file

@ -17,6 +17,7 @@ namespace TINK.Model.User.Account
PickLoggingLevel = 64, // Allows to select the logging level.
ShowDiagnostics = 128, // Turns on display of diagnostics.
SwitchNoSiteCaching = 1024, // Allows to turn off/ on caching of sites displayed in app hosted by COPRI
ReportLevel = 2048, // Allows extent to show error messages.
All = PickCopriServer +
ManageCopriCacheExpiration +
ManagePolling +
@ -24,7 +25,8 @@ namespace TINK.Model.User.Account
PickLocationServiceImplementation +
PickLoggingLevel +
ShowDiagnostics +
SwitchNoSiteCaching,
SwitchNoSiteCaching +
ReportLevel,
}
/// <summary>
@ -48,24 +50,24 @@ namespace TINK.Model.User.Account
public class Account : IAccount
{
/// <summary> Constructs an account object.</summary>
/// <param name="p_oMail">Mail addresss.</param>
/// <param name="p_Pwd">Password.</param>
/// <param name="p_oSessionCookie">Session cookie from copri.</param>
/// <param name="p_strGroup">Group holdig info about Group (TINK, Konrad, ...)</param>
/// <param name="mail">Mail addresss.</param>
/// <param name="password">Password.</param>
/// <param name="sessionCookie">Session cookie from copri.</param>
/// <param name="group">Group holdig info about Group (TINK, Konrad, ...)</param>
/// <param name="p_iDebugLevel">Flag which controls display of debug settings.</param>
public Account(
string p_oMail,
string p_Pwd,
string p_oSessionCookie,
IEnumerable<string> p_strGroup,
string mail,
string password,
string sessionCookie,
IEnumerable<string> group,
Permissions debugLevel = Permissions.None)
{
Mail = p_oMail;
Pwd = p_Pwd;
SessionCookie = p_oSessionCookie;
Mail = mail;
Pwd = password;
SessionCookie = sessionCookie;
DebugLevel = debugLevel;
Group = p_strGroup != null
? new HashSet<string>(p_strGroup).ToList()
Group = group != null
? new HashSet<string>(group).ToList()
: throw new ArgumentException("Can not instantiate account object. Reference to group list must not be empty.");
}

View file

@ -1,26 +1,26 @@
namespace TINK.Model.User.Account
using System.Threading.Tasks;
namespace TINK.Model.User.Account
{
/// <summary>
/// Interface to manage an account store.
/// </summary>
/// <summary>Interface to manage an account store.</summary>
public interface IStore
{
/// <summary>
/// Reads mail address and password from account store.
/// </summary>
/// <returns></returns>
IAccount Load();
Task<IAccount> Load();
/// <summary>
/// Writes mail address and password to account store.
/// </summary>
/// <param name="p_oMailAndPwd"></param>
void Save(IAccount p_oMailAndPwd);
/// <param name="mailAndPwd"></param>
Task Save(IAccount mailAndPwd);
/// <summary>
/// Deletes mail address and password from account store.
/// </summary>
/// <returns> Empty account instance if deleting succeeded.</returns>
IAccount Delete(IAccount p_oMailAndPwd);
IAccount Delete(IAccount mailAndPwd);
}
}

View file

@ -0,0 +1,67 @@
using Serilog;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xamarin.Essentials;
namespace TINK.Model.User.Account
{
public class Store : IStore
{
/// <summary> Holds id of the debug level key. </summary>
private const string KEY_DEBUGLEVEL = "DebugLevel";
/// <summary> Holds the id of the session. </summary>
private const string KEY_SESSIONCOOKIE = "SessionCookie";
/// <summary> Holds id of the mail address key. </summary>
private const string KEY_MAILADDRESS = "MailAddress";
public IAccount Delete(IAccount account)
{
SecureStorage.RemoveAll();
return new EmptyAccount();
}
public async Task<IAccount> Load()
{
var mail = string.Empty;
var sessionCookie = string.Empty;
var debugLevel = Permissions.None;
try
{
mail = await SecureStorage.GetAsync(KEY_MAILADDRESS);
sessionCookie = await SecureStorage.GetAsync(KEY_SESSIONCOOKIE);
Enum.TryParse(await SecureStorage.GetAsync(KEY_DEBUGLEVEL), out debugLevel);
}
catch (Exception exception)
{
Log.ForContext<Store>().Error("Loading account from store failed. {Exception}", exception);
}
return new Account(
mail,
string.Empty,
sessionCookie,
new List<string>(),
debugLevel);
}
public async Task Save(IAccount mailAndPwd)
{
try
{
await SecureStorage.SetAsync(KEY_MAILADDRESS, mailAndPwd.Mail);
await SecureStorage.SetAsync(KEY_SESSIONCOOKIE, mailAndPwd.SessionCookie);
await SecureStorage.SetAsync(KEY_DEBUGLEVEL, mailAndPwd.DebugLevel.ToString());
}
catch (Exception exception)
{
Log.ForContext<Store>().Error("Saving account from store failed. {Exception}", exception);
}
}
}
}

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using TINK.Model.User.Account;
namespace TINK.Model.User
@ -29,14 +30,14 @@ namespace TINK.Model.User
/// </summary>
/// <param name="p_oAccountStore"> Object to use for loading and saving user data.</param>
public User(
IStore p_oAccountStore,
IAccount p_oAccount,
string p_strDeviceId)
IStore accountStore,
IAccount account,
string deviceId)
{
m_oStore = p_oAccountStore
m_oStore = accountStore
?? throw new ArgumentException("Can not instantiate user- object. No store functionality available.");
DeviceId = p_strDeviceId;
m_oAccount = new AccountMutable(p_oAccount);
DeviceId = deviceId;
m_oAccount = new AccountMutable(account);
}
/// <summary> Is fired wheneverlogin state changes. </summary>
@ -109,13 +110,13 @@ namespace TINK.Model.User
/// <param name="p_oAccount">Account to use for login.</param>
/// <param name="p_str_DeviceId">Holds the Id to identify the device.</param>
/// <param name="isConnected">True if connector has access to copri server, false if cached values are used.</param>
public void Login(IAccount account)
public async Task Login(IAccount account)
{
// Update account instance from copri data.
m_oAccount.Copy(account);
// Save data to store.
m_oStore.Save(m_oAccount);
await m_oStore.Save(m_oAccount);
// Nothing to do because state did not change.
StateChanged?.Invoke(this, new EventArgs());