Exemple #1
0
        /// <summary>
        /// Outputs connection information with Debug.DevelInfo
        /// </summary>
        public virtual void DebugConnection()
        {
            string preffix = "  ";

            if (Adaptor.FinalTarget == null)
            {
                return;
            }
            string s = "Control=" + Control + " Target=" + Adaptor.FinalTarget;

            if (TypeValidator.IsCompatible(Adaptor.FinalTarget.GetType(), typeof(IAdaptor)) == true)
            {
                IAdaptor a = (IAdaptor)Adaptor.FinalTarget;
                while (TypeValidator.IsCompatible(a.GetType(), typeof(IAdaptor)) == true)
                {
                    if (a.Control == null)
                    {
                        s = s + "\n" + preffix + "Control=[POINTER] Target=" + a.FinalTarget;
                    }
                    else
                    {
                        s = s + "\n" + preffix + "Control=" + a.Control + " Target=" + a.FinalTarget;
                    }
                    preffix += "  ";
                }
                s = s + "\n" + preffix + "Control=" + a.Control + " Target=" + a.FinalTarget;
            }
            Debug.DevelInfo("ControlAdaptor.DebugConnection (" + Control + ")", s);
        }
        /// <summary>
        /// Checks specified type if it provides factory or not and then registers it
        /// if needed
        /// </summary>
        /// <param name="aType">
        /// Factory type <see cref="System.Type"/>
        /// </param>
        public static void RegisterClass(System.Type aType)
        {
            if (aType == null)
            {
                return;
            }
            object[] attrs = (object[])aType.GetCustomAttributes(false);
            if ((attrs == null) || (attrs.Length == 0))
            {
                return;
            }
            Attribute attr;

            try {
                foreach (object attrobj in attrs)
                {
                    if (TypeValidator.IsCompatible(attrobj.GetType(), typeof(Attribute)) == false)
                    {
                        continue;
                    }
                    attr = (Attribute)attrobj;
                    if (TypeValidator.IsCompatible(attr.GetType(), typeof(WidgetFactoryProviderAttribute)) == true)
                    {
                        AddClass(aType, (WidgetFactoryProviderAttribute)attr);
                    }
                    if (TypeValidator.IsCompatible(attr.GetType(), typeof(CellFactoryProviderAttribute)) == true)
                    {
                        AddClass(aType, (CellFactoryProviderAttribute)attr);
                    }
                }
            }
            catch {}
        }
 /// <summary>
 /// Checks if specified property exists in database object and returns DataColumn
 /// </summary>
 /// <param name="aObject">
 /// Object to check in <see cref="System.Object"/>
 /// </param>
 /// <param name="aPropertyName">
 /// Property name <see cref="System.String"/>
 /// </param>
 /// <returns>
 /// Object to column, null if it doesn't exists <see cref="System.Object"/>
 /// </returns>
 public static object PropertyExists(object aObject, string aPropertyName)
 {
     if ((IsValidType(aObject) == false) &&
         (IsDataRowContainer(aObject) == false) &&
         (IsDatabaseException(aObject) == false))
     {
         return(null);
     }
     if (TypeValidator.IsCompatible(aObject.GetType(), typeof(DataTable)) == true)
     {
         return((aObject as DataTable).Columns[aPropertyName.Trim()]);
     }
     if (TypeValidator.IsCompatible(aObject.GetType(), typeof(DataView)) == true)
     {
         return((aObject as DataView).Table.Columns[aPropertyName.Trim()]);
     }
     if (TypeValidator.IsCompatible(aObject.GetType(), typeof(DbObservableList)) == true)
     {
         return((aObject as DbObservableList).Table.Columns[aPropertyName.Trim()]);
     }
     if (TypeValidator.IsCompatible(aObject.GetType(), typeof(DataRowView)) == true)
     {
         return((aObject as DataRowView).Row.Table.Columns[aPropertyName.Trim()]);
     }
     return((aObject as DataRow).Table.Columns[aPropertyName.Trim()]);
 }
Exemple #4
0
        /// <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;
        }
