/// /// Copyright (c) 2013-2016 Sensus Metering Systems /// using System; using System.Collections.Generic; using Config.Entities; using Results.Entities; using Results.Resources; namespace Results { public class WMeterRsltItemSpec { /// /// Public fields /// public readonly int Uid; public readonly string OldUid; public readonly string Name; /// Name-s of all items must be unique public string Caption; /// Specifies item description to be printed as a caption (in the header, etc.) public string TestID; /// Specifies the test public Config.Unit Units; /// Specifies units for the output public string Format; /// Specifies format for the output public string Precision; /// Specifies precision for the output public int Width; /// Specifies the number of characters of the output, 0 = automatic public Config.Entities.Alignment Alignment; /// Specifies alignment for the output public WMeterRsltItemSpec Clone() { WMeterRsltItemSpec item2 = new WMeterRsltItemSpec((ItemID)Uid, Name, printDlgt); item2.Caption = Caption; item2.TestID = TestID; item2.Units = Units; item2.Format = Format; item2.Precision = Precision; item2.Width = Width; item2.Alignment = Alignment; return item2; } /// /// Function to pick a MeterTestResult field and convert it into a string /// public delegate string PrintDlgt(WaterMeter waterMeterResult, string testID, Config.Unit units, string format, string precision); private readonly PrintDlgt printDlgt; /// Safe wrapper which replaces null-s by empty strings public string Print(WaterMeter waterMeterResult) { string str = printDlgt(waterMeterResult, TestID, Units, Format, Precision); if (str == null) str = string.Empty; if (!string.IsNullOrEmpty(Format)) { str = string.Format(Format, str); } int len = str.Length; if (Width == 0 || len >= Width) { return str; } else if (Alignment == Config.Entities.Alignment.Left) { return str + new string(' ', Width - len); } else if (Alignment == Config.Entities.Alignment.Right) { return new string(' ', Width - len) + str; } else // Alignment.Center or Alignment.Justified { int nrSpaces = Width - len; return new string(' ', nrSpaces / 2) + str + new string(' ', nrSpaces - (nrSpaces / 2)); } } /// /// Public constructor /// public WMeterRsltItemSpec(ItemID itemId, string name, PrintDlgt printDlgt) { Uid = (int)itemId; OldUid = itemId.ToString().Replace("__", "/").Replace('_', ' '); Name = name; this.printDlgt = printDlgt; } /// Static list of all available items public static readonly IList AllItems; /// Static constructor that initializes the list of all items static WMeterRsltItemSpec() { AllItems = new List(); AllItems.Add(new WMeterRsltItemSpec(ItemID.String, "String", (w, t, u, f, p) => f)); /// Common AllItems.Add(new WMeterRsltItemSpec(ItemID.Test_name, Strings.Test + " *", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : w.GetTestRslt(t).Name())); AllItems.Add(new WMeterRsltItemSpec(ItemID.Procedure_name, Strings.Procedure, (w, t, u, f, p) => w.ProcedureName())); AllItems.Add(new WMeterRsltItemSpec(ItemID.Batch_number, Strings.Batch_nr, (w, t, u, f, p) => w.BatchNr().ToString())); AllItems.Add(new WMeterRsltItemSpec(ItemID.Test_method, Strings.Test_method + " *", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : w.GetTestRslt(t).Method())); AllItems.Add(new WMeterRsltItemSpec(ItemID.Density, Strings.Density + " *", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : w.GetTestRslt(t).DensityOut.ToString(string.IsNullOrEmpty(p) ? "F1" : p))); /// [kg/m3] /// Target values AllItems.Add(new WMeterRsltItemSpec(ItemID.Q_from, Strings.Q_from + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : w.GetTestRslt(t).Qfrom().ToString(string.IsNullOrEmpty(p) ? "F3" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Q_to, Strings.Q_to + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : w.GetTestRslt(t).Qto().ToString(string.IsNullOrEmpty(p) ? "F3" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Test_volume, Strings.Test_vol + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetTestRslt(t).TargetVolume()).ToString(string.IsNullOrEmpty(p) ? "F1" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Error_limit_Lo, Strings.ErrLimLo + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetTestRslt(t).ErrLimLo()).ToString(string.IsNullOrEmpty(p) ? "F1" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Error_limit_Hi, Strings.ErrLimHi + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetTestRslt(t).ErrLimHi()).ToString(string.IsNullOrEmpty(p) ? "F1" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Uncertainty, Strings.Uncertainty + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : w.GetTestRslt(t).Uncertainty().ToString(string.IsNullOrEmpty(p) ? "F2" : p))); /// Test results AllItems.Add(new WMeterRsltItemSpec(ItemID.Test_start_time, Strings.T_start + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : (string.IsNullOrEmpty(f) ? w.GetTestRslt(t).StartTime.ToString() : string.Format(f, w.GetTestRslt(t).StartTime)))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Test_end_time, Strings.T_end + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : (string.IsNullOrEmpty(f) ? w.GetTestRslt(t).EndTime.ToString() : string.Format(f, w.GetTestRslt(t).EndTime)))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Test_time, Strings.T_s + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : w.GetTestRslt(t).TestTime.ToString(string.IsNullOrEmpty(p) ? "F2" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Flow, Strings.Flow + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : Utils.DoubleToStr(Config.Units.ConvertTo(u, w.GetTestRslt(t).FlowVolume), 4))); AllItems.Add(new WMeterRsltItemSpec(ItemID.T_in, Strings.T_in + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetTestRslt(t).TempInAvrg).ToString(string.IsNullOrEmpty(p) ? "F2" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.T_out, Strings.T_out + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetTestRslt(t).TempOutAvrg).ToString(string.IsNullOrEmpty(p) ? "F2" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.T_div, Strings.T_div + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetTestRslt(t).TempDivAvrg).ToString(string.IsNullOrEmpty(p) ? "F2" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.P_up, Strings.P_up + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetTestRslt(t).PressUpAvrg).ToString(string.IsNullOrEmpty(p) ? "F3" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.P_up_start, Strings.P_up_start + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetTestRslt(t).PressUpStart).ToString(string.IsNullOrEmpty(p) ? "F3" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.P_up_end, Strings.P_up_end + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetTestRslt(t).PressUpEnd).ToString(string.IsNullOrEmpty(p) ? "F3" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.P_down, Strings.P_dn + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetTestRslt(t).PressDownAvrg).ToString(string.IsNullOrEmpty(p) ? "F3" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.P_down_start, Strings.P_dn_start + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetTestRslt(t).PressDownStart).ToString(string.IsNullOrEmpty(p) ? "F3" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.P_down_end, Strings.P_dn_end + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetTestRslt(t).PressDownEnd).ToString(string.IsNullOrEmpty(p) ? "F3" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Reference_error, Strings.ErrRef + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetTestRslt(t).ErrorMaster).ToString(string.IsNullOrEmpty(p) ? "F3" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Ambient_temperature, Strings.T_amb + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? Config.Units.ConvertTo(u, w.Batch.AmbientTempAve()).ToString(string.IsNullOrEmpty(p) ? "F1" : p) : Config.Units.ConvertTo(u, w.GetTestRslt(t).AmbientTempAve).ToString(string.IsNullOrEmpty(p) ? "F1" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Ambient_pressure, Strings.P_amb + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? Config.Units.ConvertTo(u, w.Batch.AmbientPressAve()).ToString(string.IsNullOrEmpty(p) ? "F0" : p) : Config.Units.ConvertTo(u, w.GetTestRslt(t).AmbientPressAve).ToString(string.IsNullOrEmpty(p) ? "F0" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Ambient_humidity, Strings.H_amb + "()", (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? Config.Units.ConvertTo(u, w.Batch.AmbientHumiAve()).ToString(string.IsNullOrEmpty(p) ? "F1" : p) : Config.Units.ConvertTo(u, w.GetTestRslt(t).AmbientHumiAve).ToString(string.IsNullOrEmpty(p) ? "F1" : p))); /// Single and combined meter results AllItems.Add(new WMeterRsltItemSpec(ItemID.Volume, Strings.Volume + "()", (w, t, u, f, p) => (w.GetMeterTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetMeterTestRslt(t).VolumeMeter).ToString(string.IsNullOrEmpty(p) ? "F3" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Reference_volume, Strings.VolRef + "()", (w, t, u, f, p) => (w.GetMeterTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetMeterTestRslt(t).VolumeRef).ToString(string.IsNullOrEmpty(p) ? "F3" : p))); #if HEAT_METERS_SUPPORT AllItems.Add(new WMeterRsltItemSpec(ItemID.Energy, Strings.Energy + "()", (w, t, u, f, p) => (w.GetMeterTestRslt(t, Config.Entities.CompoundMeterId.HeatMeterEnergy) == null) ? "" : Config.Units.ConvertTo(u, w.GetMeterTestRslt(t, Config.Entities.CompoundMeterId.HeatMeterEnergy).VolumeMeter).ToString(string.IsNullOrEmpty(p) ? "F1" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Reference_energy, Strings.Energy_ref + "()", (w, t, u, f, p) => (w.GetMeterTestRslt(t, Config.Entities.CompoundMeterId.HeatMeterEnergy) == null) ? "" : Config.Units.ConvertTo(u, w.GetMeterTestRslt(t, Config.Entities.CompoundMeterId.HeatMeterEnergy).VolumeRef).ToString(string.IsNullOrEmpty(p) ? "F1" : p))); #endif #if IPERLST || IPERLST_SPECIAL AllItems.Add(new WMeterRsltItemSpec(ItemID.Error, Strings.Error + "()", (w, t, u, f, p) => (w.GetMeterTestRslt(t) == null) ? "0" : Config.Units.ConvertTo(u, w.GetMeterTestRslt(t).Error).ToString(string.IsNullOrEmpty(p) ? "F2" : p))); #else AllItems.Add(new WMeterRsltItemSpec(ItemID.Error, Strings.Error + "()", (w, t, u, f, p) => (w.GetMeterTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetMeterTestRslt(t).Error).ToString(string.IsNullOrEmpty(p) ? "F2" : p))); #endif AllItems.Add(new WMeterRsltItemSpec(ItemID.Passed, Strings.Result + "()", (w, t, u, f, p) => (w.GetMeterTestRslt(t) == null) ? "" : w.GetMeterTestRslt(t).PassedColorStr())); /// Water meter info AllItems.Add(new WMeterRsltItemSpec(ItemID.Watermeter_type, Strings.WM_Type, (w, t, u, f, p) => w.WaterMeterData.ProductName)); AllItems.Add(new WMeterRsltItemSpec(ItemID.Producer, Strings.Producer, (w, t, u, f, p) => w.WaterMeterData.Producer)); AllItems.Add(new WMeterRsltItemSpec(ItemID.DN, "DN", (w, t, u, f, p) => string.IsNullOrEmpty(p) ? Config.Units.ConvertTo(u, w.WaterMeterData.DN).ToString() : Config.Units.ConvertTo(u, w.WaterMeterData.DN).ToString(p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.L, "L", (w, t, u, f, p) => string.IsNullOrEmpty(p) ? Config.Units.ConvertTo(u, w.WaterMeterData.L).ToString() : Config.Units.ConvertTo(u, w.WaterMeterData.L).ToString(p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Mounting, Strings.Mounting, (w, t, u, f, p) => w.WaterMeterData.Mounting.ToDescription())); AllItems.Add(new WMeterRsltItemSpec(ItemID.Q4, "Q4_Qmax", (w, t, u, f, p) => string.IsNullOrEmpty(p) ? Config.Units.ConvertTo(u, w.WaterMeterData.Q4_Qmax).ToString() : Config.Units.ConvertTo(u, w.WaterMeterData.Q4_Qmax).ToString(p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Q3, "Q3_Qn", (w, t, u, f, p) => string.IsNullOrEmpty(p) ? Config.Units.ConvertTo(u, w.WaterMeterData.Q3_Qn).ToString() : Config.Units.ConvertTo(u, w.WaterMeterData.Q3_Qn).ToString(p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Q2, "Q2_Qt", (w, t, u, f, p) => string.IsNullOrEmpty(p) ? Config.Units.ConvertTo(u, w.WaterMeterData.Q2_Qt).ToString() : Config.Units.ConvertTo(u, w.WaterMeterData.Q2_Qt).ToString(p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Q1, "Q1_Qmin", (w, t, u, f, p) => string.IsNullOrEmpty(p) ? Config.Units.ConvertTo(u, w.WaterMeterData.Q1_Qmin).ToString() : Config.Units.ConvertTo(u, w.WaterMeterData.Q1_Qmin).ToString(p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Metrological_class, Strings.MClass, (w, t, u, f, p) => w.WaterMeterData.MetrologicalClass)); AllItems.Add(new WMeterRsltItemSpec(ItemID.Temperature_class, "Temperature class", (w, t, u, f, p) => w.WaterMeterData.TemperatureClass.ToDescription())); AllItems.Add(new WMeterRsltItemSpec(ItemID.Pressure_loss_class, "Pressure loss class", (w, t, u, f, p) => w.WaterMeterData.PressureLossClass.ToDescription())); AllItems.Add(new WMeterRsltItemSpec(ItemID.Max_admissible_pressure, "Max. admissible pressure",(w, t, u, f, p) => w.WaterMeterData.MaxAdmissiblePressure.ToDescription())); AllItems.Add(new WMeterRsltItemSpec(ItemID.Flow_profile_sensitivity_class, "Flow profile sensitivity class",(w, t, u, f, p) => w.WaterMeterData.FlowProfileSensitivityClass.ToDescription())); AllItems.Add(new WMeterRsltItemSpec(ItemID.Approval_info, Strings.Approval, (w, t, u, f, p) => w.WaterMeterData.ApprovalInfo)); AllItems.Add(new WMeterRsltItemSpec(ItemID.Certificate, "Certificate", (w, t, u, f, p) => w.WaterMeterData.Certificate)); AllItems.Add(new WMeterRsltItemSpec(ItemID.Pulses_per_liter, Strings.PulsesLiter, (w, t, u, f, p) => string.IsNullOrEmpty(p) ? w.WaterMeterData.PulsesPerLtr.ToString() : w.WaterMeterData.PulsesPerLtr.ToString(p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Text1, "Text1", (w, t, u, f, p) => w.WaterMeterData.Text1)); AllItems.Add(new WMeterRsltItemSpec(ItemID.Text2, "Text2", (w, t, u, f, p) => w.WaterMeterData.Text2)); AllItems.Add(new WMeterRsltItemSpec(ItemID.Text3, "Text3", (w, t, u, f, p) => w.WaterMeterData.Text3)); AllItems.Add(new WMeterRsltItemSpec(ItemID.Text4, "Text4", (w, t, u, f, p) => w.WaterMeterData.Text4)); AllItems.Add(new WMeterRsltItemSpec(ItemID.Text5, "Text5", (w, t, u, f, p) => w.WaterMeterData.Text5)); /// Water meters results AllItems.Add(new WMeterRsltItemSpec(ItemID.Serial_Nr, Strings.sn, (w, t, u, f, p) => w.SerialNr)); AllItems.Add(new WMeterRsltItemSpec(ItemID.Purchase_order, Strings.PO, (w, t, u, f, p) => w.PurchaseOrder)); AllItems.Add(new WMeterRsltItemSpec(ItemID.Year_of_production, Strings.Year, (w, t, u, f, p) => w.YearOfProduction.ToString())); AllItems.Add(new WMeterRsltItemSpec(ItemID.WM_Position, Strings.Pos, (w, t, u, f, p) => w.WMPosition.ToString())); /// Water meters results (single) AllItems.Add(new WMeterRsltItemSpec(ItemID.End_state, Strings.End_state, (w, t, u, f, p) => w.EndState)); AllItems.Add(new WMeterRsltItemSpec(ItemID.Pulses, Strings.Pulses + "()", (w, t, u, f, p) => (w.GetMeterTestRslt(t) == null) ? "" : w.GetMeterTestRslt(t).PulsesMeter.ToString())); AllItems.Add(new WMeterRsltItemSpec(ItemID.Pulses__liter, Strings.PulsesLiter + "()", (w, t, u, f, p) => (w.GetMeterTestRslt(t) == null) ? "" : (string.IsNullOrEmpty(p) ? w.GetMeterTestRslt(t).PulsesPerLiter.ToString() : w.GetMeterTestRslt(t).PulsesPerLiter.ToString(p)))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Reference_pulses, Strings.RefPulses + "()", (w, t, u, f, p) => (w.GetMeterTestRslt(t) == null) ? "" : w.GetMeterTestRslt(t).PulsesMaster.ToString())); /// Water meters results (combined) //AllItems.Add(new ItemSpec("Q rise", "Q rise [m3/h]", null, (x, y, z) => (z.QRise() == 0) ? "-" : Utils.DoubleToStr(z.QRise(), 4))); //AllItems.Add(new ItemSpec("Q fall", "Q fall [m3/h]", null, (x, y, z) => (z.QFall() == 0) ? "-" : Utils.DoubleToStr(z.QFall(), 4))); //AllItems.Add(new ItemSpec("Error large WM", "Error-L [%]", null, (x, y, z) => x.Error.ToString("F2"))); //AllItems.Add(new ItemSpec("Error small WM", "Error-S [%]", null, (x, y, z) => y.Error.ToString("F2"))); //AllItems.Add(new ItemSpec("Serial Nr large WM", "s/n", null, (x, y, z) => x.SerialNr())); //AllItems.Add(new ItemSpec("Serial Nr small WM", "s/n", null, (x, y, z) => y.SerialNr())); //AllItems.Add(new ItemSpec("End state large WM", "End state", null, (x, y, z) => x.EndState())); //AllItems.Add(new ItemSpec("End state small WM", "End state", null, (x, y, z) => y.EndState())); /// Batch info AllItems.Add(new WMeterRsltItemSpec(ItemID.Test_bench_ID, Strings.Bench, (w, t, u, f, p) => w.Batch.TestBenchId.ToString())); AllItems.Add(new WMeterRsltItemSpec(ItemID.Program_version, Strings.Ver, (w, t, u, f, p) => w.Batch.ProgramVersion)); AllItems.Add(new WMeterRsltItemSpec(ItemID.User_name, Strings.User, (w, t, u, f, p) => w.Batch.UserName)); AllItems.Add(new WMeterRsltItemSpec(ItemID.User_nr, Strings.User_nr, (w, t, u, f, p) => w.Batch.UserNumber.ToString())); AllItems.Add(new WMeterRsltItemSpec(ItemID.Watermeters, Strings.WMs, (w, t, u, f, p) => w.Batch.WatermetersStr)); AllItems.Add(new WMeterRsltItemSpec(ItemID.Protocol_title, Strings.Protocol, (w, t, u, f, p) => w.Batch.ProtocolTitle)); AllItems.Add(new WMeterRsltItemSpec(ItemID.Batch_start_time, Strings.Start, (w, t, u, f, p) => string.IsNullOrEmpty(f) ? w.Batch.StartTime.ToString() : string.Format(f, w.Batch.StartTime))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Batch_end_time, Strings.End, (w, t, u, f, p) => string.IsNullOrEmpty(f) ? w.Batch.EndTime.ToString() : string.Format(f, w.Batch.EndTime))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Lite_per_pulse_Read, "1 / PlsPerLtr_Read", (w, t, u, f, p) => string.IsNullOrEmpty(p) ? ((w.WaterMeterData.PulsesPerLtr != 0) ? 1 / w.WaterMeterData.PulsesPerLtr : 0).ToString() : ((w.WaterMeterData.PulsesPerLtr != 0) ? 1 / w.WaterMeterData.PulsesPerLtr : 0).ToString(p))); /// Extra water meter data AllItems.Add(new WMeterRsltItemSpec(ItemID.Result_code, Strings.Result_code, (w, t, u, f, p) => string.IsNullOrEmpty(f) ? w.ResultCode.ToString() : string.Format(f, w.ResultCode))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Remark, Strings.Remark, (w, t, u, f, p) => w.Batch.Remark)); } /// /// Converts a list of 'Output item specifications' to a string array /// /// /// public static string[] ToStrArray(IList items) { int count = (items != null) ? items.Count : 0; string[] result = new string[count]; for (int i = 0; i < count; i++) { result[i] = string.Format("{0}~{1}~{2}~{3}~{4}~{5}~{6}~{7}", items[i].Uid, items[i].Caption, items[i].TestID, items[i].Units, items[i].Format, items[i].Precision, items[i].Width, items[i].Alignment); } return result; } /// /// Converts a string array to a list of 'Output item specifications' /// /// /// public static IList FromStrArray(string[] strArray) { IList result = new List(); if (strArray != null) { for (int i = 0; i < strArray.Length; i++) { string[] field = strArray[i].Split(new char[] { '~' }); try { WMeterRsltItemSpec item = GetItem(int.Parse(field[0])); item.Caption = field[1]; item.TestID = field[2]; item.Units = 0; for (Config.Unit u = 0; u < Config.Unit.Count; u++) if (u.ToString().Equals(field[3])) { item.Units = u; break; } item.Format = field[4]; item.Precision = field[5]; item.Width = int.Parse(field[6]); item.Alignment = 0; for (Config.Entities.Alignment a = 0; a < Config.Entities.Alignment.Count; a++) if (a.ToString().Equals(field[7])) { item.Alignment = a; break; } result.Add(item); } catch { WMeterRsltItemSpec item = GetItem(0); item.Format = string.Format("Parse error: {0}", strArray[i]); result.Add(item); } } } return result; } public static WMeterRsltItemSpec GetItem(int uid) { foreach (var item in AllItems) { if (item.Uid == uid) return item.Clone(); } return null; } public static WMeterRsltItemSpec GetItem(ItemID itemId) { return GetItem((int)itemId); } } }