-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
77 lines (67 loc) · 2.57 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
using System;
using Microsoft.Xrm.Sdk;
using PowerArgs;
using Xrm.PluginDeployer.Utility;
namespace Xrm.PluginDeployer
{
/// <summary>
/// Runs Plugin Deployer
/// </summary>
public class Program
{
/// <summary>
/// Here it all begins
/// </summary>
/// <param name="args"></param>
public static void Main( string[] args )
{
var log = new ConsoleLogger( typeof( Program ) );
CmdArgs parsedArgs;
try
{
parsedArgs = Args.Parse< CmdArgs >( args );
}
catch( ArgException e )
{
Console.WriteLine( ArgUsage.GenerateUsageFromTemplate< CmdArgs >( ) );
log.Error( $"Failed to parse arguments: {e.Message}" );
return;
}
try
{
IOrganizationService sourceService = null;
var destinationSystem = parsedArgs.DestinationSystem;
IOrganizationService destinationService = OrganizationServiceFactory.ConnectByConnectionString( destinationSystem );
if( parsedArgs.SourceSystem != null )
{
sourceService = OrganizationServiceFactory.ConnectByConnectionString( parsedArgs.SourceSystem + "RequireNewInstance = True;" );
}
var deployer = new PluginDeployer( sourceService, destinationService, parsedArgs.Prefix, log );
if( !deployer.LoadAssembly( parsedArgs.AssemblyPath ) )
{
return;
}
var assemblyName = deployer.AssemblyPlugin.GetName( ).Name;
var destinationAssembly = deployer.RetrievePluginAssembly( destinationService, assemblyName );
var createFromScratch = parsedArgs.Create;
if( createFromScratch )
{
deployer.CreateFromScratch( parsedArgs, destinationAssembly );
}
else
{
deployer.UpdateSystem( parsedArgs, destinationAssembly );
}
}
catch( Exception ex )
{
log.Error( $"Exception occured, terminating. Exception: {GetAllExceptionMessages( ex )}\n\n" );
log.Error( $"Stacktrace: {ex.StackTrace}" );
}
}
private static string GetAllExceptionMessages( Exception ex )
{
return ex == null ? string.Empty : $"{ex.Message}{GetAllExceptionMessages( ex.InnerException )}";
}
}
}