-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
62 lines (53 loc) · 2.05 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using CsvHelper;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
namespace ContractValueCalculator
{
class Program
{
static void Main(string[] args)
{
if (args.Length != 2)
{
Console.WriteLine("Please provide two contract files as arguments");
Console.WriteLine("Usage: ContractValueCalculator <contract1.yaml> <contract2.yaml>");
return;
}
// Load employee data
var employees = LoadEmployees("employees.csv");
// Load contract data
var contract1 = LoadContract(args[0]);
var contract2 = LoadContract(args[1]);
// Calculate values for each contract
var value1 = new ContractValueCalculator(contract1, employees).Calculate();
var value2 = new ContractValueCalculator(contract2, employees).Calculate();
// Output summaries
Console.WriteLine("Summary of Contract 1:");
Console.WriteLine(value1.Summary());
Console.WriteLine();
Console.WriteLine("Summary of Contract 2:");
Console.WriteLine(value2.Summary());
}
static IEnumerable<Employee> LoadEmployees(string path)
{
using (var reader = new StreamReader(path))
using (var csv = new CsvReader(reader, System.Globalization.CultureInfo.InvariantCulture))
{
csv.Configuration.PrepareHeaderForMatch = (string header, int index) => header.ToLower();
return csv.GetRecords<Employee>().ToList();
}
}
static Contract LoadContract(string path)
{
var input = File.ReadAllText(path);
var deserializer = new DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build();
return deserializer.Deserialize<Contract>(input);
}
}
}