Exemple #1
0
        private static void DemonstrateTextFileStorage()
        {
            List <Person>   people = new List <Person>();
            List <LogEntry> logs   = new List <LogEntry>();

            string peopleFile = @"C:\Demo\people.csv";
            string logFile    = @"C:\Demo\logs.csv";

            PopulateLists(people, logs);

            /* New way of doing things - generics */

            GenericTextFileProcessor.SaveToTextFile(logs, logFile);

            /* Old way of doing things - non-generics */

            //OriginalTextFileProcessor.SavePeople(people, peopleFile);

            //var newPeople = OriginalTextFileProcessor.LoadPeople(peopleFile);

            //foreach (var p in newPeople)
            //{
            //    Console.WriteLine($"{ p.FirstName } { p.LastName } (IsAlive = { p.IsAlive })");
            //}
        }
Exemple #2
0
        private static void DemonstrateTextFileStorage()
        {
            List <Person>   people = new List <Person>();
            List <LogEntry> logs   = new List <LogEntry>();

            string peopleFile = @"C:\Scratch\people.csv";
            string logFile    = @"C:\Scratch\log.csv";

            PopulateLists(people, logs);

            /* New way of doing things - generics */

            GenericTextFileProcessor.SaveToTextFile <Person>(people, peopleFile);
            GenericTextFileProcessor.SaveToTextFile <LogEntry>(logs, logFile);

            var newPeople = GenericTextFileProcessor.LoadFromTextFile <Person>(peopleFile);

            foreach (var p in newPeople)
            {
                Console.WriteLine($"{p.FirstName} {p.LastName} (IsAlive = {p.IsAlive})");
            }

            var newLogs = GenericTextFileProcessor.LoadFromTextFile <LogEntry>(logFile);

            foreach (var log in newLogs)
            {
                Console.WriteLine($"{log.ErrorCode}: {log.Message} at {log.TimeOfEvent.ToShortTimeString()}");
            }

            /* Old way of doing things - non generics */

            //OriginalTextFileProcessor.SaveLogs(logs, logFile);

            //var newLogs = OriginalTextFileProcessor.LoadLogs(logFile);

            //foreach (var log in newLogs)
            //{
            //  Console.WriteLine($"{log.ErrorCode}: {log.Message} at {log.TimeOfEvent.ToShortTimeString()}");
            //}


            //OriginalTextFileProcessor.SavePeople(people, peopleFile);

            //var newPeople = OriginalTextFileProcessor.LoadPeople(peopleFile);

            //foreach (var p in newPeople)
            //{
            //  Console.WriteLine($"{p.FirstName} {p.LastName} (IsAlive = {p.IsAlive})");
            //}
        }
Exemple #3
0
        private static void DemostrateTextFileStorage()
        {
            List <Person>   people    = new List <Person>();
            List <LogEntry> logs      = new List <LogEntry>();
            var             peopleFil = @"D:\dev\TrainingGround\Advanced topics in C#\TestData\people.csv";
            var             logFile   = @"D:\dev\TrainingGround\Advanced topics in C#\TestData\logs.csv";

            PopulateLists(people, logs);

            /*** new way of doing thingd - generics ***/
            GenericTextFileProcessor.SaveToTextFile <Person>(people, peopleFil);

            GenericTextFileProcessor.SaveToTextFile <LogEntry>(logs, logFile);

            var newPeople = GenericTextFileProcessor.LoadFromTextFile <Person>(peopleFil);

            foreach (var p in newPeople)
            {
                Console.WriteLine($"{p.FirstName} {p.LastName} (IsAlive = {p.IsAlive})");
            }

            var newLogs = GenericTextFileProcessor.LoadFromTextFile <LogEntry>(logFile);

            foreach (var log in newLogs)
            {
                Console.WriteLine($"{log.ErrorCode} {log.Message} at {log.TimeOfEvent.ToShortTimeString()}");
            }
            /*#############################################################*/
            /*** old way of doing thingd - non-generics ***/

            //OriginalTextFileProcessor.SaveLogs(logs, logFile);

            //var newLogs = OriginalTextFileProcessor.LoadLogs(logFile);

            //foreach (var log in newLogs)
            //{
            //    Console.WriteLine($"{log.ErrorCode} {log.Message} at {log.TimeOfEvent.ToShortTimeString()}");
            //}

            //OriginalTextFileProcessor.SavePeople(people, peopleFil);

            //var newPeople = OriginalTextFileProcessor.LoadPeople(peopleFil);

            //foreach (var p in newPeople)
            //{
            //    Console.WriteLine($"{p.FirstName} {p.LastName} (IsAlive = {p.IsAlive})");
            //}
            /*#############################################################*/
        }