/// /// Copyright (c) 2018 Sensus Slovensko a.s. /// using System; using System.IO; using System.Text; using System.Xml.Serialization; namespace Statistics { /// /// 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) /// [XmlRootAttribute("Statistics")] public class LocalSettings { public const int FlowsCount = 5; /// /// User interface language (used as CultureInfo(..) constructor argument). /// public string Language; /// /// Names of test benches /// public string[] BenchNames; /// public string GetBenchName(int i) { return ((BenchNames != null) && (i >= 0) && (i < BenchNames.Length)) ? BenchNames[i] : string.Empty; } /// /// Database settings of servers /// public string[] ConnectionStrings; /// public string GetConnectionString(int i) { return ((ConnectionStrings != null) && (i >= 0) && (i < ConnectionStrings.Length)) ? ConnectionStrings[i] : string.Empty; } /// /// MID-s /// public string[] MidNames; /// /// Flow settings /// public bool[] FlowEnabledI1; public bool[] FlowEnabledI2; public bool[] FlowEnabledI3; public bool[] FlowEnabledI4; public bool[] FlowEnabledI5; public bool[] FlowEnabledI6; public bool[] FlowEnabledI7; /// /// Get flow enabled info /// /// 1-based MID id /// 0-based flow id /// true = enabled public bool GetFlowEnabled(int midId, int i) { switch (midId) { case 1: return ((FlowEnabledI1 != null) && (i >= 0) && (i < FlowEnabledI1.Length)) ? FlowEnabledI1[i] : false; case 2: return ((FlowEnabledI2 != null) && (i >= 0) && (i < FlowEnabledI2.Length)) ? FlowEnabledI2[i] : false; case 3: return ((FlowEnabledI3 != null) && (i >= 0) && (i < FlowEnabledI3.Length)) ? FlowEnabledI3[i] : false; case 4: return ((FlowEnabledI4 != null) && (i >= 0) && (i < FlowEnabledI4.Length)) ? FlowEnabledI4[i] : false; case 5: return ((FlowEnabledI5 != null) && (i >= 0) && (i < FlowEnabledI5.Length)) ? FlowEnabledI5[i] : false; case 6: return ((FlowEnabledI6 != null) && (i >= 0) && (i < FlowEnabledI6.Length)) ? FlowEnabledI6[i] : false; case 7: return ((FlowEnabledI7 != null) && (i >= 0) && (i < FlowEnabledI7.Length)) ? FlowEnabledI7[i] : false; default: return false; } } /// /// Set flow enabled info /// /// 1-based MID id /// 0-based flow id /// true = enabled public void SetFlowEnabled(int midId, int i, bool value) { switch (midId) { case 1: if ((FlowEnabledI1 != null) && (i >= 0) && (i < FlowEnabledI1.Length)) { FlowEnabledI1[i] = value; }; break; case 2: if ((FlowEnabledI2 != null) && (i >= 0) && (i < FlowEnabledI2.Length)) { FlowEnabledI2[i] = value; }; break; case 3: if ((FlowEnabledI3 != null) && (i >= 0) && (i < FlowEnabledI3.Length)) { FlowEnabledI3[i] = value; }; break; case 4: if ((FlowEnabledI4 != null) && (i >= 0) && (i < FlowEnabledI4.Length)) { FlowEnabledI4[i] = value; }; break; case 5: if ((FlowEnabledI5 != null) && (i >= 0) && (i < FlowEnabledI5.Length)) { FlowEnabledI5[i] = value; }; break; case 6: if ((FlowEnabledI6 != null) && (i >= 0) && (i < FlowEnabledI6.Length)) { FlowEnabledI6[i] = value; }; break; case 7: if ((FlowEnabledI7 != null) && (i >= 0) && (i < FlowEnabledI7.Length)) { FlowEnabledI7[i] = value; }; break; default: break; } } public double[] FlowFromI1; public double[] FlowFromI2; public double[] FlowFromI3; public double[] FlowFromI4; public double[] FlowFromI5; public double[] FlowFromI6; public double[] FlowFromI7; /// /// Get lower limit of the flow /// /// 1-based MID id /// 0-based flow id /// Flow in m3/h public double GetFlowFrom(int midId, int i) { switch (midId) { case 1: return ((FlowFromI1 != null) && (i >= 0) && (i < FlowFromI1.Length)) ? FlowFromI1[i] : 0; case 2: return ((FlowFromI2 != null) && (i >= 0) && (i < FlowFromI2.Length)) ? FlowFromI2[i] : 0; case 3: return ((FlowFromI3 != null) && (i >= 0) && (i < FlowFromI3.Length)) ? FlowFromI3[i] : 0; case 4: return ((FlowFromI4 != null) && (i >= 0) && (i < FlowFromI4.Length)) ? FlowFromI4[i] : 0; case 5: return ((FlowFromI5 != null) && (i >= 0) && (i < FlowFromI5.Length)) ? FlowFromI5[i] : 0; case 6: return ((FlowFromI6 != null) && (i >= 0) && (i < FlowFromI6.Length)) ? FlowFromI6[i] : 0; case 7: return ((FlowFromI7 != null) && (i >= 0) && (i < FlowFromI7.Length)) ? FlowFromI7[i] : 0; default: return 0; } } /// /// Set lower limit of the flow /// /// 1-based MID id /// 0-based flow id /// Flow in m3/h public void SetFlowFrom(int midId, int i, double value) { switch (midId) { case 1: if ((FlowFromI1 != null) && (i >= 0) && (i < FlowFromI1.Length)) { FlowFromI1[i] = value; }; break; case 2: if ((FlowFromI2 != null) && (i >= 0) && (i < FlowFromI2.Length)) { FlowFromI2[i] = value; }; break; case 3: if ((FlowFromI3 != null) && (i >= 0) && (i < FlowFromI3.Length)) { FlowFromI3[i] = value; }; break; case 4: if ((FlowFromI4 != null) && (i >= 0) && (i < FlowFromI4.Length)) { FlowFromI4[i] = value; }; break; case 5: if ((FlowFromI5 != null) && (i >= 0) && (i < FlowFromI5.Length)) { FlowFromI5[i] = value; }; break; case 6: if ((FlowFromI6 != null) && (i >= 0) && (i < FlowFromI6.Length)) { FlowFromI6[i] = value; }; break; case 7: if ((FlowFromI7 != null) && (i >= 0) && (i < FlowFromI7.Length)) { FlowFromI7[i] = value; }; break; default: break; } } public double[] FlowToI1; public double[] FlowToI2; public double[] FlowToI3; public double[] FlowToI4; public double[] FlowToI5; public double[] FlowToI6; public double[] FlowToI7; /// /// Get upper limit of the flow /// /// 1-based MID id /// 0-based flow id /// Flow in m3/h public double GetFlowTo(int midId, int i) { switch (midId) { case 1: return ((FlowToI1 != null) && (i >= 0) && (i < FlowToI1.Length)) ? FlowToI1[i] : 0; case 2: return ((FlowToI2 != null) && (i >= 0) && (i < FlowToI2.Length)) ? FlowToI2[i] : 0; case 3: return ((FlowToI3 != null) && (i >= 0) && (i < FlowToI3.Length)) ? FlowToI3[i] : 0; case 4: return ((FlowToI4 != null) && (i >= 0) && (i < FlowToI4.Length)) ? FlowToI4[i] : 0; case 5: return ((FlowToI5 != null) && (i >= 0) && (i < FlowToI5.Length)) ? FlowToI5[i] : 0; case 6: return ((FlowToI6 != null) && (i >= 0) && (i < FlowToI6.Length)) ? FlowToI6[i] : 0; case 7: return ((FlowToI7 != null) && (i >= 0) && (i < FlowToI7.Length)) ? FlowToI7[i] : 0; default: return 0; } } /// /// Set upper limit of the flow /// /// 1-based MID id /// 0-based flow id /// Flow in m3/h public void SetFlowTo(int midId, int i, double value) { switch (midId) { case 1: if ((FlowToI1 != null) && (i >= 0) && (i < FlowToI1.Length)) { FlowToI1[i] = value; }; break; case 2: if ((FlowToI2 != null) && (i >= 0) && (i < FlowToI2.Length)) { FlowToI2[i] = value; }; break; case 3: if ((FlowToI3 != null) && (i >= 0) && (i < FlowToI3.Length)) { FlowToI3[i] = value; }; break; case 4: if ((FlowToI4 != null) && (i >= 0) && (i < FlowToI4.Length)) { FlowToI4[i] = value; }; break; case 5: if ((FlowToI5 != null) && (i >= 0) && (i < FlowToI5.Length)) { FlowToI5[i] = value; }; break; case 6: if ((FlowToI6 != null) && (i >= 0) && (i < FlowToI6.Length)) { FlowToI6[i] = value; }; break; case 7: if ((FlowToI7 != null) && (i >= 0) && (i < FlowToI7.Length)) { FlowToI7[i] = value; }; break; default: break; } } /// StatisticsDlg UI public int SelectedRadioButtonNumber; /// MainWnd public int MainWndLeft; public int MainWndTop; public int MainWndWidth; public int MainWndHeight; public bool ManiWndMaximized; public int SplitterDistance; /// /// Default constructor which is used to create default settings /// public LocalSettings() { #if GENESIS Language = "DE"; BenchNames = new string[] { "Genesis" }; ConnectionStrings = new string[] { "SERVER=localhost; DATABASE=genesis-r; UID=root; PASSWORD=; CHARSET=utf8;", }; MidNames = new string[] { string.Empty, "I11", "I12", "I2", "I3", "I4", "I5" }; /// Index is MID-id #else Language = "SK"; BenchNames = new string[] { "WR10", "WR11", "WR13", "WR14", "WR15", "PT7" }; ConnectionStrings = new string[] { "SERVER=10.42.128.93; DATABASE=st-wr10-r; UID=vysledky; PASSWORD=GAqx76QUB6NbnpZP; CHARSET=utf8;", "SERVER=10.42.128.102; DATABASE=st-wr11-r; UID=vysledky; PASSWORD=GAqx76QUB6NbnpZP; CHARSET=utf8;", "SERVER=10.42.128.89; DATABASE=st-wr13-r; UID=vysledky; PASSWORD=GAqx76QUB6NbnpZP; CHARSET=utf8;", "SERVER=10.42.128.213; DATABASE=st-wr14-r; UID=vysledky; PASSWORD=GAqx76QUB6NbnpZP; CHARSET=utf8;", "SERVER=10.42.128.214; DATABASE=st-wr15-r; UID=vysledky; PASSWORD=GAqx76QUB6NbnpZP; CHARSET=utf8;", "SERVER=10.42.129.26; DATABASE=iperlspecial-r; UID=vysledky; PASSWORD=GAqx76QUB6NbnpZP; CHARSET=utf8;", }; MidNames = new string[] { string.Empty, "I1", "I2", "I3", "I4" }; /// Index is MID-id #endif FlowEnabledI1 = new bool[FlowsCount]; FlowEnabledI2 = new bool[FlowsCount]; FlowEnabledI3 = new bool[FlowsCount]; FlowEnabledI4 = new bool[FlowsCount]; FlowEnabledI5 = new bool[FlowsCount]; FlowEnabledI6 = new bool[FlowsCount]; FlowEnabledI7 = new bool[FlowsCount]; FlowFromI1 = new double[FlowsCount]; FlowFromI2 = new double[FlowsCount]; FlowFromI3 = new double[FlowsCount]; FlowFromI4 = new double[FlowsCount]; FlowFromI5 = new double[FlowsCount]; FlowFromI6 = new double[FlowsCount]; FlowFromI7 = new double[FlowsCount]; FlowToI1 = new double[FlowsCount]; FlowToI2 = new double[FlowsCount]; FlowToI3 = new double[FlowsCount]; FlowToI4 = new double[FlowsCount]; FlowToI5 = new double[FlowsCount]; FlowToI6 = new double[FlowsCount]; FlowToI7 = new double[FlowsCount]; SelectedRadioButtonNumber = 1; } /// /// Load local settings (public fields of this class) from the XML file. /// public static LocalSettings Load(string fileName) { try { 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 return ls; } } catch (Exception e) { string msg = e.Message; return null; } } /// /// Save local settings (public fields of this class) to the XML file. /// 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; } } } }