/// <summary> /// Converts from an object /// </summary> /// <param name="context">Context of the conversion</param> /// <param name="culture">Culture info</param> /// <param name="value">Value to be converted</param> /// <returns>Object after conversion (a OtherProperty object)</returns> public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (value is string) { string result = value as string; OtherProperty op = new OtherProperty(result); return op; } else { return base.ConvertFrom(context, culture, value); } }
/// <summary> /// The property value is changed, so the the propertiesDisplayer should be /// refilled with new values /// </summary> /// <param name="catcher">Catcher of the connection</param> /// <param name="value">New value of the property</param> /// <param name="moreBoxes">If the refresh of the property grid is /// from one or more boxes</param> public void ChangedPropertyValue(AsyncPropertyCatcher catcher, object value, bool moreBoxes) { //changing one of the temporary values //writing to the temporaryValues dictionary switch (catcher.PropertyType) { case "System.Int32": Int32 int32Value = ((IntT)value).intValue; lock (tempLocker) { if (moreBoxes) { switch (moreBoxesValuesState[catcher.PropertyName]) { //no box has written to the property case EMoreBoxesTemporaryValueState.First: temporaryValues[catcher.PropertyName] = int32Value; moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Right; break; //all the previos boxes wrote the same value case EMoreBoxesTemporaryValueState.Right: if (int32Value != (Int32)temporaryValues[catcher.PropertyName]) { temporaryValues[catcher.PropertyName] = (Int32)0; moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Wrong; } break; //values from the boxes are different case EMoreBoxesTemporaryValueState.Wrong: break; } } else { temporaryValues[catcher.PropertyName] = int32Value; } } break; case "Ferda.FrontEnd.Properties.OtherProperty": //here is no moreBoxes here string resultValue = SelectedBox.GetPropertyOtherAboutFromValue(catcher.PropertyName, (PropertyValue)value); OtherProperty prop = new OtherProperty(SelectedBox, catcher.PropertyName, archiveDisplayer, viewDisplayers, this, ResManager); prop.Result = resultValue; lock (tempLocker) { temporaryValues[catcher.PropertyName] = prop; } break; case "Ferda.FrontEnd.Properties.StringSequence": string selectedValue = ((StringT)value).stringValue; //creating a new stringSequence StringSequence seq = new StringSequence(catcher.PropertyName, new IBoxModule[] { SelectedBox }, ResManager, ArchiveDisplayer, ViewDisplayers, this, selectedValue); lock (tempLocker) { temporaryValues[catcher.PropertyName] = seq; } break; case "System.String": string valueString = ((StringT)value).stringValue; lock (tempLocker) { if (moreBoxes) { switch (moreBoxesValuesState[catcher.PropertyName]) { //no box has written to the property case EMoreBoxesTemporaryValueState.First: temporaryValues[catcher.PropertyName] = valueString; moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Right; break; //all the previos boxes wrote the same value case EMoreBoxesTemporaryValueState.Right: if (valueString != (string)temporaryValues[catcher.PropertyName]) { temporaryValues[catcher.PropertyName] = string.Empty; moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Wrong; } break; //values from the boxes are different case EMoreBoxesTemporaryValueState.Wrong: break; } } else { temporaryValues[catcher.PropertyName] = valueString; } } break; case "System.Boolean": bool boolValue = ((BoolT)value).boolValue; lock (tempLocker) { if (moreBoxes) { switch (moreBoxesValuesState[catcher.PropertyName]) { //no box has written to the property case EMoreBoxesTemporaryValueState.First: temporaryValues[catcher.PropertyName] = boolValue; moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Right; break; //all the previos boxes wrote the same value case EMoreBoxesTemporaryValueState.Right: if (boolValue != (bool)temporaryValues[catcher.PropertyName]) { temporaryValues[catcher.PropertyName] = false; moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Wrong; } break; //values from the boxes are different case EMoreBoxesTemporaryValueState.Wrong: break; } } else { temporaryValues[catcher.PropertyName] = boolValue; } } break; case "System.Int16": Int16 shortValue = ((ShortT)value).shortValue; lock (tempLocker) { if (moreBoxes) { switch (moreBoxesValuesState[catcher.PropertyName]) { //no box has written to the property case EMoreBoxesTemporaryValueState.First: temporaryValues[catcher.PropertyName] = shortValue; moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Right; break; //all the previos boxes wrote the same value case EMoreBoxesTemporaryValueState.Right: if (shortValue != (Int16)temporaryValues[catcher.PropertyName]) { temporaryValues[catcher.PropertyName] = (Int16)0; moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Wrong; } break; //values from the boxes are different case EMoreBoxesTemporaryValueState.Wrong: break; } } else { temporaryValues[catcher.PropertyName] = shortValue; } } break; case "System.Int64": Int64 longValue = ((LongT)value).longValue; lock (tempLocker) { if (moreBoxes) { switch (moreBoxesValuesState[catcher.PropertyName]) { //no box has written to the property case EMoreBoxesTemporaryValueState.First: temporaryValues[catcher.PropertyName] = longValue; moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Right; break; //all the previos boxes wrote the same value case EMoreBoxesTemporaryValueState.Right: if (longValue != (Int64)temporaryValues[catcher.PropertyName]) { temporaryValues[catcher.PropertyName] = (Int64)0; moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Wrong; } break; //values from the boxes are different case EMoreBoxesTemporaryValueState.Wrong: break; } } else { temporaryValues[catcher.PropertyName] = longValue; } } break; case "System.Double": Double doubleValue = ((DoubleT)value).doubleValue; lock (tempLocker) { if (moreBoxes) { switch (moreBoxesValuesState[catcher.PropertyName]) { //no box has written to the property case EMoreBoxesTemporaryValueState.First: temporaryValues[catcher.PropertyName] = doubleValue; moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Right; break; //all the previos boxes wrote the same value case EMoreBoxesTemporaryValueState.Right: if (doubleValue != (Double)temporaryValues[catcher.PropertyName]) { temporaryValues[catcher.PropertyName] = (Double)0; moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Wrong; } break; //values from the boxes are different case EMoreBoxesTemporaryValueState.Wrong: break; } } else { temporaryValues[catcher.PropertyName] = doubleValue; } } break; case "System.Single": Single singleValue = ((FloatT)value).floatValue; lock (tempLocker) { if (moreBoxes) { switch (moreBoxesValuesState[catcher.PropertyName]) { //no box has written to the property case EMoreBoxesTemporaryValueState.First: temporaryValues[catcher.PropertyName] = singleValue; moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Right; break; //all the previos boxes wrote the same value case EMoreBoxesTemporaryValueState.Right: if (singleValue != (Single)temporaryValues[catcher.PropertyName]) { temporaryValues[catcher.PropertyName] = (Single)0; moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Wrong; } break; //values from the boxes are different case EMoreBoxesTemporaryValueState.Wrong: break; } } else { temporaryValues[catcher.PropertyName] = singleValue; } } break; case "System.DateTime": //a date property is treated differently due to unexisting conversion if (value is DateT) { DateT v = (DateT)value; DateTime dateTimeValue = new DateTime(); try { dateTimeValue = new DateTime(v.year, v.month, v.day); } catch (ArgumentOutOfRangeException) { } lock (tempLocker) { if (moreBoxes) { switch (moreBoxesValuesState[catcher.PropertyName]) { //no box has written to the property case EMoreBoxesTemporaryValueState.First: temporaryValues[catcher.PropertyName] = dateTimeValue; moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Right; break; //all the previos boxes wrote the same value case EMoreBoxesTemporaryValueState.Right: if (dateTimeValue != (DateTime)temporaryValues[catcher.PropertyName]) { temporaryValues[catcher.PropertyName] = new DateTime(); moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Wrong; } break; //values from the boxes are different case EMoreBoxesTemporaryValueState.Wrong: break; } } else { temporaryValues[catcher.PropertyName] = dateTimeValue; } } } else //it is a DateTimeT thing { DateTimeT v = (DateTimeT)value; //the value does not have to be correct DateTime dtValue = new DateTime(); try { dtValue = new DateTime(v.year, v.month, v.day, v.hour, v.minute, v.second); } catch (ArgumentOutOfRangeException) { } lock (tempLocker) { if (moreBoxes) { switch (moreBoxesValuesState[catcher.PropertyName]) { //no box has written to the property case EMoreBoxesTemporaryValueState.First: temporaryValues[catcher.PropertyName] = dtValue; moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Right; break; //all the previos boxes wrote the same value case EMoreBoxesTemporaryValueState.Right: if (dtValue != (DateTime)temporaryValues[catcher.PropertyName]) { temporaryValues[catcher.PropertyName] = new DateTime(); moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Wrong; } break; //values from the boxes are different case EMoreBoxesTemporaryValueState.Wrong: break; } } else { temporaryValues[catcher.PropertyName] = dtValue; } } } break; case "System.TimeSpan": TimeT val = (TimeT)value; TimeSpan timeSpanValue = new TimeSpan(val.hour, val.minute, val.second); lock (tempLocker) { if (moreBoxes) { switch (moreBoxesValuesState[catcher.PropertyName]) { //no box has written to the property case EMoreBoxesTemporaryValueState.First: temporaryValues[catcher.PropertyName] = timeSpanValue; moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Right; break; //all the previos boxes wrote the same value case EMoreBoxesTemporaryValueState.Right: if (timeSpanValue != (TimeSpan)temporaryValues[catcher.PropertyName]) { temporaryValues[catcher.PropertyName] = new TimeSpan(); moreBoxesValuesState[catcher.PropertyName] = EMoreBoxesTemporaryValueState.Wrong; } break; //values from the boxes are different case EMoreBoxesTemporaryValueState.Wrong: break; } } else { temporaryValues[catcher.PropertyName] = timeSpanValue; } } break; default: break; } //refilling the propertiesDisplayer SetPropertyGrid(propertyBag); }