Added Graylog and code resume
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
|
using Serilog;
|
||||||
|
using Serilog.Sinks.Graylog;
|
||||||
|
|
||||||
namespace wpf_ax_utility
|
namespace wpf_ax_utility
|
||||||
{
|
{
|
||||||
@@ -10,9 +12,17 @@ namespace wpf_ax_utility
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class App : Application
|
public partial class App : Application
|
||||||
{
|
{
|
||||||
|
public static string userName { get { return WindowsIdentity.GetCurrent().Name.Replace("PAL\\", ""); } }
|
||||||
public App()
|
public App()
|
||||||
{
|
{
|
||||||
string userName = WindowsIdentity.GetCurrent().Name.Replace("PAL\\", "");
|
Log.Logger = new LoggerConfiguration().WriteTo.Graylog(new GraylogSinkOptions
|
||||||
|
{
|
||||||
|
HostnameOrAddress = "palgraylog01.pal.it",
|
||||||
|
Port = 12202,
|
||||||
|
MinimumLogEventLevel = Serilog.Events.LogEventLevel.Verbose,
|
||||||
|
Facility = "(WPF) AX Utility"
|
||||||
|
}).CreateLogger();
|
||||||
|
|
||||||
var userGroups = GetGroups(userName);
|
var userGroups = GetGroups(userName);
|
||||||
|
|
||||||
var uriString = "/wpf_ax_utility;component/UserWindow.xaml";
|
var uriString = "/wpf_ax_utility;component/UserWindow.xaml";
|
||||||
@@ -36,7 +46,9 @@ namespace wpf_ax_utility
|
|||||||
{
|
{
|
||||||
result.Add(group.Translate(typeof(NTAccount)).ToString());
|
result.Add(group.Translate(typeof(NTAccount)).ToString());
|
||||||
}
|
}
|
||||||
catch (Exception ex) { }
|
catch (Exception ex) {
|
||||||
|
Utility.WriteLogMessage("Error retrieving groups", LogMessageSeverity.Error, ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Sort();
|
result.Sort();
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Serilog;
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
@@ -25,7 +26,7 @@ namespace wpf_ax_utility
|
|||||||
|
|
||||||
private void ButtonClicked(object sender, RoutedEventArgs e)
|
private void ButtonClicked(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
AucCleaner();
|
Utility.AucCleaner();
|
||||||
|
|
||||||
string AxArgs = string.Empty;
|
string AxArgs = string.Empty;
|
||||||
|
|
||||||
@@ -48,42 +49,9 @@ namespace wpf_ax_utility
|
|||||||
break; ;
|
break; ;
|
||||||
}
|
}
|
||||||
|
|
||||||
AxExecution(AxArgs);
|
Utility.AxExecution(AxArgs);
|
||||||
}
|
|
||||||
|
|
||||||
public static void AxExecution(string AxArgs)
|
Log.Logger.Information("Running AX client with this parameter: " + AxArgs);
|
||||||
{
|
|
||||||
string AxClient = @"C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\Ax32.exe";
|
|
||||||
|
|
||||||
if (System.IO.File.Exists(AxClient))
|
|
||||||
{
|
|
||||||
var p = new System.Diagnostics.Process();
|
|
||||||
p.StartInfo.FileName = AxClient;
|
|
||||||
p.StartInfo.Arguments = AxArgs;
|
|
||||||
p.StartInfo.RedirectStandardOutput = true;
|
|
||||||
p.StartInfo.UseShellExecute = false;
|
|
||||||
p.StartInfo.CreateNoWindow = true;
|
|
||||||
p.Start();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("Microsoft Dynamics Ax 2012 non è installato.", "Informazioni PAL Ax Utility", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AucCleaner()
|
|
||||||
{
|
|
||||||
string sourceDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
|
||||||
|
|
||||||
DirectoryInfo directory = new DirectoryInfo(sourceDir);
|
|
||||||
FileInfo[] files = directory.GetFiles();
|
|
||||||
|
|
||||||
string[] aucList = Directory.GetFiles(sourceDir, "*.auc");
|
|
||||||
|
|
||||||
foreach (string f in aucList)
|
|
||||||
{
|
|
||||||
File.Delete(f);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Serilog;
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
@@ -25,7 +26,7 @@ namespace wpf_ax_utility
|
|||||||
|
|
||||||
private void ButtonClicked(object sender, RoutedEventArgs e)
|
private void ButtonClicked(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
AucCleaner();
|
Utility.AucCleaner();
|
||||||
|
|
||||||
string AxArgs = string.Empty;
|
string AxArgs = string.Empty;
|
||||||
|
|
||||||
@@ -39,42 +40,11 @@ namespace wpf_ax_utility
|
|||||||
break; ;
|
break; ;
|
||||||
}
|
}
|
||||||
|
|
||||||
AxExecution(AxArgs);
|
Utility.AxExecution(AxArgs);
|
||||||
|
|
||||||
|
Log.Logger.Information("Running AX client with this parameter: " + AxArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AxExecution(string AxArgs)
|
|
||||||
{
|
|
||||||
string AxClient = @"C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\Ax32.exe";
|
|
||||||
|
|
||||||
if (System.IO.File.Exists(AxClient))
|
|
||||||
{
|
|
||||||
var p = new System.Diagnostics.Process();
|
|
||||||
p.StartInfo.FileName = AxClient;
|
|
||||||
p.StartInfo.Arguments = AxArgs;
|
|
||||||
p.StartInfo.RedirectStandardOutput = true;
|
|
||||||
p.StartInfo.UseShellExecute = false;
|
|
||||||
p.StartInfo.CreateNoWindow = true;
|
|
||||||
p.Start();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("Microsoft Dynamics Ax 2012 non è installato.", "Informazioni PAL Ax Utility", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AucCleaner()
|
|
||||||
{
|
|
||||||
string sourceDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
|
||||||
|
|
||||||
DirectoryInfo directory = new DirectoryInfo(sourceDir);
|
|
||||||
FileInfo[] files = directory.GetFiles();
|
|
||||||
|
|
||||||
string[] aucList = Directory.GetFiles(sourceDir, "*.auc");
|
|
||||||
|
|
||||||
foreach (string f in aucList)
|
|
||||||
{
|
|
||||||
File.Delete(f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
using Serilog;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace wpf_ax_utility
|
||||||
|
{
|
||||||
|
public enum LogMessageSeverity
|
||||||
|
{
|
||||||
|
Informational,
|
||||||
|
Error
|
||||||
|
}
|
||||||
|
public static class Utility
|
||||||
|
{
|
||||||
|
public static void AxExecution(string AxArgs)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string AxClient = @"C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\Ax32.exe";
|
||||||
|
|
||||||
|
if (System.IO.File.Exists(AxClient))
|
||||||
|
{
|
||||||
|
var p = new System.Diagnostics.Process();
|
||||||
|
p.StartInfo.FileName = AxClient;
|
||||||
|
p.StartInfo.Arguments = AxArgs;
|
||||||
|
p.StartInfo.RedirectStandardOutput = true;
|
||||||
|
p.StartInfo.UseShellExecute = false;
|
||||||
|
p.StartInfo.CreateNoWindow = true;
|
||||||
|
p.Start();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Microsoft Dynamics Ax 2012 non è installato.", "Informazioni PAL Ax Utility", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Utility.WriteLogMessage("Error executing AX", LogMessageSeverity.Error, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AucCleaner()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sourceDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||||
|
|
||||||
|
DirectoryInfo directory = new DirectoryInfo(sourceDir);
|
||||||
|
if (directory.Exists)
|
||||||
|
{
|
||||||
|
FileInfo[] files = directory.GetFiles();
|
||||||
|
|
||||||
|
string[] aucList = Directory.GetFiles(sourceDir, "*.auc");
|
||||||
|
|
||||||
|
foreach (string f in aucList)
|
||||||
|
{
|
||||||
|
File.Delete(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Utility.WriteLogMessage("Error cleaning AUCs", LogMessageSeverity.Error, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void WriteLogMessage(string message, LogMessageSeverity Severity = LogMessageSeverity.Informational, Exception exc = null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var messageTemplate = "{User}: " + message;
|
||||||
|
switch (Severity)
|
||||||
|
{
|
||||||
|
case LogMessageSeverity.Informational:
|
||||||
|
Log.Logger.Information(messageTemplate, App.userName);
|
||||||
|
break;
|
||||||
|
case LogMessageSeverity.Error:
|
||||||
|
if (exc != null)
|
||||||
|
Log.Logger.Error(exc, messageTemplate, App.userName);
|
||||||
|
else
|
||||||
|
Log.Logger.Error(messageTemplate, App.userName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,11 @@
|
|||||||
<None Remove="rdrect1197.png" />
|
<None Remove="rdrect1197.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Serilog" Version="2.10.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.Graylog" Version="2.3.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Resource Include="axlogo.ico">
|
<Resource Include="axlogo.ico">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
|||||||
Reference in New Issue
Block a user