using System; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Controls; using ProductionUiCordonelLegacy.ProductionProcesses.Enum; using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore; namespace ProductionUiCordonelLegacy.ProductionProcesses { public abstract class BaseProductionProcess : IProductionProcess { private Int32 _progress; public Int32 Progress { get => _progress; set { _progress = value; PopUpProcessProgressChangedHandler?.Invoke(this, new PopUpProcessProgressArgs(_progress, PopUpProcessProgressArgs.ProcessProgessType.SubProcess)); } } public ProductionProcessState currentProcessState; public String name; public GenesisMeter Meter { get; internal set; } public event EventHandler PopUpProcessStateChangedHandler; public event EventHandler PopUpProcessLogHandler; public event EventHandler PopUpProcessProgressChangedHandler; StringBuilder sbLog = new StringBuilder(); public String GetName() { return name; } public ProductionProcessState GetState() { return currentProcessState; } public UserControl GetUserControl() { return GetControl(); } public abstract UserControl GetControl(); public abstract void StartProcess(); public abstract void ProcessDone(); public void Start(GenesisMeter meter, CancellationToken cancellationToken) { Meter = meter; currentProcessState = ProductionProcessState.Started; PopUpProcessStateChangedHandler?.Invoke(this, EventArgs.Empty); StartProcess(); NewStatus($"Starte {name}"); while (currentProcessState == ProductionProcessState.Started) { Task.Delay(500); } ProcessDone(); NewStatus($"Prozess {name} is beendet (code:{currentProcessState.GetHashCode()})"); PopUpProcessStateChangedHandler?.Invoke(this, EventArgs.Empty); } internal void NewStatus(String v) { PopUpProcessLogHandler?.Invoke(this, new PopUpProcessLogArgs(v)); sbLog.AppendLine(v); Meter.WriteLog($"{name} : {v}"); } public abstract void InitUserControl(); public void Init() { InitUserControl(); } } }