Пример #1
0
        public static Result MigrateComplexProperties(List <IConfigurationItemViewModel> preparedData)
        {
            var sharedResourcesService = StaticContainer.Container.Resolve <ISharedResourcesGlobalViewModel>();

            try
            {
                var factory = ConfigurationItemEditorViewModelFactory.Create();
                foreach (var preparedItem in preparedData)
                {
                    if (preparedItem is IComplexPropertyEditorViewModel complexPropertyEditorViewModel)
                    {
                        if (complexPropertyEditorViewModel.IsGroupedProperty)
                        {
                            var group = factory.WithParent(
                                complexPropertyEditorViewModel.Parent as IEditorConfigurationItemViewModel)
                                        .VisitItemsGroup(null);
                            (group as IItemGroupViewModel).IsMain =
                                (complexPropertyEditorViewModel.Parent as IItemGroupViewModel).IsMain;
                            (group as IItemGroupViewModel).IsTableViewAllowed =
                                (complexPropertyEditorViewModel.Parent as IItemGroupViewModel).IsTableViewAllowed;

                            var propList =
                                ConvertComlexPropertyIntoDefaultProperties(complexPropertyEditorViewModel, group);

                            propList.resources.ForEach(tuple =>
                            {
                                sharedResourcesService.AddAsSharedResourceWithContainer(tuple.resource,
                                                                                        tuple.resourceName, false);
                            });
                            complexPropertyEditorViewModel.Parent.ChildStructItemViewModels.Add(group);
                            propList.convertedProperties.ForEach(model => { group.ChildStructItemViewModels.Add(model); });
                            group.IsCheckable = propList.convertedProperties.Any();
                            group.Name        = complexPropertyEditorViewModel.Name;
                            group.Header      = complexPropertyEditorViewModel.Header;
                            group.Description = complexPropertyEditorViewModel.Description;
                        }
                        else
                        {
                            var propList = ConvertComlexPropertyIntoDefaultProperties(complexPropertyEditorViewModel,
                                                                                      complexPropertyEditorViewModel.Parent as IEditorConfigurationItemViewModel);

                            propList.resources.ForEach(tuple =>
                            {
                                sharedResourcesService.AddAsSharedResourceWithContainer(tuple.resource,
                                                                                        tuple.resourceName, false);
                            });
                            propList.convertedProperties.ForEach(model => { complexPropertyEditorViewModel.Parent.ChildStructItemViewModels.Add(model); });
                        }
                        complexPropertyEditorViewModel.Parent.Checked?.Invoke(false);
                        complexPropertyEditorViewModel.DeleteElement();
                    }
                }

                return(Result.Create(true));
            }
            catch (Exception e)
            {
                return(Result.Create(e));
            }
        }
        public IConfigurationItemViewModel AddMatrix()
        {
            IEditorConfigurationItemViewModel newConfigurationItemViewModel =
                ConfigurationItemEditorViewModelFactory.Create().WithParent(this).VisitMatrix(null);

            ChildStructItemViewModels.Add(newConfigurationItemViewModel);
            return(newConfigurationItemViewModel);
        }
Пример #3
0
        private void OnAddRootElement()
        {
            IEditorConfigurationItemViewModel configurationItemViewModel =
                ConfigurationItemEditorViewModelFactory.Create().VisitProperty(null);

            AllRows.Add(configurationItemViewModel);
            RootConfigurationItemViewModels.Add(configurationItemViewModel);
            SelectedRow = configurationItemViewModel;
            CompleteAdding();
        }
        public IConfigurationItemViewModel AddSubProperty()
        {
            IEditorConfigurationItemViewModel subPropertyViewModel =
                ConfigurationItemEditorViewModelFactory.Create().WithParent(this).VisitSubProperty(null);

            (subPropertyViewModel as ISubPropertyEditorViewModel).BitNumbersInWord =
                this.MainBitNumbersInWordCollection;

            this.SubPropertyEditorViewModels.Add(subPropertyViewModel as ISubPropertyEditorViewModel);
            this.ChildStructItemViewModels.Add(subPropertyViewModel);
            return(subPropertyViewModel);
        }
