2015-12-12 20:44:36 +00:00
|
|
|
|
///
|
2015-12-13 08:37:48 +00:00
|
|
|
|
/// Copyright (c) 2015 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;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ResultsBrowser
|
|
|
|
|
|
{
|
2015-12-12 20:44:36 +00:00
|
|
|
|
public class Program
|
|
|
|
|
|
{
|
2015-02-20 02:59:11 +00:00
|
|
|
|
public const string HomeDir = "C:\\Tbf\\"; /// Contains subdirectories Results, Logs, Images, ...
|
|
|
|
|
|
|
|
|
|
|
|
/// log4net
|
|
|
|
|
|
static readonly ILog log = LogManager.GetLogger(typeof(Program));
|
|
|
|
|
|
const string log4netConfigFName = "log4netConfig.xml";
|
|
|
|
|
|
|
|
|
|
|
|
/// Local settings
|
2015-12-10 21:17:47 +00:00
|
|
|
|
public static LocalSettings LocalSettings;
|
|
|
|
|
|
public const string LocalSettingsFileName = "ResultsBrowser.xml";
|
|
|
|
|
|
public const string LocalSettingsBackupName = "ResultsBrowser.backup.xml";
|
|
|
|
|
|
|
|
|
|
|
|
public static System.Globalization.CultureInfo AltCulture;
|
|
|
|
|
|
|
2015-02-20 02:59:11 +00:00
|
|
|
|
|
2015-12-12 20:44:36 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Main window object.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static MainWnd MainWnd;
|
2016-03-18 07:53:33 +00:00
|
|
|
|
public static RBrowserWnd RBrowserWnd;
|
2016-06-01 10:09:03 +00:00
|
|
|
|
public static ResultsBrowserWnd ResultsBrowserWnd;
|
2015-02-20 02:59:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
2015-12-12 20:44:36 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The main entry point for the application.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[STAThread]
|
|
|
|
|
|
static void Main()
|
|
|
|
|
|
{
|
|
|
|
|
|
log.Fatal("--------------------------------------------------------------------------------");
|
2015-02-20 02:59:11 +00:00
|
|
|
|
|
2015-12-12 20:44:36 +00:00
|
|
|
|
/// Local program configuration directory including the trailing backslash
|
2015-02-20 02:59:11 +00:00
|
|
|
|
string locAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) +
|
|
|
|
|
|
Path.DirectorySeparatorChar + "TestBenchFramework" + Path.DirectorySeparatorChar;
|
|
|
|
|
|
|
2015-12-12 20:44:36 +00:00
|
|
|
|
/// Check whether local application data directory exists.
|
2015-02-20 02:59:11 +00:00
|
|
|
|
/// If not, create it and copy the initial configuration to this directory.
|
|
|
|
|
|
/// This is done only once after a clean program installation on the first program start-up
|
|
|
|
|
|
try
|
2015-12-12 20:44:36 +00:00
|
|
|
|
{
|
2015-02-20 02:59:11 +00:00
|
|
|
|
if (!Directory.Exists(locAppDataDir))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory(locAppDataDir);
|
|
|
|
|
|
Environment.CurrentDirectory = locAppDataDir;
|
|
|
|
|
|
|
|
|
|
|
|
string sampleConfig = Application.StartupPath + Path.DirectorySeparatorChar + "SampleConfig" + Path.DirectorySeparatorChar;
|
|
|
|
|
|
if (File.Exists(sampleConfig + LocalSettingsFileName)) { File.Copy(sampleConfig + LocalSettingsFileName, LocalSettingsFileName); }
|
|
|
|
|
|
if (File.Exists(sampleConfig + log4netConfigFName)) { File.Copy(sampleConfig + log4netConfigFName, log4netConfigFName); }
|
2015-12-04 16:17:20 +00:00
|
|
|
|
if (File.Exists(sampleConfig + Config.Data.SQLiteDbFName)) { File.Copy(sampleConfig + Config.Data.SQLiteDbFName, Config.Data.SQLiteDbFName); }
|
2015-02-20 02:59:11 +00:00
|
|
|
|
|
|
|
|
|
|
File.SetAttributes(LocalSettingsFileName, FileAttributes.Normal);
|
|
|
|
|
|
File.SetAttributes(log4netConfigFName, FileAttributes.Normal);
|
2015-12-04 16:17:20 +00:00
|
|
|
|
File.SetAttributes(Config.Data.SQLiteDbFName, FileAttributes.Normal);
|
2015-02-20 02:59:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Environment.CurrentDirectory = locAppDataDir;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-12-12 20:44:36 +00:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
log.Error("A problem when creating the local application data directory and preparing the initial configuration", e);
|
2015-02-20 02:59:11 +00:00
|
|
|
|
return;
|
2015-12-12 20:44:36 +00:00
|
|
|
|
}
|
2015-02-20 02:59:11 +00:00
|
|
|
|
|
|
|
|
|
|
/// Configue and start logging
|
|
|
|
|
|
log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(locAppDataDir + log4netConfigFName));
|
|
|
|
|
|
log.Info("Entering application.");
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2015-12-12 20:44:36 +00:00
|
|
|
|
if (MessageBox.Show("No program settings found. Do you want to use default settings?",
|
|
|
|
|
|
"Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Create new default settings and save them
|
|
|
|
|
|
LocalSettings = new LocalSettings();
|
|
|
|
|
|
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
|
|
|
|
|
|
{
|
|
|
|
|
|
string culture = LocalSettings.Language.Replace('_', '-');
|
|
|
|
|
|
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(culture);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
string msg = e.Message;
|
|
|
|
|
|
MessageBox.Show("Selected language not supported.\nUsing English.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
|
|
|
|
|
|
System.Threading.Thread.CurrentThread.CurrentUICulture =
|
|
|
|
|
|
new System.Globalization.CultureInfo("en");
|
|
|
|
|
|
}
|
2015-02-20 02:59:11 +00:00
|
|
|
|
|
2015-12-10 21:17:47 +00:00
|
|
|
|
//AltCulture = null;
|
|
|
|
|
|
AltCulture = new System.Globalization.CultureInfo("SK");
|
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
|
|
|
|
|
|
log.Info("Creating the main window");
|
2016-06-06 13:33:22 +00:00
|
|
|
|
#if false //IPERLST || IPERLST_SPECIAL
|
2015-12-10 21:17:47 +00:00
|
|
|
|
MainWnd = new MainWnd();
|
|
|
|
|
|
log.Info("Opening the main window");
|
|
|
|
|
|
Application.Run(MainWnd);
|
2016-03-18 07:53:33 +00:00
|
|
|
|
#else
|
2016-06-01 10:09:03 +00:00
|
|
|
|
ResultsBrowserWnd = new ResultsBrowserWnd();
|
2016-03-18 07:53:33 +00:00
|
|
|
|
log.Info("Opening the main window");
|
2016-06-01 10:09:03 +00:00
|
|
|
|
Application.Run(ResultsBrowserWnd);
|
2016-03-18 07:53:33 +00:00
|
|
|
|
#endif
|
2015-12-10 21:17:47 +00:00
|
|
|
|
log.Info("The main window was closed");
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogException(log, "Exception in Application.Run(MainWnd)", e);
|
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|