112 lines
3.9 KiB
C#
112 lines
3.9 KiB
C#
///
|
|
/// Copyright (c) 2016-2017 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
|
|
namespace DeviceTest
|
|
{
|
|
static class Program
|
|
{
|
|
/// Program information
|
|
public static string Version; /// version string
|
|
public static DateTime BuildDateTime; /// date and time of program build
|
|
|
|
/// log4net
|
|
static ILog log;
|
|
const string log4netConfigFName = "log4netConfig.xml";
|
|
|
|
/// Local settings
|
|
public static readonly string LocAppDataDir;
|
|
public static readonly string LocalSettingsFileName;
|
|
public static readonly string LocalSettingsBackupName;
|
|
public static LocalSettings LocalSettings;
|
|
|
|
static Program()
|
|
{
|
|
/// Program version string
|
|
System.Reflection.Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly();
|
|
Version ver = thisAssembly.GetName().Version;
|
|
Version = string.Format("{0}.{1}.{2}", ver.Major, ver.Minor, ver.Build);
|
|
BuildDateTime = new System.IO.FileInfo(thisAssembly.Location).LastWriteTime;
|
|
|
|
/// Local program configuration directory including the trailing backslash
|
|
LocAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) +
|
|
Path.DirectorySeparatorChar + "TestBenchFramework" + Path.DirectorySeparatorChar;
|
|
LocalSettingsFileName = LocAppDataDir + "DeviceTest.xml";
|
|
LocalSettingsBackupName = LocAppDataDir + "DeviceTest.backup.xml";
|
|
}
|
|
|
|
/// <summary>
|
|
/// The main entry point for the application.
|
|
/// </summary>
|
|
[STAThread]
|
|
static void Main()
|
|
{
|
|
///
|
|
/// Load the local settings
|
|
///
|
|
Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsFileName);
|
|
if (Program.LocalSettings == null)
|
|
{
|
|
/// Loading local seetings from regular config file failed. Use the backup
|
|
Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsBackupName);
|
|
if (Program.LocalSettings == null)
|
|
{
|
|
MessageBox.Show("Na tomto počítači nebol tento program ani raz spustený.\r\nPoužijú sa základné nastavenia.", "Upozornenie", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
Program.LocalSettings = new LocalSettings();
|
|
Directory.CreateDirectory(LocAppDataDir);
|
|
Program.LocalSettings.Save();
|
|
}
|
|
else
|
|
{
|
|
LocalSettings.Save(); /// Save the settings to overwrite the wrong file
|
|
}
|
|
}
|
|
else
|
|
{
|
|
/// Loading local seetings from the regular config file was successful. Update the backup
|
|
File.Copy(Program.LocalSettingsFileName, Program.LocalSettingsBackupName, true);
|
|
}
|
|
|
|
/// Configure and start logging
|
|
log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(LocAppDataDir + log4netConfigFName));
|
|
log = LogManager.GetLogger(typeof(Program));
|
|
log.Fatal("--------------------------------------------------------------------------------");
|
|
log.Fatal(string.Format("TBF ver.{0}", Version));
|
|
|
|
Application.EnableVisualStyles();
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
|
|
try
|
|
{
|
|
DeviceTestDlg dlg = new DeviceTestDlg();
|
|
Application.Run(dlg);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
LogException(log, "Exception in Application.Run(DeviceTestDlg)", exc);
|
|
MessageBox.Show("Program havaroval:" +
|
|
Environment.NewLine + Environment.NewLine + exc.Message +
|
|
((exc.InnerException == null) ? string.Empty : (Environment.NewLine + exc.InnerException.Message)) +
|
|
Environment.NewLine + exc.StackTrace,
|
|
"Pozor!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
}
|
|
}
|
|
|
|
static void LogException(ILog log, string description, Exception e)
|
|
{
|
|
log.FatalFormat("---------------( {0} )---------------", description);
|
|
log.FatalFormat("Message : {0}", e.Message);
|
|
if (e.InnerException != null)
|
|
{
|
|
log.FatalFormat("InnerMessage : {0}", e.InnerException.Message);
|
|
}
|
|
log.FatalFormat("StackTrace : {0}{1}", Environment.NewLine, e.StackTrace);
|
|
log.Fatal("--------------------------------------");
|
|
}
|
|
}
|
|
}
|