コード例 #1
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);
        }
コード例 #2
0
        private void OnMigrateComplexPropertiesExecute()
        {
            var res = ComplexPropertiesMigrator.GetAllComplexPropertiesInConfiguration(RootConfigurationItemViewModels
                                                                                       .ToList());

            if (!res.Any())
            {
                _applicationGlobalCommands.ShowErrorMessage("Составные свойства не найдены", null);
                return;
            }

            var askUserResult = _applicationGlobalCommands.AskUserGlobal(
                $"{res.Count} cоставных свойств будет смигрировано в свойства с выбранными битами. Продолжить?",
                "Миграция");

            if (askUserResult)
            {
                var migrationResult = ComplexPropertiesMigrator.MigrateComplexProperties(res);
                if (migrationResult.IsSuccess)
                {
                    MessageBox.Show($"{res.Count} составных свойств было успешно смигрировано");
                }
            }
        }