220 lines
8.5 KiB
C#
220 lines
8.5 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media.Animation;
|
|
|
|
using C4IT.HardwareInfo;
|
|
using C4IT.Logging;
|
|
|
|
using C4IT_CustomerPanel.libs;
|
|
|
|
using static C4IT_CustomerPanel.MainWindow;
|
|
|
|
|
|
namespace C4IT_CustomerPanel.UserControls
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ComputerInformation.xaml
|
|
/// </summary>
|
|
public partial class ComputerInformation : UserControl
|
|
{
|
|
public ComputerInformation()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Info_TXT_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
|
|
{
|
|
TextBox txtBox = (TextBox)sender;
|
|
|
|
txtBox.Select(0, txtBox.Text.Length);
|
|
|
|
if (!string.IsNullOrEmpty(txtBox.Text))
|
|
{
|
|
System.Windows.Forms.Clipboard.SetText(txtBox.Text);
|
|
DoubleAnimation animation = new DoubleAnimation(1, TimeSpan.FromSeconds(1));
|
|
animation.Completed += CopiedAnimBeginCompleted;
|
|
copied.Visibility = Visibility.Visible;
|
|
copied.BeginAnimation(Canvas.OpacityProperty, animation);
|
|
}
|
|
}
|
|
|
|
private void CopiedAnimBeginCompleted(object sender, EventArgs e)
|
|
{
|
|
DoubleAnimation animation1 = new DoubleAnimation(0, TimeSpan.FromSeconds(5));
|
|
animation1.Completed += CopiedAnimEndCompleted;
|
|
copied.BeginAnimation(OpacityProperty, animation1);
|
|
}
|
|
|
|
private void CopiedAnimEndCompleted(object sender, EventArgs e)
|
|
{
|
|
copied.Visibility = Visibility.Collapsed;
|
|
}
|
|
|
|
private void ClickCopyIcon(object sender, MouseButtonEventArgs e)
|
|
{
|
|
Image img = (Image)sender;
|
|
switch (img.Name)
|
|
{
|
|
case "icoCopyRestart":
|
|
Info_TXT_OnMouseDoubleClick(TxtLastreboot, null);
|
|
break;
|
|
case "icoCopyUser":
|
|
Info_TXT_OnMouseDoubleClick(TxtUsername, null);
|
|
break;
|
|
case "icoCopyNetwork":
|
|
Info_TXT_OnMouseDoubleClick(TxtIpaddress, null);
|
|
break;
|
|
case "icoCopyComputer":
|
|
Info_TXT_OnMouseDoubleClick(TxtComputername, null);
|
|
break;
|
|
case "icoCopyHost":
|
|
Info_TXT_OnMouseDoubleClick(TxtHostname, null);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
private void OnReportClicked(object sender, EventArgs e)
|
|
{
|
|
PRGSText.Text = Properties.Resources.genReport;
|
|
PRGSGrid.Visibility = Visibility.Visible;
|
|
Task.Factory.StartNew(() => // kann auch mit await in einer async Methode verwendet werden
|
|
{
|
|
try
|
|
{
|
|
var CI = new ComputerInformationReport(MainWindow.MainInstance?.ConfigSettings.GetCultureName()) // Configsettings noch in UC mitreinnehmen
|
|
{
|
|
SetProgress = SetProgress
|
|
};
|
|
CI.CreateReport();
|
|
CI.Save();
|
|
|
|
CI.Show();
|
|
Application.Current.Dispatcher.Invoke(new Action(() =>
|
|
PRGSGrid.Visibility = Visibility.Hidden));
|
|
|
|
}
|
|
catch (Exception exp)
|
|
{
|
|
MessageBox.Show(exp.Message);
|
|
}
|
|
});
|
|
}
|
|
|
|
private void SetProgress(double Progress)
|
|
{
|
|
|
|
// Achtung: bei UI Zugriffen muss der UI Dispatcher verwendet werden!
|
|
int p = (int)Progress;
|
|
Application.Current.Dispatcher.Invoke(new Action(() =>
|
|
((MainWindow)Application.Current.MainWindow).ComputerInfoCtrl.PRGS.ProgressValue = (int)Progress));
|
|
}
|
|
|
|
public void OnRemoteSupportClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
Process.Start(MainWindow.MainInstance?.ConfigSettings.GetRemoteAppPath());
|
|
}
|
|
catch (Exception E)
|
|
{
|
|
cLogManager.DefaultLogger.LogException(E, LogLevels.Warning);
|
|
}
|
|
}
|
|
|
|
public void FillMainInfoGrid()
|
|
{
|
|
try
|
|
{
|
|
// Add Customer Panel-Version to Information-Category
|
|
var cpVersion = Assembly.GetExecutingAssembly()
|
|
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
|
|
.InformationalVersion;
|
|
LblCustomerPanelVersion.Content = cpVersion;
|
|
|
|
TxtComputername.Text = Environment.MachineName;
|
|
var RemoteHost = Environment.GetEnvironmentVariable("ClientName");
|
|
#if DEBUG
|
|
if (string.IsNullOrEmpty(RemoteHost))
|
|
RemoteHost = Environment.GetEnvironmentVariable("ClientName2");
|
|
#endif
|
|
TxtHostname.Text = RemoteHost;
|
|
if (string.IsNullOrEmpty(RemoteHost))
|
|
CanvasHostname.Visibility = Visibility.Collapsed;
|
|
TxtUsername.Text = Environment.UserDomainName + "\\" + Environment.UserName;
|
|
TxtIpaddress.Text = InformationHelper.GetIp4Address(MainWindow.MainInstance.ConfigSettings.ShowIpInfoOnlyInCorporateNetwork);
|
|
DriveInfo[] dInfo = InformationHelper.GetDrives();
|
|
TxtLastreboot.Text = InformationHelper.GetLastReboot().ToString(CultureInfo.CurrentUICulture);
|
|
|
|
int k = 0;
|
|
foreach (DriveInfo drive in dInfo)
|
|
{
|
|
if ((drive.DriveType == DriveType.Fixed))
|
|
{
|
|
Grid gri = new Grid { HorizontalAlignment = HorizontalAlignment.Center };
|
|
Label lb = new Label { HorizontalAlignment = HorizontalAlignment.Center };
|
|
StackPanel sp = new StackPanel
|
|
{
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
Margin = new Thickness(10, 0, 0, 0)
|
|
};
|
|
var pbg = new CustomProgressBar
|
|
{
|
|
Effect = FormHelper.GetDropShadow()
|
|
};
|
|
lb.Content = drive.Name + " - " + InformationHelper.FormatBytes(drive.TotalSize - drive.TotalFreeSpace, false) + " / " + InformationHelper.FormatBytes(drive.TotalSize, true);
|
|
lb.ToolTip = lb.Content;
|
|
lb.ClipToBounds = true;
|
|
sp.Width = StPaDrives.Width / dInfo.Length;
|
|
pbg.Width = sp.Width;
|
|
pbg.Height = 20;
|
|
sp.HorizontalAlignment = HorizontalAlignment.Center;
|
|
sp.Orientation = Orientation.Vertical;
|
|
gri.Children.Add(pbg);
|
|
pbg.ProgressValue = (int)((drive.TotalSize - drive.TotalFreeSpace) * 100 / drive.TotalSize);
|
|
gri.Children.Add(lb);
|
|
sp.Children.Add(gri);
|
|
if (k > 1 & k <= 3)
|
|
{
|
|
StPaDrives2.Children.Add(sp);
|
|
}
|
|
else
|
|
{
|
|
StPaDrives.Children.Add(sp);
|
|
}
|
|
k++;
|
|
}
|
|
}
|
|
if (k <= 1)
|
|
{
|
|
// StPaDrives2.Height = 0;
|
|
// BtnRemoteSupport.Margin = new Thickness(0, -35, 0, 0);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
public void SetAppearence()
|
|
{
|
|
BtnRemoteSupport.Visibility = (string.IsNullOrEmpty(MainWindow.MainInstance.ConfigSettings.GetRemoteAppPath()) || MainWindow.MainInstance.OnlineState != enumOnlineState.Online) ? Visibility.Hidden : Visibility.Visible;
|
|
}
|
|
|
|
public void SetIpAddress(string IpAddress)
|
|
{
|
|
TxtIpaddress.Text = IpAddress;
|
|
}
|
|
}
|
|
}
|