using System; using System.Linq; using System.Windows.Controls; using System.Windows.Threading; using ProductionUiCordonelLegacy.ProductionProcesses.Enum; using ProductionUiCordonelLegacy.UserControls.FinalTest; using Xylem.Common.Hardware.WaterMeter.Genesis.Registers; namespace ProductionUiCordonelLegacy.ProductionProcesses.Actions { public class ProductionProcessFullReadOut : BaseProductionProcess { private UcFullReadOut UserControl; public ProductionProcessFullReadOut() { name = "Sicherung des Zählerzustandes"; currentProcessState = ProductionProcessState.Waiting; } public override void InitUserControl() { UserControl = new UcFullReadOut(); } public override UserControl GetControl() { if (UserControl == null) { throw new Exception($"UserControl {GetType()} not Ready"); } return UserControl; } public override void ProcessDone() { //clear } public override void StartProcess() { try { UserControl.lblHl.Dispatcher.Invoke(DispatcherPriority.Send, new Action(() => { UserControl.lblHl.Content = "Read out Registers"; } )); var oldConfigEntry = Meter.Configuration.UseRegisterWatchService; if (oldConfigEntry) { Meter.Configuration.UseRegisterWatchService = false; } var total = Meter.GetRegistersDic().Keys.ToList(); var done = 0; foreach (var dic in total) { try { var done1 = done; UserControl.lblText.Dispatcher.Invoke(DispatcherPriority.Send, new Action(() => { UserControl.lblText.Content = $"Read {dic.GetIdent()}({done1}/{total.Count})"; } )); if (dic.RegisterName.ToLower() != "password" && dic.RegisterDetail.Privilege.Lvl8 != Access.WO) { switch (dic.GetIdent().ToLower()) { case "sensusradio_encryptionkey": Meter.ReadRegister(dic.GetIdent(), 32); break; default: if (dic.DataType == typeof(UInt64) || dic.DataType == typeof(Int64)) { Meter.ReadRegister(dic.GetIdent(), 32); } else { Meter.ReadRegister(dic.GetIdent()); } break; } } Progress = (Int32)Math.Round(((Double)done / total.Count) * 100, 0); } catch (Exception ) { //todo: error logger } done += 1; } Meter.StoreCurrentRegisterDic(); Meter.Configuration.UseRegisterWatchService = oldConfigEntry; currentProcessState = ProductionProcessState.Done; } catch (Exception ) { currentProcessState = ProductionProcessState.Error; } } } }