Реализован сервис настроек приложения.

This commit is contained in:
mikhail "synzr" 2025-11-21 10:41:52 +05:00
parent afabd343f5
commit 01f9c3aa2f
3 changed files with 50 additions and 0 deletions

View file

@ -123,7 +123,9 @@
<Compile Include="Models\SessionData.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\ISessionService.cs" />
<Compile Include="Services\ISettingsService.cs" />
<Compile Include="Services\SessionService.cs" />
<Compile Include="Services\SettingsService.cs" />
<EmbeddedResource Include="Properties\Intersvyaz.Core.rd.xml" />
</ItemGroup>
<ItemGroup>

View file

@ -0,0 +1,24 @@
using System;
namespace Intersvyaz.Core.Services
{
public interface ISettingsService
{
/// <summary>
/// Событие об изменении текущего пользователя.
/// </summary>
event EventHandler<string> CurrentUserChanged;
/// <summary>
/// Получить текущего пользователя.
/// </summary>
/// <returns>Имя пользователя.</returns>
string GetCurrentUser();
/// <summary>
/// Установить нового текущего пользователя.
/// </summary>
/// <param name="value">Имя нового пользователя.</param>
void SetCurrentUser(string value);
}
}

View file

@ -0,0 +1,24 @@
using System;
using Windows.Storage;
namespace Intersvyaz.Core.Services
{
public class SettingsService : ISettingsService
{
/// <inheritdoc />
public event EventHandler<string> CurrentUserChanged;
/// <inheritdoc />
public string GetCurrentUser()
{
return (string)ApplicationData.Current.LocalSettings.Values["CurrentUser"] ?? null;
}
/// <inheritdoc />
public void SetCurrentUser(string value)
{
ApplicationData.Current.LocalSettings.Values["CurrentUser"] = value;
CurrentUserChanged?.Invoke(this, value);
}
}
}