/// /// Copyright (c) 2015-2022 Sensus Slovensko a.s. /// using System.Collections.Generic; using System.IO; using System.Xml.Serialization; using Common; using Config.Entities; using TBF.Resources; using TBF.Rig.Generic; using TBF.Rig.TestMethods.iPerlCommunication; using TBF.Rig.Uni.SharedDialogs.SmartMetersCommunication; namespace TBF.Rig.TestMethods.SmartMeterFlyingStartMassCollection { public class SmartCommunicationParams : TestParamsBase, ITestParams { public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(SmartCommunicationParams) })[0]; public override XmlSerializer GetSerializer() { return Serializer; } //public string Activity { get; set; } /// Communication activity //public bool SimultWithPrevious { get; set; } //public bool SimultWithNext { get; set; } 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(iPerlCommunicationConstants.ReadConfigurationStr); retVal.Add(string.Format("{0} A0", iPerlCommunicationConstants.SetTestModeStr)); retVal.Add(string.Format("{0} A4", iPerlCommunicationConstants.SetTestModeStr)); retVal.Add(iPerlCommunicationConstants.ReadCalibrationStr); retVal.Add(iPerlCommunicationConstants.ReadCalibrationV4Str); retVal.Add(iPerlCommunicationConstants.NormalizeCalibrationFactorStr); retVal.Add(iPerlCommunicationConstants.NormalizeCalibrationV4FactorsStr); retVal.Add(iPerlCommunicationConstants.GetDefaultQ2CorrectionsStr); retVal.Add(iPerlCommunicationConstants.ReadQ2CorrectionStr); retVal.Add(iPerlCommunicationConstants.ResetQ2CorrectionStr); retVal.Add(iPerlCommunicationConstants.WriteDefaultQ2CorrectionsStr); retVal.Add(iPerlCommunicationConstants.InitOrReadQ2CorrectionsStr); retVal.Add(iPerlCommunicationConstants.WriteCalibrationFactorStr); retVal.Add(iPerlCommunicationConstants.WriteCalibrationV4FactorsStr); retVal.Add(iPerlCommunicationConstants.WriteQ2CorrectionStr); retVal.Add(iPerlCommunicationConstants.WriteQ2CorrectionAltStr); retVal.Add(iPerlCommunicationConstants.WriteQ2CorrectionGreeceStr); retVal.Add(iPerlCommunicationConstants.WriteQ2CorrectionRLStr); retVal.Add(iPerlCommunicationConstants.WriteQ2CorrectionLRStr); retVal.Add(iPerlCommunicationConstants.WriteQ2CorrectionIncl05Str); retVal.Add(iPerlCommunicationConstants.WriteQ2CorrectionAltIncl05Str); retVal.Add(iPerlCommunicationConstants.WriteQ2CorrectionPlusIncl05Str); retVal.Add(iPerlCommunicationConstants.WriteQ2CorrectionPlusAltIncl05Str); retVal.Add(iPerlCommunicationConstants.WriteQ2CorrectionGreeceIncl05Str); retVal.Add(iPerlCommunicationConstants.WriteQ2CorrectionRLIncl05Str); retVal.Add(iPerlCommunicationConstants.WriteQ2CorrectionLRIncl05Str); retVal.Add(iPerlCommunicationConstants.Q2correctedFromCmd + "Qx"); retVal.Add(iPerlCommunicationConstants.StrictQ2ErrorCheckStr + "Qx"); retVal.Add(iPerlCommunicationConstants.Q2correctionCheckCmd); retVal.Add(iPerlCommunicationConstants.IperlCheckCmd); retVal.Add(iPerlCommunicationConstants.UpdateBothQ2FactorsTestRLOnlyStr); retVal.Add(iPerlCommunicationConstants.UpdateBothQ2FactorsTestLROnlyStr); retVal.Add(iPerlCommunicationConstants.UpdateQ2CorrectionsStr); retVal.Add(iPerlCommunicationConstants.ConditnlUpdateQ2CorrectionsStr); retVal.Add(iPerlCommunicationConstants.ConditnlUpdateQ2CorrRLStr); retVal.Add(iPerlCommunicationConstants.ConditnlUpdateQ2CorrLRStr); retVal.Add("Q2 corrected from Q2adj"); retVal.Add("Q2 correction check Q2bc Q2ac"); retVal.Add(iPerlCommunicationConstants.SetActiveModeStr); retVal.Add("---"); retVal.Add(iPerlCommunicationConstants.Reset2HzCorrectionStr); retVal.Add(iPerlCommunicationConstants.Write2HzCorrectionStr); retVal.Add(iPerlCommunicationConstants.DewaReworkRLStr); retVal.Add(iPerlCommunicationConstants.DewaReworkLRStr); retVal.Add(iPerlCommunicationConstants.StartTestingSealedMetersStr); retVal.Add(iPerlCommunicationConstants.EndTestingSealedMetersStr); retVal.Add(string.Format("{0} if enabled", iPerlCommunicationConstants.ReadConfigurationStr)); retVal.Add(string.Format("{0} 80", iPerlCommunicationConstants.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(SmartCommunicationParams prms) { prms.Activity = this.Activity; prms.SimultWithPrevious = this.SimultWithPrevious; prms.SimultWithNext = this.SimultWithNext; } public IParamsProvider Clone() { SmartCommunicationParams pars = new SmartCommunicationParams(); CopyContentTo(pars); return pars; } public override void UpdateFromDbEntity(ComponentTest dbEntity) { if (dbEntity == null) return; try { SmartCommunicationParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as SmartCommunicationParams; testParamsEntity = dbEntity; componentName = dbEntity.CmpntName; test = dbEntity.Test; if (tmp != null) tmp.CopyContentTo(this); } catch { } } /// /// Parameterless constructor initializes the parameters /// public SmartCommunicationParams() { } public SmartCommunicationParams(bool initialize) { if (initialize) InitializeAll(); } public SmartCommunicationParams(ComponentTest testParamsEntity, string componentName, Test test) { this.testParamsEntity = testParamsEntity; this.componentName = componentName; this.test = test; } } }