2014-07-28 07:54:35 +00:00
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
|
|
|
|
|
namespace TBF
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class to be serialized to an XML file...
|
|
|
|
|
/// Public members are local settings.
|
|
|
|
|
/// These settings are modified by dialogs invoked by menu items
|
|
|
|
|
/// 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")]
|
|
|
|
|
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>
|
|
|
|
|
public string Language = "en";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Names and database settings of test benches.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[XmlArrayAttribute("TestBenches")]
|
|
|
|
|
public DatabaseSettings[] testBenches;
|
|
|
|
|
|
|
|
|
|
[XmlIgnore]
|
|
|
|
|
public DatabaseSettings[] TestBenches { get { return testBenches; } }
|
|
|
|
|
|
|
|
|
|
[XmlIgnore]
|
2014-09-03 11:42:46 +00:00
|
|
|
public int BenchesCount { get { return (testBenches != null) ? testBenches.GetLength(0) : 0; } }
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Currently selected bench name (local or remote) or null (= no selection done).
|
|
|
|
|
/// </summary>
|
|
|
|
|
[XmlElementAttribute("LastBench")]
|
|
|
|
|
public string LastBenchName;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Currently selected procedure name or null (= no selection done yet).
|
|
|
|
|
/// </summary>
|
|
|
|
|
[XmlElementAttribute("LastProcedure")]
|
|
|
|
|
public string LastProcedureName;
|
|
|
|
|
|
|
|
|
|
public int RightPaneHorizSplitterDistance;
|
|
|
|
|
|
2014-09-03 11:42:46 +00:00
|
|
|
[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; } }
|
|
|
|
|
|
|
|
|
|
public Forms.ResultsConfig.Meters ResultsConfigMeters;
|
2014-07-28 07:54:35 +00:00
|
|
|
public Forms.ResultsConfig.TestsAre ResultsConfigTests;
|
|
|
|
|
|
|
|
|
|
/// <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;
|
2014-09-03 11:42:46 +00:00
|
|
|
testBenches = new DatabaseSettings[ls.BenchesCount];
|
|
|
|
|
for (int i = 0; i < BenchesCount; i++) testBenches[i] = ls.testBenches[i];
|
2014-07-28 07:54:35 +00:00
|
|
|
LastBenchName = ls.LastBenchName;
|
|
|
|
|
LastProcedureName = ls.LastProcedureName;
|
|
|
|
|
RightPaneHorizSplitterDistance = ls.RightPaneHorizSplitterDistance;
|
2014-09-03 11:42:46 +00:00
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
|
|
ResultsConfigMeters = ls.ResultsConfigMeters;
|
2014-07-28 07:54:35 +00:00
|
|
|
ResultsConfigTests = ls.ResultsConfigTests;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (TextReader reader = new StreamReader(Program.LocalSettingsFileName))
|
|
|
|
|
{
|
|
|
|
|
LocalSettings ls = (new XmlSerializer(typeof(LocalSettings))).Deserialize(reader) as LocalSettings;
|
|
|
|
|
// Copy the settings just in case De-serialize() completes OK
|
|
|
|
|
this.Assign(ls);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
string msg = e.Message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Save public fields of this class to the XML file.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Save()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (TextWriter writer = new StreamWriter(Program.LocalSettingsFileName))
|
|
|
|
|
{
|
|
|
|
|
(new XmlSerializer(typeof(LocalSettings))).Serialize(writer, this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
string msg = e.Message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|