-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Leonard Sperry
committed
Dec 7, 2020
1 parent
eaa36a6
commit 854de29
Showing
38 changed files
with
1,667 additions
and
1,480 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace CsvProcessor | ||
{ | ||
class Account | ||
{ | ||
public int ID { get; set; } | ||
public string Name { get; set; } | ||
public decimal? Value { get; set; } | ||
} | ||
} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace CsvProcessor | ||
{ | ||
class Account | ||
{ | ||
public int ID { get; set; } | ||
public string Name { get; set; } | ||
public decimal? Value { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace CsvProcessor | ||
{ | ||
class AccountParsingLogic : IAccountParsingLogic | ||
{ | ||
public bool AccountIsValid(Account account) | ||
{ | ||
return | ||
account.ID > 0 && | ||
!string.IsNullOrEmpty(account.Name) && | ||
account.Value != null; | ||
} | ||
|
||
public int? GetAccountNumber(string input) | ||
{ | ||
if (int.TryParse(input, out int accountNumber)) | ||
{ | ||
return accountNumber; | ||
} | ||
return null; | ||
} | ||
|
||
public string GetNameForSaving(string input) | ||
{ | ||
if (string.IsNullOrEmpty(input)) | ||
{ | ||
return null; | ||
} | ||
return input.Length > 50 ? input.Substring(0, 50) : input; | ||
} | ||
|
||
public decimal? GetValue(string input) | ||
{ | ||
if (decimal.TryParse(input, out decimal val)) | ||
{ | ||
return val; | ||
} | ||
return null; | ||
} | ||
} | ||
} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace CsvProcessor | ||
{ | ||
class AccountParsingLogic : IAccountParsingLogic | ||
{ | ||
public bool AccountIsValid(Account account) | ||
{ | ||
return | ||
account.ID > 0 && | ||
!string.IsNullOrEmpty(account.Name) && | ||
account.Value != null; | ||
} | ||
|
||
public int? GetAccountNumber(string input) | ||
{ | ||
if (int.TryParse(input, out int accountNumber)) | ||
{ | ||
return accountNumber; | ||
} | ||
return null; | ||
} | ||
|
||
public string GetNameForSaving(string input) | ||
{ | ||
if (string.IsNullOrEmpty(input)) | ||
{ | ||
return null; | ||
} | ||
return input.Length > 50 ? input.Substring(0, 50) : input; | ||
} | ||
|
||
public decimal? GetValue(string input) | ||
{ | ||
if (decimal.TryParse(input, out decimal val)) | ||
{ | ||
return val; | ||
} | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace CsvProcessor | ||
{ | ||
class AccountProvider : IAccountProvider | ||
{ | ||
public void SaveAccounts(IEnumerable<Account> accounts) | ||
{ | ||
foreach (var account in accounts) | ||
{ | ||
// save to the database | ||
} | ||
} | ||
} | ||
} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace CsvProcessor | ||
{ | ||
class AccountProvider : IAccountProvider | ||
{ | ||
public void SaveAccounts(IEnumerable<Account> accounts) | ||
{ | ||
foreach (var account in accounts) | ||
{ | ||
// save to the database | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace CsvProcessor | ||
{ | ||
class CsvReader<T> : ICsvReader<T> where T : class | ||
{ | ||
string _path; | ||
Func<string[], T> _lineParser; | ||
|
||
public bool FileHasHeader { get; set; } = true; | ||
|
||
public CsvReader(string path, Func<string[], T> lineParser) | ||
{ | ||
_path = path; | ||
} | ||
|
||
public IEnumerable<T> Read() | ||
{ | ||
StreamReader rdr = new StreamReader(_path); | ||
if (FileHasHeader) | ||
{ | ||
//ignore the first line | ||
rdr.ReadLine(); | ||
} | ||
string line; | ||
T item; | ||
while ((line = rdr.ReadLine()) != null) | ||
{ | ||
item = null; | ||
try | ||
{ | ||
item = _lineParser(line.Split(',')); | ||
} | ||
catch (Exception) | ||
{ | ||
//log the error | ||
} | ||
if (item != null) | ||
{ | ||
yield return item; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace CsvProcessor | ||
{ | ||
class CsvReader<T> : ICsvReader<T> where T : class | ||
{ | ||
string _path; | ||
Func<string[], T> _lineParser; | ||
|
||
public bool FileHasHeader { get; set; } = true; | ||
|
||
public CsvReader(string path, Func<string[], T> lineParser) | ||
{ | ||
_path = path; | ||
} | ||
|
||
public IEnumerable<T> Read() | ||
{ | ||
StreamReader rdr = new StreamReader(_path); | ||
if (FileHasHeader) | ||
{ | ||
//ignore the first line | ||
rdr.ReadLine(); | ||
} | ||
string line; | ||
T item; | ||
while ((line = rdr.ReadLine()) != null) | ||
{ | ||
item = null; | ||
try | ||
{ | ||
item = _lineParser(line.Split(',')); | ||
} | ||
catch (Exception) | ||
{ | ||
//log the error | ||
} | ||
if (item != null) | ||
{ | ||
yield return item; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace CsvProcessor | ||
{ | ||
interface ICustomFileReader<T> | ||
{ | ||
T ReadLine(); | ||
} | ||
|
||
|
||
class CustomFileReader | ||
{ | ||
} | ||
} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace CsvProcessor | ||
{ | ||
interface ICustomFileReader<T> | ||
{ | ||
T ReadLine(); | ||
} | ||
|
||
|
||
class CustomFileReader | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace CsvProcessor | ||
{ | ||
interface ICsvReader<T> where T: class | ||
{ | ||
IEnumerable<T> Read(); | ||
} | ||
|
||
interface IAccountParsingLogic | ||
{ | ||
string GetNameForSaving(string input); | ||
int? GetAccountNumber(string input); | ||
decimal? GetValue(string input); | ||
bool AccountIsValid(Account account); | ||
} | ||
|
||
interface IAccountProvider | ||
{ | ||
void SaveAccounts(IEnumerable<Account> accounts); | ||
} | ||
} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace CsvProcessor | ||
{ | ||
interface ICsvReader<T> where T: class | ||
{ | ||
IEnumerable<T> Read(); | ||
} | ||
|
||
interface IAccountParsingLogic | ||
{ | ||
string GetNameForSaving(string input); | ||
int? GetAccountNumber(string input); | ||
decimal? GetValue(string input); | ||
bool AccountIsValid(Account account); | ||
} | ||
|
||
interface IAccountProvider | ||
{ | ||
void SaveAccounts(IEnumerable<Account> accounts); | ||
} | ||
} |
Oops, something went wrong.