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 { /// /// Interaction logic for ComputerInformation.xaml /// 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() .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; CanvasHostname.Visibility = string.IsNullOrEmpty(RemoteHost) ? Visibility.Collapsed : Visibility.Visible; 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); StPaDrives.Children.Clear(); StPaDrives2.Children.Clear(); int fixedDriveCount = 0; foreach (DriveInfo drive in dInfo) { if (drive.DriveType == DriveType.Fixed) fixedDriveCount++; } int cardsPerRow = fixedDriveCount <= 1 ? 1 : 2; double availableDriveWidth = StPaDrives.Width > 0 ? StPaDrives.Width : 334; double driveCardWidth = Math.Max(120, (availableDriveWidth / cardsPerRow) - 4); int k = 0; foreach (DriveInfo drive in dInfo) { if ((drive.DriveType == DriveType.Fixed)) { Grid gri = new Grid { HorizontalAlignment = HorizontalAlignment.Stretch, Width = driveCardWidth }; Label lb = new Label { HorizontalAlignment = HorizontalAlignment.Stretch, HorizontalContentAlignment = HorizontalAlignment.Center, FontSize = 11, Padding = new Thickness(2, 0, 2, 0) }; StackPanel sp = new StackPanel { HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness((k % cardsPerRow) == 0 ? 0 : 8, 0, 0, 0), Width = driveCardWidth }; 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; pbg.Width = driveCardWidth; pbg.Height = 20; 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++; } } StPaDrives2.Visibility = k > 2 ? Visibility.Visible : Visibility.Collapsed; } 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; } } }