Esempio n. 1
0
        private void InitializeProperty(IPropertyEditorViewModel editorPropertyViewModel, IProperty property)
        {
            editorPropertyViewModel.IsMeasureUnitEnabled = property.IsMeasureUnitEnabled;
            editorPropertyViewModel.MeasureUnit          = property.MeasureUnit;
            editorPropertyViewModel.IsRangeEnabled       = property.IsRangeEnabled;
            if (property.IsRangeEnabled)
            {
                IRangeViewModel rangeViewModel = _container.Resolve <IRangeViewModel>();
                rangeViewModel.RangeFrom = property.Range.RangeFrom.ToString();
                rangeViewModel.RangeTo   = property.Range.RangeTo.ToString();
                editorPropertyViewModel.RangeViewModel = rangeViewModel;
            }

            editorPropertyViewModel.Address        = property.Address.ToString();
            editorPropertyViewModel.NumberOfPoints = property.NumberOfPoints.ToString();
            var formatterParametersViewModel = StaticContainer.Container.Resolve <IFormatterViewModelFactory>()
                                               .CreateFormatterViewModel(property.UshortsFormatter);

            editorPropertyViewModel.FormatterParametersViewModel = formatterParametersViewModel;

            editorPropertyViewModel.NumberOfWriteFunction = property.NumberOfWriteFunction;


            ISharedResourcesGlobalViewModel sharedResourcesGlobalViewModel =
                StaticContainer.Container.Resolve <ISharedResourcesGlobalViewModel>();

            if (sharedResourcesGlobalViewModel.CheckDeviceSharedResourcesWithContainersContainsModel(property))
            {
                sharedResourcesGlobalViewModel.AddExistingResourceWithContainer(editorPropertyViewModel, property);
            }

            if (property.Dependencies != null && property.Dependencies.Count > 0)
            {
                editorPropertyViewModel.DependencyViewModels.Clear();
                editorPropertyViewModel.DependencyViewModels.AddCollection(property.Dependencies
                                                                           .Select(_container.Resolve <DependencyFillHelper>().CreateDependencyViewModel).ToList());
            }

            editorPropertyViewModel.IsFromBits = property.IsFromBits;
            if (editorPropertyViewModel.BitNumbersInWord != null)
            {
                property.BitNumbers.ForEach(bitNum =>
                                            editorPropertyViewModel.BitNumbersInWord.First(model => model.BitNumber == bitNum).IsChecked =
                                                true);
            }

            if (editorPropertyViewModel is ICanBeHidden canBeHidden)
            {
                canBeHidden.IsHidden = property.IsHidden;
            }

            InitializeBaseProperties(editorPropertyViewModel, property);
        }
        private void InitDefaults(IMeasuringElementEditorViewModel measuringElementEditorViewModel,
                                  IMeasuringElement measuringElement)
        {
            measuringElementEditorViewModel.Header = measuringElement.Name;
            measuringElementEditorViewModel.SetId(measuringElement.Id);
            if (_sharedResourcesGlobalViewModel.CheckDeviceSharedResourcesWithContainersContainsModel(measuringElement))
            {
                _sharedResourcesGlobalViewModel.AddExistingResourceWithContainer(measuringElementEditorViewModel, measuringElement);
            }

            foreach (var dependency in measuringElement.Dependencies)
            {
                if (dependency is IBoolToAddressDependency boolToAddressDependency)
                {
                    measuringElementEditorViewModel.DependencyViewModels.Add(CreateBoolToAddressDependencyViewModel(boolToAddressDependency));
                }
            }
        }