commit d3917497edbcaaaba5a187c4f19badd8981203a5 Author: Eugen Höglinger Date: Thu Feb 27 14:25:34 2020 +0100 Projekt neu angelegt. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5a5f80a --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ + +#Ignore thumbnails created by Windows +Thumbs.db +#Ignore files built by Visual Studio +*.obj +*.exe +*.pdb +*.user +*.aps +*.pch +*.vspscc +*_i.c +*_p.c +*.ncb +*.suo +*.tlb +*.tlh +*.bak +*.cache +*.ilk +*.log +[Bb]in +[Dd]ebug*/ +*.lib +*.sbr +obj/ +[Rr]elease*/ +_ReSharper*/ +[Tt]est[Rr]esult* +.vs/ +#Nuget packages folder +packages/ diff --git a/Test_VaribleThroughString/App.config b/Test_VaribleThroughString/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/Test_VaribleThroughString/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Test_VaribleThroughString/Form1.Designer.cs b/Test_VaribleThroughString/Form1.Designer.cs new file mode 100644 index 0000000..2fa0bb9 --- /dev/null +++ b/Test_VaribleThroughString/Form1.Designer.cs @@ -0,0 +1,92 @@ +namespace Eugen.ESystem +{ + partial class Form1 + { + /// + /// Erforderliche Designervariable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Verwendete Ressourcen bereinigen. + /// + /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Vom Windows Form-Designer generierter Code + + /// + /// Erforderliche Methode für die Designerunterstützung. + /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); + this.labelResult = new System.Windows.Forms.Label(); + this.buttonStart = new System.Windows.Forms.Button(); + this.labelSourceString = new System.Windows.Forms.Label(); + this.labelDllInfo = new System.Windows.Forms.Label(); + this.buttonStartWithMessage = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelResult + // + resources.ApplyResources(this.labelResult, "labelResult"); + this.labelResult.Name = "labelResult"; + // + // buttonStart + // + resources.ApplyResources(this.buttonStart, "buttonStart"); + this.buttonStart.Name = "buttonStart"; + this.buttonStart.UseVisualStyleBackColor = true; + this.buttonStart.Click += new System.EventHandler(this.buttonStart_Click); + // + // labelSourceString + // + resources.ApplyResources(this.labelSourceString, "labelSourceString"); + this.labelSourceString.Name = "labelSourceString"; + // + // labelDllInfo + // + resources.ApplyResources(this.labelDllInfo, "labelDllInfo"); + this.labelDllInfo.Name = "labelDllInfo"; + // + // buttonStartWithMessage + // + resources.ApplyResources(this.buttonStartWithMessage, "buttonStartWithMessage"); + this.buttonStartWithMessage.Name = "buttonStartWithMessage"; + this.buttonStartWithMessage.UseVisualStyleBackColor = true; + this.buttonStartWithMessage.Click += new System.EventHandler(this.buttonStartWithMessage_Click); + // + // Form1 + // + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.buttonStartWithMessage); + this.Controls.Add(this.labelDllInfo); + this.Controls.Add(this.labelSourceString); + this.Controls.Add(this.buttonStart); + this.Controls.Add(this.labelResult); + this.Name = "Form1"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label labelResult; + private System.Windows.Forms.Button buttonStart; + private System.Windows.Forms.Label labelSourceString; + private System.Windows.Forms.Label labelDllInfo; + private System.Windows.Forms.Button buttonStartWithMessage; + } +} + diff --git a/Test_VaribleThroughString/Form1.cs b/Test_VaribleThroughString/Form1.cs new file mode 100644 index 0000000..ec2a00c --- /dev/null +++ b/Test_VaribleThroughString/Form1.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Eugen.ESystem +{ + public partial class Form1 : Form + { + #region Version und Copyright + // Version und Copyright + string programName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen + string programVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); + static object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); + string copyright = ((AssemblyCopyrightAttribute)attributes[0]).Copyright; + string icon = Application.StartupPath + "\\Info.bmp"; + //Assembly Datum und Zeit + static DateTime value = AssemblyDateTime(); + string date = value.ToShortDateString(); + string time = value.ToLongTimeString(); + private static DateTime AssemblyDateTime() + { + var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; + var buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + TimeSpan.TicksPerSecond * 2 * version.Revision)); + //Tage seit dem 1. Januar 2000 und Sekunden seit Mitternacht, (multiplizier mit 2 ergibt das Original) + return buildDateTime; + } + #endregion + + #region Programm-Info + /// + /// Contains the name of the program file + /// + public static string ProgramName { set; get; } + + /// + /// Contains the version of the program file + /// + public static string ProgramVersion { set; get; } + + /// + /// Contains the copyright notice + /// + public static string Copyright { set; get; } + + private void SetProgramInfo() + { + //Name, Version und Copyright setzen + ProgramName = programName; + ProgramVersion = programVersion; + Copyright = copyright; + } + #endregion + + public Form1() + { + SetProgramInfo(); //Name, Version und Copyright setzen + InitializeComponent(); + } + + private void buttonStart_Click(object sender, EventArgs e) + { + string text = "NX ist im Verzeichns ${UGII_BASE_DIR} installiert. Im Verzeichnis ${UGII_ROOT_DIR} sind die Befehle.\nAls Systemsprache ist %UGII_LANG% eingestellt. Als temporäres NX Verzeichnis ist %UGII_TMP_DIR% definiert."; + + labelSourceString.Text = text; + + // + //Diese Zeile in das Programm kopieren + // + //Tauscht bekannte Umgebungsvariblen gegen ihren Wert aus. Unbekannte Umgebungsvariablen werden nicht getauscht. + string textNeu = VaribleThroughString.Replace(text); + // + labelResult.Text = textNeu; //Hier wird der Text beispielhaft ausgegeben + + //DLL Information abrufen + var vts = new VaribleThroughString(); + string dllInfo = String.Concat(VaribleThroughString.DllName, "\n", VaribleThroughString.DllVersion, "\n", VaribleThroughString.Copyright); + labelDllInfo.Text = dllInfo; + } + + private void buttonStartWithMessage_Click(object sender, EventArgs e) + { + string text = "NX ist im Verzeichns ${UGII_BASE_DIR} installiert. Im Verzeichnis ${UGII_ROOT_DIR} sind die Befehle.\nAls Systemsprache ist %UGII_LANG% eingestellt. Als temporäres NX Verzeichnis ist %UGII_TMP_DIR% definiert."; + + labelSourceString.Text = text; + + // + //Diese Zeilen in das Programm kopieren + // + //Tauscht bekannte Umgebungsvariblen gegen ihren Wert aus. Unbekannte Umgebungsvariablen lösen eine Exception aus. + try + { + string textNeu = VaribleThroughString.Replace(text, true); + labelResult.Text = textNeu; //Hier wird der Text beispielhaft ausgegeben + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + // + + //DLL Information abrufen + var vts = new VaribleThroughString(); + string dllInfo = String.Concat(VaribleThroughString.DllName, "\n", VaribleThroughString.DllVersion, "\n", VaribleThroughString.Copyright); + labelDllInfo.Text = dllInfo; + } + } +} diff --git a/Test_VaribleThroughString/Form1.de.resx b/Test_VaribleThroughString/Form1.de.resx new file mode 100644 index 0000000..a5c621a --- /dev/null +++ b/Test_VaribleThroughString/Form1.de.resx @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + 379, 257 + + + 648, 292 + + \ No newline at end of file diff --git a/Test_VaribleThroughString/Form1.en.resx b/Test_VaribleThroughString/Form1.en.resx new file mode 100644 index 0000000..6b601ff --- /dev/null +++ b/Test_VaribleThroughString/Form1.en.resx @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + 304, 23 + + + Replace variable through value (without message when error) + + + 339, 257 + + + 297, 23 + + + Replace variable through value (with message when error) + + \ No newline at end of file diff --git a/Test_VaribleThroughString/Form1.resx b/Test_VaribleThroughString/Form1.resx new file mode 100644 index 0000000..f031b66 --- /dev/null +++ b/Test_VaribleThroughString/Form1.resx @@ -0,0 +1,276 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + 12, 9 + + + $this + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 6, 13 + + + + Bottom, Right + + + 4 + + + 12, 83 + + + + 2 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + buttonStart + + + 16, 13 + + + 0 + + + System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + 0 + + + Form1 + + + ... + + + $this + + + 290, 23 + + + $this + + + labelResult + + + 12, 257 + + + True + + + True + + + 648, 292 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + Bottom, Left + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 2 + + + 4 + + + 3 + + + 3 + + + 1 + + + 1 + + + $this + + + 379, 257 + + + 257, 23 + + + labelSourceString + + + buttonStartWithMessage + + + 16, 13 + + + labelDllInfo + + + Tausche Varable geben Wert (Meldung bei Fehler) + + + 15, 171 + + + ... + + + 16, 13 + + + Form1 + + + ... + + + Tausche Varable geben Wert (Ohne Meldung bei Fehler) + + + True + + \ No newline at end of file diff --git a/Test_VaribleThroughString/Program.cs b/Test_VaribleThroughString/Program.cs new file mode 100644 index 0000000..957ae98 --- /dev/null +++ b/Test_VaribleThroughString/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Eugen.ESystem +{ + static class Program + { + /// + /// Der Haupteinstiegspunkt für die Anwendung. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/Test_VaribleThroughString/Properties/AssemblyInfo.cs b/Test_VaribleThroughString/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d52c5a7 --- /dev/null +++ b/Test_VaribleThroughString/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("Test_VaribleThroughString")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Test_VaribleThroughString")] +[assembly: AssemblyCopyright("Copyright © 2019 by Eugen Höglinger")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly +// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("196a7f39-5bda-4e02-84e8-b30973309c8b")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// übernehmen, indem Sie "*" eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.*")] +//[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Test_VaribleThroughString/Properties/Resources.Designer.cs b/Test_VaribleThroughString/Properties/Resources.Designer.cs new file mode 100644 index 0000000..3dfeed8 --- /dev/null +++ b/Test_VaribleThroughString/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion: 4.0.30319.42000 +// +// Änderungen an dieser Datei können fehlerhaftes Verhalten verursachen und gehen verloren, wenn +// der Code neu generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Test_VaribleThroughString.Properties +{ + + + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder-Klasse + // über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der Option /str erneut aus, oder erstellen Sie Ihr VS-Projekt neu. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Test_VaribleThroughString.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenlookups, die diese stark typisierte Ressourcenklasse verwenden. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Test_VaribleThroughString/Properties/Resources.resx b/Test_VaribleThroughString/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Test_VaribleThroughString/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Test_VaribleThroughString/Properties/Settings.Designer.cs b/Test_VaribleThroughString/Properties/Settings.Designer.cs new file mode 100644 index 0000000..3b60519 --- /dev/null +++ b/Test_VaribleThroughString/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Test_VaribleThroughString.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Test_VaribleThroughString/Properties/Settings.settings b/Test_VaribleThroughString/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Test_VaribleThroughString/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Test_VaribleThroughString/Test_VaribleThroughString.csproj b/Test_VaribleThroughString/Test_VaribleThroughString.csproj new file mode 100644 index 0000000..d58d8d0 --- /dev/null +++ b/Test_VaribleThroughString/Test_VaribleThroughString.csproj @@ -0,0 +1,95 @@ + + + + + Debug + AnyCPU + {196A7F39-5BDA-4E02-84E8-B30973309C8B} + WinExe + Test_VaribleThroughString + Test_VaribleThroughString + v4.6.1 + 512 + true + false + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + Form1.cs + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + {8d5c22c1-dd1a-4a28-b636-445f02adb815} + VaribleThroughString + + + + \ No newline at end of file diff --git a/VaribleThroughString.sln b/VaribleThroughString.sln new file mode 100644 index 0000000..45fcaef --- /dev/null +++ b/VaribleThroughString.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.572 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VaribleThroughString", "VaribleThroughString\VaribleThroughString.csproj", "{8D5C22C1-DD1A-4A28-B636-445F02ADB815}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_VaribleThroughString", "Test_VaribleThroughString\Test_VaribleThroughString.csproj", "{196A7F39-5BDA-4E02-84E8-B30973309C8B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8D5C22C1-DD1A-4A28-B636-445F02ADB815}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8D5C22C1-DD1A-4A28-B636-445F02ADB815}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8D5C22C1-DD1A-4A28-B636-445F02ADB815}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8D5C22C1-DD1A-4A28-B636-445F02ADB815}.Release|Any CPU.Build.0 = Release|Any CPU + {196A7F39-5BDA-4E02-84E8-B30973309C8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {196A7F39-5BDA-4E02-84E8-B30973309C8B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {196A7F39-5BDA-4E02-84E8-B30973309C8B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {196A7F39-5BDA-4E02-84E8-B30973309C8B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {039A859E-4FEE-4D4F-AD8D-56F191271930} + EndGlobalSection +EndGlobal diff --git a/VaribleThroughString/Language.Designer.cs b/VaribleThroughString/Language.Designer.cs new file mode 100644 index 0000000..e5c5ed7 --- /dev/null +++ b/VaribleThroughString/Language.Designer.cs @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Eugen.ESystem { + using System; + + + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Language { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Language() { + } + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("VaribleThroughString.Language", typeof(Language).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Die Umgebungsvariable ' ähnelt. + /// + internal static string message001seg01 { + get { + return ResourceManager.GetString("message001seg01", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die ' wurde nicht gefunden! ähnelt. + /// + internal static string message001seg02 { + get { + return ResourceManager.GetString("message001seg02", resourceCulture); + } + } + } +} diff --git a/VaribleThroughString/Language.de.resx b/VaribleThroughString/Language.de.resx new file mode 100644 index 0000000..b6d0409 --- /dev/null +++ b/VaribleThroughString/Language.de.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Die Umgebungsvariable ' + + + ' wurde nicht gefunden! + + \ No newline at end of file diff --git a/VaribleThroughString/Language.en.resx b/VaribleThroughString/Language.en.resx new file mode 100644 index 0000000..a99e19f --- /dev/null +++ b/VaribleThroughString/Language.en.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + The environment variable ' + + + ' was not found! + + \ No newline at end of file diff --git a/VaribleThroughString/Language.resx b/VaribleThroughString/Language.resx new file mode 100644 index 0000000..b6d0409 --- /dev/null +++ b/VaribleThroughString/Language.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Die Umgebungsvariable ' + + + ' wurde nicht gefunden! + + \ No newline at end of file diff --git a/VaribleThroughString/Properties/AssemblyInfo.cs b/VaribleThroughString/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..288c9cd --- /dev/null +++ b/VaribleThroughString/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("VaribleThroughString")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("VaribleThroughString")] +[assembly: AssemblyCopyright("Copyright © 2019 by Eugen Höglinger")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly +// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("8d5c22c1-dd1a-4a28-b636-445f02adb815")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// indem Sie "*" wie unten gezeigt eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.*")] +//[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/VaribleThroughString/VaribleThroughString.cs b/VaribleThroughString/VaribleThroughString.cs new file mode 100644 index 0000000..e75c485 --- /dev/null +++ b/VaribleThroughString/VaribleThroughString.cs @@ -0,0 +1,239 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Resources; +using System.Text; +using System.Threading.Tasks; + +namespace Eugen.ESystem +{ + public class VaribleThroughString + { + #region Version und Copyright + // Version und Copyright + string dllName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen + string dllVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); + static object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); + string copyright = ((AssemblyCopyrightAttribute)attributes[0]).Copyright; + //Assembly Datum und Zeit + static DateTime value = AssemblyDateTime(); + string date = value.ToShortDateString(); + string time = value.ToLongTimeString(); + private static DateTime AssemblyDateTime() + { + var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; + var buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + TimeSpan.TicksPerSecond * 2 * version.Revision)); + //Tage seit dem 1. Januar 2000 und Sekunden seit Mitternacht, (multiplizier mit 2 ergibt das Original) + return buildDateTime; + } + #endregion + + #region DLL-Info + /// + /// Contains the name of the dll file. + /// + public static string DllName { private set; get; } + + /// + /// Contains the version of the dll file. + /// + public static string DllVersion { private set; get; } + + /// + /// Contains the copyright notice. + /// + public static string Copyright { private set; get; } + + /// + /// Contains the name-, version- and copyright-information of the dll file. + /// + public static string[] DllInfo { private set; get; } + + private void SetDllInfo() + { + //Name, Version und Copyright setzen + DllName = dllName; + DllVersion = dllVersion; + Copyright = this.copyright; + + string[] dllInfo = new string[3]; + dllInfo[0] = dllName; + dllInfo[1] = dllVersion; + dllInfo[2] = this.copyright; + DllInfo = dllInfo; + } + #endregion + + /// + /// Replaces a Environment variable through the variable value. + /// + public VaribleThroughString() + { + SetDllInfo(); //Name, Version und Copyright der DLL setzen + } + + const string repStart = "<§<§<§<"; + const string repEnd = ">§>§>§>"; + + /// + /// Replaces variables with the pattern ${variable} or %variable% with their value. + /// + /// The environment variable containing text. If a variable was not found, then the variable name is not replaced. + /// The edited text. + public static string Replace(string text) + { + if (!(text.Contains("${") || text.Contains("%")) || String.IsNullOrEmpty(text)) + { + return text; + } + + while (text.Contains("${")) + { + text = ReplaceVarible(text, "${", "}"); + } + + //Wenn die Umgebungsvariable nicht gefunden wurde, dann die Ursprüngliche Umgebungsvariable wieder herstellen + if (text.Contains(repStart)) + { + text.Replace(repStart, "${"); + text.Replace(repEnd, "}"); + } + + while (text.Contains("%")) + { + text = ReplaceVarible(text, "%", "%"); + } + + //Wenn die Umgebungsvariable nicht gefunden wurde, dann die Ursprüngliche Umgebungsvariable wieder herstellen + if (text.Contains(repStart)) + { + text = text.Replace(repStart, "%"); + text = text.Replace(repEnd, "%"); + } + + return text; + } + + /// + /// Replaces variables with the pattern ${variable} or %variable% with their value. + /// + /// The environment variable containing text. + /// Behavior if variable was not found. True=An exception is thrown. False=The variable is not replaced. + /// The edited text + public static string Replace(string text, bool messageWhenError) + { + if (!(text.Contains("${") || !text.Contains("%")) || String.IsNullOrEmpty(text)) + { + return text; + } + + while (text.Contains("${")) + { + text = ReplaceVarible(text, "${", "}"); + } + + //Wenn die Umgebungsvariable nicht gefunden wurde, dann die Ursprüngliche Umgebungsvariable wieder herstellen + if (text.Contains(repStart)) + { + if (messageWhenError) + { + string varName = text.Remove(0, text.IndexOf(repStart) + 7); + varName = varName.Remove(varName.IndexOf(repEnd)); + + text.Replace(repStart, "${"); + text.Replace(repEnd, "}"); + + throw new NoEnvironmentVariableFoundException(String.Concat(Language.message001seg01, varName, Language.message001seg02)); + } + else + { + text.Replace(repStart, "${"); + text.Replace(repEnd, "}"); + } + } + + while (text.Contains("%")) + { + text = ReplaceVarible(text, "%", "%"); + } + + //Wenn die Umgebungsvariable nicht gefunden wurde, dann die Ursprüngliche Umgebungsvariable wieder herstellen + if (text.Contains(repStart)) + { + if (messageWhenError) + { + string varName = text.Remove(0, text.IndexOf(repStart) + 7); + varName = varName.Remove(varName.IndexOf(repEnd)); + + text = text.Replace(repStart, "%"); + text = text.Replace(repEnd, "%"); + + throw new NoEnvironmentVariableFoundException(String.Concat(Language.message001seg01, varName, Language.message001seg02)); + } + else + { + text = text.Replace(repStart, "%"); + text = text.Replace(repEnd, "%"); + } + } + + return text; + } + + private static string ReplaceVarible(string text, string startSign, string endSign) + { + //Wert vor der Variablen sichern + string temp = text.Remove(text.IndexOf(startSign)); + + //Variable extrahieren + text = text.Remove(0, text.IndexOf(startSign)); //'temp' entfernen + text = text.Remove(0, startSign.Length); //'startSign' entfernen + string variableName = text.Remove(text.IndexOf(endSign)); //'endSign' und nachfolgenden Text entfernen + + //Restlicher Text (hinter 'endSign') erzeugen + text = text.Remove(0, text.IndexOf(endSign) + 1); + + //Variable umwandeln und Text wieder zusammenbauen + string variable = ReplaceEnvironmentVariable(variableName); + text = temp + variable + text; //Text wieder zusammensetzen + + return text; + } + + private static string ReplaceEnvironmentVariable(string variableName) + { + string variableValue = ""; + + //Wenn im Text eine bekannte Umgebungsvariable enthalten ist, dann gegen den aktuellen Wert tauschen + variableValue = Environment.GetEnvironmentVariable(variableName); + + if (String.IsNullOrEmpty(variableValue)) + { + variableValue = String.Concat(repStart, variableName, repEnd); //Wird keine Umgebungsvariable gefunden, dann wieder den Variblen Namen zurückgeben + } + + return variableValue; + } + } + + #region Exceptions + class NoEnvironmentVariableFoundException : ApplicationException + { + public NoEnvironmentVariableFoundException() + { + } + + public NoEnvironmentVariableFoundException(string message) + : base(message) + { + } + + public NoEnvironmentVariableFoundException(string message, Exception inner) + : base(message, inner) + { + } + } + #endregion +} diff --git a/VaribleThroughString/VaribleThroughString.csproj b/VaribleThroughString/VaribleThroughString.csproj new file mode 100644 index 0000000..6c34b9f --- /dev/null +++ b/VaribleThroughString/VaribleThroughString.csproj @@ -0,0 +1,66 @@ + + + + + Debug + AnyCPU + {8D5C22C1-DD1A-4A28-B636-445F02ADB815} + Library + Properties + VaribleThroughString + VaribleThroughString + v4.6.1 + 512 + false + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + True + True + Language.resx + + + + + + + Eugen.ESystem + + + Eugen.ESystem + + + ResXFileCodeGenerator + Language.Designer.cs + Eugen.ESystem + + + + \ No newline at end of file