using System; using System.IO; using System.Reflection; using System.Windows.Forms; namespace CheckEnvironment { public partial class CheckEnvironment : 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 = GenerateCopyright(); 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; } private static string CurrentYear() { DateTime dtn = DateTime.Now; return dtn.Year.ToString(); } private static string StartYear() { //string startYear = ((AssemblyCopyrightAttribute)attributes[0]).Copyright; //return startYear.Remove(0, startYear.LastIndexOf(" ") + 1); string startYear = ""; if (((AssemblyCopyrightAttribute)attributes[0]).Copyright.Contains("Copyright © ")) { startYear = ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace("Copyright © ", ""); while (startYear.StartsWith(" ")) { startYear = startYear.Remove(0, 1); } startYear = startYear.Remove(startYear.IndexOf(" ")); return startYear; } else { DateTime dtn = DateTime.Now; return dtn.Year.ToString(); } } private static string GenerateCopyright() { string startYear = StartYear(); string currentYear = CurrentYear(); if (startYear == currentYear) { return ((AssemblyCopyrightAttribute)attributes[0]).Copyright; } else { //return String.Concat(((AssemblyCopyrightAttribute)attributes[0]).Copyright, "-", currentYear); return ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace(startYear, String.Concat(startYear, "-", currentYear)); } } #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 CheckEnvironment() { InitializeComponent(); SetProgramInfo(); } private void buttonClose_Click(object sender, EventArgs e) { this.Close(); } private string CheckEnv(string env) { return Environment.GetEnvironmentVariable(env); } private void Form1_Load(object sender, EventArgs e) { string result = ""; result = CheckEnv("NX_ONLINE"); if (String.IsNullOrEmpty(result)) { textBoxNxOnline.Text = ""; labelNxOnlineResult.Text = "MISSING"; } else { textBoxNxOnline.Text = result; labelNxOnlineResult.Text = "OK"; } result = CheckEnv("NX_OFFLINE"); if (String.IsNullOrEmpty(result)) { textBoxNxOffline.Text = ""; labelNxOfflineResult.Text = "MISSING"; } else { textBoxNxOffline.Text = result; labelNxOfflineResult.Text = "OK"; } result = CheckEnv("UGII_ENV_FILE"); if (String.IsNullOrEmpty(result)) { textBoxUgiiEnvFile.Text = ""; labelUgiiEnvFileResult.Text = "MISSING"; } else { textBoxUgiiEnvFile.Text = result; labelUgiiEnvFileResult.Text = "OK"; } result = CheckEnv("COMPSOLV_MACHINE"); if (String.IsNullOrEmpty(result)) { textBoxCompsolveMachine.Text = ""; labelCompsolveMachineResult.Text = "MISSING"; } else { textBoxCompsolveMachine.Text = result; labelCompsolveMachineResult.Text = "OK"; } result = CheckEnv("COMPSOLV_TOOLS"); if (String.IsNullOrEmpty(result)) { textBoxCompsolvTools.Text = ""; labelCompsolvToolsResult.Text = "MISSING"; } else { textBoxCompsolvTools.Text = result; labelCompsolvToolsResult.Text = "OK"; } result = CheckEnv("COMPSOLVE_STDLIB"); if (String.IsNullOrEmpty(result)) { textBoxCompsolvStdLib.Text = ""; labelCompsolvStdLibResult.Text = "MISSING"; } else { textBoxCompsolvStdLib.Text = result; labelCompsolvStdLibResult.Text = "OK"; } result = CheckEnv("COMPSOLV_UGII_SETTINGS"); if (String.IsNullOrEmpty(result)) { textBoxCompsolvUgiiSettings.Text = ""; labelCompsolvUgiiSettingsResult.Text = "MISSING"; } else { textBoxCompsolvUgiiSettings.Text = result; labelCompsolvUgiiSettingsResult.Text = "OK"; } } } }