Add window, user group filtering and minor change
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.DirectoryServices;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.Security.Principal;
|
||||||
|
|
||||||
namespace wpf_ax_utility
|
namespace wpf_ax_utility
|
||||||
{
|
{
|
||||||
@@ -15,8 +17,35 @@ namespace wpf_ax_utility
|
|||||||
{
|
{
|
||||||
public App()
|
public App()
|
||||||
{
|
{
|
||||||
// TODO: Verifica se l'utente fa parte di GG IT, in caso yes fai apparire una pagina, in caso no ne fai apparire un'altra
|
string userName = WindowsIdentity.GetCurrent().Name.Replace("PAL\\", "");
|
||||||
this.StartupUri = new Uri("/wpf_ax_utility;component/MainWindow.xaml", UriKind.Relative);
|
var userGroups = GetGroups(userName);
|
||||||
|
|
||||||
|
var uriString = "/wpf_ax_utility;component/UserWindow.xaml";
|
||||||
|
|
||||||
|
if (userGroups.Contains("PAL\\BRAIN FORCE - AX DEV ADMINS") || userGroups.Contains("PAL\\PAL GG ITe"))
|
||||||
|
{
|
||||||
|
uriString = "/wpf_ax_utility;component/MainWindow.xaml";
|
||||||
|
}
|
||||||
|
|
||||||
|
this.StartupUri = new Uri(uriString, UriKind.Relative);
|
||||||
|
}
|
||||||
|
|
||||||
|
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) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Sort();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,36 +59,46 @@
|
|||||||
<Button Style="{StaticResource TabButton}"
|
<Button Style="{StaticResource TabButton}"
|
||||||
x:Name="LIVE"
|
x:Name="LIVE"
|
||||||
Click="ButtonClicked"
|
Click="ButtonClicked"
|
||||||
Height="115" Width="320"
|
Height="115" Width="325"
|
||||||
Content="LIVE"
|
Content="LIVE"
|
||||||
FontSize="36"/>
|
FontSize="36"
|
||||||
|
Background="LightGray"/>
|
||||||
<DockPanel HorizontalAlignment="Center"
|
<DockPanel HorizontalAlignment="Center"
|
||||||
Margin="0,10,0,0">
|
Margin="0,10,0,0">
|
||||||
|
<Button Style="{StaticResource TabButton}"
|
||||||
|
x:Name="LIVE02"
|
||||||
|
Click="ButtonClicked"
|
||||||
|
Height="45" Width="75"
|
||||||
|
Margin="0,0,5,0"
|
||||||
|
Content="LIVE 02"
|
||||||
|
FontSize="16"
|
||||||
|
FontWeight="DemiBold"
|
||||||
|
Background="LightGray"/>
|
||||||
<Button Style="{StaticResource TabButton}"
|
<Button Style="{StaticResource TabButton}"
|
||||||
x:Name="DEV"
|
x:Name="DEV"
|
||||||
Click="ButtonClicked"
|
Click="ButtonClicked"
|
||||||
Height="45" Width="100"
|
Height="45" Width="75"
|
||||||
Margin="0,0,5,0"
|
Margin="0,0,5,0"
|
||||||
Content="DEV"
|
Content="DEV"
|
||||||
FontSize="18"
|
FontSize="16"
|
||||||
FontWeight="DemiBold"
|
FontWeight="DemiBold"
|
||||||
Background="#00FF80"/>
|
Background="#00FF80"/>
|
||||||
<Button Style="{StaticResource TabButton}"
|
<Button Style="{StaticResource TabButton}"
|
||||||
x:Name="TEST"
|
x:Name="TEST"
|
||||||
Click="ButtonClicked"
|
Click="ButtonClicked"
|
||||||
Height="45" Width="100"
|
Height="45" Width="75"
|
||||||
Margin="5,0,5,0"
|
Margin="5,0,5,0"
|
||||||
Content="TEST"
|
Content="TEST"
|
||||||
FontSize="18"
|
FontSize="16"
|
||||||
FontWeight="DemiBold"
|
FontWeight="DemiBold"
|
||||||
Background="#8080FF"/>
|
Background="#8080FF"/>
|
||||||
<Button Style="{StaticResource TabButton}"
|
<Button Style="{StaticResource TabButton}"
|
||||||
x:Name="STAGING"
|
x:Name="STAGING"
|
||||||
Click="ButtonClicked"
|
Click="ButtonClicked"
|
||||||
Height="45" Width="100"
|
Height="45" Width="75"
|
||||||
Margin="5,0,0,0"
|
Margin="5,0,0,0"
|
||||||
Content="STAGING"
|
Content="STAGING"
|
||||||
FontSize="18"
|
FontSize="16"
|
||||||
FontWeight="DemiBold"
|
FontWeight="DemiBold"
|
||||||
Background="#FFFF00"/>
|
Background="#FFFF00"/>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
|
|||||||
@@ -27,12 +27,14 @@ namespace wpf_ax_utility
|
|||||||
{
|
{
|
||||||
AucCleaner();
|
AucCleaner();
|
||||||
|
|
||||||
string AxClient = @"C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\Ax32.exe";
|
|
||||||
string AxArgs = string.Empty;
|
string AxArgs = string.Empty;
|
||||||
|
|
||||||
switch (((Button)sender).Name)
|
switch (((Button)sender).Name)
|
||||||
{
|
{
|
||||||
case "LIVE":
|
case "LIVE":
|
||||||
|
AxArgs = @"-regConfig=L:\Link\PAL_LIVE_USR.axc";
|
||||||
|
break;
|
||||||
|
case "LIVE02":
|
||||||
AxArgs = @"-regConfig=L:\Link\PAL_LIVE_02_USR.axc";
|
AxArgs = @"-regConfig=L:\Link\PAL_LIVE_02_USR.axc";
|
||||||
break;
|
break;
|
||||||
case "DEV":
|
case "DEV":
|
||||||
@@ -46,11 +48,13 @@ namespace wpf_ax_utility
|
|||||||
break; ;
|
break; ;
|
||||||
}
|
}
|
||||||
|
|
||||||
AxExecution(AxClient, AxArgs);
|
AxExecution(AxArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AxExecution(string AxClient, string 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))
|
if (System.IO.File.Exists(AxClient))
|
||||||
{
|
{
|
||||||
var p = new System.Diagnostics.Process();
|
var p = new System.Diagnostics.Process();
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
<Window x:Class="wpf_ax_utility.UserWindow"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
MouseLeftButtonDown="MouseLeftDrag"
|
||||||
|
Height="260" Width="400"
|
||||||
|
ResizeMode="NoResize"
|
||||||
|
WindowStyle="None"
|
||||||
|
WindowStartupLocation="CenterScreen"
|
||||||
|
AllowsTransparency="True"
|
||||||
|
Background="Transparent"
|
||||||
|
Title="PAL Ax Utility"
|
||||||
|
Icon="/axlogo.ico">
|
||||||
|
|
||||||
|
<Window.Resources>
|
||||||
|
<Style TargetType="Button" x:Key="TabButton">
|
||||||
|
<Setter Property="Background" Value="White"/>
|
||||||
|
<Setter Property="TextBlock.TextAlignment" Value="Center"/>
|
||||||
|
<Style.Resources>
|
||||||
|
<Style TargetType="Border">
|
||||||
|
<Setter Property="CornerRadius" Value="3"/>
|
||||||
|
</Style>
|
||||||
|
</Style.Resources>
|
||||||
|
</Style>
|
||||||
|
</Window.Resources>
|
||||||
|
|
||||||
|
<Grid>
|
||||||
|
<Border BorderBrush="#0082C4" BorderThickness="1.5" CornerRadius="10" Background="White">
|
||||||
|
<StackPanel>
|
||||||
|
<DockPanel>
|
||||||
|
<Border Height="25" Width="25" CornerRadius="5" Margin="2,0,0,0">
|
||||||
|
<Border.Background>
|
||||||
|
<ImageBrush Stretch="Fill" ImageSource="/axlogo.ico"/>
|
||||||
|
</Border.Background>
|
||||||
|
</Border>
|
||||||
|
<TextBlock Margin="5,0,0,0" FontWeight="DemiBold" Text="PAL Ax Utility" VerticalAlignment="Center"/>
|
||||||
|
<Button Style="{StaticResource TabButton}"
|
||||||
|
Click="CloseButton"
|
||||||
|
Height="25" Width="25"
|
||||||
|
FontSize="18"
|
||||||
|
FontWeight="DemiBold"
|
||||||
|
Background="Transparent"
|
||||||
|
HorizontalAlignment="Right"
|
||||||
|
BorderBrush="{x:Null}"
|
||||||
|
Margin="0,3,3,0">
|
||||||
|
<TextBlock Text="x" Margin="0,-5,0,0"/>
|
||||||
|
</Button>
|
||||||
|
</DockPanel>
|
||||||
|
<GroupBox Margin="15,5,15,10"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
BorderBrush="LightGray"
|
||||||
|
BorderThickness="1"
|
||||||
|
Header="Ambienti">
|
||||||
|
<StackPanel Name="LayoutRoot"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Margin="5,5,5,5">
|
||||||
|
<Button Style="{StaticResource TabButton}"
|
||||||
|
x:Name="LIVE"
|
||||||
|
Click="ButtonClicked"
|
||||||
|
Height="115" Width="325"
|
||||||
|
Content="LIVE"
|
||||||
|
FontSize="36"
|
||||||
|
Background="LightGray"/>
|
||||||
|
<DockPanel HorizontalAlignment="Center"
|
||||||
|
Margin="0,10,0,0">
|
||||||
|
<Button Style="{StaticResource TabButton}"
|
||||||
|
x:Name="STAGING"
|
||||||
|
Click="ButtonClicked"
|
||||||
|
Height="45" Width="325"
|
||||||
|
Content="STAGING"
|
||||||
|
FontSize="18"
|
||||||
|
FontWeight="DemiBold"
|
||||||
|
Background="#FFFF00"/>
|
||||||
|
</DockPanel>
|
||||||
|
</StackPanel>
|
||||||
|
</GroupBox>
|
||||||
|
</StackPanel>
|
||||||
|
</Border>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Input;
|
||||||
|
|
||||||
|
namespace wpf_ax_utility
|
||||||
|
{
|
||||||
|
public partial class UserWindow : Window
|
||||||
|
{
|
||||||
|
public UserWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MouseLeftDrag(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
DragMove();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CloseButton(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonClicked(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
AucCleaner();
|
||||||
|
|
||||||
|
string AxArgs = string.Empty;
|
||||||
|
|
||||||
|
switch (((Button)sender).Name)
|
||||||
|
{
|
||||||
|
case "LIVE":
|
||||||
|
AxArgs = @"-regConfig=L:\Link\PAL_LIVE_USR.axc";
|
||||||
|
break;
|
||||||
|
case "STAGING":
|
||||||
|
AxArgs = @"-regConfig=L:\Link\PAL_STAGING_USR.axc";
|
||||||
|
break; ;
|
||||||
|
}
|
||||||
|
|
||||||
|
AxExecution(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user