77 lines
2.4 KiB
C#
77 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows;
|
|
using System.Security.Principal;
|
|
using Serilog;
|
|
using Serilog.Sinks.Graylog;
|
|
using DevExpress.Mvvm;
|
|
using DevExpress.Xpf.Core;
|
|
|
|
namespace wpf_ax_utility
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for App.xaml
|
|
/// </summary>
|
|
public partial class App : Application
|
|
{
|
|
public static string userName { get { return WindowsIdentity.GetCurrent().Name.Replace("PAL\\", ""); } }
|
|
public App()
|
|
{
|
|
BeforeStart();
|
|
}
|
|
|
|
private List<string> GetGroups(string userName)
|
|
{
|
|
List<string> result = new List<string>();
|
|
WindowsIdentity wi = new WindowsIdentity(userName);
|
|
|
|
foreach (IdentityReference group in wi.Groups)
|
|
{
|
|
try
|
|
{
|
|
result.Add(group.Translate(typeof(NTAccount)).ToString());
|
|
}
|
|
catch (Exception ex) {
|
|
Utility.WriteLogMessage("Error retrieving groups", LogMessageSeverity.Error, ex);
|
|
}
|
|
}
|
|
|
|
result.Sort();
|
|
return result;
|
|
}
|
|
|
|
private void BeforeStart()
|
|
{
|
|
//SplashScreen
|
|
var splashScreenViewModel = new DXSplashScreenViewModel() {
|
|
Title = "PAL Ax Utility",
|
|
Copyright = "",
|
|
Logo = new Uri("res/pallogo.png", UriKind.Relative),
|
|
|
|
};
|
|
SplashScreenManager.Create(() => new AxUtilitySplashScreen(), splashScreenViewModel).ShowOnStartup();
|
|
|
|
//Log Endpoint
|
|
Log.Logger = new LoggerConfiguration().WriteTo.Graylog(new GraylogSinkOptions
|
|
{
|
|
HostnameOrAddress = "palgraylog01.pal.it",
|
|
Port = 12202,
|
|
MinimumLogEventLevel = Serilog.Events.LogEventLevel.Verbose,
|
|
Facility = "(WPF) AX Utility"
|
|
}).CreateLogger();
|
|
|
|
//View selection with group filter
|
|
var userGroups = GetGroups(userName);
|
|
|
|
var uriString = "/wpf_ax_utility;component/AppUserWindow.xaml";
|
|
|
|
if (userGroups.Contains("PAL\\BRAIN FORCE - AX DEV ADMINS") || userGroups.Contains("PAL\\PAL GG IT"))
|
|
{
|
|
uriString = "/wpf_ax_utility;component/AppMainWindow.xaml";
|
|
}
|
|
|
|
this.StartupUri = new Uri(uriString, UriKind.Relative);
|
|
}
|
|
}
|
|
}
|