Example #1
0
        /// <summary>
        /// Gets the nested array.
        /// </summary>
        /// <param name="ct">Ct.</param>
        /// <param name="nestedString">Nested string.</param>
        /// <param name="dashes">Dashes.</param>
        /// <param name="alphabetize">If set to <c>true</c> alphabetize.</param>
        public void GetNestedArray(int ct, string nestedString, string dashes, bool alphabetize)
        {
            List <string> pump = new List <string>();

            pump = StringHelper.UnboxParenthesis(nestedString);
            if (alphabetize)
            {
                pump = pump.OrderBy(a => a).ToList();
            }
            foreach (var s in pump)
            {
                ct++;
                OutputCollection.Insert(ct, dashes + s);
            }
        }
Example #2
0
        /// <summary>
        /// Обновляет выходную коллекцию, стараясь изменить ее по минимуму, чтобы не перестраивать визуальное представление списка авторов
        /// </summary>
        public static void Refresh()
        {
            if (_isListUpdates)
            {
                return;
            }
            try
            {
                #region Создаем преставление данных из списка Authors, фильруем, сортируем

                ListCollectionView authorCollectionView = new ListCollectionView(Authors.Where(a => !a.IsDeleted).ToList());
                authorCollectionView.Filter += CheckIncludeAuthorInCollection;
                switch (_sortProperty)
                {
                case "UpdateDate":
                    authorCollectionView.SortDescriptions.Add(new SortDescription("Group", ListSortDirection.Ascending));
                    authorCollectionView.SortDescriptions.Add(new SortDescription(_sortProperty, _sortDirection));
                    break;

                case "Name":
                    authorCollectionView.SortDescriptions.Add(new SortDescription(_sortProperty, _sortDirection));
                    break;
                }

                #endregion

                #region Создаем из представления промежуточный список, который учитывает наличие категорий и их раскрытость

                List <object> tempList = new List <object>();
                if (UseCategory)
                {
                    string[] categoryFromAuthors = Authors.GetCategoryNames();
                    // подергиваем все категории из Authors, чтоб они создались в Categories, если их еще не было
                    foreach (string categoryName in categoryFromAuthors)
                    {
                        Categories.GetCategoryFromName(categoryName);
                    }
                    // заполняем промежуточный список
                    foreach (Category category in Categories)
                    {
                        category.SetVisualNameAndIsNew(authorCollectionView);
                        tempList.Add(category);
                        if (category.Collapsed)
                        {
                            continue;
                        }
                        foreach (Author author in authorCollectionView)
                        {
                            if (author.Category == category.Name)//&& !author.IsDeleted - сюда больше не попадают удаленные авторы, см. создание authorCollectionView в начале функции
                            {
                                tempList.Add(author);
                            }
                        }
                    }
                }
                else
                {
                    foreach (var collectionItem in authorCollectionView)
                    {
                        tempList.Add(collectionItem);
                    }
                }

                authorCollectionView.Filter -= CheckIncludeAuthorInCollection;

                #endregion

                #region Заполняем выходную коллекцию, стараясь по максимуму использовать имеющиеся элементы

                // Просматриваем выходную коллекцию, удаляя элементы, отсутствующие во временном списке
                for (int i = OutputCollection.Count - 1; i >= 0; i--)
                {
                    if (!tempList.Contains(OutputCollection[i]))
                    {
                        OutputCollection.RemoveAt(i);
                    }
                }
                // Просматриваем временную коллекцию, добавляя из нее в выходную те элементы,
                // которые отсутствуют в выходной коллекции. Одновременно выходная сортируется по временной
                for (int i = 0; i < tempList.Count; i++)
                {
                    object currentItem = tempList[i];
                    int    outPos      = OutputCollection.IndexOf(currentItem);
                    if (outPos == i)
                    {
                        continue;
                    }
                    if (outPos >= 0)
                    {
                        OutputCollection.Move(outPos, i);
                    }
                    else
                    {
                        OutputCollection.Insert(i, currentItem);
                    }
                }

                #endregion

                OnInfoUpdaterRefresh();
            }
            catch
            {}
        }