Exemple #5
0
 /// <summary>
 /// Subscribers should call this routine when widget changes. If DataSource
 /// supports EApplyMethod.Instant then it will simply invoke this adaptors
 /// Post routine
 /// </summary>
 public virtual void DemandOnLeavePost()
 {
     dataChanged = true;
     if (TypeValidator.IsCompatible(Control.GetType(), typeof(IPostableControl)) == true)
     {
         if (DataSourceNeedsUpdateOn(EApplyMethod.OnLeave) == true)
         {
             InvokeControlDataChange(Control as IPostableControl, this);
         }
     }
 }
 public DevelopmentDescriptionCollection(MemberInfo aMember)
 {
     object[] attrs = aMember.GetCustomAttributes(false);
     foreach (object attr in attrs)
     {
         if (TypeValidator.IsCompatible(attr.GetType(), typeof(DevelopmentInformationAttribute)) == true)
         {
             Add(attr as DevelopmentInformationAttribute);
         }
     }
 }
 public void Parse(MemberInfo aMember)
 {
     object[] attrs = aMember.GetCustomAttributes(false);
     foreach (object attr in attrs)
     {
         if (TypeValidator.IsCompatible(attr.GetType(), typeof(DevelopmentInformationAttribute)) == true)
         {
             members.Add((DevelopmentInformationAttribute)attr);
         }
     }
 }
 /// <summary>
 /// Checks if object has collection of datarows
 /// </summary>
 /// <param name="aObject">
 /// A <see cref="System.Object"/>
 /// </param>
 /// <returns>
 /// A <see cref="System.Boolean"/>
 /// </returns>
 public static bool IsDatabaseException(object aObject)
 {
     if (aObject == null)
     {
         return(false);
     }
     if (TypeValidator.IsCompatible(aObject.GetType(), databaseExceptionTypes) == true)
     {
         return(true);
     }
     return(false);
 }
 /// <summary>
 /// Checks if object has collection of datarows
 /// </summary>
 /// <param name="aObjectType">
 /// A <see cref="System.Type"/>
 /// </param>
 /// <returns>
 /// A <see cref="System.Boolean"/>
 /// </returns>
 public static bool IsDataRowContainer(System.Type aObjectType)
 {
     if (aObjectType == null)
     {
         return(false);
     }
     if (TypeValidator.IsCompatible(aObjectType, databaseRowTypes) == true)
     {
         return(true);
     }
     return(false);
 }
