Esempio n. 1
0
        public bool ItemExists(T item)
        {
            IHaveUniqueKey haveUniqueKey = (object)item as IHaveUniqueKey;

            if (haveUniqueKey != null)
            {
                return(this._collectionItemsDict.ContainsKey(haveUniqueKey.GetKey()));
            }
            return(false);
        }
Esempio n. 2
0
        public void ReadData(ListWithCount <T> listWithCount)
        {
            this._updatingCollection = true;
            this._totalCount         = listWithCount.TotalCount;
            bool receivedNewData = false;

            this.RaiseOnStartedEdit();
            listWithCount.List.ForEach((Action <T>)(t =>
            {
                IList list1 = t as IList;
                bool flag1  = false;
                if (list1 != null)
                {
                    int index = listWithCount.List.IndexOf(t);
                    if (index >= 0 && index < this._collection.Count)
                    {
                        IList list2 = this._collection[index] as IList;
                        foreach (object obj in list1)
                        {
                            list2.Add(obj);
                        }
                        receivedNewData = true;
                        flag1           = true;
                    }
                }
                if (flag1)
                {
                    return;
                }
                bool flag2 = true;
                IHaveUniqueKey haveUniqueKey = t as IHaveUniqueKey;
                if (haveUniqueKey != null && this._collectionItemsDict.ContainsKey(haveUniqueKey.GetKey()))
                {
                    flag2 = false;
                }
                if (!flag2)
                {
                    return;
                }
                this._collection.Add(t);
                this.AddRemoveKeyToDict(t, true);
                receivedNewData = true;
            }));
            this.RaiseOnEndedEdit();
            this._noDataOnLastFetch  = listWithCount.List.Count == 0 || !receivedNewData;
            this._updatingCollection = false;
        }
 private void ReadLocalData(List <T> data, Action callback)
 {
     Execute.ExecuteOnUIThread((Action)(() =>
     {
         foreach (T obj in data)
         {
             IHaveUniqueKey haveUniqueKey = obj as IHaveUniqueKey;
             if (haveUniqueKey == null || !this._collectionItemsDict.ContainsKey(haveUniqueKey.GetKey()))
             {
                 this._localGroup.Add(obj);
                 this.AddRemoveKeyToDict(obj, true);
                 this._preloadedItemsCount = this._preloadedItemsCount + 1;
             }
         }
         Action action = callback;
         if (action == null)
         {
             return;
         }
         action();
     }));
 }
        private void AddRemoveKeyToDict(object t, bool add)
        {
            IHaveUniqueKey haveUniqueKey = t as IHaveUniqueKey;

            if (haveUniqueKey == null)
            {
                return;
            }
            string key = haveUniqueKey.GetKey();

            if (string.IsNullOrEmpty(key))
            {
                return;
            }
            if (add)
            {
                this._collectionItemsDict[key] = key;
            }
            else
            {
                this._collectionItemsDict.Remove(key);
            }
        }
        public bool ReadData(ListWithCount <T> listWithCount)
        {
            this._updatingCollection = true;
            bool flag1 = false;

            this._totalCount = listWithCount.TotalCount;
            IList collection      = this.IsGroupedMode ? (IList)this._globalGroup : (IList)this._collection;
            bool  receivedNewData = false;

            this.RaiseOnStartedEdit();
            listWithCount.List.ForEach((Action <T>)(listItem =>
            {
                IList list1 = listItem as IList;
                if (list1 != null)
                {
                    IList list2 = null;
                    int index   = listWithCount.List.IndexOf(listItem);
                    if (index > -1 && index < collection.Count)
                    {
                        list2 = collection[index] as IList;
                    }
                    if (list2 == null)
                    {
                        if (list1.Count <= 0)
                        {
                            return;
                        }
                        bool flag2             = false;
                        IEnumerator enumerator = ((IEnumerable)list1).GetEnumerator();
                        try
                        {
                            while (enumerator.MoveNext())
                            {
                                object current = enumerator.Current;
                                IHaveUniqueKey haveUniqueKey = current as IHaveUniqueKey;
                                if (haveUniqueKey != null && !this._collectionItemsDict.ContainsKey(haveUniqueKey.GetKey()))
                                {
                                    this.AddRemoveKeyToDict(current, true);
                                    flag2 = true;
                                }
                            }
                        }
                        finally
                        {
                            IDisposable disposable = enumerator as IDisposable;
                            if (disposable != null)
                            {
                                disposable.Dispose();
                            }
                        }
                        if (!flag2)
                        {
                            return;
                        }
                        collection.Add(listItem);
                        receivedNewData = true;
                    }
                    else
                    {
                        IEnumerator enumerator = ((IEnumerable)list2).GetEnumerator();
                        try
                        {
                            while (enumerator.MoveNext())
                            {
                                object current = enumerator.Current;
                                bool flag2     = true;
                                IHaveUniqueKey haveUniqueKey = current as IHaveUniqueKey;
                                if (haveUniqueKey != null && this._collectionItemsDict.ContainsKey(haveUniqueKey.GetKey()))
                                {
                                    flag2 = false;
                                }
                                if (flag2)
                                {
                                    list2.Add(current);
                                    this.AddRemoveKeyToDict(current, true);
                                    receivedNewData = true;
                                }
                            }
                        }
                        finally
                        {
                            IDisposable disposable = enumerator as IDisposable;
                            if (disposable != null)
                            {
                                disposable.Dispose();
                            }
                        }
                    }
                }
                else
                {
                    bool flag2 = true;
                    IHaveUniqueKey haveUniqueKey = listItem as IHaveUniqueKey;
                    if (haveUniqueKey != null && this._collectionItemsDict.ContainsKey(haveUniqueKey.GetKey()))
                    {
                        flag2 = false;
                    }
                    if (!flag2)
                    {
                        return;
                    }
                    if (this.IsGroupedMode)
                    {
                        if (this._localDataProvider.GetIsLocalItem(listItem))
                        {
                            this._localGroup.Add(listItem);
                        }
                        else
                        {
                            this._globalGroup.Add(listItem);
                        }
                    }
                    else
                    {
                        collection.Add(listItem);
                    }
                    this.AddRemoveKeyToDict(listItem, true);
                    receivedNewData = true;
                }
            }));
            this.RaiseOnEndedEdit();
            if (listWithCount.List.Count == 0 || !receivedNewData)
            {
                this._noDataOnLastFetch = this._noDataOnLastFetch + 1;
                if (this._noDataOnLastFetch < 2)
                {
                    flag1 = true;
                }
            }
            else
            {
                this._noDataOnLastFetch = 0;
            }
            this._updatingCollection = false;
            return(flag1);
        }