Ejemplo n.º 1
0
        public ObservableCollection <T> Load()
        {
            this.Logger.Log(LogLevel.Debug, "Loading {0}...", this.SettingName);

            string str = this.GetLocalSetting();

            if (String.IsNullOrEmpty(str))
            {
                return(this.CreateNew());
            }

            List <T> list = Deserialize(str);

            ObservableCollection <T> result = new ObservableCollection <T>(list);

            // Clear the dirty flag.
            if (list.Count > 0 && list[0] is IDirty)
            {
                foreach (T item in list)
                {
                    IDirty dirtyObject = (IDirty)item;
                    dirtyObject.Dirty = false;
                }
            }

            this.Logger.Log(LogLevel.Info, "{0} {1} loaded", list.Count, this.SettingName);

            return(result);
        }
Ejemplo n.º 2
0
        internal static void MarkDirtySafe(this IDirty dirty)
        {
            if (dirty == null)
            {
                return;
            }

            dirty.MarkDirty();
        }
Ejemplo n.º 3
0
        public IEnumerable <UserModel> GetUsers(IDirty viewModel)
        {
            IEnumerable <UserModel> users = _dataSource.GetUsers();

            foreach (UserModel user in users)
            {
                user.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(viewModel.PropertyDirty);
            }

            return(users);
        }
        public RegisterRangeViewModel(IModbusAdapterProvider modbusAdapterProvider, RangeModel rangeModel, SlaveViewModel parent, IDirty dirty)
            : base(dirty)
        {
            if (rangeModel == null)
                throw new ArgumentNullException(nameof(rangeModel));

            _parent = parent;
            _dirty = dirty;
            _modbusAdapterProvider = modbusAdapterProvider;

            EditCommand = new RelayCommand(Edit, CanEdit);
            ReadCommand = new RelayCommand(Read, CanRead);
            WriteCommand = new RelayCommand(Write, CanWrite);
            DeleteCommand = new RelayCommand(Delete, CanDelete);

            PopulateFromModel(rangeModel);
        }
Ejemplo n.º 5
0
        public RegisterRangeViewModel(IModbusAdapterProvider modbusAdapterProvider, RangeModel rangeModel, SlaveViewModel parent, IDirty dirty)
            : base(dirty)
        {
            if (rangeModel == null)
            {
                throw new ArgumentNullException(nameof(rangeModel));
            }

            _parent = parent;
            _dirty  = dirty;
            _modbusAdapterProvider = modbusAdapterProvider;


            EditCommand   = new RelayCommand(Edit, CanEdit);
            ReadCommand   = new RelayCommand(Read, CanRead);
            WriteCommand  = new RelayCommand(Write, CanWrite);
            DeleteCommand = new RelayCommand(Delete, CanDelete);

            PopulateFromModel(rangeModel);
        }
Ejemplo n.º 6
0
        public void Save(ObservableCollection <T> list)
        {
            this.Logger.Log(LogLevel.Debug, "Saving {0}...", this.SettingName);

            List <T> temp = list.ToList();
            string   str  = Serialize(temp);

            this.SetLocalSetting(str);

            // Clear the dirty flag.
            if (list.Count > 0 && list[0] is IDirty)
            {
                foreach (T item in list)
                {
                    IDirty dirtyObject = (IDirty)item;
                    dirtyObject.Dirty = false;
                }
            }

            this.Logger.Log(LogLevel.Debug, "{0} {1} saved.", list.Count, this.SettingName);
        }
        public SlaveViewModel(IModbusAdapterProvider modbusAdapterProvider, SlaveModel slaveModel, IDirty dirty)
        {
            _modbusAdapterProvider = modbusAdapterProvider;
            _dirty = dirty;
            if (slaveModel == null) throw new ArgumentNullException(nameof(slaveModel));

            Name = slaveModel.Name;
            SlaveId = slaveModel.SlaveId;

            AddRegistersCommand = new RelayCommand(AddRegisters, CanAdd);

            if (slaveModel.Ranges != null)
            {
                foreach (var range in slaveModel.Ranges)
                {
                    var rangeViewModel = new RegisterRangeViewModel(modbusAdapterProvider, range, this, _dirty);

                    _ranges.Add(rangeViewModel);
                }
            }

            RenameCommand = new RelayCommand(Rename, CanRename);
        }
 protected RangeViewModelBase(IDirty dirty)
 {
     _dirty = dirty;
 }
Ejemplo n.º 9
0
 internal Task GetPopulateDirtyAsync(string?requestUri, string?queryString, string methodName, string?resourceId, IDirty target, bool populate, CancellationToken cancellationToken) => PopulateDirtyInternalAsync(HttpMethod.Get, requestUri, queryString, null, methodName, resourceId, target, populate, cancellationToken);
Ejemplo n.º 10
0
 protected RangeViewModelBase(IDirty dirty)
 {
     _dirty = dirty;
 }
Ejemplo n.º 11
0
 private Task PopulateDirtyInternalAsync(HttpMethod method, string requestUri, string queryString, HttpContent content, string methodName, string resourceId, IDirty target, bool populate, CancellationToken cancellationToken) => SendAsync(method, requestUri, queryString, content, methodName, resourceId, cancellationToken, async response =>
 {
     if (populate)
     {
         await response.Content.PopulateAsync(target).ConfigureAwait(false);
     }
     target.Dirty = false;
     return(string.Empty);
 });
Ejemplo n.º 12
0
 internal Task PutPopulateDirtyAsync(string requestUri, string queryString, HttpContent content, string methodName, string resourceId, IDirty target, bool populate, CancellationToken cancellationToken) => PopulateDirtyInternalAsync(HttpMethod.Put, requestUri, queryString, content, methodName, resourceId, target, populate, cancellationToken);
Ejemplo n.º 13
0
 internal Task PatchPopulateDirtyAsync(string requestUri, HttpContent content, string methodName, string resourceId, IDirty target, bool populate, CancellationToken cancellationToken) => PopulateDirtyInternalAsync(s_patchMethod, requestUri, populate ? ViewEntityQueryString : null, content, methodName, resourceId, target, populate, cancellationToken);