/// <summary> /// Initializes a new instance of the <see cref="PropertyItemValue"/> class. /// </summary> /// <param name="property">The property.</param> public PropertyItemValue(PropertyItem property) { if (property == null) { throw new ArgumentNullException("property"); } ParentProperty = property; HasSubProperties = property.Converter.GetPropertiesSupported(); if (HasSubProperties) { object value = property.GetValue(); PropertyDescriptorCollection descriptors = property.Converter.GetProperties(value); foreach (PropertyDescriptor d in descriptors) { SubProperties.Add(new PropertyItem(property.Owner, value, d)); // TODO: Move to PropertyData as a public property NotifyParentPropertyAttribute notifyParent = d.Attributes[KnownTypes.Attributes.NotifyParentPropertyAttribute] as NotifyParentPropertyAttribute; if (notifyParent != null && notifyParent.NotifyParent) { d.AddValueChanged(value, NotifySubPropertyChanged); } } } this.ParentProperty.PropertyChanged += ParentPropertyChanged; }
//public override async Task<bool> Write() //{ // bool isToWrite = false; // if (this.LocalUshortsValue == null) return false; // foreach (ISubProperty subProperty in SubProperties) // { // if (!subProperty.IsValuesEqual) // { // isToWrite = true; // } // } // if (isToWrite) // { // this.LocalUshortsValue = GetParentLocalUshortsFromChildren(SubProperties); // if (_dataProvider is IQuickMemoryAccessDataProviderStub) // { // List<int> bitNumbers = new List<int>(); // SubProperties.ForEach((property => bitNumbers.AddRange(property.BitNumbersInWord))); // await (_dataProvider as IQuickMemoryAccessDataProviderStub).WriteMultipleRegistersByBitNumbersAsync( // Address, this.LocalUshortsValue, "WritingComplexProperty", bitNumbers); // } // else // { // return await base.Write(); // } // } // return isToWrite; //} // IQueryResult queryResult = this._queryResultFactory.CreateDefaultQueryResult(); //if (this.IsMemoryValuesSetsContainsAddress(startAddress)) //{ // bool[] bitArrayToWrite = dataToWrite.GetBoolArrayFromUshortArray(); // bool[] bitArrayExisting = // (new[] { this.GetValueFromMemoryValuesSets(startAddress) }).GetBoolArrayFromUshortArray(); // for (int i = 0; i < bitArrayToWrite.Length; i++) // { // if (bitNumbers.Contains(i)) // { // bitArrayExisting[i] = bitArrayToWrite[i]; // } // } // this.SetValueFromMemoryValuesSets(startAddress, bitArrayExisting.BoolArrayToUshort()); //} //queryResult.IsSuccessful = true; //return queryResult; //private ushort[] GetParentLocalUshortsFromChildren(List<ISubProperty> subProperties) //{ // foreach (ISubProperty subProperty in subProperties) // { // BitArray subPropertyBitArray = new BitArray(new int[] { subProperty.LocalUshortsValue[0] }); // foreach (int bitNum in subProperty.BitNumbersInWord) // { // _baseBools[bitNum] = subPropertyBitArray[subProperty.BitNumbersInWord.IndexOf(bitNum)]; // } // } // return new[] { (ushort)(new BitArray(_baseBools).GetIntFromBitArray()) }; //} protected override IConfigurationItem OnCloning() { ComplexProperty complexProperty = new ComplexProperty(); SubProperties.ForEach((property => { ISubProperty subProperty = property.Clone() as ISubProperty; complexProperty.SubProperties.Add(subProperty); })); complexProperty.UshortsFormatter = UshortsFormatter; complexProperty.Address = Address; complexProperty.NumberOfPoints = NumberOfPoints; complexProperty.MeasureUnit = MeasureUnit; complexProperty.IsMeasureUnitEnabled = IsMeasureUnitEnabled; complexProperty.Range = Range.Clone() as IRange; complexProperty.IsRangeEnabled = IsRangeEnabled; return(complexProperty); }