157 lines
6.4 KiB
C#
157 lines
6.4 KiB
C#
///
|
|
/// Copyright (c) 2020 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
using EventViewer.Resources;
|
|
|
|
namespace EventViewer
|
|
{
|
|
static class Program
|
|
{
|
|
/// Program information
|
|
public static string Version; /// version string
|
|
public static DateTime BuildDateTime; /// date and time of program build
|
|
|
|
/// Local settings
|
|
public static string ExecutableDirectory;
|
|
public static string ConfigDirectory;
|
|
public static string LocalSettingsFileName;
|
|
public static string LocalSettingsBackupName;
|
|
public static LocalSettings LocalSettings;
|
|
|
|
/// <summary>
|
|
/// The main entry point for the application.
|
|
/// </summary>
|
|
[STAThread]
|
|
static void Main(string[] args)
|
|
{
|
|
/// 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
|
|
ExecutableDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
|
|
|
/// Config directory is a sibling directory of the executable directory
|
|
ConfigDirectory = Path.Combine(ExecutableDirectory, "..", string.Format("Cfg{0}", (args.Length >= 1) ? args[0] : string.Empty));
|
|
LocalSettingsFileName = Path.Combine(ConfigDirectory, "config.xml");
|
|
LocalSettingsBackupName = Path.Combine(ConfigDirectory, "config.backup.xml");
|
|
|
|
///// Configue and start logging
|
|
//log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(ConfigDirectory + "log4netConfig.xml"));
|
|
//log = LogManager.GetLogger(typeof(Program));
|
|
//log.Fatal("------------------------------------------------------------------------------------------------");
|
|
//log.Fatal("started");
|
|
|
|
///
|
|
/// Load the local settings
|
|
///
|
|
bool isConfigReadOnly = false;
|
|
LocalSettings = LocalSettings.Load(Program.LocalSettingsFileName);
|
|
if (LocalSettings == null)
|
|
{
|
|
/// Loading local seetings from regular config file failed. Use the backup
|
|
LocalSettings = LocalSettings.Load(Program.LocalSettingsBackupName);
|
|
if (LocalSettings == null)
|
|
{
|
|
MessageBox.Show(Strings.No_program_settings_found + Strings.Using_default_settings,
|
|
string.Empty,
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Information);
|
|
|
|
/// Create new default settings
|
|
LocalSettings = new LocalSettings(true);
|
|
}
|
|
|
|
try
|
|
{
|
|
/// Create config directory if it is missing
|
|
if (!Directory.Exists(ConfigDirectory)) Directory.CreateDirectory(ConfigDirectory);
|
|
/// Save settings (overwrite a wrong file in case loading settings failed
|
|
LocalSettings.Save();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
isConfigReadOnly = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
/// Loading local seetings from the regular config file was successful. Update the backup
|
|
File.Copy(Program.LocalSettingsFileName, Program.LocalSettingsBackupName, true);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
isConfigReadOnly = true;
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
string culture = (LocalSettings.Language != null) ? LocalSettings.Language.Replace('_', '-') : "EN";
|
|
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(culture);
|
|
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(culture);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
string msg = e.Message;
|
|
MessageBox.Show(Strings.Selected_language_is_not_supported + Environment.NewLine + Strings.Using_English,
|
|
Strings.Warning,
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Asterisk);
|
|
|
|
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en");
|
|
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
|
|
}
|
|
|
|
|
|
/// This belongs to Application.Run(new MainWnd()) ...
|
|
/// and should be executed before opening 'loginDlg'
|
|
Application.EnableVisualStyles();
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
|
|
|
|
try
|
|
{
|
|
/// Open the main application window
|
|
Application.Run(new EventViewerWnd());
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
//LogException(log, "Exception in Application.Run(new ResultsBrowserWnd(args))", e);
|
|
}
|
|
finally
|
|
{
|
|
/// Save local settings
|
|
LocalSettings.Save();
|
|
}
|
|
|
|
/// Close Fluent NHibernate
|
|
/// Todo
|
|
}
|
|
|
|
static void MyHandler(object sender, UnhandledExceptionEventArgs args)
|
|
{
|
|
//LogException(log, "Unhandled exception", (Exception)args.ExceptionObject);
|
|
}
|
|
|
|
//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("--------------------------------------");
|
|
//}
|
|
}
|
|
}
|