-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
129 lines (110 loc) · 4.48 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using Mono.Options;
using JNCC.Microsite.SAC.Data;
using JNCC.Microsite.SAC.Generators;
namespace JNCC.Microsite.SAC
{
class Program
{
static void ShowHelp(OptionSet p)
{
Console.WriteLine("Usage: dotnet run -- [OPTIONS]+");
Console.WriteLine("Regenerates the JNCC SAC microsite from a given access db and displays a locally hosted testing copy");
Console.WriteLine();
Console.WriteLine("Options:");
p.WriteOptionDescriptions(Console.Out);
}
public static void Main(string[] args)
{
var showHelp = false;
string accessDbPath = null;
bool update = false;
bool generate = false;
bool generateSearchDocuments = false;
string searchIndex = null;
bool view = false;
string root = null;
GeneratorConfig generatorConfig = new GeneratorConfig();
var options = new OptionSet {
{ "u|update=", "run data update from Database and generate outputs", u => {update = true; accessDbPath = u;}},
{ "g|generate", "generate web pages from extracted data", g => generate = true},
{ "c|cookiecontrol", "cookie consent control", c => generatorConfig.CookieConsentControl = true},
{ "t|tag=", "google tag manager id", t => generatorConfig.GoogleTagMangerId = t},
{ "s|search=", "the JNCC search page url", s => generatorConfig.JnccSearchUrl = s},
{ "v|view", "view the static web site", v => view = true},
{ "r|root=", "the root path on which to run the generate and view processes", r => root = r},
{ "i|index=", "the search index to generate index documents for", i => {generateSearchDocuments = true; searchIndex = i;}},
{ "h|help", "show this message and exit", h => showHelp = h != null }
};
try
{
options.Parse(args);
}
catch (OptionException ex)
{
Console.Write("JNCC.Micosite.SAC: ");
Console.Write(ex.Message);
Console.Write("Try `dotnet run -- -h` for more information");
}
if (string.IsNullOrEmpty(root))
{
root = Environment.CurrentDirectory;
}
Console.WriteLine("Root path set to {0}", root);
if (showHelp)
{
ShowHelp(options);
return;
}
if (update)
{
if (String.IsNullOrWhiteSpace(accessDbPath))
{
Console.Write("-u | --update option must have a non blank value");
}
else
{
DatabaseExtractor.ExtractData(accessDbPath, root);
}
}
if (generate || generateSearchDocuments)
{
if (! String.IsNullOrEmpty(generatorConfig.GoogleTagMangerId))
{
Console.WriteLine("Enabling google tag manager with ID {0}", generatorConfig.GoogleTagMangerId);
}
if (generatorConfig.CookieConsentControl)
{
Console.WriteLine("Enabling Cookie consent control");
}
Generator.MakeSite(generatorConfig, root, generateSearchDocuments, searchIndex);
}
if (view)
{
Console.WriteLine("Starting Webserver:");
string webRoot = Path.Combine(root, "output/html");
CreateWebHostBuilder(args)
.UseWebRoot(webRoot)
.UseContentRoot(webRoot)
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
logging.AddConsole();
logging.AddDebug();
})
.UseStartup<Startup>()
.Build()
.Run();
}
}
static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
return WebHost.CreateDefaultBuilder(args);
}
}
}