using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media; using System.Xml.Serialization; using Tango.BL.Entities; using Tango.SharedUI.Helpers; namespace Tango.MachineStudio.Technician.TechItems { /// /// Represents an analog style integer monitor item. /// /// [TechItem(2, true)] public class MonitorItem : TechItem { private String _format; private TechMonitor _techMonitor; /// /// Gets or sets the db tech monitor. /// [XmlIgnore] public TechMonitor TechMonitor { get { return _techMonitor; } set { _techMonitor = value; RaisePropertyChangedAuto(); TechName = _techMonitor != null ? _techMonitor.Description : null; ItemGuid = value != null ? value.Guid : null; } } private double _value; /// /// Gets or sets the current value. /// [XmlIgnore] public double Value { get { return _value; } set { _value = Math.Round(value, DecimalPoints); RaisePropertyChanged(nameof(Value)); RaisePropertyChanged(nameof(ValueString)); LastUpdateTime = DateTime.Now; } } public String ValueString { get { return _value.ToString($"F{DecimalPoints}"); } } private int _updateInterval; /// /// Gets or sets the update interval. /// public int UpdateInterval { get { return _updateInterval; } set { _updateInterval = value; RaisePropertyChangedAuto(); } } private int _decimalPoints; /// /// Gets or sets the decimal points. /// public int DecimalPoints { get { return _decimalPoints; } set { _decimalPoints = value; RaisePropertyChangedAuto(); if (_decimalPoints > 0) { _format = "0." + String.Join("", Enumerable.Range(0, DecimalPoints).Select(x => "#")); } else { _format = "0"; } } } /// /// Gets or sets the last update time. /// [XmlIgnore] public DateTime LastUpdateTime { get; set; } /// /// Initializes a new instance of the class. /// public MonitorItem() : base() { Name = "Monitor"; Color = Colors.White; Description = "Simple analogue monitor"; Image = ResourceHelper.GetImageFromResources("Images/analog.png"); LastUpdateTime = DateTime.Now; UpdateInterval = 10; DecimalPoints = 2; } /// /// Initializes a new instance of the class. /// /// The db tech monitor. public MonitorItem(TechMonitor techMonitor) : this() { TechMonitor = techMonitor; } /// /// Clones this instance. /// /// public override TechItem Clone() { MonitorItem cloned = base.Clone() as MonitorItem; cloned.TechMonitor = TechMonitor; cloned.UpdateInterval = UpdateInterval; cloned.DecimalPoints = DecimalPoints; return cloned; } } }