Add project files.
This commit is contained in:
6
ConsoleUI/App.config
Normal file
6
ConsoleUI/App.config
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||
</startup>
|
||||
</configuration>
|
||||
59
ConsoleUI/ConsoleUI.csproj
Normal file
59
ConsoleUI/ConsoleUI.csproj
Normal file
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{D9FBF1D4-90F4-4014-A9EE-59CD1D0C0858}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>ConsoleUI</RootNamespace>
|
||||
<AssemblyName>ConsoleUI</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Models\LogEntry.cs" />
|
||||
<Compile Include="Models\Person.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="WithoutGenerics\OriginalTextFileProcessor.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="WithGenerics\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
15
ConsoleUI/Models/LogEntry.cs
Normal file
15
ConsoleUI/Models/LogEntry.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
15
ConsoleUI/Models/Person.cs
Normal file
15
ConsoleUI/Models/Person.cs
Normal file
@ -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; }
|
||||
}
|
||||
}
|
||||
68
ConsoleUI/Program.cs
Normal file
68
ConsoleUI/Program.cs
Normal file
@ -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<int> ages = new List<int>();
|
||||
//ages.Add(23);
|
||||
Console.ReadLine();
|
||||
|
||||
DemostrateTextFileStorage();
|
||||
|
||||
Console.WriteLine();
|
||||
Console.Write($"Press enter to shut down...");
|
||||
Console.ReadLine();
|
||||
|
||||
}
|
||||
|
||||
private static void DemostrateTextFileStorage()
|
||||
{
|
||||
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);
|
||||
|
||||
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<Person> people, List<LogEntry> 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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
36
ConsoleUI/Properties/AssemblyInfo.cs
Normal file
36
ConsoleUI/Properties/AssemblyInfo.cs
Normal file
@ -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")]
|
||||
88
ConsoleUI/WithoutGenerics/OriginalTextFileProcessor.cs
Normal file
88
ConsoleUI/WithoutGenerics/OriginalTextFileProcessor.cs
Normal file
@ -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<Person> LoadPeople(string filePath)
|
||||
{
|
||||
List<Person> output = new List<Person>();
|
||||
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<LogEntry> LoadLogs(string filePath)
|
||||
{
|
||||
List<LogEntry> output = new List<LogEntry>();
|
||||
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<Person> people, string filePath)
|
||||
{
|
||||
List<string> lines = new List<string>();
|
||||
|
||||
//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<LogEntry> logs, string filePath)
|
||||
{
|
||||
List<string> lines = new List<string>();
|
||||
|
||||
//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);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
ConsoleUIApp.sln
Normal file
25
ConsoleUIApp.sln
Normal file
@ -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
|
||||
Reference in New Issue
Block a user