Skip to content

Commit 72db5f4

Browse files
Sergio FerreiraSergio Ferreira
Sergio Ferreira
authored and
Sergio Ferreira
committed
created confusing useless code to introduct SOLID
1 parent 0006b09 commit 72db5f4

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

SOLID/01 - Introduction/Liquid/Liquid/Liquid.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
</ItemGroup>
4949
<ItemGroup>
5050
<None Include="App.config" />
51-
<None Include="SomeDataFile.csv" />
51+
<None Include="FL_insurance_sample.csv">
52+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
53+
</None>
5254
</ItemGroup>
5355
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5456
</Project>
Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,55 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.IO;
45
using System.Linq;
56
using System.Text;
67
using System.Threading.Tasks;
78

89
namespace Liquid
910
{
11+
// Read from a csv file
12+
// Get the total value of insured houses
13+
// Store the Value by country
14+
// The last line must have the total and the current date
15+
// -----
16+
// Client 1: Ignore Residential type of housing.
17+
// Client 2: Ignore Commercial type of housing.
1018
class Program
1119
{
1220
static void Main(string[] args)
1321
{
22+
var client = 2;
1423
var fileLines = File.ReadAllLines(".\\FL_insurance_sample.csv");
15-
24+
var output = new StreamWriter(File.OpenWrite("MyOutput.csv"));
25+
output.WriteLine($"Country,Value");
26+
var total = 0.0;
1627
for (var i = 1; i < fileLines.Length; i++)
1728
{
18-
29+
if (double.TryParse(fileLines[i].Split(',')[8], NumberStyles.Any, CultureInfo.InvariantCulture, out var value))
30+
{
31+
if (client == 1)
32+
{
33+
if (fileLines[i].Split(',')[15] == "Residential")
34+
{
35+
output.WriteLine($"{fileLines[i].Split(',')[3]},{value.ToString("F2", CultureInfo.InvariantCulture)}");
36+
total += value;
37+
}
38+
}
39+
if (client == 2)
40+
{
41+
if (fileLines[i].Split(',')[15] == "Commercial")
42+
{
43+
output.WriteLine($"{fileLines[i].Split(',')[3]},{value.ToString("F2", CultureInfo.InvariantCulture)}");
44+
total += value;
45+
}
46+
}
47+
}
1948
}
2049

21-
22-
50+
output.WriteLine("{0},{1}", total.ToString("F2", CultureInfo.InvariantCulture), DateTime.Now.ToString("d", CultureInfo.InvariantCulture));
51+
output.Flush();
52+
output.Close();
2353
}
2454
}
2555
}

0 commit comments

Comments
 (0)