136 lines
4.2 KiB
C#
136 lines
4.2 KiB
C#
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]
|
|
public int BenchesCount { get { return testBenches != null ? testBenches.GetLength(0) : 0; } }
|
|
|
|
/// <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;
|
|
|
|
public Forms.ResultsConfig.Meters ResultsConfigMeters;
|
|
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;
|
|
testBenches = new DatabaseSettings[ls.testBenches.Length];
|
|
for (int i = 0; i < testBenches.Length; i++) testBenches[i] = ls.testBenches[i];
|
|
LastBenchName = ls.LastBenchName;
|
|
LastProcedureName = ls.LastProcedureName;
|
|
RightPaneHorizSplitterDistance = ls.RightPaneHorizSplitterDistance;
|
|
ResultsConfigMeters = ls.ResultsConfigMeters;
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|