Пример #5
0
        ConvertComlexPropertyIntoDefaultProperties(IComplexPropertyEditorViewModel complexPropertyEditorViewModel,
                                                   IEditorConfigurationItemViewModel parent)
        {
            List <IPropertyEditorViewModel> res = new List <IPropertyEditorViewModel>();
            List <(string resourceName, IPropertyEditorViewModel resource)> resourcesResult =
                new List <(string resourceName, IPropertyEditorViewModel resource)>();

            foreach (var subPropertyEditorViewModel in complexPropertyEditorViewModel.SubPropertyEditorViewModels)
            {
                var factory = ConfigurationItemEditorViewModelFactory.Create().WithParent(parent);
                var bits    = subPropertyEditorViewModel.BitNumbersInWord.Where(model =>
                                                                                model.Value && model.Owner == subPropertyEditorViewModel).ToList();

                var property = factory.VisitProperty(null) as IPropertyEditorViewModel;
                property.Name                  = subPropertyEditorViewModel.Name;
                property.Header                = subPropertyEditorViewModel.Header;
                property.Address               = complexPropertyEditorViewModel.Address;
                property.Description           = subPropertyEditorViewModel.Description;
                property.NumberOfWriteFunction = complexPropertyEditorViewModel.NumberOfWriteFunction;
                property.NumberOfPoints        = complexPropertyEditorViewModel.NumberOfPoints;
                property.IsMeasureUnitEnabled  = subPropertyEditorViewModel.IsMeasureUnitEnabled;
                property.MeasureUnit           = subPropertyEditorViewModel.MeasureUnit;
                property.IsRangeEnabled        = subPropertyEditorViewModel.IsRangeEnabled;
                property.DependencyViewModels.AddCollection(subPropertyEditorViewModel.DependencyViewModels
                                                            .Select(model => model.Clone()));
                property.RangeViewModel = subPropertyEditorViewModel.RangeViewModel.Clone() as IRangeViewModel;

                property.IsFromBits = true;
                property.FormatterParametersViewModel = subPropertyEditorViewModel.FormatterParametersViewModel?.Clone();
                foreach (var bit in bits)
                {
                    property.BitNumbersInWord.First(model => model.BitNumber == bit.NumberOfBit).IsChecked =
                        true;
                }

                var sharedResourcesService = StaticContainer.Container.Resolve <ISharedResourcesGlobalViewModel>();

                var resourceInfo = sharedResourcesService.GetNameByResourceViewModel(subPropertyEditorViewModel);
                if (resourceInfo.IsSuccess)
                {
                    resourcesResult.Add((resourceInfo.Item, property));
                    sharedResourcesService.RemoveResourceByViewModel(subPropertyEditorViewModel);
                }


                res.Add(property);
            }

            return(res, resourcesResult);
        }
Пример #6
0
        public static IPropertyEditorViewModel AddPropertyViewModel(
            IList <IConfigurationItemViewModel> collection, int identity, ITypesContainer typesContainer)
        {
            IPropertyEditorViewModel rootProperty =
                ConfigurationItemEditorViewModelFactory.Create().VisitProperty(null) as IPropertyEditorViewModel;

            rootProperty.Address               = (identity + _addressModifier).ToString();
            rootProperty.NumberOfPoints        = (identity + _numOfPointsModifier).ToString();
            rootProperty.Name                  = (identity + _nameModifier).ToString();
            rootProperty.NumberOfWriteFunction = (ushort)(identity + _numOfFunctionModifier);
            collection?.Add(rootProperty);

            InitFormatterViewModel(rootProperty, CreateFormatterViewModel(identity, typesContainer));
            return(rootProperty);
        }
