mirror of
https://github.com/gwdevhub/Daybreak.git
synced 2026-09-24 17:24:56 +00:00
34 lines
1.3 KiB
C#
34 lines
1.3 KiB
C#
using Daybreak.Models;
|
|
using Daybreak.Services.ViewManagement;
|
|
using Daybreak.Views;
|
|
using Microsoft.Extensions.Logging;
|
|
using System.Extensions;
|
|
using System.Security.Principal;
|
|
using System.Windows.Controls;
|
|
|
|
namespace Daybreak.Services.Privilege
|
|
{
|
|
public sealed class PrivilegeManager : IPrivilegeManager
|
|
{
|
|
public bool AdminPrivileges => new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
|
|
|
|
private readonly IViewManager viewManager;
|
|
private readonly ILogger<PrivilegeManager> logger;
|
|
|
|
public PrivilegeManager(
|
|
IViewManager viewManager,
|
|
ILogger<PrivilegeManager> logger)
|
|
{
|
|
this.logger = logger.ThrowIfNull(nameof(logger));
|
|
this.viewManager = viewManager.ThrowIfNull(nameof(viewManager));
|
|
}
|
|
|
|
public void RequestAdminPrivileges<TCancelView>(string messageToUser, object dataContextOfCancelView = null)
|
|
where TCancelView : UserControl
|
|
{
|
|
this.logger.LogInformation("Requesting admin privileges");
|
|
this.viewManager.ShowView<RequestElevationView>(new ElevationRequest { View = typeof(TCancelView), DataContext = dataContextOfCancelView, MessageToUser = messageToUser });
|
|
}
|
|
}
|
|
}
|