Erweiterungen

- Erzeugte MenuItems können beliebig eingefärbt werden
- Ein bestimmtes MenuItem kann ausgewählt werden
- Das ausgewählte MenuItem kann im Roaming gespeichert werden
- Funktionsbeschreibung dazu
This commit is contained in:
Eugen Höglinger 2023-03-30 15:53:25 +02:00
parent 63a46abc19
commit 8933cb8cee
39 changed files with 160 additions and 6 deletions

Binary file not shown.

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Configuration;
using System.IO;
using System.Linq;
using System.Reflection;
@ -10,6 +11,7 @@ using System.Windows.Forms;
using System.Xml.Linq;
using Eugen.ESystem.IO;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
using static Eugen.ESystem.IO.LoadXMLFile;
using AppRes = Eugen.ESystem.Properties.AppResources;
@ -141,32 +143,102 @@ namespace Eugen.ESystem
SetDllInfo();
}
/// <summary>
/// Log file name
/// </summary>
public static string LogFile { get; set; }
/// <summary>
/// Name of the roaming file
/// </summary>
public static string FileNameRoaming { get; set; }
/// <summary>
/// Password for encryption
/// </summary>
public string Password { get; set; }
/// <summary>
/// File name of the configuration
/// </summary>
public string XmlFile { get; set; }
/// <summary>
/// The XML topic
/// </summary>
public string Topic { get; set; }
/// <summary>
/// The XML group
/// </summary>
public string Group { get; set; }
/// <summary>
/// The XML key
/// </summary>
public string Key { get; set; }
/// <summary>
/// The values stored in the XML file
/// </summary>
public string[,] Values { get; set; }
/// <summary>
/// List of menu entries to be created
/// </summary>
public string[] MenuItems { get; set; }
/// <summary>
/// The selected menu item
/// </summary>
public string Standard { get; set; }
/// <summary>
/// Menu into which the submenus are inserted
/// </summary>
public ToolStripMenuItem Menu { get; set; }
//private string SelectedItem { get; set; }
/// <summary>
/// The backcolor of a menu entry
/// </summary>
public Color BackColor { get; set; }
/// <summary>
/// The forcolor of a menu entry
/// </summary>
public Color ForeColor { get; set; }
//Logfile global setzen
LogWriter log = new LogWriter(Path.GetDirectoryName(LogFile), Path.GetFileName(LogFile));
/// <summary>
/// Insert a menu item
/// </summary>
/// <param name="menuItem">Name of the Menu item</param>
public void AddMenuItem(string menuItem)
{
ToolStripMenuItem menu = (ToolStripMenuItem)(Menu);
Menu.DropDownItems.Add(menuItem, null, new EventHandler(ToolStripMenuItem_Click));
//Wenn BackColor und ForeColor einen Wert enthalten, dann das Menü einfärben
if (BackColor != null & ForeColor != null)
{
foreach (ToolStripMenuItem item in menu.DropDownItems)
{
item.BackColor = BackColor;
item.ForeColor = ForeColor;
}
}
if (File.Exists(LogFile))
{
log.WriteMessage("License bundle menu entry \'" + menuItem + "\' generated", LogWriter.LogLevel.Information, LogWriter.Time.Write); //Logdatei schreiben
log.WriteMessage("License value menu entry \'" + menuItem + "\' generated", LogWriter.LogLevel.Information, LogWriter.Time.Write); //Logdatei schreiben
}
}
/// <summary>
/// Insert menu entry from a list that is in an XML file
/// </summary>
public void AddMenuItemsFromXML()
{
if (File.Exists(LogFile))
@ -178,8 +250,8 @@ namespace Eugen.ESystem
ExtractMenuItem(); //Die Menueinträge aus den XML-Daten ermitteln
ExtractStandardItem(); //Das Standard Item ermitteln
AddMenuItems(MenuItems); //Lizenz Bundles
CheckMenuItem(Standard);
AddMenuItems(MenuItems); //Item zum Menü hinzufügen
CheckMenuItem(Standard); //Standard Menü Item auswählen
if (File.Exists(LogFile))
{
@ -187,6 +259,10 @@ namespace Eugen.ESystem
}
}
/// <summary>
/// Insert menu entry from a list
/// </summary>
/// <param name="menuList">List of menu items</param>
public void AddMenuItems(string[] menuList)
{
//Menueinträge erzeugen
@ -210,6 +286,10 @@ namespace Eugen.ESystem
}
}
/// <summary>
/// Check a menu item
/// </summary>
/// <param name="selectedItem">Item name</param>
public void CheckMenuItem(string selectedItem)
{
//Hier soll der Menüeintrag, der dem Übergebenen Wert entspricht, auf 'Checked = true' gesetzt werden
@ -230,6 +310,10 @@ namespace Eugen.ESystem
}
}
/// <summary>
/// Removes a menu item
/// </summary>
/// <param name="item">Item name</param>
public void RemoveMenuItem(string item)
{
ToolStripMenuItem menu = (ToolStripMenuItem)(Menu);
@ -249,6 +333,10 @@ namespace Eugen.ESystem
}
}
/// <summary>
/// Removes the menu items specified in a list
/// </summary>
/// <param name="itemList">Item list</param>
public void RemoveMenuItems(string[] itemList)
{
foreach (string item in itemList)
@ -257,6 +345,9 @@ namespace Eugen.ESystem
}
}
/// <summary>
/// Removes all menu items
/// </summary>
public void RemoveAllMenuItems()
{
ToolStripMenuItem menu = (ToolStripMenuItem)(Menu);
@ -269,6 +360,30 @@ namespace Eugen.ESystem
}
}
/// <summary>
/// Saves a license value to the roaming area
/// </summary>
/// <param name="value">A valid string</param>
/// <exception cref="UnableToSaveLicenseBundleException">Unable to save license value</exception>
public void SaveValueToRoaming(string value, string key)
{
string password = Environment.GetEnvironmentVariable("USERNAME");
var cryption = new Cryption();
try
{
var roaming = new Roaming();
roaming.MainKey = "NX-Portal";
roaming.Key = key;
roaming.Value = cryption.EncryptString(value, password);
roaming.WriteKey();
}
catch (Exception)
{
throw new UnableToSaveLicenseBundleException();
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
ToolStripMenuItem MenuItem = (ToolStripMenuItem)sender;
@ -278,7 +393,12 @@ namespace Eugen.ESystem
CheckMenuItem(MenuItem.Text);
//TODO: License Bundle ins Roaming schreiben
//License Bundle ins Roaming schreiben
if (!String.IsNullOrEmpty(FileNameRoaming))
{
SaveValueToRoaming(MenuItem.Text, FileNameRoaming); //In Roaming speichern
log.WriteMessage("The license value was saved to roaming", LogWriter.LogLevel.Information, LogWriter.Time.Write); //Logdatei schreiben
}
}
private void LoadXmlFile(string xmlFileName, string topic, string group, string key)
@ -333,4 +453,18 @@ namespace Eugen.ESystem
}
}
}
#region Exceptions
class UnableToSaveLicenseBundleException : ApplicationException
{
public UnableToSaveLicenseBundleException()
{ }
public UnableToSaveLicenseBundleException(string message) : base(message)
{ }
public UnableToSaveLicenseBundleException(string message, Exception inner) : base(message, inner)
{ }
}
#endregion
}

