Exemple #1
0
        private SortableList <StatsDomainObject> GetStats(string mode, string filterTourType)
        {
            var list = new SortableList <StatsDomainObject>();

            switch (mode)
            {
            case "Fighter":
                list = Registry.GetPilotStats(PilotName).FighterStatsList;
                break;

            case "Attack":
                list = Registry.GetPilotStats(PilotName).AttackStatsList;
                break;

            case "Bomber":
                list = Registry.GetPilotStats(PilotName).BomberStatsList;
                break;

            case "Vehicle/Boat":
                list = Registry.GetPilotStats(PilotName).VehicleBoatStatsList;
                break;
            }

            var filteredList = new SortableList <StatsDomainObject>();

            filteredList.AddRange(list.Where(statsObj => statsObj.TourType == filterTourType));

            if (filteredList.Count > 0)
            {
                filteredList.SortList("TourNumber", ListSortDirection.Ascending);
            }

            return(filteredList);
        }
Exemple #2
0
        private void LoadStatsObjects(string selectedPilot)
        {
            var stats        = new SortableList <AcesHighPilotStats>();
            var xmlFileNames = Directory.GetFiles(@"data", string.Format("{0}*_Stats*.xml", selectedPilot));

            stats.AddRange(from xmlFileName in xmlFileNames
                           let xSerializer = new XmlSerializer(typeof(AcesHighPilotStats))
                                             select(AcesHighPilotStats) xSerializer.Deserialize(new StreamReader(xmlFileName)));

            if (!_pilotStatsObjMap.ContainsKey(selectedPilot))
            {
                _pilotStatsObjMap.Add(selectedPilot, stats);
            }
        }
        /// <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();
        }