/// <summary> /// To ensure connection didn't happen twice it first checks if /// adaptor with that object already exists. /// If Adaptor with this object specified as Target is already /// present then object was connected already anyway /// </summary> /// <param name="aObject"> /// Object being connected <see cref="System.Object"/> /// </param> /// <remarks> /// If object being connected to is type of PropertyChangedEventHandler /// then connection to PropertyChanged happens, otherwise it /// connects to all PropertyChangedEventHandler properties /// </remarks> public static void ConnectEvent(object aObject) { if (aObject == null) { return; } if (DataSourceController.CountDataSourceOwners(aObject) > 1) { return; } if (aObject is INotifyPropertyChanged) { (aObject as INotifyPropertyChanged).PropertyChanged += OnObjectPropertyChanged; } else { // Connect to all PropertyChangedEventHandler properties foreach (EventInfo ev in aObject.GetType().GetEvents()) { if (ev.EventHandlerType is PropertyChangedEventHandler) { ev.AddEventHandler(aObject, OnObjectPropertyChanged); } } } }
/// <summary> /// Disconect only happens if only one Adaptor has this object /// specified as Target. /// If not then connection is still valid /// </summary> /// <param name="aObject"> /// Object being diconnected <see cref="System.Object"/> /// </param> /// <remarks> /// If object being disconnected from is type of PropertyChangedEventHandler /// then disconnection from PropertyChanged happens, otherwise it /// disconnects from all PropertyChangedEventHandler properties /// </remarks> public static void DisconnectEvent(object aObject) { if (aObject == null) { return; } if (DataSourceController.CountDataSourceOwners(aObject) > 1) { return; } if (aObject is INotifyPropertyChanged) { (aObject as INotifyPropertyChanged).PropertyChanged -= OnObjectPropertyChanged; } else { // Disconnect from all PropertyChangedEventHandler properties foreach (EventInfo ev in aObject.GetType().GetEvents()) { if (ev.EventHandlerType is PropertyChangedEventHandler) { // ev.RemoveEventHandler (aObject, new PropertyChangedEventHandler(ObjectPropertyChanged)); ev.RemoveEventHandler(aObject, OnObjectPropertyChanged); } } } }
/// <summary> /// Assigns data or disqualifies validity if needed /// </summary> public void CheckControl() { if (destroyed == true) { return; } if (Activated == false) { return; } if (checkup == true) { return; } if (IsControllingWidget == false) { return; } checkup = true; bool canuse = adaptor.IsValidMapping; IObserveable observer = null; IObserveable boundaryobserver = null; if (Adaptor != null) { observer = DataSourceController.GetInfoFor(Adaptor.FinalTarget); } if (Adaptor != null) { boundaryobserver = DataSourceController.GetInfoFor(BoundaryAdaptor.FinalTarget); } if ((canuse == true) && (Control != null)) { if (Control is IChangeableControl) { if (observer != null) { if (observer.CanGet == true) { InvokeAdapteeDataChange((Control as IChangeableControl), Adaptor.FinalTarget); } } if (boundaryobserver != null) { if (boundaryobserver.CanGet == true) { if (TypeValidator.IsCompatible(Control.GetType(), typeof(IBoundedContainer)) == true) { InvokeBoundaryDataChange((Control as IBoundedContainer), this); } } } } } observer = null; boundaryobserver = null; checkup = false; }
/// <summary> /// Executes notification ReloadObject in Triggers engine /// </summary> /// <param name="aObject"> /// DataSource Object which was subject to event <see cref="System.Object"/> /// </param> /// <param name="aChangedBy"> /// Object that caused the event, this client will avoid update <see cref="System.Object"/> /// </param> public static void ReloadObjectNotification(object aObject, object aChangedBy) { if (aObject == null) { return; } DataSourceController.PostRequest(aObject); }
/// <summary> /// Checks if Get request is possible in this moment /// </summary> /// <param name="aState"> /// State <see cref="EObserveableState"/> /// </param> /// <returns> /// true if successful <see cref="System.Boolean"/> /// </returns> public bool SetState(EObserveableState aState) { IObserveable observer = DataSourceController.GetInfoFor(adaptor.FinalTarget); if (observer == null) { return(false); } bool res = observer.SetState(aState); observer = null; return(res); }
/// <summary> /// Assigns Value in given direction between Control and DataSource Target /// </summary> /// <param name="aDirection"> /// Direction of data <see cref="EDataDirection"/> /// </param> /// <param name="aObject"> /// Object which contains data <see cref="System.Object"/> /// </param> /// <param name="aControl"> /// Control used to edit <see cref="System.Object"/> /// </param> /// <returns> /// Returns true if successful <see cref="System.Boolean"/> /// </returns> public bool AssignValueToObject(EDataDirection aDirection, object aObject, object aControl) { bool res = false; // Check if if (IsGlobal == true) { if (aDirection == EDataDirection.FromControlToDataSource) { throw new ExceptionGlobalMappingAssignedFromControlToTarget(); } #if NEWCACHE if (dataCache == null) { dataCache = new CachedProperty(Adaptor.FinalTarget, Name); } if (controlCache == null) { controlCache = new CachedProperty(aControl, MappingTarget); } if (controlCache.IsCached == true) { object val; if (dataCache.IsCached == true) { if (dataCache.GetValue(out val) == true) { if (controlCache.SetValue(val) == true) { val = null; return(true); } } } } return(false); #endif #if OLDCACHE object FromObject = aObject; object ToObject = aControl; string FromProperty = Name; string ToProperty = MappingTarget; // assign, direction is already correct res = ConnectionProvider.CopyPropertyValue(FromObject, FromProperty, ToObject, ToProperty); FromObject = null; ToObject = null; return(res); #endif } else { #if NEWCACHE CachedProperty FromObject; CachedProperty ToObject; bool canbedone; if (aDirection == EDataDirection.FromControlToDataSource) { FromObject = controlCache; ToObject = dataCache; canbedone = AllowedToWrite; if (ToObject is IObserveable) { (ToObject as IObserveable).ResetChangeCallCheckup(); } } else { FromObject = dataCache; ToObject = controlCache; canbedone = AllowedToRead; } if (controlCache == null) { controlCache = new CachedProperty(aControl, MappingTarget); } object val = null; // assign in set direction if ((canbedone == true) && (FromObject != null) && (ToObject != null)) { if (FromObject.GetValue(out val) == true) { if (ToObject.SetValue(val) == true) { if (aDirection == EDataDirection.FromControlToDataSource) { if ((ToObject is IObserveable) == false) { DataSourceController.CallChangedFor(ToObject); } else if ((ToObject as IObserveable).HasCalledForChange == false) { (ToObject as IObserveable).HasChanged = true; } } } res = true; } } FromObject = null; ToObject = null; return(res); #endif #if OLDCACHE object FromObject; object ToObject; string FromProperty; string ToProperty; bool canbedone; // swap direction if needed if (aDirection == EDataDirection.FromControlToDataSource) { FromObject = aControl; ToObject = aObject; FromProperty = MappingTarget; ToProperty = Name; canbedone = AllowedToWrite; if (ToObject is IObserveable) { (ToObject as IObserveable).ResetChangeCallCheckup(); } } else { FromObject = aObject; ToObject = aControl; FromProperty = Name; ToProperty = MappingTarget; canbedone = AllowedToRead; } // assign in set direction if (canbedone == true) { if (ConnectionProvider.CopyPropertyValue(FromObject, FromProperty, ToObject, ToProperty) == true) { if (aDirection == EDataDirection.FromControlToDataSource) { if ((ToObject is IObserveable) == false) { DataSourceController.CallChangedFor(ToObject); } else if ((ToObject as IObserveable).HasCalledForChange == false) { (ToObject as IObserveable).HasChanged = true; } } res = true; } // else // Debug.Warning ("MappedProperty.AssignValueToObject", "CopyPropertyValue not successful"); } FromObject = null; ToObject = null; return(res); #endif } }
/// <summary> /// gets value from referenced Target /// </summary> /// <param name="aValue"> /// Value to set <see cref="System.Object"/> /// </param> public void SetValue(object aValue) { #if NEWCACHE if (Adaptor.FinalTarget is IObserveable) { (Adaptor.FinalTarget as IObserveable).ResetChangeCallCheckup(); } if (Resolve() == true) { if (dataCache.SetValue(Adaptor.FinalTarget, Name, aValue) == true) { if ((Adaptor.FinalTarget is IObserveable) == false) { DataSourceController.CallChangedFor(Adaptor.FinalTarget); } else if ((Adaptor.FinalTarget as IObserveable).HasCalledForChange == false) { (Adaptor.FinalTarget as IObserveable).HasChanged = true; } } } #endif #if OLDCACHE if (cached == false) { Name = name; } if ((cached == false) && (Adaptor.InheritedTarget == false)) { return; } if (cached == false) { if (Adaptor.InheritedTarget == true) { if (Resolve() == false) { return; } } else { return; } } if (Adaptor.FinalTarget is IObserveable) { (Adaptor.FinalTarget as IObserveable).ResetChangeCallCheckup(); } if (ConnectionProvider.SetPropertyValue(Adaptor.FinalTarget, Info, aValue) == true) { if ((Adaptor.FinalTarget is IObserveable) == false) { DataSourceController.CallChangedFor(Adaptor.FinalTarget); } else if ((Adaptor.FinalTarget as IObserveable).HasCalledForChange == false) { (Adaptor.FinalTarget as IObserveable).HasChanged = true; } } #endif }
/// <summary> /// Valid for complex controls like TreeView /// </summary> /* public virtual void ClearBeforeRemapping() * { * if (Control is IComplexAdaptableControl) * (Control as IComplexAdaptableControl).ClearBeforeRemapping(); * } * * /// <summary> * /// Valid for complex controls like TreeView * /// </summary> * public virtual void RemapControl() * { * if (Control is IComplexAdaptableControl) * (Control as IComplexAdaptableControl).RemapControl(); * }*/ /// <summary> /// Sets method of DataSource update /// </summary> /// <param name="aMethod"> /// Method of update <see cref="EApplyMethod"/> /// </param> /// <returns> /// true if succeessful <see cref="System.Boolean"/> /// </returns> public bool DataSourceNeedsUpdateOn(EApplyMethod aMethod) { return(DataSourceController.DataSourceNeedsUpdateOn(adaptor.FinalTarget, aMethod)); }