-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebResourceDeployerExecution.cs
97 lines (84 loc) · 3.02 KB
/
WebResourceDeployerExecution.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
using System;
using log4net;
using log4net.Config;
using PowerArgs;
namespace Xrm.WebResource.Deployer
{
/// <summary>
/// WebRessource Deployer
/// </summary>
[ArgExceptionBehavior(ArgExceptionPolicy.StandardExceptionHandling)]
public class WebResourceDeployerExecution
{
private readonly ILog err = LogManager.GetLogger("root");
private readonly ILog log = LogManager.GetLogger(typeof(Program));
/// <summary>
/// Runner
/// </summary>
public WebResourceDeployerExecution()
{
XmlConfigurator.Configure();
}
/// <summary>
/// Helper
/// </summary>
[HelpHook, ArgShortcut("-?"), ArgDescription("Shows help")]
// ReSharper disable once UnusedMember.Global
public bool Help { get; set; }
/// <summary>
/// Deployer
/// </summary>
/// <param name="args"></param>
[ArgActionMethod, ArgDescription("Deploy web resource(s)")]
// ReSharper disable once UnusedMember.Global
public void Deploy(CmdArgs args)
{
StartDeployment(args, i => i.DeployWebresource());
}
/// <summary>
/// Deployer
/// </summary>
/// <param name="args"></param>
[ArgActionMethod, ArgDescription("Generates a new package.xml file from given source folder")]
// ReSharper disable once UnusedMember.Global
public void Generate(GenerationArgs args)
{
StartGeneration(args, i => i.GeneratePackagesXml());
}
private void StartDeployment(CmdArgs args, Action<WebResourceDeployer> action)
{
try
{
if (string.IsNullOrEmpty(args.ConnectionString) || string.IsNullOrEmpty(args.FileName) && !args.PublishAll && args.FileNames == null)
{
Console.WriteLine("Please maintain correct execution parameter to deploy webresources to the designated CRM system.");
Environment.Exit(1);
}
var webResourceDeployer = new WebResourceDeployer(args, log, err);
action(webResourceDeployer);
}
catch (Exception ex)
{
err.Error($"Exception occured, terminating. Message: {ex.Message}", ex);
}
}
private void StartGeneration(GenerationArgs args, Action<PackageGenerator> action)
{
try
{
if (args.SourceFolder == "")
{
Console.WriteLine("Please maintain correct source folder which holds all web resources of project.");
Environment.Exit(1);
}
var generator = new PackageGenerator(args, log);
action(generator);
}
catch (Exception ex)
{
log.Error($"Exception occured, terminating. Message: {ex.Message}", ex);
Environment.Exit(1);
}
}
}
}