-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathProgram.cs
42 lines (36 loc) · 1.21 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace PlayingWithProjections
{
public class Program
{
public static void Main(string[] args)
{
var events = GetEvents(args);
Console.WriteLine("Number of events: {0}", EventCounter.Count(events));
}
private static IEnumerable<Event> GetEvents(string[] args)
{
return FileNames(args)
.Select(file => new FileEventReader().Read(file))
.Select(events => new JsonEventParser().Parse(events))
.Aggregate((accu, events) => accu.Union(events));
}
private static IEnumerable<string> FileNames(string[] args)
{
if (!args.Any()) throw new ArgumentException("Expected a file or directory as parameter");
if (args[0].EndsWith(".json")) return new[] {args[0]};
return Directory.GetFiles(args[0])
.Where(file => file.EndsWith(".json"));
}
}
public class EventCounter
{
public static int Count(IEnumerable<Event> events)
{
return events.Count();
}
}
}