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);
        }
        private void Open()
        {
            if (!SaveIfDirty())
                return;

            var dialog = new OpenFileDialog()
            {
                Filter = Filter
            };

            if (dialog.ShowDialog() == true)
            {
                _path = dialog.FileName;

                //Load up the project
                var projectModel = ProjectFactory.LoadProject(_path);

                //Get the slave (we're only going to grab the first one
                var slaveModel = projectModel?.Slaves?.FirstOrDefault() ?? new SlaveModel();

                //Create the view model
                Slave = new SlaveViewModel(_modbusAdapters, slaveModel, _dirty);

                //We're clean people.
                _dirty.MarkClean();
            }

            RaisePropertyChanged(() => Title);
        }
        private void New()
        {
            if (!SaveIfDirty())
                return;

            Slave = new SlaveViewModel(_modbusAdapters, new SlaveModel(), _dirty);

            _dirty.MarkClean();
        }