Example #1
0
        public async Task BitOwnershipHelperCheckNoSameAddresses()
        {
            List <IConfigurationItemViewModel> list = new List <IConfigurationItemViewModel>();


            var property = EditorHelpers.AddPropertyViewModel(list, 1, _typesContainer);

            var res = BitOwnershipHelper.CreateBitViewModelsWithOwnership(
                property, list);

            Assert.True(res.All(model => model.IsBitEditEnabled));
        }
Example #2
0
        public async Task BitOwnershipHelperCheckOneBitWithSameAddress()
        {
            List <IConfigurationItemViewModel> list = new List <IConfigurationItemViewModel>();


            var property   = EditorHelpers.AddPropertyViewModel(list, 1, _typesContainer);
            var secondProp = EditorHelpers.AddPropertyViewModel(list, 1, _typesContainer);

            secondProp.IsFromBits = true;
            property.IsFromBits   = true;
            secondProp.BitNumbersInWord[15].IsChecked = true;
            var res = BitOwnershipHelper.CreateBitViewModelsWithOwnership(
                property, list);

            Assert.False(res[15].IsBitEditEnabled);
            Assert.True(res.Where(model => model != res[15]).All(model => model.IsBitEditEnabled));
        }
        public FormatterSelectionViewModel(ITypesContainer container,
                                           List <IUshortFormattableEditorViewModel> ushortFormattableViewModels,
                                           List <IConfigurationItemViewModel> rootConfigurationItemViewModels)
        {
            CurrentResourceString       = null;
            _container                  = container;
            _ushortFormattableViewModel = ushortFormattableViewModels;

            _sharedResourcesGlobalViewModel = _container.Resolve <ISharedResourcesGlobalViewModel>();

            _ushortsFormatterViewModels = new ObservableCollection <IUshortsFormatterViewModel>();
            UshortsFormatterViewModels.AddCollection(_container.ResolveAll <IUshortsFormatterViewModel>());
            BitNumbersInWord = new ObservableCollection <IBitViewModel>();

            // for (int i = 15; i >= 0; i--)
            // {
            //    IBitViewModel bitViewModel = new BitViewModel(i, true);
            //   BitNumbersInWord.Add(bitViewModel);
            //}

            IsBitsEditingEnabled = false;


            if (ushortFormattableViewModels.Count == 1)
            {
                var ushortFormattableViewModel = ushortFormattableViewModels.First();

                if (ushortFormattableViewModel is IBitsConfigViewModel bitsConfigViewModel)
                {
                    BitNumbersInWord.AddCollection(
                        BitOwnershipHelper.CreateBitViewModelsWithOwnership(bitsConfigViewModel,
                                                                            rootConfigurationItemViewModels));
                    bitsConfigViewModel.CopyBitsTo(this);
                    IsBitsEditingEnabled = true;
                }

                if (ushortFormattableViewModel.FormatterParametersViewModel != null)
                {
                    if (_sharedResourcesGlobalViewModel.GetResourceViewModelByName(
                            ushortFormattableViewModel.FormatterParametersViewModel.Name).IsSuccess)
                    {
                        CurrentResourceString    = ushortFormattableViewModel.FormatterParametersViewModel.Name;
                        _isFormatterFromResource = true;
                        ushortFormattableViewModel.FormatterParametersViewModel.RelatedUshortsFormatterViewModel =
                            container.Resolve <IFormatterViewModelFactory>().CreateFormatterViewModel(
                                _sharedResourcesGlobalViewModel.GetResourceByName(_currentResourceString) as
                                IUshortsFormatter).RelatedUshortsFormatterViewModel;
                    }

                    var formatter =
                        _ushortsFormatterViewModels.FirstOrDefault(f =>
                                                                   f.StrongName == ushortFormattableViewModel.FormatterParametersViewModel
                                                                   .RelatedUshortsFormatterViewModel.StrongName);
                    var existingIndex =
                        _ushortsFormatterViewModels.IndexOf(formatter);
                    _ushortsFormatterViewModels.RemoveAt(existingIndex);
                    _ushortsFormatterViewModels.Insert(existingIndex,
                                                       ushortFormattableViewModel.FormatterParametersViewModel.RelatedUshortsFormatterViewModel);
                    SelectedUshortsFormatterViewModel = ushortFormattableViewModel.FormatterParametersViewModel
                                                        .RelatedUshortsFormatterViewModel;
                }
            }

            CancelCommand              = new RelayCommand <object>(OnCancelExecute);
            OkCommand                  = new RelayCommand <object>(OnOkExecute);
            ResetCommand               = new RelayCommand(OnResetExecute);
            AddAsResourceCommand       = new RelayCommand(OnAddAsResourceExecute);
            SelectFromResourcesCommand = new RelayCommand(OnSelectFromResourcesExecute);
        }