From 893210d970dd3edb644a28c2f140419c1c546534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Sat, 24 Oct 2020 09:11:51 +0200 Subject: [PATCH] Add project files. --- ConsoleUI/App.config | 6 ++ ConsoleUI/ConsoleUI.csproj | 59 +++++++++++++ ConsoleUI/Models/LogEntry.cs | 15 ++++ ConsoleUI/Models/Person.cs | 15 ++++ ConsoleUI/Program.cs | 68 ++++++++++++++ ConsoleUI/Properties/AssemblyInfo.cs | 36 ++++++++ .../OriginalTextFileProcessor.cs | 88 +++++++++++++++++++ ConsoleUIApp.sln | 25 ++++++ 8 files changed, 312 insertions(+) create mode 100644 ConsoleUI/App.config create mode 100644 ConsoleUI/ConsoleUI.csproj create mode 100644 ConsoleUI/Models/LogEntry.cs create mode 100644 ConsoleUI/Models/Person.cs create mode 100644 ConsoleUI/Program.cs create mode 100644 ConsoleUI/Properties/AssemblyInfo.cs create mode 100644 ConsoleUI/WithoutGenerics/OriginalTextFileProcessor.cs create mode 100644 ConsoleUIApp.sln diff --git a/ConsoleUI/App.config b/ConsoleUI/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/ConsoleUI/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ConsoleUI/ConsoleUI.csproj b/ConsoleUI/ConsoleUI.csproj new file mode 100644 index 0000000..d929ab2 --- /dev/null +++ b/ConsoleUI/ConsoleUI.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {D9FBF1D4-90F4-4014-A9EE-59CD1D0C0858} + Exe + ConsoleUI + ConsoleUI + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ConsoleUI/Models/LogEntry.cs b/ConsoleUI/Models/LogEntry.cs new file mode 100644 index 0000000..52ec9e2 --- /dev/null +++ b/ConsoleUI/Models/LogEntry.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleUI.Models +{ + public class LogEntry + { + public string Message { get; set; } + public int ErrorCode { get; set; } + public DateTime TimeOfEvent { get; set; } = DateTime.UtcNow; + } +} diff --git a/ConsoleUI/Models/Person.cs b/ConsoleUI/Models/Person.cs new file mode 100644 index 0000000..2cd6def --- /dev/null +++ b/ConsoleUI/Models/Person.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleUI.Models +{ + public class Person + { + public string FirstName { get; set; } + public string LastName { get; set; } + public bool IsAlive { get; set; } + } +} diff --git a/ConsoleUI/Program.cs b/ConsoleUI/Program.cs new file mode 100644 index 0000000..7072467 --- /dev/null +++ b/ConsoleUI/Program.cs @@ -0,0 +1,68 @@ +using ConsoleUI.Models; +using ConsoleUI.WithoutGenerics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleUI +{ + class Program + { + static void Main(string[] args) + { + //List ages = new List(); + //ages.Add(23); + Console.ReadLine(); + + DemostrateTextFileStorage(); + + Console.WriteLine(); + Console.Write($"Press enter to shut down..."); + Console.ReadLine(); + + } + + private static void DemostrateTextFileStorage() + { + List people = new List(); + List logs = new List(); + + string peopleFile = @"C:\Temp\people.csv"; + string logFile = @"C:\Temp\logs.csv"; + + PopulateLists(people, logs); + + 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})"); + //} + } + + private static void PopulateLists(List people, List logs) + { + people.Add(new Person { FirstName = "Tim", LastName = "Corey" }); + people.Add(new Person { FirstName = "Sue", LastName = "Storm", IsAlive=false }); + people.Add(new Person { FirstName = "Greg", LastName = "Olsen" }); + + logs.Add(new LogEntry { Message = "I blew up", ErrorCode = 9999 }); + logs.Add(new LogEntry { Message = "I'm too awesome", ErrorCode = 1337 }); + logs.Add(new LogEntry { Message = "I was tired", ErrorCode = 2222 }); + } + } +} diff --git a/ConsoleUI/Properties/AssemblyInfo.cs b/ConsoleUI/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b8cfb00 --- /dev/null +++ b/ConsoleUI/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ConsoleUI")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ConsoleUI")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d9fbf1d4-90f4-4014-a9ee-59cd1d0c0858")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ConsoleUI/WithoutGenerics/OriginalTextFileProcessor.cs b/ConsoleUI/WithoutGenerics/OriginalTextFileProcessor.cs new file mode 100644 index 0000000..f863ab8 --- /dev/null +++ b/ConsoleUI/WithoutGenerics/OriginalTextFileProcessor.cs @@ -0,0 +1,88 @@ +using ConsoleUI.Models; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleUI.WithoutGenerics +{ + public class OriginalTextFileProcessor + { + + public static List LoadPeople(string filePath) + { + List output = new List(); + Person p; + var lines = System.IO.File.ReadAllLines(filePath).ToList(); + + // remove the header row + lines.RemoveAt(0); + + foreach (var line in lines) + { + var vals = line.Split(';'); + p = new Person(); + p.FirstName = vals[0]; + p.IsAlive = bool.Parse(vals[1]); + p.LastName = vals[2]; + + output.Add(p); + } + + return output; + } + + public static List LoadLogs(string filePath) + { + List output = new List(); + LogEntry log; + var lines = System.IO.File.ReadAllLines(filePath).ToList(); + + // remove the header row + lines.RemoveAt(0); + + foreach (var line in lines) + { + var vals = line.Split(';'); + log = new LogEntry(); + log.ErrorCode= int.Parse(vals[0]); + log.Message = vals[1]; + log.TimeOfEvent = DateTime.Parse(vals[2]); + + output.Add(log); + } + + return output; + } + + public static void SavePeople(List people, string filePath) + { + List lines = new List(); + + //Add a header row + lines.Add("FirstName,IsAlive,LastName"); + foreach(var p in people) + { + lines.Add($"{p.FirstName};{p.IsAlive};{p.LastName}"); + } + + System.IO.File.WriteAllLines(filePath, lines); + } + public static void SaveLogs(List logs, string filePath) + { + List lines = new List(); + + //Add a header row + lines.Add("ErrorCode,Message,TimeOfEvent"); + foreach (var l in logs) + { + lines.Add($"{l.ErrorCode};{l.Message};{l.TimeOfEvent}"); + } + + System.IO.File.WriteAllLines(filePath, lines); + } + } +} diff --git a/ConsoleUIApp.sln b/ConsoleUIApp.sln new file mode 100644 index 0000000..1a283f0 --- /dev/null +++ b/ConsoleUIApp.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30517.126 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleUI", "ConsoleUI\ConsoleUI.csproj", "{D9FBF1D4-90F4-4014-A9EE-59CD1D0C0858}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D9FBF1D4-90F4-4014-A9EE-59CD1D0C0858}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D9FBF1D4-90F4-4014-A9EE-59CD1D0C0858}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D9FBF1D4-90F4-4014-A9EE-59CD1D0C0858}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D9FBF1D4-90F4-4014-A9EE-59CD1D0C0858}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1F99C1A6-0AD4-4762-ABED-58BBC241B7A6} + EndGlobalSection +EndGlobal