Пример #7
0
        public static IPropertyEditorViewModel AddPropertyWithFormatterFromResourceViewModel(
            ObservableCollection <IConfigurationItemViewModel> collection, int identity)
        {
            IPropertyEditorViewModel property =
                ConfigurationItemEditorViewModelFactory.Create().VisitProperty(null) as IPropertyEditorViewModel;

            property.Address               = (identity + _addressModifier).ToString();
            property.NumberOfPoints        = (identity + _numOfPointsModifier).ToString();
            property.Name                  = (identity + _nameModifier).ToString();
            property.NumberOfWriteFunction = (ushort)(identity + _numOfFunctionModifier);
            collection.Add(property);
            property.FormatterParametersViewModel = new FormatterParametersViewModel()
            {
                Name = "formatter" + identity,
                IsFromSharedResources = true,
            };
            return(property);
        }
Пример #8
0
        public static IPropertyEditorViewModel AddPropertyWithBitsViewModel(
            IList <IConfigurationItemViewModel> collection, int identity, ITypesContainer typesContainer)
        {
            IPropertyEditorViewModel rootProperty =
                ConfigurationItemEditorViewModelFactory.Create().VisitProperty(null) as IPropertyEditorViewModel;

            rootProperty.Address               = (identity + _addressModifier).ToString();
            rootProperty.NumberOfPoints        = (identity + _numOfPointsModifier).ToString();
            rootProperty.Name                  = (identity + _nameModifier).ToString();
            rootProperty.NumberOfWriteFunction = (ushort)(identity + _numOfFunctionModifier);
            collection?.Add(rootProperty);

            rootProperty.IsFromBits = true;
            rootProperty.BitNumbersInWord.FirstOrDefault(model => model.BitNumber == identity).IsChecked = true;

            InitFormatterViewModel(rootProperty, CreateFormatterViewModel(identity, typesContainer));
            return(rootProperty);
        }
Пример #9
0
        public void CheckMigrator()
        {
            var rootItems = new List <IConfigurationItemViewModel>();


            var complexProperty = ConfigurationItemEditorViewModelFactory.Create().VisitComplexProperty(null) as ComplexPropertyEditorViewModel;

            complexProperty.AddSubProperty();
            complexProperty.AddSubProperty();
            complexProperty.AddSubProperty();
            complexProperty.SubPropertyEditorViewModels[0].BitNumbersInWord[0].ChangeValueByOwnerCommand.Execute(complexProperty.SubPropertyEditorViewModels[0]);
            complexProperty.SubPropertyEditorViewModels[1].BitNumbersInWord[10].ChangeValueByOwnerCommand.Execute(complexProperty.SubPropertyEditorViewModels[1]);
            complexProperty.SubPropertyEditorViewModels[2].BitNumbersInWord[12].ChangeValueByOwnerCommand.Execute(complexProperty.SubPropertyEditorViewModels[2]);



            var complexProperty2 = ConfigurationItemEditorViewModelFactory.Create().VisitComplexProperty(null) as ComplexPropertyEditorViewModel;

            complexProperty2.AddSubProperty();
            complexProperty2.SubPropertyEditorViewModels[0].BitNumbersInWord[0].ChangeValueByOwnerCommand.Execute(complexProperty2.SubPropertyEditorViewModels[0]);
            complexProperty2.IsGroupedProperty = true;

            var rootGroup = new ConfigurationGroupEditorViewModel()
            {
                ChildStructItemViewModels = new ObservableCollection <IConfigurationItemViewModel>()
                {
                    complexProperty, complexProperty2
                }
            };

            complexProperty.Parent  = rootGroup;
            complexProperty2.Parent = rootGroup;

            rootItems.Add(rootGroup);


            var resPrepared = ComplexPropertiesMigrator.GetAllComplexPropertiesInConfiguration(rootItems);

            Assert.AreEqual(2, resPrepared.Count);

            var res = ComplexPropertiesMigrator.MigrateComplexProperties(resPrepared);

            Assert.True(res.IsSuccess);
        }
