Exemplo n.º 1
0
        /// <summary>
        /// Creates temporary cache and sets value to the property
        /// </summary>
        /// <param name="aObject">
        /// Object which needs value to be set <see cref="System.Object"/>
        /// </param>
        /// <param name="aProperty">
        /// Property name <see cref="System.String"/>
        /// </param>
        /// <param name="aValue">
        /// New property value <see cref="System.Object"/>
        /// </param>
        /// <returns>
        /// true if successful, false if not <see cref="System.Boolean"/>
        /// </returns>
        public static bool UncachedSetValue(object aObject, string aProperty, object aValue)
        {
            bool           res       = false;
            CachedProperty tempCache = new CachedProperty(aObject, aProperty);

            if (tempCache.IsAccessValid == EPropertyAccess.Valid)
            {
                res = tempCache.SetValue(aObject, aProperty, aValue);
            }
            tempCache.Disconnect();
            tempCache = null;
            return(res);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets value to cached property
        /// </summary>
        /// <param name="aObject">
        /// Object where property resides <see cref="System.Object"/>
        /// </param>
        /// <param name="aProperty">
        /// Property name <see cref="System.String"/>
        /// </param>
        /// <param name="aValue">
        /// New value <see cref="System.Object"/>
        /// </param>
        /// <param name="aDefaultValue">
        /// Default value which should be returned if method was unsuccessful <see cref="System.Object"/>
        /// </param>
        /// <returns>
        /// true if successful, false if not <see cref="System.Boolean"/>
        /// </returns>
        public bool GetValue(object aObject, string aProperty, out object aValue, object aDefaultValue)
        {
            bool startMethod = false;

            aValue = aDefaultValue;
            if (IsCached == true)
            {
                if (aProperty == PropertyName)
                {
                    startMethod = true;
                }
            }
            else
            {
                if (IsCompatible(aObject) == true)
                {
                    if (aProperty == PropertyName)
                    {
                        startMethod = IsCached;
                    }
                }
            }
            // Start copying data
            if (startMethod == true)
            {
                if (IsProperty == true)
                {
                    aValue = ConnectionProvider.GetPropertyValue(aObject, propInfo);
                    return(true);
                }
                if (IsVirtualProperty == true)
                {
                    aValue = propVirtual.Value;
                    return(true);
                }
                if (IsDataRowField == true)
                {
                    return(DatabaseProvider.GetValue(aObject, propColumn, out aValue, aDefaultValue));
                }
                throw new ExceptionCachedPropertyGetValueFailed(this);
            }
            else
            {
                // If method arrived here then this is not a valid cache for that property
                // fallback creates temporary cache and gets value trough it
                return(CachedProperty.UncachedGetValue(aObject, aProperty, out aValue, aDefaultValue));
            }
            return(false);
        }
		/// <summary>
		/// Creates temporary cache and gets value from the property
		/// </summary>
		/// <param name="aObject">
		/// Object which needs value to be set <see cref="System.Object"/>
		/// </param>
		/// <param name="aProperty">
		/// Property name <see cref="System.String"/>
		/// </param>
		/// <param name="aValue">
		/// Property value <see cref="System.Object"/>
		/// </param>
		/// <param name="aDefaultValue">
		/// Default value which should be returned if method was unsuccessful <see cref="System.Object"/>
		/// </param>
		/// <returns>
		/// true if successful, false if not <see cref="System.Boolean"/>
		/// </returns>
		public static bool UncachedGetValue (object aObject, string aProperty, out object aValue, object aDefaultValue)
		{
			aValue = aDefaultValue;
			bool res = false;
			CachedProperty tempCache = new CachedProperty (aObject, aProperty);
			if (tempCache.IsAccessValid == EPropertyAccess.Valid)
				res = tempCache.GetValue (aObject, aProperty, out aValue, aDefaultValue);
			tempCache.Disconnect();
			tempCache = null;
			return (res);
		}
		/// <summary>
		/// Disconnects on adaptors OnTargetChange
		/// </summary>
		public void Disconnect()
		{
			if (dataCache != null)
				dataCache.Disconnect();
			dataCache = null;
			if (controlCache != null)
				controlCache.Disconnect();
			controlCache = null;
			if (IsSubItem == true)
				MasterItem.Submappings.RemoveMapping (this);
			else
				if (submappings != null)
					submappings.Disconnect();
			submappings = null;
			masterItem = null;
			if (Adaptor != null)
			{
				Adaptor.TargetChanged -= TargetChanged;
				adaptor.Target = null;
			}
			adaptor = null;
		}
		/// <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>
		/// Resoves PropertyInfo from connected object
		/// </summary>
		public bool Resolve()
		{
#if NEWCACHE
			if (dataCache == null)
				dataCache = new CachedProperty (Adaptor.FinalTarget, Name);
			if (resetResolve == true) {
				dataCache.SetObject (Adaptor.FinalTarget);
				dataCache.SetProperty (Name.Trim());
			}
/*			if (dataCache.IsAccessValid == EPropertyAccess.Invalid)
				if (Adaptor.FinalTarget != null)	{
					dataCache.SetObject (Adaptor.FinalTarget);
					dataCache.SetProperty (Name.Trim());
				}*/
			return (dataCache.IsAccessValid == EPropertyAccess.Valid);
#endif			
#if OLDCACHE
			if (cached == true)
				return (true);
				
			if (name == "")
				return (false);
			
			cached = false;
			cachedInfo = null;
			if (Adaptor.FinalTarget != null)
				cachedInfo = ConnectionProvider.ResolveMappingProperty (Adaptor.FinalTarget, Name, false);
				
			cached = (cachedInfo != null);
			invalid = (cachedInfo == null);
			return (cachedInfo != null);
#endif
		}
Exemplo n.º 7
0
 /// <summary>
 /// Creates temporary cache and gets value from the property
 /// </summary>
 /// <param name="aObject">
 /// Object which needs value to be set <see cref="System.Object"/>
 /// </param>
 /// <param name="aProperty">
 /// Property name <see cref="System.String"/>
 /// </param>
 /// <param name="aValue">
 /// Property value <see cref="System.Object"/>
 /// </param>
 /// <returns>
 /// true if successful, false if not <see cref="System.Boolean"/>
 /// </returns>
 /// <remarks>
 /// calls CachedProperty.UncachedGetValue with null as default value
 /// </remarks>
 public static bool UncachedGetValue(object aObject, string aProperty, out object aValue)
 {
     return(CachedProperty.UncachedGetValue(aObject, aProperty, out aValue, null));
 }