Example #1
0
        /// <summary>
        /// Calls PostRequest 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 PostRequest(object aDataSource)
        {
            if (aDataSource == null)
            {
                return;
            }

            postQueue.Current = aDataSource;
            if (postQueue.Current != aDataSource)
            {
                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).PostRequest();
            }
            else
            {
                // Since DataSource is a stupid object registry has to handle his bindings and connections
                DataSourceInfo ds = (DataSourceInfo)GetInfoFor(aDataSource);
                if (ds != null)
                {
                    ds.PostRequest();
                    ds = null;
                }
            }
            postQueue.Current = null;
            if (postQueue.Current != null)
            {
                PostRequest(postQueue.Current);
            }
        }
Example #2
0
 /// <summary>
 /// Usefull if one does want to provide caching method for geting updates and avoid discovery each time
 /// </summary>
 public static void GetRequestForInfo(DataSourceInfo aInfo)
 {
     if (aInfo == null)
     {
         return;
     }
     aInfo.GetRequest();
 }
Example #3
0
 /// <summary>
 /// Adds object to registry or connects events with Adaptor if object is
 /// supporting interface IObserveable
 ///
 /// If DataSource is IObserveable then it will be bypassing registry all the time
 /// </summary>
 public static bool Add(object aDataSource, IAdaptor aAdaptor, EApplyMethod aInstant)
 {
     if (aDataSource is IDataAdaptor)
     {
         return(Add((aDataSource as IDataAdaptor).FinalTarget, aAdaptor, aInstant));
     }
     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
         if (aAdaptor.IsBoundaryAdaptor == false)
         {
             (aDataSource as IObserveable).PostRequested += aAdaptor.PostMethod;
             (aDataSource as IObserveable).DataChanged   += aAdaptor.AdapteeDataChanged;
         }
         else
         {
             (aDataSource as IObserveable).DataChanged += aAdaptor.BoundaryAdapteeDataChanged;
         }
     }
     else
     {
         IObserveable ob = GetInfoFor(aDataSource);
         if (ob != null)
         {
             DataSourceInfo ds = (DataSourceInfo)ob;
             if (aAdaptor.IsBoundaryAdaptor == false)
             {
                 ds.PostRequested += aAdaptor.PostMethod;
                 ds.DataChanged   += aAdaptor.AdapteeDataChanged;
             }
             else
             {
                 ds.DataChanged += aAdaptor.BoundaryAdapteeDataChanged;
             }
             // Count direct adaptors only, ignore indirect
             if ((aAdaptor.Target is IAdaptor) == false)
             {
                 ds.RefCount += 1;
             }
             ds = null;
             return(true);
         }
         DataSourceInfo nds = new DataSourceInfo(aDataSource, aInstant);
         if (aAdaptor.IsBoundaryAdaptor == false)
         {
             nds.PostRequested += aAdaptor.PostMethod;
             nds.DataChanged   += aAdaptor.AdapteeDataChanged;
         }
         else
         {
             nds.DataChanged += aAdaptor.BoundaryAdapteeDataChanged;
         }
         datasources.Add(nds);
         nds = null;
     }
     return(true);
 }
Example #4
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);
            }
        }
Example #5
0
 /// <summary>
 /// Threadsafe index get, just assign null as ReferenceTarget if you don't need specific Target
 /// </summary>
 public static IObserveable GetInfo(int aIdx, object aReferenceTarget)
 {
     if ((aIdx >= 0) && (aIdx < Count))
     {
         DataSourceInfo res = (DataSourceInfo)datasources[aIdx];
         if (aReferenceTarget != null)
         {
             if (aReferenceTarget == res.Target)
             {
                 return(res);
             }
             else
             {
                 return(GetInfoFor(aReferenceTarget));
             }
         }
         else
         {
             return(res);
         }
     }
     return(null);
 }
Example #6
0
        /// <summary>
        /// Either removes object from central registry or disconnects Adaptor from the
        /// DataSource if object is supporting interface IObserveable
        ///
        /// If DataSource is IObserveable then it was bypassing registry all along
        /// </summary>
        public static void Remove(object aDataSource, IAdaptor aAdaptor)
        {
            int  idx   = 0;
            bool found = false;

            if (aDataSource is IDataAdaptor)
            {
                Remove((aDataSource as IDataAdaptor).FinalTarget, aAdaptor);
                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
                if (aAdaptor != null)
                {
                    if (aAdaptor.IsBoundaryAdaptor == false)
                    {
                        (aDataSource as IObserveable).PostRequested -= aAdaptor.PostMethod;
                        (aDataSource as IObserveable).DataChanged   -= aAdaptor.AdapteeDataChanged;
                    }
                    else
                    {
                        (aDataSource as IObserveable).DataChanged -= aAdaptor.BoundaryAdapteeDataChanged;
                    }
                }
            }
            else
            {
                foreach (DataSourceInfo ds in datasources)
                {
                    if (ds.Target == aDataSource)
                    {
                        found = true;
                        break;
                    }
                    else
                    {
                        idx++;
                    }
                }
                if (found == true)
                {
                    DataSourceInfo ds = (DataSourceInfo)datasources[idx];
                    // Count direct adaptors only, ignore indirect
                    if ((aAdaptor.Target is IAdaptor) == false)
                    {
                        ds.RefCount--;
                    }
                    if (ds != null)
                    {
                        if (ds.RefCount <= 0)
                        {
                            if (aAdaptor != null)
                            {
                                if (aAdaptor.IsBoundaryAdaptor == false)
                                {
                                    ds.PostRequested -= aAdaptor.PostMethod;
                                    ds.DataChanged   -= aAdaptor.AdapteeDataChanged;
                                }
                                else
                                {
                                    ds.DataChanged -= aAdaptor.BoundaryAdapteeDataChanged;
                                }
                            }
                            ds.Target = null;
                            datasources.RemoveAt(idx);
                        }
                    }
                    ds = null;
                }
            }
        }