Пример #10
0
        public void RemoveSubproperty()
        {
            var configurationEditorViewModel = _typesContainer.Resolve <IFragmentEditorViewModel>(
                ApplicationGlobalNames.FragmentInjectcionStrings.CONFIGURATION +
                ApplicationGlobalNames.CommonInjectionStrings.EDITOR_VIEWMODEL) as ConfigurationEditorViewModel;

            var rootGroup = new ConfigurationGroupEditorViewModel()
            {
                Name = "root"
            };


            var complexPropertyEditorViewModel =
                ConfigurationItemEditorViewModelFactory.Create().VisitComplexProperty(null) as
                IComplexPropertyEditorViewModel;

            var subprop1 = ConfigurationItemEditorViewModelFactory.Create().WithParent(complexPropertyEditorViewModel)
                           .VisitSubProperty(null) as ISubPropertyEditorViewModel;
            var subprop2 = ConfigurationItemEditorViewModelFactory.Create().WithParent(complexPropertyEditorViewModel)
                           .VisitSubProperty(null) as ISubPropertyEditorViewModel;


            complexPropertyEditorViewModel.ChildStructItemViewModels.Add(subprop1);
            complexPropertyEditorViewModel.ChildStructItemViewModels.Add(subprop2);
            complexPropertyEditorViewModel.SubPropertyEditorViewModels.Add(subprop1);
            complexPropertyEditorViewModel.SubPropertyEditorViewModels.Add(subprop2);

            subprop1.BitNumbersInWord =
                complexPropertyEditorViewModel.MainBitNumbersInWordCollection;
            subprop2.BitNumbersInWord =
                complexPropertyEditorViewModel.MainBitNumbersInWordCollection;

            complexPropertyEditorViewModel.MainBitNumbersInWordCollection[0].ChangeValueByOwnerCommand
            .Execute(subprop1);
            complexPropertyEditorViewModel.MainBitNumbersInWordCollection[1].ChangeValueByOwnerCommand
            .Execute(subprop1);
            complexPropertyEditorViewModel.MainBitNumbersInWordCollection[2].ChangeValueByOwnerCommand
            .Execute(subprop2);
            complexPropertyEditorViewModel.MainBitNumbersInWordCollection[3].ChangeValueByOwnerCommand
            .Execute(subprop2);

            rootGroup.ChildStructItemViewModels.Add(complexPropertyEditorViewModel);

            configurationEditorViewModel.RootConfigurationItemViewModels.Add(rootGroup);

            var result = ConfigurationFragmentFactory.CreateConfiguration(configurationEditorViewModel);

            var resSubProp1 =
                ((result.RootConfigurationItemList[0] as IItemsGroup).ConfigurationItemList[0] as IComplexProperty)
                .SubProperties[0];
            var resSubProp2 =
                ((result.RootConfigurationItemList[0] as IItemsGroup).ConfigurationItemList[0] as IComplexProperty)
                .SubProperties[1];

            Assert.True(resSubProp1.BitNumbersInWord.Count == 2);
            Assert.True(resSubProp2.BitNumbersInWord.Count == 2);

            Assert.True(resSubProp1.BitNumbersInWord.Contains(15));
            Assert.True(resSubProp1.BitNumbersInWord.Contains(14));
            Assert.True(resSubProp2.BitNumbersInWord.Contains(13));
            Assert.True(resSubProp2.BitNumbersInWord.Contains(12));


            complexPropertyEditorViewModel.RemoveChildItem(subprop2);

            Assert.True(complexPropertyEditorViewModel.MainBitNumbersInWordCollection.All(model => model.Owner != subprop2));
            Assert.True(complexPropertyEditorViewModel.MainBitNumbersInWordCollection.First(model => model.NumberOfBit == 13).Value == false);
            Assert.True(complexPropertyEditorViewModel.MainBitNumbersInWordCollection.First(model => model.NumberOfBit == 12).Value == false);

            Assert.True(complexPropertyEditorViewModel.MainBitNumbersInWordCollection.First(model => model.NumberOfBit == 13).Owner == null);
            Assert.True(complexPropertyEditorViewModel.MainBitNumbersInWordCollection.First(model => model.NumberOfBit == 12).Owner == null);
        }
