ResultsBrowser : ../Cfg directory used for configuration instead of AppData/Local/..., ver. 2.9.336

This commit is contained in:
Milan Hanajik 2016-08-16 16:39:55 +02:00
parent 0859dd28d5
commit 91cb245f84
8 changed files with 170 additions and 108 deletions

View File

@ -23,13 +23,12 @@ namespace ResultsBrowser
/// </summary>
public string Language;
/// Names of servers.
public string Bench1;
public string Bench2;
public string Bench3;
/// <summary>C:\VSProjects\TBF\TestBenchFramework\LocalSettings.cs
/// Names and database settings of test benches.
/// </summary>
/// Database settings of servers.
public string ConnectionString1;
public string ConnectionString2;
public string ConnectionString3;
@ -38,6 +37,7 @@ namespace ResultsBrowser
public bool Bench2Selected;
public bool Bench3Selected;
/// Statistics options
public bool TwoDim;
public int RowItemID;
public int ColumnItemID;
@ -57,6 +57,7 @@ namespace ResultsBrowser
public int MainWndWidth;
public int MainWndHeight;
public bool ManiWndMaximized;
public int SplitterDistance;
/// Purchase order history
public string LastPurchaseOrder;

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2015 Sensus Metering Systems
/// Copyright (c) 2015-2016 Sensus Metering Systems
///
using System;
using System.IO;
@ -8,24 +8,28 @@ using System.Windows.Forms;
using log4net;
using Config.Entities;
using ResultsBrowser.Forms;
using ResultsBrowser.Resources;
namespace ResultsBrowser
{
public class Program
{
public const string HomeDir = "C:\\Tbf\\"; /// Contains subdirectories Results, Logs, Images, ...
/// Program information
public static string Version; /// version string
public static DateTime BuildDateTime; /// date and time of program build
/// log4net
static readonly ILog log = LogManager.GetLogger(typeof(Program));
const string log4netConfigFName = "log4netConfig.xml";
/// Local settings
public static readonly string ExecutableDirectory;
public static readonly string ConfigDirectory;
public static readonly string LogDirectory;
public static readonly string LocalSettingsFileName;
public static readonly string LocalSettingsBackupName;
public static LocalSettings LocalSettings;
/// Local settings
public static LocalSettings LocalSettings;
public const string LocalSettingsFileName = "ResultsBrowser.xml";
public const string LocalSettingsBackupName = "ResultsBrowser.backup.xml";
public static System.Globalization.CultureInfo AltCulture;
static readonly ILog log; /// log4net
/// <summary>
/// Main window object.
@ -34,6 +38,28 @@ namespace ResultsBrowser
public static RBrowserWnd RBrowserWnd;
public static ResultsBrowserWnd ResultsBrowserWnd;
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
ExecutableDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
ConfigDirectory = Path.Combine(ExecutableDirectory, "..\\Cfg\\");
LogDirectory = Path.Combine(ExecutableDirectory, "..\\Log\\");
LocalSettingsFileName = ConfigDirectory + "config.xml";
LocalSettingsBackupName = 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");
}
/// <summary>
/// The main entry point for the application.
@ -41,46 +67,6 @@ namespace ResultsBrowser
[STAThread]
static void Main()
{
log.Fatal("--------------------------------------------------------------------------------");
/// Local program configuration directory including the trailing backslash
string locAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) +
Path.DirectorySeparatorChar + "TestBenchFramework" + Path.DirectorySeparatorChar;
/// Check whether local application data directory exists.
/// 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
{
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); }
if (File.Exists(sampleConfig + Config.Data.SQLiteDbFName)) { File.Copy(sampleConfig + Config.Data.SQLiteDbFName, Config.Data.SQLiteDbFName); }
File.SetAttributes(LocalSettingsFileName, FileAttributes.Normal);
File.SetAttributes(log4netConfigFName, FileAttributes.Normal);
File.SetAttributes(Config.Data.SQLiteDbFName, FileAttributes.Normal);
}
else
{
Environment.CurrentDirectory = locAppDataDir;
}
}
catch (Exception e)
{
log.Error("A problem when creating the local application data directory and preparing the initial configuration", e);
return;
}
/// Configue and start logging
log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(locAppDataDir + log4netConfigFName));
log.Info("Entering application.");
///
/// Load the local settings
///
@ -91,15 +77,15 @@ namespace ResultsBrowser
LocalSettings = LocalSettings.Load(Program.LocalSettingsBackupName);
if (LocalSettings == null)
{
if (MessageBox.Show("No program settings found. Do you want to use default settings?",
"Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
MessageBox.Show(Strings.No_program_settings_found + Strings.Using_default_settings,
string.Empty,
MessageBoxButtons.OK,
MessageBoxIcon.Information);
/// Create new default settings and save them
LocalSettings = new LocalSettings();
LocalSettings.Save();
Directory.CreateDirectory(ConfigDirectory);
LocalSettings.Save();
}
else
{
@ -120,7 +106,10 @@ namespace ResultsBrowser
catch (Exception e)
{
string msg = e.Message;
MessageBox.Show("Selected language not supported.\nUsing English.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
MessageBox.Show(Strings.Selected_language_not_supported + Environment.NewLine + Strings.Using_English,
Strings.Warning,
MessageBoxButtons.OK,
MessageBoxIcon.Asterisk);
System.Threading.Thread.CurrentThread.CurrentUICulture =
new System.Globalization.CultureInfo("en");
}

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.7.303.0")]
[assembly: AssemblyFileVersion("2.7.303.0")]
[assembly: AssemblyVersion("2.9.336.0")]
[assembly: AssemblyFileVersion("2.9.336.0")]

View File

@ -780,4 +780,19 @@
<data name="Query_files" xml:space="preserve">
<value>Query files</value>
</data>
<data name="No_program_settings_found" xml:space="preserve">
<value>No program settings found. </value>
</data>
<data name="Using_default_settings" xml:space="preserve">
<value>Using default settings. </value>
</data>
<data name="Selected_language_not_supported" xml:space="preserve">
<value>Selected language not supported.</value>
</data>
<data name="Using_English" xml:space="preserve">
<value>Using English.</value>
</data>
<data name="Warning" xml:space="preserve">
<value>Warning</value>
</data>
</root>

View File

@ -1617,6 +1617,15 @@ namespace ResultsBrowser.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to No program settings found. .
/// </summary>
internal static string No_program_settings_found {
get {
return ResourceManager.GetString("No_program_settings_found", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to No test bench in the program configuration..
/// </summary>
@ -1932,6 +1941,15 @@ namespace ResultsBrowser.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Selected language not supported..
/// </summary>
internal static string Selected_language_not_supported {
get {
return ResourceManager.GetString("Selected_language_not_supported", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Selected results.
/// </summary>
@ -2031,6 +2049,24 @@ namespace ResultsBrowser.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Using default settings. .
/// </summary>
internal static string Using_default_settings {
get {
return ResourceManager.GetString("Using_default_settings", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Using English..
/// </summary>
internal static string Using_English {
get {
return ResourceManager.GetString("Using_English", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Version.
/// </summary>
@ -2040,6 +2076,15 @@ namespace ResultsBrowser.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Warning.
/// </summary>
internal static string Warning {
get {
return ResourceManager.GetString("Warning", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Water Meter.
/// </summary>

View File

@ -33,21 +33,21 @@
this.filtersGroupBox = new System.Windows.Forms.GroupBox();
this.filtersFlowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel();
this.resultsGroupBox = new System.Windows.Forms.GroupBox();
this.resultsListView = new System.Windows.Forms.ListView();
this.statisticsBtn = new System.Windows.Forms.Button();
this.printQueryResultsBtn = new System.Windows.Forms.Button();
this.exportQueryResultsBtn = new System.Windows.Forms.Button();
this.formatOfResultsBtn = new System.Windows.Forms.Button();
this.clearFiltersBtn = new System.Windows.Forms.Button();
this.settingsBtn = new System.Windows.Forms.Button();
this.saveFiltersBtn = new System.Windows.Forms.Button();
this.loadFiltersBtn = new System.Windows.Forms.Button();
this.saveConfigBtn = new System.Windows.Forms.Button();
this.loadConfigBtn = new System.Windows.Forms.Button();
this.executeQueryBtn = new System.Windows.Forms.Button();
this.addFilterBtn = new System.Windows.Forms.Button();
this.testBenchesGroupBox = new System.Windows.Forms.GroupBox();
this.checkBox3 = new System.Windows.Forms.RadioButton();
this.checkBox2 = new System.Windows.Forms.RadioButton();
this.checkBox1 = new System.Windows.Forms.RadioButton();
this.resultsListView = new System.Windows.Forms.ListView();
((System.ComponentModel.ISupportInitialize)(this.vSplitContainer)).BeginInit();
this.vSplitContainer.Panel1.SuspendLayout();
this.vSplitContainer.Panel2.SuspendLayout();
@ -81,8 +81,8 @@
this.vSplitContainer.Panel2.Controls.Add(this.formatOfResultsBtn);
this.vSplitContainer.Panel2.Controls.Add(this.clearFiltersBtn);
this.vSplitContainer.Panel2.Controls.Add(this.settingsBtn);
this.vSplitContainer.Panel2.Controls.Add(this.saveFiltersBtn);
this.vSplitContainer.Panel2.Controls.Add(this.loadFiltersBtn);
this.vSplitContainer.Panel2.Controls.Add(this.saveConfigBtn);
this.vSplitContainer.Panel2.Controls.Add(this.loadConfigBtn);
this.vSplitContainer.Panel2.Controls.Add(this.executeQueryBtn);
this.vSplitContainer.Panel2.Controls.Add(this.addFilterBtn);
this.vSplitContainer.Panel2.Controls.Add(this.testBenchesGroupBox);
@ -139,9 +139,19 @@
this.resultsGroupBox.TabStop = false;
this.resultsGroupBox.Text = "Query results";
//
// resultsListView
//
this.resultsListView.Dock = System.Windows.Forms.DockStyle.Fill;
this.resultsListView.Location = new System.Drawing.Point(3, 16);
this.resultsListView.Name = "resultsListView";
this.resultsListView.Size = new System.Drawing.Size(834, 409);
this.resultsListView.TabIndex = 0;
this.resultsListView.UseCompatibleStateImageBehavior = false;
this.resultsListView.View = System.Windows.Forms.View.Details;
//
// statisticsBtn
//
this.statisticsBtn.Location = new System.Drawing.Point(8, 521);
this.statisticsBtn.Location = new System.Drawing.Point(8, 562);
this.statisticsBtn.Name = "statisticsBtn";
this.statisticsBtn.Size = new System.Drawing.Size(125, 33);
this.statisticsBtn.TabIndex = 10;
@ -151,7 +161,7 @@
//
// printQueryResultsBtn
//
this.printQueryResultsBtn.Location = new System.Drawing.Point(8, 461);
this.printQueryResultsBtn.Location = new System.Drawing.Point(8, 487);
this.printQueryResultsBtn.Name = "printQueryResultsBtn";
this.printQueryResultsBtn.Size = new System.Drawing.Size(125, 33);
this.printQueryResultsBtn.TabIndex = 9;
@ -161,7 +171,7 @@
//
// exportQueryResultsBtn
//
this.exportQueryResultsBtn.Location = new System.Drawing.Point(8, 424);
this.exportQueryResultsBtn.Location = new System.Drawing.Point(8, 448);
this.exportQueryResultsBtn.Name = "exportQueryResultsBtn";
this.exportQueryResultsBtn.Size = new System.Drawing.Size(125, 33);
this.exportQueryResultsBtn.TabIndex = 8;
@ -171,7 +181,7 @@
//
// formatOfResultsBtn
//
this.formatOfResultsBtn.Location = new System.Drawing.Point(8, 387);
this.formatOfResultsBtn.Location = new System.Drawing.Point(8, 255);
this.formatOfResultsBtn.Name = "formatOfResultsBtn";
this.formatOfResultsBtn.Size = new System.Drawing.Size(125, 33);
this.formatOfResultsBtn.TabIndex = 7;
@ -181,7 +191,7 @@
//
// clearFiltersBtn
//
this.clearFiltersBtn.Location = new System.Drawing.Point(8, 179);
this.clearFiltersBtn.Location = new System.Drawing.Point(8, 177);
this.clearFiltersBtn.Name = "clearFiltersBtn";
this.clearFiltersBtn.Size = new System.Drawing.Size(125, 33);
this.clearFiltersBtn.TabIndex = 2;
@ -199,29 +209,29 @@
this.settingsBtn.UseVisualStyleBackColor = true;
this.settingsBtn.Click += new System.EventHandler(this.settingsBtn_Click);
//
// saveFiltersBtn
// saveConfigBtn
//
this.saveFiltersBtn.Location = new System.Drawing.Point(8, 290);
this.saveFiltersBtn.Name = "saveFiltersBtn";
this.saveFiltersBtn.Size = new System.Drawing.Size(125, 33);
this.saveFiltersBtn.TabIndex = 5;
this.saveFiltersBtn.Text = "Save filters";
this.saveFiltersBtn.UseVisualStyleBackColor = true;
this.saveFiltersBtn.Click += new System.EventHandler(this.saveFiltersBtn_Click);
this.saveConfigBtn.Location = new System.Drawing.Point(8, 294);
this.saveConfigBtn.Name = "saveConfigBtn";
this.saveConfigBtn.Size = new System.Drawing.Size(125, 33);
this.saveConfigBtn.TabIndex = 5;
this.saveConfigBtn.Text = "Save configuration";
this.saveConfigBtn.UseVisualStyleBackColor = true;
this.saveConfigBtn.Click += new System.EventHandler(this.saveConfigBtn_Click);
//
// loadFiltersBtn
// loadConfigBtn
//
this.loadFiltersBtn.Location = new System.Drawing.Point(8, 253);
this.loadFiltersBtn.Name = "loadFiltersBtn";
this.loadFiltersBtn.Size = new System.Drawing.Size(125, 33);
this.loadFiltersBtn.TabIndex = 4;
this.loadFiltersBtn.Text = "Load filters";
this.loadFiltersBtn.UseVisualStyleBackColor = true;
this.loadFiltersBtn.Click += new System.EventHandler(this.loadFiltersBtn_Click);
this.loadConfigBtn.Location = new System.Drawing.Point(8, 333);
this.loadConfigBtn.Name = "loadConfigBtn";
this.loadConfigBtn.Size = new System.Drawing.Size(125, 33);
this.loadConfigBtn.TabIndex = 4;
this.loadConfigBtn.Text = "Load configuration";
this.loadConfigBtn.UseVisualStyleBackColor = true;
this.loadConfigBtn.Click += new System.EventHandler(this.loadConfigBtn_Click);
//
// executeQueryBtn
//
this.executeQueryBtn.Location = new System.Drawing.Point(8, 350);
this.executeQueryBtn.Location = new System.Drawing.Point(8, 409);
this.executeQueryBtn.Name = "executeQueryBtn";
this.executeQueryBtn.Size = new System.Drawing.Size(125, 33);
this.executeQueryBtn.TabIndex = 6;
@ -287,16 +297,6 @@
this.checkBox1.UseVisualStyleBackColor = true;
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
//
// resultsListView
//
this.resultsListView.Dock = System.Windows.Forms.DockStyle.Fill;
this.resultsListView.Location = new System.Drawing.Point(3, 16);
this.resultsListView.Name = "resultsListView";
this.resultsListView.Size = new System.Drawing.Size(834, 409);
this.resultsListView.TabIndex = 0;
this.resultsListView.UseCompatibleStateImageBehavior = false;
this.resultsListView.View = System.Windows.Forms.View.Details;
//
// ResultsBrowserWnd
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -328,8 +328,8 @@
private System.Windows.Forms.SplitContainer hSplitContainer;
private System.Windows.Forms.FlowLayoutPanel filtersFlowLayoutPanel;
private System.Windows.Forms.GroupBox testBenchesGroupBox;
private System.Windows.Forms.Button saveFiltersBtn;
private System.Windows.Forms.Button loadFiltersBtn;
private System.Windows.Forms.Button saveConfigBtn;
private System.Windows.Forms.Button loadConfigBtn;
private System.Windows.Forms.Button executeQueryBtn;
private System.Windows.Forms.Button addFilterBtn;
private System.Windows.Forms.Button settingsBtn;

View File

@ -15,6 +15,9 @@ namespace ResultsBrowser
{
public partial class ResultsBrowserWnd : Form
{
const string OpenFileDlg_SaveFileDlg_Filter = "{0} (*.qry)|*.qry|{1} (*.*)|*.*";
IList<Filters.IFilter> filters; /// Filters and the UI of filters
FiltersConfig filtersConfig; /// Serializable configuration of filters and displayed results
@ -29,7 +32,17 @@ namespace ResultsBrowser
private void ResultsBrowserWnd_Load(object sender, EventArgs e)
{
Text = string.Format("{0} ver.{1}", Strings.Results_Browser, Program.Version);
ResultsBrowser.LocalSettings ls = Program.LocalSettings;
Width = (ls.MainWndWidth > 0) ? ls.MainWndWidth : 1000;
Height = (ls.MainWndHeight > 0) ? ls.MainWndHeight : 750;
Left = (ls.MainWndLeft != 0) ? ls.MainWndLeft : 50;
Top = (ls.MainWndTop != 0) ? ls.MainWndTop : 50;
hSplitContainer.SplitterDistance = (ls.SplitterDistance != 0) ? ls.SplitterDistance : 280;
Localize();
RedrawTestBenches();
checkBox1.Checked = Program.LocalSettings.Bench1Selected;
@ -50,15 +63,14 @@ namespace ResultsBrowser
void Localize()
{
Text = Strings.Results_Browser; /// or Statistics
filtersGroupBox.Text = Strings.Filters;
resultsGroupBox.Text = Strings.Query_results;
settingsBtn.Text = Strings.Settings;
testBenchesGroupBox.Text = Strings.Test_benches;
clearFiltersBtn.Text = Strings.Clear_filters;
addFilterBtn.Text = Strings.Add_filter;
loadFiltersBtn.Text = Strings.Load_filters;
saveFiltersBtn.Text = Strings.Save_filters;
loadConfigBtn.Text = Strings.Load_filters;
saveConfigBtn.Text = Strings.Save_filters;
executeQueryBtn.Text = Strings.Execute_query;
formatOfResultsBtn.Text = Strings.Format_of_results;
exportQueryResultsBtn.Text = Strings.Export_query_results;
@ -103,7 +115,7 @@ namespace ResultsBrowser
}
}
private void loadFiltersBtn_Click(object sender, EventArgs e)
private void loadConfigBtn_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = string.Format("{0} (*.qry)|*.qry|{1} (*.*)|*.*", Strings.Query_files, Strings.All_files);
@ -127,7 +139,7 @@ namespace ResultsBrowser
}
}
private void saveFiltersBtn_Click(object sender, EventArgs e)
private void saveConfigBtn_Click(object sender, EventArgs e)
{
if (filtersConfig.UpdateFromFilters(filters)) /// filtersConfig members related to filters
{
@ -143,7 +155,7 @@ namespace ResultsBrowser
/// Save the file
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = string.Format("{0} (*.qry)|*.qry|{1} (*.*)|*.*", Strings.Query_files, Strings.All_files);
dlg.Filter = string.Format(OpenFileDlg_SaveFileDlg_Filter, Strings.Query_files, Strings.All_files);
if (dlg.ShowDialog() == DialogResult.OK)
{
filtersConfig.Save(dlg.FileName);

View File

@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.9.335.1")]
[assembly: AssemblyFileVersion("2.9.335.1")]
[assembly: AssemblyVersion("2.9.336.1")]
[assembly: AssemblyFileVersion("2.9.336.1")]