Neuerstellung

This commit is contained in:
maier_S
2022-03-11 14:59:36 +01:00
parent 072072202a
commit cc720e6421
128 changed files with 16224 additions and 0 deletions

View File

@@ -0,0 +1,153 @@
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using Hardcodet.Wpf.TaskbarNotification;
namespace FSI.BT.Tools.Commands
{
/// <summary>
/// Basic implementation of the <see cref="ICommand"/>
/// interface, which is also accessible as a markup
/// extension.
/// </summary>
public abstract class CommandBase<T> : MarkupExtension, ICommand
where T : class, ICommand, new()
{
/// <summary>
/// A singleton instance.
/// </summary>
private static T? command;
/// <summary>
/// Gets a shared command instance.
/// </summary>
public override object ProvideValue(IServiceProvider serviceProvider)
{
if (command == null) command = new T();
return command;
}
/// <summary>
/// Fires when changes occur that affect whether
/// or not the command should execute.
/// </summary>
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
/// <summary>
/// Defines the method to be called when the command is invoked.
/// </summary>
/// <param name="parameter">Data used by the command.
/// If the command does not require data to be passed,
/// this object can be set to null.
/// </param>
public abstract void Execute(object parameter);
/// <summary>
/// Defines the method that determines whether the command
/// can execute in its current state.
/// </summary>
/// <returns>
/// This default implementation always returns true.
/// </returns>
/// <param name="parameter">Data used by the command.
/// If the command does not require data to be passed,
/// this object can be set to null.
/// </param>
public virtual bool CanExecute(object parameter)
{
return !IsDesignMode;
}
public static bool IsDesignMode
{
get
{
return (bool)
DependencyPropertyDescriptor.FromProperty(DesignerProperties.IsInDesignModeProperty,
typeof(FrameworkElement))
.Metadata.DefaultValue;
}
}
/// <summary>
/// Resolves the window that owns the TaskbarIcon class.
/// </summary>
/// <param name="commandParameter"></param>
/// <returns>Window</returns>
protected Window? GetTaskbarWindow(object commandParameter)
{
if (IsDesignMode)
return null;
// get the showcase window off the taskbar icon
var tb = commandParameter as TaskbarIcon;
return tb == null ? null : TryFindParent<Window>(tb);
}
#region TryFindParent helper
/// <summary>
/// Finds a parent of a given item on the visual tree.
/// </summary>
/// <typeparam name="TParent">The type of the queried item.</typeparam>
/// <param name="child">A direct or indirect child of the
/// queried item.</param>
/// <returns>The first parent item that matches the submitted
/// type parameter. If not matching item can be found, a null
/// reference is being returned.</returns>
public static TParent? TryFindParent<TParent>(DependencyObject child) where TParent : DependencyObject
{
//get parent item
DependencyObject parentObject = GetParentObject(child);
//we've reached the end of the tree
if (parentObject == null) return null;
//check if the parent matches the type we're looking for
if (parentObject is TParent parent)
{
return parent;
}
//use recursion to proceed with next level
return TryFindParent<TParent>(parentObject);
}
/// <summary>
/// This method is an alternative to WPF's
/// <see cref="VisualTreeHelper.GetParent"/> method, which also
/// supports content elements. Keep in mind that for content element,
/// this method falls back to the logical tree of the element!
/// </summary>
/// <param name="child">The item to be processed.</param>
/// <returns>The submitted item's parent, if available. Otherwise
/// null.</returns>
public static DependencyObject? GetParentObject(DependencyObject child)
{
if (child == null) return null;
if (child is ContentElement contentElement)
{
DependencyObject parent = ContentOperations.GetParent(contentElement);
if (parent != null) return parent;
FrameworkContentElement? fce = contentElement as FrameworkContentElement;
return fce?.Parent;
}
//if it's not a ContentElement, rely on VisualTreeHelper
return VisualTreeHelper.GetParent(child);
}
#endregion
}
}

