using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ShakerService.ViewModel { internal abstract class ViewModelBase : ViewModelBase where TModel :IModel.IModel { public virtual bool AllowSave => true; public ViewModelBase():base() { if(typeof(TModel).IsAnsiClass && !typeof(TModel).IsAbstract) { ReadModel(); SetFpga(); if (AllowSave) { Communication.Instance.Context.GetEvent()?.Subscrip((sender, args) => { UpModel(args.Data); }); } } } private protected virtual void ReadModel() { } private protected virtual void UpModel(TModel model) { CurrentModel = model; SetFpga(); SaveModel(); } private protected virtual void SaveModel() { } [AllowNull] public TModel CurrentModel { get; private protected set; } } }