/// /// Copyright (c) 2015-2022 Sensus Slovensko a.s. /// using System; using System.IO; using System.Text; using System.Xml.Serialization; using Common; using Config.Entities; using TBF.Rig.Generic; using TBF.Resources; using System.Collections.Generic; namespace TBF.Rig.TestMethods.iPerlCommunication { public class iPerlCommunicationParams : TestParamsBase, IParamsProvider, ITestParams { public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(iPerlCommunicationParams) })[0]; public override XmlSerializer GetSerializer() { return Serializer; } public string Activity; /// Communication activity public bool SimultWithPrevious; public bool SimultWithNext; public override void InitializeAll() { Activity = "Read Configuration"; SimultWithPrevious = false; SimultWithNext = false; } string[] paramNames = new string[] { Strings.Activity, Strings.Simultaneous_with_previous_step, Strings.Simultaneous_with_next_step, }; public override string ParamName(int i) { return paramNames[i]; } public override int ParamsCount() { return paramNames.Length; } public override ICollection ParamValues(int i) { if (i == 0) { var retVal = new List(); retVal.Add(iPerlCommunicationForm.ReadConfigurationStr); retVal.Add(string.Format("{0} A0", iPerlCommunicationForm.SetTestModeStr)); retVal.Add(string.Format("{0} A4", iPerlCommunicationForm.SetTestModeStr)); retVal.Add(iPerlCommunicationForm.ReadCalibrationStr); retVal.Add(iPerlCommunicationForm.ReadCalibrationV4Str); retVal.Add(iPerlCommunicationForm.NormalizeCalibrationFactorStr); retVal.Add(iPerlCommunicationForm.NormalizeCalibrationV4FactorsStr); retVal.Add(iPerlCommunicationForm.GetDefaultQ2CorrectionsStr); retVal.Add(iPerlCommunicationForm.ReadQ2CorrectionStr); retVal.Add(iPerlCommunicationForm.ResetQ2CorrectionStr); retVal.Add(iPerlCommunicationForm.WriteDefaultQ2CorrectionsStr); retVal.Add(iPerlCommunicationForm.InitOrReadQ2CorrectionsStr); retVal.Add(iPerlCommunicationForm.WriteCalibrationFactorStr); retVal.Add(iPerlCommunicationForm.WriteCalibrationV4FactorsStr); retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionStr); retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionAltStr); retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionGreeceStr); retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionRLStr); retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionLRStr); retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionIncl05Str); retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionAltIncl05Str); retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionGreeceIncl05Str); retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionRLIncl05Str); retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionLRIncl05Str); retVal.Add(iPerlCommunicationSeq.Q2correctedFromCmd + "Qx"); retVal.Add(iPerlCommunicationSeq.StrictQ2ErrorCheckStr + "Qx"); retVal.Add(iPerlCommunicationSeq.Q2correctionCheckCmd); retVal.Add(iPerlCommunicationSeq.IperlCheckCmd); retVal.Add(iPerlCommunicationForm.UpdateBothQ2FactorsTestRLOnlyStr); retVal.Add(iPerlCommunicationForm.UpdateBothQ2FactorsTestLROnlyStr); retVal.Add(iPerlCommunicationForm.UpdateQ2CorrectionsStr); retVal.Add(iPerlCommunicationForm.ConditnlUpdateQ2CorrectionsStr); retVal.Add(iPerlCommunicationForm.ConditnlUpdateQ2CorrRLStr); retVal.Add(iPerlCommunicationForm.ConditnlUpdateQ2CorrLRStr); retVal.Add("Q2 corrected from Q2adj"); retVal.Add("Q2 correction check Q2bc Q2ac"); retVal.Add(iPerlCommunicationForm.SetActiveModeStr); retVal.Add("---"); retVal.Add(iPerlCommunicationForm.Reset2HzCorrectionStr); retVal.Add(iPerlCommunicationForm.Write2HzCorrectionStr); retVal.Add(iPerlCommunicationForm.DewaReworkRLStr); retVal.Add(iPerlCommunicationForm.DewaReworkLRStr); retVal.Add(iPerlCommunicationForm.StartTestingSealedMetersStr); retVal.Add(iPerlCommunicationForm.EndTestingSealedMetersStr); retVal.Add(string.Format("{0} if enabled", iPerlCommunicationForm.ReadConfigurationStr)); retVal.Add(string.Format("{0} 80", iPerlCommunicationForm.SetTestModeStr)); retVal.Add("iPerl_check prevWorkStep direction q2factors"); for (ConditionID id = ConditionID.A; id < ConditionID.Count; id++) { retVal.Add(string.Format(SequenceConditionOp.ConditionNameFmt, id)); } return retVal; } else { return new string[] { Strings.yes, Strings.no }; } } public override string ToString(int i) { switch (i) { case 0: return Activity; case 1: return (SimultWithPrevious ? Strings.yes : Strings.no); case 2: return (SimultWithNext ? Strings.yes : Strings.no); default: return string.Empty; } } public CfgUpdateFlags UpdateParam(int i, string strValue) { switch (i) { case 0: Activity = strValue; return CfgUpdateFlags.None; case 1: SimultWithPrevious = strValue.ToLower().Equals(Strings.yes.ToLower()); return CfgUpdateFlags.None; case 2: SimultWithNext = strValue.ToLower().Equals(Strings.yes.ToLower()); return CfgUpdateFlags.None; default: return CfgUpdateFlags.None; } } public bool ValidateParam(int i, string strValue, out string message) { message = string.Empty; switch (i) { case 0: return true; case 1: case 2: if (strValue.Equals(Strings.yes) || strValue.Equals(Strings.no)) return true; break; default: message = "Invalid index"; return false; } message = ParamName(i) + " is invalid"; return false; } void CopyContentTo(iPerlCommunicationParams prms) { prms.Activity = this.Activity; prms.SimultWithPrevious = this.SimultWithPrevious; prms.SimultWithNext = this.SimultWithNext; } public IParamsProvider Clone() { iPerlCommunicationParams pars = new iPerlCommunicationParams(); CopyContentTo(pars); return pars; } public override void UpdateFromDbEntity(ComponentTest dbEntity) { if (dbEntity == null) return; try { iPerlCommunicationParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as iPerlCommunicationParams; testParamsEntity = dbEntity; componentName = dbEntity.CmpntName; test = dbEntity.Test; if (tmp != null) tmp.CopyContentTo(this); } catch { } } /// /// Parameterless constructor initializes the parameters /// public iPerlCommunicationParams() { } public iPerlCommunicationParams(bool initialize) { if (initialize) InitializeAll(); } public iPerlCommunicationParams(ComponentTest testParamsEntity, string componentName, Test test) { this.testParamsEntity = testParamsEntity; this.componentName = componentName; this.test = test; } } }