Пример #1
0
        private bool CheckRemoved(bool removed)
        {
            var collection = Client.GetDatabase(DatabaseName).GetCollection <T>(CollectionName);

            List <T> reloadedItems = new List <T>();

            using (var cursor = collection.FindSync(Filter))
            {
                var countryList = cursor.ToList();
                foreach (var country in countryList)
                {
                    reloadedItems.Add(country);
                }
            }

            if (reloadedItems.Count != LoadedItems.Count)
            {
                removed = true;
                LoadedItems.Clear();
                foreach (var item in reloadedItems)
                {
                    LoadedItems.Add(item);
                }
            }

            return(removed);
        }
Пример #2
0
        public IList <TNode> TakeAllUnreadedNodes()
        {
            var readedCount = ReadedItemsCount;

            ReadedItemsCount = LoadedItems.Count;
            return(LoadedItems.Skip(readedCount).ToList());
        }
Пример #3
0
        internal override void ValidateCollectionStateAfterLoad()
        {
            base.ValidateCollectionStateAfterLoad();

            if (this.Select(i => new { i.SystemId, i.KeyId }).Distinct().Count() != LoadedItems.Count())
            {
                throw new InvalidCpixDataException(
                          "The collection contains multiple DRM system signaling entries with the same system ID and content key ID combination.");
            }
        }
Пример #4
0
        /// <summary>
        /// Command callback.
        /// Called to switch between two variants of a vocab entry.
        /// </summary>
        /// <param name="variant">Variant to switch to.</param>
        private void OnSwitchVocab(VocabVariant variant)
        {
            int index = LoadedItems.IndexOf(variant.Parent);

            if (index >= 0)
            {
                VocabEntity newVocab = new VocabDao().GetVocabById(variant.Variant.ID);

                LoadedItems[index] = new ExtendedVocab(newVocab, newVocab.SrsEntries.Any() ?
                                                       new ExtendedSrsEntry(newVocab.SrsEntries.First()) : null);
            }
        }
        /// <summary>
        /// Loads all the items from the database into the list.
        /// </summary>
        /// <param name="itemsRead">The items retrieved from the database.</param>
        private void LoadAllItemsFromDatabase(IMongoCollection <T> itemsRead)
        {
            LoadedItems.Clear();

            using (IAsyncCursor <T> cursor = itemsRead.FindSync(Filter))
            {
                List <T> itemList = cursor.ToList();
                foreach (T item in itemList)
                {
                    LoadedItems.Add(item);
                }
            }
        }
        /// <summary>
        /// Loads all the items from the database into the list.
        /// </summary>
        /// <param name="itemsRead">The items retrieved from the database.</param>
        private void LoadAllItemsFromDatabase(IMongoCollection <T> itemsRead)
        {
            LoadedItems.Clear();

            using (var cursor = itemsRead.FindSync(Filter))
            {
                var countryList = cursor.ToList();
                foreach (var country in countryList)
                {
                    LoadedItems.Add(country);
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Executes the operation of retrieving and processing new items.
        /// </summary>
        private void LoadMoreAction()
        {
            // Get the amount of items to load.
            int loadCount = GetItemsPerPage();

            // Get the next batch of items.
            IEnumerable <Tentity> nextItems = _itemList.GetNext(loadCount);

            // Browse  and process each retrieved item.
            foreach (Tentity item in nextItems)
            {
                Tmodel model = ProcessItem(item);

                // Invoke the item addition on the dispatcher.
                DispatcherHelper.Invoke(() =>
                {
                    LoadedItems.Add(model);
                });

                LoadedItemCount++;
            }
        }
        /// <summary>
        /// Gets the loaded items matching the database after an item has been removed.
        /// </summary>
        private void UpdateLoadedAfterRemove()
        {
            IMongoCollection <T> collection =
                Client.GetDatabase(DatabaseName).GetCollection <T>(CollectionName);

            List <T> reloadedItems = new List <T>();

            using (IAsyncCursor <T> cursor = collection.FindSync(Filter))
            {
                List <T> itemList = cursor.ToList();
                reloadedItems.AddRange(itemList);
            }

            if (reloadedItems.Count != LoadedItems.Count)
            {
                LoadedItems.Clear();
                foreach (T item in reloadedItems)
                {
                    LoadedItems.Add(item);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Removes an item from the database.
        /// </summary>
        /// <param name="deleteItem">The item to remove.</param>
        public bool RemoveItemFromDatabase(T deleteItem)
        {
            bool removed = false;

            Client = new MongoClient(DatabaseConnectionString);

            ItemsDatabase = Client.GetDatabase(DatabaseName);

            IMongoCollection <T> itemsRead = ItemsDatabase.GetCollection <T>(CollectionName);

            LoadAllItemsFromDatabase(itemsRead);
            T foundItem = LoadedItems.Where(x => x.EquivalenceName == deleteItem.EquivalenceName).Select(x => x).FirstOrDefault();

            if (foundItem != null)
            {
                itemsRead.DeleteOne(a => a.Id == foundItem.Id);

                removed = CheckRemoved(removed);
            }

            return(removed);
        }
Пример #10
0
 /// <summary>
 /// Refreshes the selection information.
 /// </summary>
 public void RefreshSelection()
 {
     SelectedItems = LoadedItems.Where(i => i.IsSelected).ToList();
     ComputeSelectionStats();
 }