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); }
public IConfigurationItem VisitComplexProperty(IComplexPropertyEditorViewModel propertyViewModel) { var complexProperty = _container.Resolve <IComplexProperty>(); complexProperty.Address = ushort.Parse(propertyViewModel.Address ?? "0"); complexProperty.NumberOfPoints = ushort.Parse(propertyViewModel.NumberOfPoints ?? "0"); foreach (var childStructItemViewModel in propertyViewModel.SubPropertyEditorViewModels) { if (childStructItemViewModel is ISubPropertyEditorViewModel subPropertyEditorViewModel) { complexProperty.SubProperties.Add(subPropertyEditorViewModel.Accept(this) as ISubProperty); } } complexProperty.IsGroupedProperty = propertyViewModel.IsGroupedProperty; return(InitializeProperty(propertyViewModel, complexProperty)); }