ResultsBrowser changes (does not run correctly).

This commit is contained in:
Milan Hanajik 2015-12-10 22:17:47 +01:00
parent d9e7efa15a
commit 89ecf478ba
9 changed files with 4508 additions and 470 deletions

View File

@ -73,7 +73,6 @@ namespace ResultsBrowser
// editButton
//
resources.ApplyResources(this.editButton, "editButton");
this.editButton.ImageKey = global::TBF.Resources.Strings.String1;
this.editButton.Name = "editButton";
this.editButton.UseVisualStyleBackColor = true;
this.editButton.Click += new System.EventHandler(this.editButton_Click);
@ -81,7 +80,6 @@ namespace ResultsBrowser
// addButton
//
resources.ApplyResources(this.addButton, "addButton");
this.addButton.ImageKey = global::TBF.Resources.Strings.String1;
this.addButton.Name = "addButton";
this.addButton.UseVisualStyleBackColor = true;
this.addButton.Click += new System.EventHandler(this.addButton_Click);
@ -89,7 +87,6 @@ namespace ResultsBrowser
// removeButton
//
resources.ApplyResources(this.removeButton, "removeButton");
this.removeButton.ImageKey = global::TBF.Resources.Strings.String1;
this.removeButton.Name = "removeButton";
this.removeButton.UseVisualStyleBackColor = true;
this.removeButton.Click += new System.EventHandler(this.removeButton_Click);
@ -97,7 +94,6 @@ namespace ResultsBrowser
// copyButton
//
resources.ApplyResources(this.copyButton, "copyButton");
this.copyButton.ImageKey = global::TBF.Resources.Strings.String1;
this.copyButton.Name = "copyButton";
this.copyButton.UseVisualStyleBackColor = true;
this.copyButton.Click += new System.EventHandler(this.copyButton_Click);

View File

