public List <EditorValidationErrorViewModel> CheckItem(List <EditorValidationErrorViewModel> initialErrors, IConfigurationItemViewModel configurationEditorViewModel) { if (configurationEditorViewModel is IPropertyEditorViewModel propertyEditorViewModel && !(configurationEditorViewModel is IComplexPropertyEditorViewModel)) { var resources = propertyEditorViewModel.DependencyViewModels .Where(model => model is ConditionResultDependencyViewModel) .Select(model => (model as ConditionResultDependencyViewModel).SelectedConditionViewModel) .Where(model => model is RegexMatchConditionViewModel) .Cast <RegexMatchConditionViewModel>() .Select(model => _sharedResourcesGlobalViewModel.GetResourceViewModelByName(model.ReferencedResourcePropertyName)) .Choose() .Where(nameable => nameable is IPropertyEditorViewModel) .Select(nameable => (nameable as IPropertyEditorViewModel).FormatterParametersViewModel) .ToList(); if (resources.Any(model => !_formatterInfoService.ReturnsString(model.RelatedUshortsFormatterViewModel))) { initialErrors.Add(new EditorValidationErrorViewModel( $"{propertyEditorViewModel.Name} ({_localizerService.GetLocalizedString("Address")}:{propertyEditorViewModel.Address}): {_localizerService.GetLocalizedString(ApplicationGlobalNames.StatusMessages.REGEX_RESOURCE_FORMATTER_IS_NOT_STRING_MESSAGE)}", Result <Action> .Create( () => { _dependenciesService.EditDependencies(propertyEditorViewModel, new DependenciesConfiguration(("ConditionResultDependency", () => _dependencyFillHelper.CreateEmptyConditionResultDependencyViewModel()))); }, true))); } } if (configurationEditorViewModel is IConfigurationGroupEditorViewModel configurationGroupEditorViewModel) { configurationGroupEditorViewModel.ChildStructItemViewModels.ForEach(model => CheckItem(initialErrors, model)); } if (configurationEditorViewModel is IComplexPropertyEditorViewModel complexPropertyEditorViewModel) { complexPropertyEditorViewModel.SubPropertyEditorViewModels.ForEach(model => CheckItem(initialErrors, model)); } return(initialErrors); }
public List <EditorValidationErrorViewModel> CheckItem(List <EditorValidationErrorViewModel> initialErrors, IConfigurationItemViewModel configurationEditorViewModel) { if (configurationEditorViewModel is IPropertyEditorViewModel propertyEditorViewModel && !(configurationEditorViewModel is IComplexPropertyEditorViewModel)) { var dependenciesWithResources = propertyEditorViewModel.DependencyViewModels .Where(model => model is ConditionResultDependencyViewModel) .Select(model => (model as ConditionResultDependencyViewModel).SelectedConditionViewModel) .Where(model => model is IConditionWithResourceViewModel) .Cast <IConditionWithResourceViewModel>() .ToList(); if (dependenciesWithResources.Any(model => string.IsNullOrEmpty(model.ReferencedResourcePropertyName)) || dependenciesWithResources.Any(model => !_sharedResourcesGlobalViewModel.GetResourceViewModelByName( model.ReferencedResourcePropertyName).IsSuccess)) { initialErrors.Add(new EditorValidationErrorViewModel( $"{propertyEditorViewModel.Name} ({_localizerService.GetLocalizedString("Address")}:{propertyEditorViewModel.Address}): {_localizerService.GetLocalizedString(ApplicationGlobalNames.StatusMessages.RESOURCE_FOR_DEPENDENCY_NOT_FOUND_MESSAGE)}", Result <Action> .Create( () => { _dependenciesService.EditDependencies(propertyEditorViewModel, new DependenciesConfiguration(("ConditionResultDependency", () => _dependencyFillHelper.CreateEmptyConditionResultDependencyViewModel()))); }, true))); } } if (configurationEditorViewModel is IConfigurationGroupEditorViewModel configurationGroupEditorViewModel) { configurationGroupEditorViewModel.ChildStructItemViewModels.ForEach(model => CheckItem(initialErrors, model)); } if (configurationEditorViewModel is IComplexPropertyEditorViewModel complexPropertyEditorViewModel) { complexPropertyEditorViewModel.SubPropertyEditorViewModels.ForEach(model => CheckItem(initialErrors, model)); } return(initialErrors); }
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); }