2015-12-12 20:44:36 +00:00
|
|
|
|
///
|
2016-08-16 14:39:55 +00:00
|
|
|
|
/// Copyright (c) 2015-2016 Sensus Metering Systems
|
2015-04-15 20:03:23 +00:00
|
|
|
|
///
|
2015-02-20 02:59:11 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
using log4net;
|
2015-12-04 16:17:20 +00:00
|
|
|
|
using Config.Entities;
|
2015-02-20 02:59:11 +00:00
|
|
|
|
using ResultsBrowser.Forms;
|
2016-08-16 14:39:55 +00:00
|
|
|
|
using ResultsBrowser.Resources;
|
2015-02-20 02:59:11 +00:00
|
|
|
|
|
|
|
|
|
|
namespace ResultsBrowser
|
|
|
|
|
|
{
|
2015-12-12 20:44:36 +00:00
|
|
|
|
public class Program
|
|
|
|
|
|
{
|
2019-01-11 12:25:39 +00:00
|
|
|
|
static ILog log; /// log4net
|
|
|
|
|
|
|
2016-08-16 14:39:55 +00:00
|
|
|
|
/// Program information
|
|
|
|
|
|
public static string Version; /// version string
|
|
|
|
|
|
public static DateTime BuildDateTime; /// date and time of program build
|
2015-02-20 02:59:11 +00:00
|
|
|
|
|
2016-08-16 14:39:55 +00:00
|
|
|
|
/// Local settings
|
2019-01-11 12:25:39 +00:00
|
|
|
|
public static string ExecutableDirectory;
|
|
|
|
|
|
public static string ConfigDirectory;
|
|
|
|
|
|
public static string LogDirectory;
|
|
|
|
|
|
public static string LocalSettingsFileName;
|
|
|
|
|
|
public static string LocalSettingsBackupName;
|
2016-08-16 14:39:55 +00:00
|
|
|
|
public static LocalSettings LocalSettings;
|
2015-02-20 02:59:11 +00:00
|
|
|
|
|
2019-01-11 12:25:39 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The main entry point for the application.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[STAThread]
|
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
|
{
|
2016-08-16 14:39:55 +00:00
|
|
|
|
/// 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);
|
2019-01-11 12:25:39 +00:00
|
|
|
|
#if false
|
|
|
|
|
|
/// 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));
|
2016-08-16 14:39:55 +00:00
|
|
|
|
LogDirectory = Path.Combine(ExecutableDirectory, "..\\Log\\");
|
2019-01-11 12:25:39 +00:00
|
|
|
|
#else
|
|
|
|
|
|
/// Config directory is a directory in 'C:\Users\username\AppData\Local' folder
|
|
|
|
|
|
ConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
|
|
|
|
|
string.Format("ResultsBrowser{0}", (args.Length >= 1) ? args[0] : string.Empty));
|
|
|
|
|
|
LogDirectory = "C:\\Temp\\ResultsBrowserLog\\";
|
|
|
|
|
|
#endif
|
|
|
|
|
|
LocalSettingsFileName = Path.Combine(ConfigDirectory, "config.xml");
|
|
|
|
|
|
LocalSettingsBackupName = Path.Combine(ConfigDirectory, "config.backup.xml");
|
2016-08-16 14:39:55 +00:00
|
|
|
|
|
|
|
|
|
|
/// 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");
|
2019-01-11 12:25:39 +00:00
|
|
|
|
|
|
|
|
|
|
///
|
2015-12-10 21:17:47 +00:00
|
|
|
|
/// Load the local settings
|
|
|
|
|
|
///
|
2015-12-12 20:44:36 +00:00
|
|
|
|
LocalSettings = LocalSettings.Load(Program.LocalSettingsFileName);
|
2016-01-13 04:21:36 +00:00
|
|
|
|
if (LocalSettings == null)
|
2015-12-10 21:17:47 +00:00
|
|
|
|
{
|
|
|
|
|
|
/// Loading local seetings from regular config file failed. Use the backup
|
2015-12-12 20:44:36 +00:00
|
|
|
|
LocalSettings = LocalSettings.Load(Program.LocalSettingsBackupName);
|
2016-01-13 04:21:36 +00:00
|
|
|
|
if (LocalSettings == null)
|
2015-12-10 21:17:47 +00:00
|
|
|
|
{
|
2016-08-16 14:39:55 +00:00
|
|
|
|
MessageBox.Show(Strings.No_program_settings_found + Strings.Using_default_settings,
|
|
|
|
|
|
string.Empty,
|
|
|
|
|
|
MessageBoxButtons.OK,
|
|
|
|
|
|
MessageBoxIcon.Information);
|
2015-12-12 20:44:36 +00:00
|
|
|
|
|
|
|
|
|
|
/// Create new default settings and save them
|
|
|
|
|
|
LocalSettings = new LocalSettings();
|
2016-08-16 14:39:55 +00:00
|
|
|
|
Directory.CreateDirectory(ConfigDirectory);
|
|
|
|
|
|
LocalSettings.Save();
|
2015-12-10 21:17:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2019-01-11 12:25:39 +00:00
|
|
|
|
string culture = (LocalSettings.Language != null) ? LocalSettings.Language.Replace('_', '-') : "EN";
|
2015-12-10 21:17:47 +00:00
|
|
|
|
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(culture);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
string msg = e.Message;
|
2016-08-16 14:39:55 +00:00
|
|
|
|
MessageBox.Show(Strings.Selected_language_not_supported + Environment.NewLine + Strings.Using_English,
|
|
|
|
|
|
Strings.Warning,
|
|
|
|
|
|
MessageBoxButtons.OK,
|
|
|
|
|
|
MessageBoxIcon.Asterisk);
|
2015-12-10 21:17:47 +00:00
|
|
|
|
System.Threading.Thread.CurrentThread.CurrentUICulture =
|
|
|
|
|
|
new System.Globalization.CultureInfo("en");
|
|
|
|
|
|
}
|
2015-02-20 02:59:11 +00:00
|
|
|
|
|
2016-01-13 04:21:36 +00:00
|
|
|
|
|
2015-12-12 20:44:36 +00:00
|
|
|
|
/// This belongs to Application.Run(new MainWnd()) ...
|
|
|
|
|
|
/// and should be executed before opening 'loginDlg'
|
|
|
|
|
|
Application.EnableVisualStyles();
|
|
|
|
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
2015-02-20 02:59:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
2015-12-10 21:17:47 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Open the main application window
|
2016-11-18 10:39:07 +00:00
|
|
|
|
log.Info("Creating and opening the main window");
|
|
|
|
|
|
Application.Run(new ResultsBrowserWnd(args));
|
2015-12-10 21:17:47 +00:00
|
|
|
|
log.Info("The main window was closed");
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
2016-11-18 10:39:07 +00:00
|
|
|
|
LogException(log, "Exception in Application.Run(new ResultsBrowserWnd(args))", e);
|
2015-12-10 21:17:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Save local settings
|
|
|
|
|
|
LocalSettings.Save();
|
|
|
|
|
|
}
|
2015-02-20 02:59:11 +00:00
|
|
|
|
|
2015-12-12 20:44:36 +00:00
|
|
|
|
/// Close Fluent NHibernate
|
|
|
|
|
|
/// Todo
|
|
|
|
|
|
|
2015-02-20 02:59:11 +00:00
|
|
|
|
log.Info("Exiting application.");
|
2015-12-12 20:44:36 +00:00
|
|
|
|
}
|
2015-12-10 21:17:47 +00:00
|
|
|
|
|
|
|
|
|
|
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("--------------------------------------");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-02-20 02:59:11 +00:00
|
|
|
|
}
|