View File

@ -32,12 +32,18 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="hecryption">
<HintPath>..\..\Cryption.git\Cryption\bin\Debug\hecryption.dll</HintPath>
</Reference>
<Reference Include="helogwri">
<HintPath>..\..\LogWriter.git\LogWriter\bin\Debug\helogwri.dll</HintPath>
</Reference>
<Reference Include="heloxmlf">
<HintPath>..\..\LoadXMLFile.git\LoadXMLFile\bin\Debug\heloxmlf.dll</HintPath>
</Reference>
<Reference Include="heroaming">
<HintPath>..\..\Roaming.git\Roaming\bin\Debug\heroaming.dll</HintPath>
</Reference>
<Reference Include="heshowtf">
<HintPath>..\..\ShowTextFile.git\ShowTextFile\bin\Debug\heshowtf.dll</HintPath>
</Reference>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1 +1 @@
d2bb09221837221f875fcd4652cd9c1d74fd34d1
32b1ba0bfbae947ce449f27cb464c37775844145

View File

@ -20,3 +20,7 @@ H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\DynamicMenuItems.git\Dynam
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\DynamicMenuItems.git\DynamicMenuItems\obj\Debug\DynamicMenuItems.csproj.CopyComplete
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\DynamicMenuItems.git\DynamicMenuItems\obj\Debug\hedynmeit.dll
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\DynamicMenuItems.git\DynamicMenuItems\obj\Debug\hedynmeit.pdb
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\DynamicMenuItems.git\DynamicMenuItems\bin\Debug\hecryption.dll
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\DynamicMenuItems.git\DynamicMenuItems\bin\Debug\heroaming.dll
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\DynamicMenuItems.git\DynamicMenuItems\bin\Debug\hecryption.pdb
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\DynamicMenuItems.git\DynamicMenuItems\bin\Debug\heroaming.pdb

View File

@ -130,6 +130,8 @@ namespace Test_DynamicMenuItems
dmi.Group = "Bundle";
dmi.Key = "License";
dmi.Menu = subtestToolStripMenuItem;
//dmi.BackColor = Color.FromArgb(60, 60, 60);
//dmi.ForeColor = SystemColors.ControlDark;
dmi.AddMenuItem("NX91110"); //Einen Menüeintrag erzeugen
}
@ -146,6 +148,8 @@ namespace Test_DynamicMenuItems
dmi.Group = "Bundle";
dmi.Key = "License";
dmi.Menu = subtestToolStripMenuItem;
dmi.BackColor = Color.FromArgb(60, 60, 60);
dmi.ForeColor = SystemColors.ControlDark;
string[] items = { "NX91110", "NX93300", "SC13500" };
dmi.AddMenuItems(items); //Menüeinträge aus einer List erzeugen
@ -163,6 +167,8 @@ namespace Test_DynamicMenuItems
dmi.Group = "Bundle";
dmi.Key = "License";
dmi.Menu = subtestToolStripMenuItem;
dmi.BackColor = Color.FromArgb(60, 60, 60);
dmi.ForeColor = SystemColors.ControlDark;
dmi.AddMenuItemsFromXML(); //Alle Menüeinträge aus einer XML-Datei erzeugen
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -19,3 +19,7 @@ H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\DynamicMenuItems.git\Test_
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\DynamicMenuItems.git\Test_DynamicMenuItems\obj\Debug\Test_DynamicMenuItems.exe
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\DynamicMenuItems.git\Test_DynamicMenuItems\obj\Debug\Test_DynamicMenuItems.pdb
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\DynamicMenuItems.git\Test_DynamicMenuItems\bin\Debug\hedynmeit.dll
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\DynamicMenuItems.git\Test_DynamicMenuItems\bin\Debug\hecryption.dll
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\DynamicMenuItems.git\Test_DynamicMenuItems\bin\Debug\heroaming.dll
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\DynamicMenuItems.git\Test_DynamicMenuItems\bin\Debug\hecryption.pdb
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\DynamicMenuItems.git\Test_DynamicMenuItems\bin\Debug\heroaming.pdb