-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
79 lines (67 loc) · 3.36 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
using System.Drawing;
using Autofac;
using TagsCloudVisualization.CloudBuilding;
using TagsCloudVisualization.Visualization;
using TagsCloudVisualization.WordsExtraction;
namespace TagsCloudVisualization
{
class Program
{
static void Main(string[] args)
{
var options = new Options();
CommandLine.Parser.Default.ParseArguments(args, options);
var optionStatus = Options.CheckOptions(options);
if (!optionStatus.IsSuccess)
{
Console.WriteLine(optionStatus.Error);
return;
}
var fileReader = new FileReader();
var resultOfSourceReading = fileReader.ReadFile(options.Source);
if (!resultOfSourceReading.IsSuccess)
{
Console.WriteLine(resultOfSourceReading.Error);
Console.WriteLine("Check presence and corretnes of the file and try again.");
return;
}
var lines = resultOfSourceReading.Value;
var resultOfBannedWordsReading = fileReader.ReadFile(options.BannedWords);
if (!resultOfBannedWordsReading.IsSuccess)
{
Console.WriteLine(resultOfSourceReading.Error);
Console.WriteLine(
"Provide correct path to file with banned words in txt format. Otherwise no words will be filtered.");
}
var bannedWords = resultOfBannedWordsReading.Value;
var container = BuildContainer(options, fileReader, bannedWords);
var cloudBilder = container.Resolve<ICloudBuilder>();
var cloud = cloudBilder.BuildCloud(lines, options.Count, container.Resolve<IDrawingConfig>());
var result = container.Resolve<ICloudSaver>().SaveCloud(cloud, options.Destination, options.Extension);
if (result.IsSuccess) return;
Console.WriteLine(
"Cannot save file. Make sure that you've provided correct extensions and have writing access to destination directory");
Console.WriteLine(result.Error);
}
private static IContainer BuildContainer(Options options, IFileReader fileReader, IEnumerable<string> bannedWords)
{
var builder = new ContainerBuilder();
builder.RegisterInstance(new FrequencyAnalyzer()).As<IFrequencyAnalyzer>();
builder.RegisterInstance(new DictionaryNormalizer()).As<IDictionaryNormalizer>();
builder.RegisterInstance(new CloudLayouter(new Point(0, 0), options.HorizontalExtensionCoefficient))
.As<ICloudLayouter>();
builder.RegisterInstance(new WordsFilter(bannedWords)).As<IWordsFilter>();
builder.RegisterInstance(new LayoutNormalizer()).As<ILayoutNormalizer>();
builder.RegisterType<CloudBuilder>().As<ICloudBuilder>();
builder.RegisterType<CloudDrawer>().As<ICloudDrawer>();
builder.RegisterInstance(fileReader).As<IFileReader>();
builder.RegisterInstance(new CloudSaver()).As<ICloudSaver>();
var size = new Size(options.Width, options.Height);
builder.RegisterInstance(new DrawingConfig(options.FontName, options.BrushColor, size))
.As<IDrawingConfig>();
return builder.Build();
}
}
}