Exemple #10
0
        private void Parse(Assembly aAssembly)
        {
            if (aAssembly.GetName().Name == "System")
            {
                return;
            }
            BindingFlags flags = BindingFlags.DeclaredOnly | BindingFlags.Public |
                                 BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField |
                                 BindingFlags.GetProperty | BindingFlags.SetField |
                                 BindingFlags.SetProperty | BindingFlags.Instance |
                                 BindingFlags.InvokeMethod | BindingFlags.CreateInstance |
                                 BindingFlags.ExactBinding | BindingFlags.OptionalParamBinding |
                                 BindingFlags.PutDispProperty | BindingFlags.PutRefDispProperty |
                                 BindingFlags.SuppressChangeType;

            object[] attrs;

            foreach (System.Type type in aAssembly.GetTypes())
            {
                bool found = false;
                attrs = type.GetCustomAttributes(false);
                foreach (object attr in attrs)
                {
                    if (TypeValidator.IsCompatible(attr.GetType(), typeof(DevelopmentInformationAttribute)) == true)
                    {
                        types.Add(type);
                        found = true;
                        break;
                    }
                }
                if (found == false)
                {
                    foreach (MemberInfo info in type.GetMembers(flags))
                    {
                        try { attrs = info.GetCustomAttributes(false); }
                        catch { break; }
                        foreach (object attr in attrs)
                        {
                            if (TypeValidator.IsCompatible(attr.GetType(), typeof(DevelopmentInformationAttribute)) == true)
                            {
                                types.Add(type);
                                found = true;
                                break;
                            }
                        }
                        if (found == true)
                        {
                            break;
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Checks if object has collection of datarows
 /// </summary>
 /// <param name="aObjectType">
 /// A <see cref="System.Type"/>
 /// </param>
 /// <returns>
 /// A <see cref="System.Boolean"/>
 /// </returns>
 public static bool IsDatabaseException(System.Type aObjectType)
 {
     if (aObjectType == null)
     {
         return(false);
     }
     if (TypeValidator.IsCompatible(aObjectType, databaseExceptionTypes) == true)
     {
         return(true);
     }
     return(false);
 }
 /// <summary>
 /// Checks if object is virtual object related or not
 /// </summary>
 /// <param name="aObject">
 /// A <see cref="System.Object"/>
 /// </param>
 /// <returns>
 /// A <see cref="System.Boolean"/>
 /// </returns>
 public static bool IsValidType(object aObject)
 {
     if (aObject == null)
     {
         return(false);
     }
     if (TypeValidator.IsCompatible(aObject.GetType(), typeof(IVirtualObject)) == true)
     {
         return(true);
     }
     return(false);
 }
 /// <summary>
 /// Checks if object is database elated or not
 /// </summary>
 /// <param name="aObjectType">
 /// A <see cref="System.Type"/>
 /// </param>
 /// <returns>
 /// A <see cref="System.Boolean"/>
 /// </returns>
 public static bool IsValidType(System.Type aObjectType)
 {
     if (aObjectType == null)
     {
         return(false);
     }
     if ((TypeValidator.IsCompatible(aObjectType, databaseTypes) == true) ||
         (TypeValidator.IsCompatible(aObjectType, databaseRowTypes) == true))
     {
         return(true);
     }
     return(false);
 }
Exemple #14
0
 /// <summary>
 /// Subscribers should call this routine when widget changes. If DataSource
 /// supports EApplyMethod.Instant then it will simply invoke this adaptors
 /// Post routine
 /// </summary>
 public virtual void DemandInstantPost()
 {
     dataChanged = true;
     if (Control == null)
     {
         return;
     }
     if (TypeValidator.IsCompatible(Control.GetType(), typeof(IPostableControl)) == true)
     {
         if (DataSourceNeedsUpdateOn(EApplyMethod.Instant) == true)
         {
             InvokeControlDataChange(Control as IPostableControl, this);
         }
     }
 }
        /// <summary>
        /// Current assembly wide search for the type, type will be found even
        /// if this assembly doesn't reference to the assembly where type resides
        /// As long as type is loaded, it will found it no matter what.
        /// </summary>
        /// <param name="aAssembly">
        /// Assembly to check in <see cref="Assembly"/>
        /// </param>
        /// <param name="aCache">
        /// Cache of already checked libraries <see cref="StringCollection"/>
        /// </param>
        private static void GetWidgetsInAssembly(Assembly aAssembly, StringCollection aCache)
        {
            bool found = false;

            foreach (System.Type exptype in aAssembly.GetExportedTypes())
            {
                foreach (Attribute attr in exptype.GetCustomAttributes(false))
                {
                    if ((TypeValidator.IsCompatible(attr.GetType(), typeof(WidgetFactoryProviderAttribute)) == true) ||
                        (TypeValidator.IsCompatible(attr.GetType(), typeof(CellFactoryProviderAttribute)) == true))
                    {
                        RegisterClass(exptype);
                        break;
                    }
                }
            }
        }
 /// <summary>
 /// Enumerates all factory providers by specified filter
 /// </summary>
 /// <param name="aFilter">
 /// Filter string <see cref="System.String"/>
 /// </param>
 /// <param name="aType">
 /// Type for which responsible widgets should be enumerated <see cref="System.Type"/>
 /// </param>
 /// <returns>
 /// All invoker classes by specified filter <see cref="IEnumerable"/>
 /// </returns>
 public static IEnumerable AllCellsByFilterForType(string aFilter, System.Type aType)
 {
     aFilter = aFilter.Trim().ToLower();
     foreach (CellFactoryInvokerClass fi in CellHandlers)
     {
         if (TypeValidator.IsCompatible(fi.FactoryProvider.GetType(), typeof(TypeCellFactoryProviderAttribute)) == true)
         {
             if (fi.FactoryProvider.FactoryFilter == aFilter)
             {
                 if ((fi.FactoryProvider as TypeCellFactoryProviderAttribute).ValueType == aType)
                 {
                     yield return(fi);
                 }
             }
         }
     }
 }
Exemple #17
0
        /// <summary>
        /// Calls GetRequest for the datasource, and which invokes the action
        /// where all Adaptors connected start posting data back to the DataSource
        ///
        /// If DataSource is IObserveable then this request is redirected directly to
        /// the DataSource, otherwise it is redirected to central registry where all
        /// information needed for this to happen' is collected
        /// </summary>
        public static void GetRequest(object aDataSource)
        {
            if (aDataSource == null)
            {
                return;
            }

            getQueue.Current = aDataSource;
            if (getQueue.Current != aDataSource)
            {
                return;
            }

            // Check if this is adaptor we're asking about
            if (TypeValidator.IsCompatible(aDataSource.GetType(), typeof(Adaptor)) == true)
            {
                aDataSource = (aDataSource as Adaptor).FinalTarget;
                if (aDataSource == null)
                {
                    return;
                }
            }

            if (aDataSource is IObserveable)
            {
                // If target is IObserveable then there's no need to enter it into the registry
                // it can handle all on its own, so connection is made to him directly
                (aDataSource as IObserveable).GetRequest();
            }
            else
            {
                // Since DataSource is a stupid object registry has to handle his bindings and connections
                DataSourceInfo ds = (DataSourceInfo)GetInfoFor(aDataSource);
                if (ds != null)
                {
                    GetRequestForInfo(ds);
                    ds = null;
                }
            }
            getQueue.Current = null;
            if (getQueue.Current != null)
            {
                GetRequest(getQueue.Current);
            }
        }
Exemple #18
0
 private void Parse(System.Type aType)
 {
     object[] attrs;
     foreach (MemberInfo info in aType.GetMembers())
     {
         bool found = false;
         attrs = info.GetCustomAttributes(false);
         foreach (object attr in attrs)
         {
             if (TypeValidator.IsCompatible(attr.GetType(), typeof(DevelopmentInformationAttribute)) == true)
             {
                 members.Add(info);
                 found = true;
                 break;
             }
         }
     }
 }
Exemple #19
0
 /// <summary>
 /// Copies all data to object
 /// </summary>
 /// <param name="a_From">
 /// Source object <see cref="IVirtualObject"/>
 /// </param>
 /// <param name="a_To">
 /// Destination object <see cref="IVirtualObject"/>
 /// </param>
 public static void CopyDataTo(IVirtualObject a_From, IVirtualObject a_To)
 {
     if ((a_From == null) && (a_To == null))
     {
         return;
     }
     for (int i = 0; i < a_From.ObjectType.Count; i++)
     {
         VirtualProperty vp = a_To[a_From[i].Name];
         if (vp != null)
         {
             if (TypeValidator.IsCompatible(vp.PropertyType, a_From[i].PropertyType) == true)
             {
                 vp.Value = a_From[i].Value;
             }
         }
         vp = null;
     }
 }
Exemple #20
0
        public DevelopmentInformationAttribute[] GetDevelopmentInformations(Type aType)
        {
            ArrayList res = new ArrayList();

            Attribute[] attrs = (Attribute[])aType.GetCustomAttributes(false);
            foreach (Attribute attr in attrs)
            {
                if (TypeValidator.IsCompatible(attr.GetType(), typeof(DevelopmentInformationAttribute)) == true)
                {
                    res.Add(attr);
                }
            }
            DevelopmentInformationAttribute[] arr = new DevelopmentInformationAttribute[res.Count];
            for (int i = 0; i < Count; i++)
            {
                arr[i] = (DevelopmentInformationAttribute)res[i];
            }
            res.Clear();
            res = null;
            return(arr);
        }
        public static void DisconnectEventFromObserveableList(IObserveableList aList, object aObject)
        {
            if ((aList == null) || (aObject == null))
            {
                return;
            }
            int i = 0;

            foreach (object o in aList)
            {
                if (o == aObject)
                {
                    i++;
                }
            }
            if (i > 1)
            {
                return;
            }
            if (TypeValidator.IsCompatible(aList.GetType(), typeof(ObserveableList)) == false)
            {
                return;
            }
            if (aObject is INotifyPropertyChanged)
            {
                (aObject as INotifyPropertyChanged).PropertyChanged -= (aList as ObserveableList).ListItemPropertyChangedMethod;
            }
            else
            {
                // Disconnect from all PropertyChangedEventHandler properties
                foreach (EventInfo ev in aObject.GetType().GetEvents())
                {
                    if (ev.EventHandlerType is PropertyChangedEventHandler)
                    {
                        ev.RemoveEventHandler(aObject, (aList as ObserveableList).ListItemPropertyChangedMethod);
                    }
                }
            }
        }
        /// <summary>
        /// Resolves final target for Adaptor
        /// </summary>
        /// <returns>
        /// Object of the final target this adaptor is pointing to <see cref="System.Object"/>
        /// </returns>
        protected override object DoGetFinalTarget(out bool aCallControl)
        {
            aCallControl = false;
            if (GetDefaultProperty() == null)
            {
                return(null);
            }
            object res = base.DoGetFinalTarget(out aCallControl);

            finalTarget.Target = null;
            if (res == null)
            {
                return(null);
            }
            // Resolve forward if mapped property is adaptor
            object tgt = null;

            if (GetDefaultProperty() == null)
            {
                return(null);
            }
            if (CachedProperty.UncachedGetValue(res, GetDefaultProperty().Name, out tgt) == false)
            {
                tgt = ConnectionProvider.ResolveTargetForObject(tgt);
            }
            // set checks
            if (DataSourceType != null)
            {
                if (TypeValidator.IsCompatible(tgt.GetType(), DataSourceType) == true)
                {
                    return(tgt);
                }
                return(null);
            }
            else
            {
                return(tgt);
            }
        }
 /// <summary>
 /// Resolves property info, description and range
 /// </summary>
 private void Resolve()
 {
     if ((DataSourceType != null) && (PropertyName != ""))
     {
         if (TypeValidator.IsCompatible(DataSourceType, typeof(DataRow)) == true)
         {
             throw new NotSupportedException("DataRow is not supported");
         }
         if (TypeValidator.IsCompatible(DataSourceType, typeof(IVirtualObject)) == true)
         {
             throw new NotSupportedException("IVirtualObject is not supported");
         }
         propertyInfo = DataSourceType.GetProperty(PropertyName);
         if (State == PropertyDefinition.ReadWrite)
         {
             if (propertyInfo != null)
             {
                 if (propertyInfo.CanWrite == false)
                 {
                     State = PropertyDefinition.ReadOnly;
                 }
             }
         }
         if (propertyInfo != null)
         {
             description = propertyInfo.GetPropertyDescription();
             range       = propertyInfo.GetPropertyRange();
         }
         else
         {
             description = null;
             range       = null;
         }
         return;
     }
     propertyInfo = null;
     description  = null;
     range        = null;
 }
Exemple #24
0
        /// <summary>
        /// Copies all data to object
        /// </summary>
        /// <param name="a_From">
        /// Source object <see cref="IVirtualObject"/>
        /// </param>
        /// <param name="a_To">
        /// Destination object <see cref="System.Object"/>
        /// </param>
        public static void CopyDataTo(IVirtualObject a_From, object a_To)
        {
            if ((a_From == null) && (a_To == null))
            {
                return;
            }

            foreach (PropertyInfo prop in a_To.GetType().GetProperties())
            {
                VirtualProperty vp = a_From[prop.Name];
                if ((prop != null) && (vp != null))
                {
                    if (prop.CanWrite == true)
                    {
                        if (TypeValidator.IsCompatible(vp.PropertyType, prop.PropertyType) == true)
                        {
                            prop.SetValue(a_To, vp.Value, null);
                        }
                    }
                }
                vp = null;
            }
        }
Exemple #25
0
 /// <summary>
 /// Calls controls PutDataToDataSource, in case of gtk this handles being called
 /// in the right thread
 /// </summary>
 /// <param name="aControl">
 /// Control to call PutDataToDataSource <see cref="IPostableControl"/>
 /// </param>
 /// <param name="aSender">
 /// Sender object <see cref="System.Object"/>
 /// </param>
 /// <remarks>
 /// By overriding this method one can handle things differently. Specific
 /// example of this is GTK+ which needs to call control changes in its master thread
 /// </remarks>
 public virtual void InvokeDirectControlDataChange(IPostableControl aControl, object aSender)
 {
     if (TypeValidator.IsCompatible(aControl.GetType(), typeof(ICustomPostData)) == true)
     {
         if (ActivateUserPostData() == true)
         {
             return;
         }
     }
     // Since control will load new values clear flag that data has changed
     DataChanged = false;
     // Transfer data
     aControl.PutDataToDataSource(aSender);
     if (DisableMappingsDataTransfer == false)
     {
         if (TypeValidator.IsCompatible(adaptor.GetType(), typeof(Adaptor)) == true)
         {
             if ((adaptor as Adaptor).SingleMappingOnly == false)
             {
                 PutValuesToDataSource();
             }
         }
     }
 }