@ -1,3 +1,6 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Windows.Forms;
@ -18,8 +21,9 @@ namespace ResultsBrowser
/// </summary>
public BenchesDlg()
{
localSettings = new LocalSettings();
localSettings.Assign(Program.LocalSettings);
Program.LocalSettings.Save();
localSettings = LocalSettings.Load(Program.LocalSettingsFileName);
if (localSettings == null) throw new Exception("Cannot load local settings");
InitializeComponent();
RedrawTestBenchesListBox();
@ -28,12 +32,12 @@ namespace ResultsBrowser
void RedrawTestBenchesListBox()
{
testBenchesListBox.Items.Clear();
if (localSettings.testBenches != null)
if (localSettings.TestBenches != null)
{
int nrBenches = localSettings.testBenches.GetLength(0);
int nrBenches = localSettings.TestBenches.GetLength(0);
for (int i = 0; i < nrBenches; i++)
{
testBenchesListBox.Items.Add(localSettings.testBenches[i].BenchName);
testBenchesListBox.Items.Add(localSettings.TestBenches[i].BenchName);
}
}
}
@ -45,28 +49,28 @@ namespace ResultsBrowser
/// <param name="e">Not used</param>
private void addButton_Click(object sender, EventArgs e)
{
DatabaseSettings bench = new DatabaseSettings();
DatabaseSettingsDlg dlg = new DatabaseSettingsDlg(bench);
Config.DatabaseSettings bench = new Config.DatabaseSettings();
Config.DatabaseSettingsDlg dlg = new Config.DatabaseSettingsDlg(bench);
DialogResult dr = dlg.ShowDialog();
if (dr == DialogResult.OK)
{
int nrBenches =
(localSettings.testBenches == null) ? 0 : localSettings.testBenches.GetLength(0);
(localSettings.TestBenches == null) ? 0 : localSettings.TestBenches.GetLength(0);
if (nrBenches == 0)
{
localSettings.testBenches = new DatabaseSettings[1];
localSettings.testBenches[0] = bench;
localSettings.TestBenches = new Config.DatabaseSettings[1];
localSettings.TestBenches[0] = bench;
}
else
{
DatabaseSettings[] newTestBenches = new DatabaseSettings[nrBenches + 1];
Config.DatabaseSettings[] newTestBenches = new Config.DatabaseSettings[nrBenches + 1];
for (int i = 0; i < nrBenches; i++)
{
newTestBenches[i] = localSettings.testBenches[i];
newTestBenches[i] = localSettings.TestBenches[i];
}
newTestBenches[nrBenches] = bench;
localSettings.testBenches = newTestBenches;
localSettings.TestBenches = newTestBenches;
}
testBenchesListBox.Items.Add(bench.BenchName);
@ -83,23 +87,23 @@ namespace ResultsBrowser
{
if (testBenchesListBox.SelectedIndex >= 0)
{
DatabaseSettings ori = localSettings.testBenches[testBenchesListBox.SelectedIndex];
DatabaseSettings bench = (DatabaseSettings)ori.Clone();
Config.DatabaseSettings ori = localSettings.TestBenches[testBenchesListBox.SelectedIndex];
Config.DatabaseSettings bench = (Config.DatabaseSettings)ori.Clone();
DatabaseSettingsDlg dlg = new DatabaseSettingsDlg(bench);
Config.DatabaseSettingsDlg dlg = new Config.DatabaseSettingsDlg(bench);
DialogResult dr = dlg.ShowDialog();
if (dr == DialogResult.OK)
{
int nrBenches =
(localSettings.testBenches == null) ? 0 : localSettings.testBenches.GetLength(0);
(localSettings.TestBenches == null) ? 0 : localSettings.TestBenches.GetLength(0);
DatabaseSettings[] newTestBenches = new DatabaseSettings[nrBenches + 1];
Config.DatabaseSettings[] newTestBenches = new Config.DatabaseSettings[nrBenches + 1];
for (int i = 0; i < nrBenches; i++)
{
newTestBenches[i] = localSettings.testBenches[i];
newTestBenches[i] = localSettings.TestBenches[i];
}
newTestBenches[nrBenches] = bench;
localSettings.testBenches = newTestBenches;
localSettings.TestBenches = newTestBenches;
testBenchesListBox.Items.Add(bench.BenchName);
}
@ -115,13 +119,13 @@ namespace ResultsBrowser
{
if (testBenchesListBox.SelectedIndex >= 0)
{
DatabaseSettingsDlg dlg = new DatabaseSettingsDlg(localSettings.testBenches[testBenchesListBox.SelectedIndex]);
Config.DatabaseSettingsDlg dlg = new Config.DatabaseSettingsDlg(localSettings.TestBenches[testBenchesListBox.SelectedIndex]);
DialogResult dr = dlg.ShowDialog();
if (dr == DialogResult.OK)
{
// Update the item name
testBenchesListBox.Items[testBenchesListBox.SelectedIndex] =
localSettings.testBenches[testBenchesListBox.SelectedIndex].BenchName;
localSettings.TestBenches[testBenchesListBox.SelectedIndex].BenchName;
}
}
}
@ -137,24 +141,24 @@ namespace ResultsBrowser
if (selectedIx >= 0)
{
int nrBenches =
(localSettings.testBenches == null) ? 0 : localSettings.testBenches.GetLength(0);
(localSettings.TestBenches == null) ? 0 : localSettings.TestBenches.GetLength(0);
if (nrBenches == 1)
{
localSettings.testBenches = null;
localSettings.TestBenches = null;
}
else
{
DatabaseSettings[] newTestBenches = new DatabaseSettings[nrBenches - 1];
Config.DatabaseSettings[] newTestBenches = new Config.DatabaseSettings[nrBenches - 1];
for (int i = 0; i < selectedIx; i++)
{
newTestBenches[i] = localSettings.testBenches[i];
newTestBenches[i] = localSettings.TestBenches[i];
}
for (int i = selectedIx + 1; i < nrBenches; i++)
{
newTestBenches[i - 1] = localSettings.testBenches[i];
newTestBenches[i - 1] = localSettings.TestBenches[i];
}
localSettings.testBenches = newTestBenches;
localSettings.TestBenches = newTestBenches;
}
RedrawTestBenchesListBox();
@ -168,7 +172,8 @@ namespace ResultsBrowser
/// <param name="e">Not used</param>
private void okButton_Click(object sender, EventArgs e)
{
Program.LocalSettings.Assign(localSettings); // Update Program.localSettings
localSettings.Save();
Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsFileName);
DialogResult = DialogResult.OK;
Close();
return;

View File

@ -1,148 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="okButton.Text" xml:space="preserve">
<value>&amp;OK</value>
</data>
<data name="cancelButton.Text" xml:space="preserve">
<value>&amp;Abbrechen</value>
</data>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="label1.Size" type="System.Drawing.Size, System.Drawing">
<value>58, 13</value>
</data>
<data name="label1.Text" xml:space="preserve">
<value>Prüfstände</value>
</data>
<data name="editButton.Text" xml:space="preserve">
<value>&amp;Bearbeiten...</value>
</data>
<data name="addButton.Text" xml:space="preserve">
<value>&amp;Neu...</value>
</data>
<data name="removeButton.Text" xml:space="preserve">
<value>&amp;Löschen</value>
</data>
<data name="copyButton.Text" xml:space="preserve">
<value>&amp;Kopieren</value>
</data>
<data name="$this.Text" xml:space="preserve">
<value>Datenbank Einstellungen</value>
</data>
</root>

View File

@ -18,7 +18,7 @@ namespace ResultsBrowser.Forms
// Private fields
string user;
string password;
Grp.GID requiredGroupMembership = Grp.GID.Invalid;
Config.Grp.GID requiredGroupMembership = Config.Grp.GID.Invalid;
bool noDatabase;
/// <summary>
@ -51,7 +51,7 @@ namespace ResultsBrowser.Forms
/// <summary>
/// Constructor when a specific group membership is required.
/// </summary>
public LoginDlg(Grp.GID requiredGroupMembership)
public LoginDlg(Config.Grp.GID requiredGroupMembership)
: this()
{
this.requiredGroupMembership = requiredGroupMembership;
@ -60,7 +60,7 @@ namespace ResultsBrowser.Forms
/// <summary>
/// Constructor with a predefined user when a specific group membership is required.
/// </summary>
public LoginDlg(string predefinedUser, Grp.GID requiredGroupMembership)
public LoginDlg(string predefinedUser, Config.Grp.GID requiredGroupMembership)
: this()
{
user = predefinedUser;
@ -95,7 +95,7 @@ namespace ResultsBrowser.Forms
Entities.User loadedUser = Entities.User.LoadUserByName(user);
if (loadedUser != null)
{
if (requiredGroupMembership == Grp.GID.Invalid)
if (requiredGroupMembership == Config.Grp.GID.Invalid)
{
authorized = loadedUser.Authorize(user, password);
}
@ -124,7 +124,7 @@ namespace ResultsBrowser.Forms
/// </summary>
private void cancelButton_Click(object sender, EventArgs e)
{
if (requiredGroupMembership == Grp.GID.Invalid)
if (requiredGroupMembership == Config.Grp.GID.Invalid)
{
Entities.User.Unauthorize();
}

View File

@ -12,38 +12,22 @@ namespace ResultsBrowser
/// Edit->Preferences ... PreferencesDlg ... S1.1(language, etc. local settings), and
/// Edit->Advanced settings ... AdvancedSettingsDlg ... S1.2(spec. where bench settings are stored)
/// </summary>
[XmlRootAttribute("TestBenchFramework")]
[XmlRootAttribute("ResultsBrowser")]
public class LocalSettings
{
/// <summary>
/// Available languages.
/// Method ToString should give a supported culture info string:
/// ("en","de","fr","es","it","cn", etc.).
/// </summary>
public enum Languages
{
en,
de,
sk,
Count,
}
/// <summary>
/// User interface language ("en","de","fr","es","it","cn", etc.).
/// </summary>
/// User interface language (used as CultureInfo(..) constructor argument).
/// </summary>
public string Language = "en";
/// <summary>
/// Names and database settings of test benches.
/// </summary>
[XmlArrayAttribute("TestBenches")]
public Config.DatabaseSettings[] testBenches;
public Config.DatabaseSettings[] TestBenches;
[XmlIgnore]
public Config.DatabaseSettings[] TestBenches { get { return testBenches; } }
[XmlIgnore]
public int BenchesCount { get { return (testBenches != null) ? testBenches.GetLength(0) : 0; } }
public int BenchesCount { get { return (TestBenches != null) ? TestBenches.GetLength(0) : 0; } }
/// <summary>
/// Currently selected bench name (local or remote) or null (= no selection done).
@ -51,16 +35,6 @@ namespace ResultsBrowser
[XmlElementAttribute("LastBench")]
public string LastBenchName;
/// <summary>
/// Currently selected procedure name or null (= no selection done yet).
/// </summary>
[XmlElementAttribute("LastProcedure")]
public string LastProcedureName;
public int BatchNr;
public int RightPaneHorizSplitterDistance;
/// MainWnd
public int MainWndLeft;
public int MainWndTop;
@ -68,226 +42,29 @@ namespace ResultsBrowser
public int MainWndHeight;
public bool ManiWndMaximized;
/// Components
public int ComponentsDlgLeft;
public int ComponentsDlgTop;
public int ComponentsDlgWidth;
public int ComponentsDlgHeight;
/// Paths
public int PathsDlgLeft;
public int PathsDlgTop;
public int PathsDlgWidth;
public int PathsDlgHeight;
[XmlArrayAttribute("FeedingColumnWidths")]
public int[] FeedingColumnWidths;
[XmlIgnore]
public int FeedingColumnCount { get { return (FeedingColumnWidths != null) ? FeedingColumnWidths.Length : 0; } }
[XmlArrayAttribute("BenchColumnWidths")]
public int[] BenchColumnWidths;
[XmlIgnore]
public int BenchColumnCount { get { return (BenchColumnWidths != null) ? BenchColumnWidths.Length : 0; } }
[XmlArrayAttribute("OutputColumnWidths")]
public int[] OutputColumnWidths;
[XmlIgnore]
public int OutputColumnCount { get { return (OutputColumnWidths != null) ? OutputColumnWidths.Length : 0; } }
[XmlArrayAttribute("MetersColumnWidths")]
public int[] MetersColumnWidths;
[XmlIgnore]
public int MetersColumnCount { get { return (MetersColumnWidths != null) ? MetersColumnWidths.Length : 0; } }
/// Transitions
public int TransitionsDlgLeft;
public int TransitionsDlgTop;
public int TransitionsDlgWidth;
public int TransitionsDlgHeight;
[XmlArrayAttribute("TransitionsColumnWidths")]
public int[] TransitionsColumnWidths;
[XmlIgnore]
public int TransitionsColumnCount { get { return (TransitionsColumnWidths != null) ? TransitionsColumnWidths.Length : 0; } }
/// Metrology
public int MetrologyDlgLeft;
public int MetrologyDlgTop;
public int MetrologyDlgWidth;
public int MetrologyDlgHeight;
/// Procedures
public int ProceduresDlgLeft;
public int ProceduresDlgTop;
public int ProceduresDlgWidth;
public int ProceduresDlgHeight;
/// OneProcedure
public int OneProcedureDlgLeft;
public int OneProcedureDlgTop;
public int OneProcedureDlgWidth;
public int OneProcedureDlgHeight;
/// Configuration of results
public Config.Entities.MetersArrangement ResultsConfigMeters;
public Config.Entities.TestsArrangement ResultsConfigTests;
public string[] RsltItems_Screen_SingleWM;
public string[] RsltItems_Screen_CombinedWM;
public string[] RsltItems_Printer_SingleWM;
public string[] RsltItems_Printer_CombinedWM;
public string[] RsltItems_Disk_SingleWM;
public string[] RsltItems_Disk_CombinedWM;
[XmlArrayAttribute("RsltsSingleClmnWdths")]
public int[] RsltsSingleClmnWdths;
[XmlIgnore]
public int RsltsSingleClmnCount { get { return (RsltsSingleClmnWdths != null) ? RsltsSingleClmnWdths.Length : 0; } }
[XmlArrayAttribute("RsltsCombinedClmnWdths")]
public int[] RsltsCombinedClmnWdths;
[XmlIgnore]
public int RsltsCombinedClmnCount { get { return (RsltsCombinedClmnWdths != null) ? RsltsCombinedClmnWdths.Length : 0; } }
/// <summary>
/// Copy public fields from a LocalSettings object to this object.
/// </summary>
/// <param name="ls">Origin</param>
public void Assign(LocalSettings ls)
{
if (ls != null)
{
Language = ls.Language;
testBenches = new DatabaseSettings[ls.BenchesCount];
for (int i = 0; i < BenchesCount; i++)
testBenches[i] = ls.testBenches[i];
LastBenchName = ls.LastBenchName;
LastProcedureName = ls.LastProcedureName;
BatchNr = ls.BatchNr;
MainWndLeft = ls.MainWndLeft;
MainWndTop = ls.MainWndTop;
MainWndWidth = ls.MainWndWidth;
MainWndHeight = ls.MainWndHeight;
ManiWndMaximized = ls.ManiWndMaximized;
RightPaneHorizSplitterDistance = ls.RightPaneHorizSplitterDistance;
ComponentsDlgLeft = ls.ComponentsDlgLeft;
ComponentsDlgTop = ls.ComponentsDlgTop;
ComponentsDlgWidth = ls.ComponentsDlgWidth;
ComponentsDlgHeight = ls.ComponentsDlgHeight;
PathsDlgLeft = ls.PathsDlgLeft;
PathsDlgTop = ls.PathsDlgTop;
PathsDlgWidth = ls.PathsDlgWidth;
PathsDlgHeight = ls.PathsDlgHeight;
FeedingColumnWidths = new int[ls.FeedingColumnCount];
for (int i = 0; i < FeedingColumnCount; i++)
FeedingColumnWidths[i] = ls.FeedingColumnWidths[i];
BenchColumnWidths = new int[ls.BenchColumnCount];
for (int i = 0; i < BenchColumnCount; i++)
BenchColumnWidths[i] = ls.BenchColumnWidths[i];
OutputColumnWidths = new int[ls.OutputColumnCount];
for (int i = 0; i < OutputColumnCount; i++)
OutputColumnWidths[i] = ls.OutputColumnWidths[i];
MetersColumnWidths = new int[ls.MetersColumnCount];
for (int i = 0; i < MetersColumnCount; i++)
MetersColumnWidths[i] = ls.MetersColumnWidths[i];
TransitionsDlgLeft = ls.TransitionsDlgLeft;
TransitionsDlgTop = ls.TransitionsDlgTop;
TransitionsDlgWidth = ls.TransitionsDlgWidth;
TransitionsDlgHeight = ls.TransitionsDlgHeight;
TransitionsColumnWidths = new int[ls.TransitionsColumnCount];
for (int i = 0; i < TransitionsColumnCount; i++)
TransitionsColumnWidths[i] = ls.TransitionsColumnWidths[i];
MetrologyDlgLeft = ls.MetrologyDlgLeft;
MetrologyDlgTop = ls.MetrologyDlgTop;
MetrologyDlgWidth = ls.MetrologyDlgWidth;
MetrologyDlgHeight = ls.MetrologyDlgHeight;
ProceduresDlgLeft = ls.ProceduresDlgLeft;
ProceduresDlgTop = ls.ProceduresDlgTop;
ProceduresDlgWidth = ls.ProceduresDlgWidth;
ProceduresDlgHeight = ls.ProceduresDlgHeight;
OneProcedureDlgLeft = ls.OneProcedureDlgLeft;
OneProcedureDlgTop = ls.OneProcedureDlgTop;
OneProcedureDlgWidth = ls.OneProcedureDlgWidth;
OneProcedureDlgHeight = ls.OneProcedureDlgHeight;
ResultsConfigMeters = ls.ResultsConfigMeters;
ResultsConfigTests = ls.ResultsConfigTests;
int count = (ls.RsltItems_Screen_SingleWM != null) ? ls.RsltItems_Screen_SingleWM.Length : 0;
RsltItems_Screen_SingleWM = new string[count];
for (int i = 0; i < count; i++) RsltItems_Screen_SingleWM[i] = ls.RsltItems_Screen_SingleWM[i];
count = (ls.RsltItems_Screen_CombinedWM != null) ? ls.RsltItems_Screen_CombinedWM.Length : 0;
RsltItems_Screen_CombinedWM = new string[count];
for (int i = 0; i < count; i++) RsltItems_Screen_CombinedWM[i] = ls.RsltItems_Screen_CombinedWM[i];
count = (ls.RsltItems_Printer_SingleWM != null) ? ls.RsltItems_Printer_SingleWM.Length : 0;
RsltItems_Printer_SingleWM = new string[count];
for (int i = 0; i < count; i++) RsltItems_Printer_SingleWM[i] = ls.RsltItems_Printer_SingleWM[i];
count = (ls.RsltItems_Printer_CombinedWM != null) ? ls.RsltItems_Printer_CombinedWM.Length : 0;
RsltItems_Printer_CombinedWM = new string[count];
for (int i = 0; i < count; i++) RsltItems_Printer_CombinedWM[i] = ls.RsltItems_Printer_CombinedWM[i];
count = (ls.RsltItems_Disk_SingleWM != null) ? ls.RsltItems_Disk_SingleWM.Length : 0;
RsltItems_Disk_SingleWM = new string[count];
for (int i = 0; i < count; i++) RsltItems_Disk_SingleWM[i] = ls.RsltItems_Disk_SingleWM[i];
count = (ls.RsltItems_Disk_CombinedWM != null) ? ls.RsltItems_Disk_CombinedWM.Length : 0;
RsltItems_Disk_CombinedWM = new string[count];
for (int i = 0; i < count; i++) RsltItems_Disk_CombinedWM[i] = ls.RsltItems_Disk_CombinedWM[i];
RsltsSingleClmnWdths = new int[ls.RsltsSingleClmnCount];
for (int i = 0; i < RsltsSingleClmnCount; i++)
RsltsSingleClmnWdths[i] = ls.RsltsSingleClmnWdths[i];
RsltsCombinedClmnWdths = new int[ls.RsltsCombinedClmnCount];
for (int i = 0; i < RsltsCombinedClmnCount; i++)
RsltsCombinedClmnWdths[i] = ls.RsltsCombinedClmnWdths[i];
}
}
[XmlIgnore]
public readonly bool AlwaysAskPasswdWhenUnlocking;
[XmlIgnore]
public readonly bool RestoreUserWhenLeavingDialog;
public LocalSettings()
{
AlwaysAskPasswdWhenUnlocking = false;
RestoreUserWhenLeavingDialog = true;
}
/// <summary>
/// Load public fields of this class from the XML file.
/// </summary>
public void Load()
public static LocalSettings Load(string fileName)
{
try
{
using (TextReader reader = new StreamReader(Program.LocalSettingsFileName))
{
using (TextReader reader = new StreamReader(fileName))
{
LocalSettings ls = (new XmlSerializer(typeof(LocalSettings))).Deserialize(reader) as LocalSettings;
// Copy the settings just in case De-serialize() completes OK
this.Assign(ls);
return ls;
}
}
catch (Exception e)
{
string msg = e.Message;
return null;
}
}
@ -308,5 +85,52 @@ namespace ResultsBrowser
string msg = e.Message;
}
}
}
/// <summary>
/// Updates history stored in a string array by a new latest string.
/// </summary>
/// <param name="lastStrValue">Lste entered string</param>
/// <returns>true = updated and saved</returns>
public bool UpdateHistory(string lastStrValue, ref string[] history, int maxHistoryLen = 10)
{
if (string.IsNullOrEmpty(lastStrValue)) return false;
int currentHistoryCount = (history != null) ? history.Length : 0;
int match = -1;
for (int i = 0; i < currentHistoryCount; i++)
{
if (history[i] == lastStrValue)
{
match = i;
break;
}
}
if (match >= 0 || currentHistoryCount >= maxHistoryLen)
{
/// History does not have to be (because of a match) or should not be extended (because of the lenght)
if (match < 0) match = currentHistoryCount - 1;
for (int j = match; j > 0; j--)
{
history[j] = history[j - 1];
}
history[0] = lastStrValue;
}
else
{
/// History wiil be extended, new item inserted at the beginning
string[] newHistory = new string[currentHistoryCount + 1];
newHistory[0] = lastStrValue;
for (int j = 1; j <= currentHistoryCount; j++)
{
newHistory[j] = history[j - 1];
}
history = newHistory;
}
Save();
return true;
}
}
}

View File

@ -20,22 +20,12 @@ namespace ResultsBrowser
const string log4netConfigFName = "log4netConfig.xml";
/// Local settings
public static LocalSettings LocalSettings = new LocalSettings();
public const string LocalSettingsFileName = "config.xml";
public static LocalSettings LocalSettings;
public const string LocalSettingsFileName = "ResultsBrowser.xml";
public const string LocalSettingsBackupName = "ResultsBrowser.backup.xml";
public static System.Globalization.CultureInfo AltCulture;
/// <summary>
/// Selected procedure data
/// - before the main program window is open, objects referenced by this variable
/// are loaded from the database.
/// - user interface displays data stored in objects referenced by this variable.
/// When user modifies procedure settings and confirms changes (choses to save them),
/// data referenced by this variable are updated and written to the database.
/// - when users starts a test procedure, state machine creates its own copy
/// of procedure data and uses them for the test. Changes of 'SelectedProcedure'
/// done during the test do not have any influence on the currently running test.
/// </summary>
public static Config.Entities.Procedure SelectedProcedure = null;
/// <summary>
/// Main window object.
@ -89,11 +79,44 @@ namespace ResultsBrowser
log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(locAppDataDir + log4netConfigFName));
log.Info("Entering application.");
/// Load the local settings
if (Program.LocalSettings == null) return; /// Fatal error
LocalSettings.Load();
///
/// Load the local settings
///
Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsFileName);
if (Program.LocalSettings == null || Program.LocalSettings.TestBenches == null)
{
/// Loading local seetings from regular config file failed. Use the backup
Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsBackupName);
if (Program.LocalSettings == null || Program.LocalSettings.TestBenches == null)
{
return; /// Fatal error
}
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);
}
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(LocalSettings.Language);
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");
}
//AltCulture = null;
AltCulture = new System.Globalization.CultureInfo("SK");
/// This belongs to Application.Run(new MainWnd()) ...
/// and should be executed before opening 'loginDlg'
@ -101,7 +124,7 @@ namespace ResultsBrowser
Application.SetCompatibleTextRenderingDefault(false);
/// Ensure that there is at least one bench in the configuration
while (Program.LocalSettings.testBenches.GetLength(0) == 0)
while (Program.LocalSettings.BenchesCount == 0)
{
log.Warn("No test benches in the local configuration -> display an appropriate dialog.");
@ -114,7 +137,8 @@ namespace ResultsBrowser
}
log.Warn("Loading the local settings again.");
LocalSettings.Load();
Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsFileName);
if (Program.LocalSettings == null) return; /// Fatal error
}
/// User login
@ -200,7 +224,8 @@ namespace ResultsBrowser
{
return; /// Exit program
}
LocalSettings.Load();
Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsFileName);
if (Program.LocalSettings == null) return; /// Fatal error
break; /// Retry the loop
}
}
@ -210,37 +235,47 @@ namespace ResultsBrowser
} //do
while (retryLogin);
///
/// Load the last procedure or create a new, default one
///
if (LocalSettings.LastProcedureName != null)
{
IList<Procedure> listOfProcedures = Config.FluentCommon.CreateSession(Config.Database.Procedures)
.CreateQuery("FROM Procedure WHERE ProcedureState = 'Active' AND Name = :procName")
.SetParameter("procName", LocalSettings.LastProcedureName)
.List<Procedure>();
if (listOfProcedures.Count == 1)
{
log.InfoFormat("Pre-selecting the procedure {0}", LocalSettings.LastProcedureName);
SelectedProcedure = listOfProcedures[0];
}
}
/// Open the main application window
log.Info("Creating the main window");
MainWnd = new MainWnd();
log.Info("Opening the main window");
Application.Run(MainWnd);
/// Save local settings
log.Info("The main window was closed, saving the local parameters");
LocalSettings.Save();
try
{
/// Open the main application window
log.Info("Creating the main window");
MainWnd = new MainWnd();
log.Info("Opening the main window");
Application.Run(MainWnd);
log.Info("The main window was closed");
}
catch (Exception e)
{
LogException(log, "Exception in Application.Run(MainWnd)", e);
}
finally
{
/// Save local settings
LocalSettings.Save();
}
/// Close Fluent NHibernate
/// Todo
log.Info("Exiting application.");
}
}
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("--------------------------------------");
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -33,6 +33,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject>ResultsBrowser.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<HintPath>..\packages\log4net.2.0.2\lib\net40-full\log4net.dll</HintPath>
@ -82,9 +85,7 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="BenchesDlg.de.resx">
<DependentUpon>BenchesDlg.cs</DependentUpon>
</EmbeddedResource>
<Compile Include="Resources\Strings.Designer.cs" />
<EmbeddedResource Include="BenchesDlg.resx">
<DependentUpon>BenchesDlg.cs</DependentUpon>
</EmbeddedResource>
@ -115,6 +116,7 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<EmbeddedResource Include="Resources\Strings.resx" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>