-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
79 lines (64 loc) · 2.74 KB
/
Copy pathProgram.cs
File metadata and controls
79 lines (64 loc) · 2.74 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using SizeMatters.JsonVsYaml.Model;
using System;
using System.Collections.Generic;
using System.IO;
namespace SizeMatters.JsonVsYaml
{
internal class Program
{
private static void Main(string[] args)
{
var superHeroes = PopulateSuperHeroesWithSampleData(10);
// Force several collection to be null for testing purposes.
for (int i = 0; i < superHeroes.Count; i++)
{
if (i % 2 == 0) // Empty the Movies collection
superHeroes[i].Movies.Clear();
else
{
for (int j = 0; j < superHeroes[i].Movies.Count; j++)
{
if (j % 2 == 0) // Empty the Lines collection
superHeroes[i].Movies[j].Lines.Clear();
}
}
}
SaveData(superHeroes);
System.Console.ReadKey();
}
private static List<SuperHero> PopulateSuperHeroesWithSampleData(int numberOfSetsToPopulate = 1)
{
var retVal = new List<SuperHero>();
for (int i = 0; i < numberOfSetsToPopulate; i++)
{
retVal.AddRange(SampleData.GetSuperHeroes());
}
foreach (var superHero in retVal)
{
superHero.Movies = SampleData.GetRandomNumberOfMovies(min: 0, max: 3);
foreach (var movie in superHero.Movies)
{
movie.Lines = SampleData.GetRandomNumberOfLines(min: 10, max: 1000);
}
}
return retVal;
}
private static void SaveData(List<SuperHero> superHeroes)
{
FileInfo fiDotNetZip = new FileInfo(Path.Combine(Environment.CurrentDirectory, "dotNetZip.zip"));
FileInfo fiSystemIoCompression = new FileInfo(Path.Combine(Environment.CurrentDirectory, "systemIoCompression.zip"));
string optimizedJson = Serializer.ToJson(superHeroes, Serializer.GetSerializerJsonOptimized());
string optimizedYaml = Serializer.ToYaml(superHeroes, Serializer.GetSerializerYamlOptimized());
Console.WriteLine($"\n\tOptimized JSON:\t\t{String.Format("{0:#,##0}", optimizedJson.Length)}");
Console.WriteLine($"\tOptimized YAML:\t\t{String.Format("{0:#,##0}", optimizedYaml.Length)}");
string unOptimizedJson = Serializer.ToJson(superHeroes, Serializer.GetSerializerJsonUnOptimized());
string unOptimizedYaml = Serializer.ToYaml(superHeroes, Serializer.GetSerializerYamlUnOptimized());
Console.WriteLine($"\n\tUnoptimized JSON:\t{String.Format("{0:#,##0}", unOptimizedJson.Length)}");
Console.WriteLine($"\tUnoptimized YAML:\t{String.Format("{0:#,##0}", unOptimizedYaml.Length)}");
Serializer.ZipUsingDotNetZip(json: optimizedJson, yaml: optimizedYaml, filePath: fiDotNetZip.FullName);
Serializer.ZipUsingSystemIO(json: optimizedJson, yaml: optimizedYaml, filePath: fiSystemIoCompression.FullName);
Console.WriteLine($"\n\tFile Size DotNetZip:\t{String.Format("{0:#,##0}", fiDotNetZip.Length)}");
Console.WriteLine($"\tSystem.Io.Compression:\t{String.Format("{0:#,##0}", fiSystemIoCompression.Length)}");
}
}
}