Пример #11
0
        public void GroupFilterSaveLoad()
        {
            var configurationEditorViewModel = _typesContainer.Resolve <IFragmentEditorViewModel>(
                ApplicationGlobalNames.FragmentInjectcionStrings.CONFIGURATION +
                ApplicationGlobalNames.CommonInjectionStrings.EDITOR_VIEWMODEL) as ConfigurationEditorViewModel;

            var rootGroup = new ConfigurationGroupEditorViewModel()
            {
                Name = "root"
            };

            rootGroup.FilterViewModels.AddRange(new ObservableCollection <IFilterViewModel>()
            {
                new FilterViewModel(new ObservableCollection <IConditionViewModel>())
                {
                    Name = "F1"
                },
                new FilterViewModel(new ObservableCollection <IConditionViewModel>()
                {
                    new CompareConditionViewModel(new List <string>()
                    {
                        "c1"
                    })
                    {
                        SelectedCondition    = ConditionsEnum.Equal.ToString(),
                        UshortValueToCompare = 1
                    }
                })
                {
                    Name = "F2"
                }
            });

            configurationEditorViewModel.RootConfigurationItemViewModels.Add(rootGroup);

            var result = ConfigurationFragmentFactory.CreateConfiguration(configurationEditorViewModel);

            var groupFilter = (result.RootConfigurationItemList[0] as IItemsGroup).GroupFilter as GroupFilterInfo;

            Assert.True(groupFilter.Filters.Count == 2);

            DefaultFilter defaultFilter1 = groupFilter.Filters[0] as DefaultFilter;

            DefaultFilter defaultFilter2 = groupFilter.Filters[1] as DefaultFilter;

            Assert.True(defaultFilter1.Conditions.Count == 0);
            Assert.True(defaultFilter1.Name == "F1");

            Assert.True(defaultFilter2.Conditions.Count == 1);
            Assert.True(defaultFilter2.Name == "F2");

            var condition = defaultFilter2.Conditions[0] as CompareCondition;

            Assert.True(condition.ConditionsEnum == ConditionsEnum.Equal);
            Assert.True(condition.UshortValueToCompare == 1);


            ConfigurationItemEditorViewModelFactory configurationItemEditorViewModelFactory =
                ConfigurationItemEditorViewModelFactory.Create();

            var loadedRootItem =
                configurationItemEditorViewModelFactory.VisitItemsGroup(
                    result.RootConfigurationItemList[0] as IItemsGroup);


            FilterViewModel filterViewModel1 =
                (loadedRootItem as IConfigurationGroupEditorViewModel).FilterViewModels[0] as FilterViewModel;

            FilterViewModel filterViewModel2 =
                (loadedRootItem as IConfigurationGroupEditorViewModel).FilterViewModels[1] as FilterViewModel;

            Assert.True(filterViewModel1.Name == "F1");
            Assert.True(filterViewModel2.Name == "F2");

            Assert.True(filterViewModel1.ConditionViewModels.Count == 0);
            Assert.True(filterViewModel2.ConditionViewModels.Count == 1);

            CompareConditionViewModel compareConditionViewModel =
                filterViewModel2.ConditionViewModels[0] as CompareConditionViewModel;

            Assert.True(compareConditionViewModel.SelectedCondition == ConditionsEnum.Equal.ToString());
            Assert.True(compareConditionViewModel.UshortValueToCompare == 1);
        }