View File

@@ -0,0 +1,20 @@
using System.Windows;
namespace FSI.BT.Tools.Commands
{
/// <summary>
/// Shows the main window.
/// </summary>
public class ExitCommand : CommandBase<ExitCommand>
{
public override void Execute(object parameter)
{
Application.Current.Shutdown();
}
public override bool CanExecute(object parameter)
{
return true;
}
}
}

View File

@@ -0,0 +1,29 @@
using System.Windows;
namespace FSI.BT.Tools.Commands
{
/// <summary>
/// Shows the main window.
/// </summary>
public class LoginCommand : CommandBase<LoginCommand>
{
public override void Execute(object parameter)
{
Lib.Guis.AutoPw.FrmMain frmMain = new()
{
CloseAtLostFocus = true,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
};
frmMain.ShowDialog();
Global.UserRights =
Global.AdminRights = frmMain.PwOk;
}
public override bool CanExecute(object parameter)
{
return true;
}
}
}

View File

@@ -0,0 +1,313 @@
using FSI.Lib;
using System;
using System.Diagnostics;
using System.IO;
using System.Windows;
namespace FSI.BT.Tools.Commands
{
/// <summary>
/// Shows the main window.
/// </summary>
public class OpenAppCommand : CommandBase<OpenAppCommand>
{
public override void Execute(object parameter)
{
string[] files = new string[] { };
string[] pathes = new string[] { };
string arguments = string.Empty;
switch ((string)parameter)
{
case "SimaticManager":
files = Global.Settings.Apps.SieSimaticManagerExe.Split(";");
break;
case "TIAv13":
files = Global.Settings.Apps.SieTiaV13Exe.Split(";");
break;
case "TIAv14":
files = Global.Settings.Apps.SieTiaV14Exe.Split(";");
break;
case "TIAv15":
files = Global.Settings.Apps.SieTiaV15Exe.Split(";");
break;
case "TIAv16":
files = Global.Settings.Apps.SieTiaV16Exe.Split(";");
break;
case "TIAv17":
files = Global.Settings.Apps.SieTiaV17Exe.Split(";");
break;
case "Starter":
files = Global.Settings.Apps.SieTiaVStarterExe.Split(";");
break;
case "Epl":
files = Global.Settings.Apps.Epl.Exe.Split(";");
arguments = Global.Settings.Apps.Epl.Arguments;
break;
case "EplPrj":
Lib.Guis.Prj.Mgt.FrmMain frmMainEplPrj = new()
{
ShowPdf = false,
CloseAtLostFocus = true,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
};
frmMainEplPrj.Show();
return;
case "EplPdf":
Lib.Guis.Prj.Mgt.FrmMain frmMainEplPdf = new()
{
ShowPdf = true,
CloseAtLostFocus = true,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
};
frmMainEplPdf.Show();
return;
case "EplPdfMgt":
Lib.Guis.Pdf.Mgt.FrmMain frmMainEplPdfMgt = new()
{
CloseAtLostFocus = true
};
frmMainEplPdfMgt.Show();
return;
case "Npp":
files = Global.Settings.Apps.NppExe.Split(";");
break;
case "TotalCmd":
files = Global.Settings.Apps.TotalCmdExe.Split(";");
break;
case "TeXstudio":
files = Global.Settings.Apps.TeXstudioExe.Split(";");
pathes = Global.Settings.Apps.TeXstudioPath.Split(";");
break;
case "VS":
files = Global.Settings.Apps.VsExe.Split(";");
break;
case "VS.Code":
files = Global.Settings.Apps.VsCodeExe.Split(";");
break;
case "Rdp":
files = Global.Settings.Apps.RdpExe.Split(";"); ;
break;
case "DeEncrypt":
Lib.Guis.DeEncryptMessage.FrmMain frmMainDeEnCrypt = new()
{
Password = Global.Settings.General.DeEnCryptPasswort,
CloseAtLostFocus = true,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
};
frmMainDeEnCrypt.Show();
return;
case "StarterCsvExporter":
Lib.Guis.SieStarterCsvExporter.FrmMain frmMain = new();
frmMain.Show();
return;
}
string fileName = string.Empty;
string path = string.Empty;
for (int i = 0; i <= files.Length - 1; i++)
{
if (File.Exists(Environment.ExpandEnvironmentVariables(files[i].Trim())))
{
fileName = Environment.ExpandEnvironmentVariables(files[i].Trim());
}
if (pathes.Length == 0)
{
path = Path.GetDirectoryName(fileName);
}
else
{
path = Environment.ExpandEnvironmentVariables(pathes[i].Trim());
}
}
if (ProgramIsRunning(fileName))
{
ProgramToFront(fileName);
}
else
{
Process process = new();
process.StartInfo.FileName = fileName;
process.StartInfo.WorkingDirectory = path;
process.StartInfo.Arguments = arguments;
try
{
process.Start();
}
catch (System.ComponentModel.Win32Exception ex) when (ex.NativeErrorCode == 740)
{
try
{
process.StartInfo.UseShellExecute = true;
process.StartInfo.Verb = "runas";
process.Start();
}
catch { }
}
}
}
public override bool CanExecute(object parameter)
{
string[] files = new string[] { };
switch ((string)parameter)
{
case "SimaticManager":
files = Global.Settings.Apps.SieSimaticManagerExe.Split(";");
break;
case "TIAv13":
files = Global.Settings.Apps.SieTiaV13Exe.Split(";");
break;
case "TIAv14":
files = Global.Settings.Apps.SieTiaV14Exe.Split(";");
break;
case "TIAv15":
files = Global.Settings.Apps.SieTiaV15Exe.Split(";");
break;
case "TIAv16":
files = Global.Settings.Apps.SieTiaV16Exe.Split(";");
break;
case "TIAv17":
files = Global.Settings.Apps.SieTiaV17Exe.Split(";");
break;
case "Starter":
files = Global.Settings.Apps.SieTiaVStarterExe.Split(";");
break;
case "Epl":
files = Global.Settings.Apps.Epl.Exe.Split(";");
break;
case "EplPrj":
return true;
case "EplPdf":
return true;
case "EplPdfMgt":
return Global.AdminRights;
case "Npp":
files = Global.Settings.Apps.NppExe.Split(";");
break;
case "TotalCmd":
files = Global.Settings.Apps.TotalCmdExe.Split(";");
break;
case "TeXstudio":
files = Global.Settings.Apps.TeXstudioExe.Split(";");
break;
case "VS":
files = Global.Settings.Apps.VsExe.Split(";");
break;
case "VS.Code":
files = Global.Settings.Apps.VsCodeExe.Split(";");
break;
case "Rdp":
files = Global.Settings.Apps.RdpExe.Split(";"); ;
break;
case "DeEncrypt":
return Global.AdminRights;
case "StarterCsvExporter":
return Global.AdminRights;
default: return false;
}
foreach (string file in files)
{
if (File.Exists(Environment.ExpandEnvironmentVariables(file.Trim())))
{
return true;
}
}
return false;
}
private bool ProgramIsRunning(string FullPath)
{
string FilePath = Path.GetDirectoryName(FullPath);
string FileName = Path.GetFileNameWithoutExtension(FullPath).ToLower();
bool isRunning = false;
Process[] pList = Process.GetProcessesByName(FileName);
foreach (Process p in pList)
{
if (p.MainModule.FileName.StartsWith(FilePath, StringComparison.InvariantCultureIgnoreCase))
{
isRunning = true;
break;
}
}
return isRunning;
}
[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr handle);
[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern bool ShowWindow(IntPtr handle, int nCmdShow);
[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern bool IsIconic(IntPtr handle);
private void ProgramToFront(string FullPath)
{
string FilePath = Path.GetDirectoryName(FullPath);
string FileName = Path.GetFileNameWithoutExtension(FullPath).ToLower();
Process[] pList = Process.GetProcessesByName(FileName);
foreach (Process p in pList)
{
if (p.MainModule.FileName.StartsWith(FilePath, StringComparison.InvariantCultureIgnoreCase))
{
IntPtr handle = p.MainWindowHandle;
if (IsIconic(handle))
{
ShowWindow(handle, 9);
}
SetForegroundWindow(handle);
break;
}
}
}
}
}

View File

@@ -0,0 +1,79 @@
using FSI.Lib;
using System;
using System.Diagnostics;
namespace FSI.BT.Tools.Commands
{
/// <summary>
/// Shows the main window.
/// </summary>
public class OpenLinkCommand : CommandBase<OpenLinkCommand>
{
public override void Execute(object parameter)
{
string url = String.Empty;
switch ((string)parameter)
{
case "ZentralWeb":
url = Global.Settings.Urls.ZentralWeb;
break;
case "Schichtbuch":
url = Global.Settings.Urls.Schichtbuch;
break;
case "SPS":
url = Global.Settings.Urls.SPS;
break;
case "PL1.Pls":
url = Global.Settings.Urls.Pl1Pls;
break;
case "PL2.Pls":
url = Global.Settings.Urls.Pl2Pls;
break;
case "PL2.Als":
url = Global.Settings.Urls.Pl2Als;
break;
case "PL3.Pls":
url = Global.Settings.Urls.Pl3Pls;
break;
case "FSI.Gitea":
url = Global.Settings.Urls.Gitea;
break;
case "FSI.Wiki":
url = Global.Settings.Urls.Wiki;
break;
case "Erp":
url = Global.Settings.Urls.Erp;
break;
}
url = url.Replace("&", "^&");
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
}
public override bool CanExecute(object parameter)
{
string url = String.Empty;
switch ((string)parameter)
{
case "FSI.Gitea":
return Global.AdminRights;
case "FSI.Wiki":
return Global.AdminRights;
default:
return true;
}
}
}
}

View File

@@ -0,0 +1,37 @@
using FSI.Lib.Wpf.ExtensionMethods;
using System.Windows;
namespace FSI.BT.Tools.Commands
{
/// <summary>
/// Shows the main window.
/// </summary>
public class RadialMenuCommand : CommandBase<RadialMenuCommand>
{
public override void Execute(object parameter)
{
if (Global.FrmRadialMenu.Visibility == Visibility.Collapsed)
{
Global.FrmRadialMenu.ShowCenteredToMouse();
Global.FrmRadialMenu.ActivateCenteredToMouse();
return;
}
if (Global.FrmRadialMenu.Visibility == Visibility.Hidden)
{
Global.FrmRadialMenu.Visibility = Visibility.Visible;
}
else
{
Global.FrmRadialMenu.Visibility = Visibility.Hidden;
}
Global.FrmRadialMenu.ActivateCenteredToMouse();
}
public override bool CanExecute(object parameter)
{
return Global.AdminRights || Global.UserRights;
}
}
}

View File

@@ -0,0 +1,26 @@
using System.Windows.Controls.Primitives;
namespace FSI.BT.Tools.Commands
{
/// <summary>
/// Shows the main window.
/// </summary>
public class TimeStampToClipboardCommand : CommandBase<TimeStampToClipboardCommand>
{
public override void Execute(object parameter)
{
System.Windows.Forms.Clipboard.SetDataObject(Global.Settings.General.TimeStampFormat);
var balloon = new ToolTip()
{
BalloonText = "Zeitstempel",
BalloonDesc = "Der aktuelle Zeitstempel wurde in die Zwischenablage kopiert."
};
Global.TaskbarIcon.ShowCustomBalloon(balloon, PopupAnimation.Slide, 2000);
}
public override bool CanExecute(object parameter)
{
return true;
}
}
}