예제 #1
0
        private void AddItemToGroup(SerializableDictionary <string, SortableList <IHistoryItem> > groupedByDate, HistoryItem item)
        {
            string intervalName = HistoryIntervals.GetDateIntervalName(item.Date);
            SortableList <IHistoryItem> timeIntervalItems = GetTimeIntervalItems(intervalName, groupedByDate);

            if (!timeIntervalItems.Contains(item)) // add each item only once
            {
                timeIntervalItems.Add(item);
            }
        }
예제 #2
0
        private static SortableList <IFavorite> SelectFavoritesFromHistoryItems(
            SortableList <IHistoryItem> groupedByDate)
        {
            var selection = new SortableList <IFavorite>();

            foreach (IHistoryItem favoriteTouch in groupedByDate)
            {
                IFavorite favorite = favoriteTouch.Favorite;
                if (favorite != null && !selection.Contains(favorite)) // add each favorite only once
                {
                    selection.Add(favorite);
                }
            }

            return(selection);
        }
예제 #3
0
        private static SortableList <FavoriteConfigurationElement> SelectFavoritesFromHistoryItems(SortableList <HistoryItem> groupedByDate)
        {
            FavoriteConfigurationElementCollection      favorites = Settings.GetFavorites(false);
            SortableList <FavoriteConfigurationElement> selection = new SortableList <FavoriteConfigurationElement>();

            foreach (HistoryItem favoriteTouch in groupedByDate)
            {
                FavoriteConfigurationElement favorite = favorites[favoriteTouch.Name];
                if (favorite != null && !selection.Contains(favorite))
                {
                    selection.Add(favorite);
                }
            }

            return(selection);
        }
예제 #4
0
        public SerializableDictionary <string, SortableList <HistoryItem> > GroupByDate()
        {
            Kohl.Framework.Logging.Log.Info("Grouping history items by date.");

            SerializableDictionary <string, SortableList <HistoryItem> > groupedByDate = this.InitializeGroups();

            foreach (string name in this.Keys)           //name is the favorite name
            {
                foreach (HistoryItem item in this[name]) //each history item per favorite
                {
                    SortableList <HistoryItem> timeIntervalItems = this.GetTimeIntervalItems(item.DateGroup,
                                                                                             groupedByDate);
                    if (!timeIntervalItems.Contains(item))
                    {
                        timeIntervalItems.Add(item);
                    }
                }
            }
            return(groupedByDate);
        }
예제 #5
0
        /// <summary>
        /// Entry point for the SortableList use case.
        /// </summary>
        public static void Main()
        {
            try
            {
                Console.WriteLine("You create a new SortableList.");
                SortableList SL = new SortableList();

                Console.Write("You set the KeepSorted property to false and you fill it with the strings X, B, A, D: ");
                SL.KeepSorted = false;
                SL.Add("X");
                SL.Add("B");
                SL.Add("A");
                SL.Add("D");
                Console.WriteLine(SL);

                Console.Write("You can insert or set elements where you want since KeepSorted==false. Let's set 'C' to index 4: ");
                SL[3] = "C";
                Console.WriteLine(SL);

                Console.Write("You decide to sort the list: ");
                SL.Sort();
                Console.WriteLine(SL);

                Console.Write("You now set the KeepSorted property to true and add some new strings: ");
                SL.KeepSorted = true;
                SL.Add("J");
                SL.Add("E");
                SL.Add("E");
                SL.Add("B");
                SL.Add("X");
                SL.Add("E");
                SL.Add("E");
                Console.WriteLine(SL);

                Console.WriteLine("'E' is found at index " + SL.IndexOf("E").ToString());
                Console.WriteLine("Is the list containing an 'X' value ?: " + SL.Contains("X").ToString());
                Console.WriteLine("Is the list containing an 'M' value ?: " + SL.Contains("M").ToString());

                Console.Write("You limit the number of occurrences of 'E' to 2: ");
                SL.LimitNbOccurrences("E", 2);
                Console.WriteLine(SL);

                Console.Write("After all you do not want any duplicates: ");
                SL.RemoveDuplicates();
                Console.WriteLine(SL);

                Console.Write("You set the AddDuplicates property to false and try to add J and E again: ");
                SL.AddDuplicates = false;
                SL.Add("J");
                SL.Add("E");
                Console.WriteLine(SL);

                Console.WriteLine("Now you create another SortableList but this time you give it an IComparer class which is the anti-alphabetical order.");
                SL = new SortableList(new AntiAlphabeticalComparer());

                Console.Write("You fill the list by adding a range of vowels in alphabetical order. Result: ");
                string[] Vowels = new string[] { "A", "E", "I", "O", "U" };
                SL.AddRange(Vowels);
                Console.WriteLine(SL);

                Console.Write("Serialize and Deserialize: ");
                Stream          StreamWrite = File.Create("SortableListSaved.bin");
                BinaryFormatter BinaryWrite = new BinaryFormatter();
                BinaryWrite.Serialize(StreamWrite, SL);
                StreamWrite.Close();

                Stream          StreamRead = File.OpenRead("SortableListSaved.bin");
                BinaryFormatter BinaryRead = new BinaryFormatter();
                SortableList    SL2        = (SortableList)BinaryRead.Deserialize(StreamRead);
                StreamRead.Close();
                Console.WriteLine(SL2);
            }
            catch (Exception e) { Console.Write("Error :\n\n" + e.ToString()); }

            Console.ReadLine();
        }
        private static SortableList<IFavorite> SelectFavoritesFromHistoryItems(
            SortableList<IHistoryItem> groupedByDate)
        {
            var selection = new SortableList<IFavorite>();
            foreach (IHistoryItem favoriteTouch in groupedByDate)
            {
                IFavorite favorite = favoriteTouch.Favorite;
                if (favorite != null && !selection.Contains(favorite)) // add each favorite only once
                    selection.Add(favorite);
            }

            return selection;
        }
예제 #7
0
        private static SortableList<FavoriteConfigurationElement> SelectFavoritesFromHistoryItems(SortableList<HistoryItem> groupedByDate)
        {
            FavoriteConfigurationElementCollection favorites = Settings.GetFavorites(false);
            SortableList<FavoriteConfigurationElement> selection = new SortableList<FavoriteConfigurationElement>();
            foreach (HistoryItem favoriteTouch in groupedByDate)
            {
                FavoriteConfigurationElement favorite = favorites[favoriteTouch.Name];
                if (favorite != null && !selection.Contains(favorite))
                    selection.Add(favorite);
            }

            return selection;
        }