Exemplo n.º 1
0
        private static void DemonstrateTextFileStorage()
        {
            List <Person>   people = new List <Person>();
            List <LogEntry> logs   = new List <LogEntry>();

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

            PopulateLists(people, logs);

            /* -- With Generics */
            GenericTextFileProcessor.SaveToTextFile <Person>(people, peopleFile);
            GenericTextFileProcessor.SaveToTextFile <LogEntry>(logs, logFile);

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

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

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

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

            /* ----- without generics -----
             *
             * OriginalTextFileProcessor.SavePerson(people, peopleFile);
             *
             * var newPeople = OriginalTextFileProcessor.LoadPeople(peopleFile);
             *
             * foreach (var p in newPeople)
             * {
             *  Console.WriteLine($"{ p.FirstName } { p.LastName } ( IsAlive= { p.IsAlive })");
             * }
             *
             * OriginalTextFileProcessor.SaveLog(logs, logFile);
             *
             * var newLogs = OriginalTextFileProcessor.LoadLogs(logFile);
             *
             * foreach (var p in newLogs)
             * {
             *  Console.WriteLine($"Message = { p.Message }, ErrorCode = { p.ErrorCode } at { p.TimeOfEvent.ToShortTimeString() }");
             * }
             *
             */
        }
Exemplo n.º 2
0
        private static void DemonstrateTextFileStorage()
        {
            var people = new List <Person>();
            var logs   = new List <LogEntry>();

            string peopleFile = @"C:\Users\racol\OneDrive\Desktop\C# Learning\Learning_C#\Learning-.NET\Generics\Generics\people.csv";
            string logFile    = @"C:\Users\racol\OneDrive\Desktop\C# Learning\Learning_C#\Learning-.NET\Generics\Generics\logs.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 })");
            }

            Console.WriteLine();

            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 })");
            //}
        }
Exemplo n.º 3
0
        private static void DemonstrateTextFileStorage()
        {
            List <Person>   people = new List <Person> ();
            List <LogEntry> logs   = new List <LogEntry> ();

            string peopleFile = @"./people.csv";
            string logFile    = @"./logs.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 l in newLogs)
            {
                Console.WriteLine($"{ l.ErrorCode }: { l.Message } at { l.TimeOfEvent.ToShortTimeString() }");
            }

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

            // OriginalTextFileProcessor.SaveLogs (logs, logFile);

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

            // foreach (var l in newLogs) {
            //   Console.WriteLine ($"{ l.ErrorCode }: { l.Message } at { l.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 })");
            // }
        }
Exemplo n.º 4
0
        private static void TextFileStorage()
        {
            List <Person>   people     = new List <Person>();
            List <LogEntry> logEntries = new List <LogEntry>();

            string peopleFile = @"G:\document\Programing\C#\Generics\Generics\Temp\Person.csv";
            string logFile    = @"G:\document\Programing\C#\Generics\Generics\Temp\Logs.csv";

            PopulateList(people, logEntries);

            //********************** With Generics ***************

            GenericTextFileProcessor.SaveData <Person>(people, peopleFile);
            List <Person> peopleList = GenericTextFileProcessor.LoadDataFromFile <Person>(peopleFile);

            GenericTextFileProcessor.SaveData <LogEntry>(logEntries, logFile);
            List <LogEntry> LogList = GenericTextFileProcessor.LoadDataFromFile <LogEntry>(peopleFile);

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

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

            //**************** Without Generics ********************

            //OriginalTextFileProcessor.SavePeople(people, peopleFile);
            //List<Person> peopleList = OriginalTextFileProcessor.LoadPeople(peopleFile);

            //OriginalTextFileProcessor.SaveLogs(logEntries, logFile);
            //List<LogEntry> LogList = OriginalTextFileProcessor.Loadlogs(logFile);

            //foreach (var person in peopleList)
            //{
            //    Console.WriteLine($"{person.FirstName} {person.LastName} (IsAlive = {person.IsAlive})");
            //}

            //foreach (var log in LogList)
            //{
            //    Console.WriteLine($"{log.ErrorCode} : {log.Message} at {log.TimeOfEvent}");
            //}
        }
Exemplo n.º 5
0
        private static void DemonstrateTextFileStorage()
        {
            List <Person>   people     = new List <Person>();
            List <LogEntry> logs       = new List <LogEntry>();
            string          peopleFile = @"C:\Temp\people.csv";
            string          logFile    = @"C:\Temp\logs.csv";

            PopulateLists(people, logs);

            /* With Generics (good way of doing) */
            // instead of copy-paste and configure methods inside we have like OriginalTextFileProcessor
            // we can use generic method like this example.
            // if we have another model, not a problem. We dont need to configure another method for it.
            // GenericTextFileProcessor configures for all list types.
            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()}");
            }

            /* Without Generics (bad way of doing) */
            //OriginalTextFileProcessor.SavePeople(people, peopleFile);
            //var newPeople = OriginalTextFileProcessor.LoadPeople(peopleFile);
            //foreach (var p in newPeople)
            //{
            //    Console.WriteLine($"{ p.FirstName } { p.LastName } (IsAlive = { p.IsAlive })");
            //}

            //OriginalTextFileProcessor.SaveLogs(logs,logFile);
            //var newLogs = OriginalTextFileProcessor.LoadLogs(logFile);
            //foreach (var log in newLogs)
            //{
            //    Console.WriteLine($"{log.ErrorCode} : {log.Message} at {log.TimeOfEvent.ToShortTimeString()}");
            //}
        }
Exemplo n.º 6
0
        private static void DemonstrateTextFileStorage()
        {
            List <Person>   people = new List <Person>();
            List <LogEntry> logs   = new List <LogEntry>();

            string peopleFile = @"C:\Users\mindaugas.pikelis\source\repos\Generics\people.txt";
            string logFile    = @"C:\Users\mindaugas.pikelis\source\repos\Generics\logs.txt";

            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.SavePeople(people, peopleFile);

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

            //foreach (var p in newPeople)
            //{
            //    Console.WriteLine($"{ p.FirstName} { p.LastName } (IsAlive = { p.IsAlive })");
            //}
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press ENTER to start!");

            Console.ReadKey();

            List <Person> people = new List <Person>();
            List <Log>    logs   = new List <Log>();

            var peopleFile = @"C:\Users\JEAN-NOTE\AppData\Local\Temp\people.txt";
            var logFile    = @"C:\Users\JEAN-NOTE\AppData\Local\Temp\log.txt";

            PopulateLists(people, logs);

            /* New way of doing things - generics */
            GenericTextFileProcessor.SaveToTextFile <Person>(people, peopleFile);
            GenericTextFileProcessor.SaveToTextFile <Log>(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 <Log>(logFile);

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

            Console.WriteLine("Press ENTER to complete");
            Console.ReadKey();
        }