예제 #1
0
        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);
        }
예제 #2
0
        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);
        }