using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using Tango.BL.Entities; using Tango.BL.Enumerations; using Tango.FSE.Common.Diagnostics; namespace Tango.FSE.Diagnostics.Project.Widgets.Input { [Description("Digital Input LED")] public class InputWidget : DiagnosticsWidget, ISupportsComponentSelection { public TechIos IO { get; set; } = TechIos.LS_DH_CLEAN_DOWN; private TechIo _techIO; [JsonIgnore] public TechIo TechIo { get { return _techIO; } set { _techIO = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(DisplayName)); } } [JsonIgnore] public override string DisplayName { get { return this.TechIo != null ? this.TechIo.InterfaceName : String.Empty; } } private bool _value; [JsonIgnore] public bool Value { get { return _value; } set { if (_value != value) { _value = value; RaisePropertyChangedAuto(); } } } public override async Task Init() { int io = (int)IO; TechIo = await Services.TechComponentsService.IOs.FindOne(x => x.Code == io); } public override void OnDiagnosticsData(DiagnosticsPackage package) { var state = package.GetDigitalInterfaceState(IO); if (state != null) { Value = state.Value; } } public override FrameworkElement GetView() { return new InputWidgetView(); } #region Component Selection public List> Components { get { return Services.TechComponentsService.IOs.FindAll().Result.Where(x => x.Type == (int)IOType.DigitalInput).Select(x => new DiagnosticsWidgetComponent() { DisplayName = x.InterfaceName, Object = (TechIos)x.Code, }).OrderByAlphaNumeric(x => x.DisplayName).ToList(); } } public TechIos SelectedComponent { get { return IO; } set { if (IO != value) { IO = value; InitAsync(); } } } public bool EnableComponentSelection { get; set; } #endregion } }