Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // The Length property is used to obtain the length of the array.
            // Notice that Length is a read-only property:
            Output("Number of command line parameters = {0}", args.Length);

            try
            {
                _format = (SortOutputFormat)Convert.ToInt32(args[1]);
                _fileName = args[0].ToString().Trim();
                Output("Input - Filename: {0} Sort Format: {1}", _fileName, _format.ToString());

            }
            catch(Exception)
            {
                Output("ERROR: Please provide valid arguments ex: c:\temp\testdata.txt 1");
                PauseExit();
            }

            // Create the Worker classes - These contain all the implementation code.
            FileParser parser = new FileParser();
            Sorter sorter = new Sorter();

            // Parse People from file
            IList<Person> people = parser.ParseFile(_fileName);

            // Sort People
            IList<Person> sorted = sorter.Sort(people, _format);

            // Display People
            Output(people);

            // Call REST Api
            CallRestApi();

            // Wait for Press any Key
            PauseExit();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sorts a Person collection and returns the sorted results.
        /// </summary>
        /// <param name="people"></param>
        /// <param name="sortFormat"></param>
        /// <returns></returns>
        public IList<Person> Sort(IList<Person> people, SortOutputFormat sortFormat)
        {
            IList<Person> sorted = null;

            switch(sortFormat)
            {
                case SortOutputFormat.Output1:
                    {
                        sorted = people.OrderBy(p => p.Gender).ThenBy((p => p.LastName)).ToList();
                        break;
                    }
                case SortOutputFormat.Output2:
                    {
                        sorted = people.OrderBy(p => p.DateOfBirth).ToList();
                        break;
                    }
                case SortOutputFormat.Output3:
                        sorted = people.OrderByDescending(p => p.LastName).ToList();
                        break;
            }

            return sorted;
        }