private static void RunTask(CommandLineArgs arguments, IOrganizationService service, ITrace trace) { if (arguments.Path == null) { arguments.Path = Directory.GetCurrentDirectory(); } else { // Strip trailing \ arguments.Path = arguments.Path.TrimEnd('\\'); arguments.Path = Path.Combine(Directory.GetCurrentDirectory(), arguments.Path); } BaseTask task = null; string command = arguments.Task.ToLower(); switch (command) { case "plugins": trace.WriteLine("Deploying Plugins"); task = new DeployPluginsTask(service, trace); break; case "workflow": trace.WriteLine("Deploying Custom Workflow Activities"); task = new DeployWorkflowActivitiesTask(service, trace); break; case "webresources": trace.WriteLine("Deploying WebResources"); task = new DeployWebResourcesTask(service, trace); break; case "instrument": trace.WriteLine("Downloading Plugin/Workflow Activity Metadata"); task = new DownloadPluginMetadataTask(service, trace); break; case "download-webresources": trace.WriteLine("Downloading Webresources"); task = new DownloadWebresourceFileTask(service, trace) { Overwrite = arguments.Overwrite }; break; case "get-webresources": trace.WriteLine("Downloading Webresources"); task = new DownloadWebresourceConfigTask(service, trace); task.Prefix = arguments.Prefix; break; case "earlybound": trace.WriteLine("Generating early bound types"); var earlyBound = new EarlyBoundClassGeneratorTask(service, trace); task = earlyBound; earlyBound.ConectionString = arguments.Connection; break; case "unpack": trace.WriteLine("Unpacking solution"); var packager = new SolutionPackagerTask(service, trace); packager.command = command; task = packager; break; case "unpacksolution": trace.WriteLine("Unpacking solution Zip"); var unpackfromsolution = new SolutionPackagerTask(service, trace); unpackfromsolution.command = command; task = unpackfromsolution; break; case "pack": trace.WriteLine("Packing Solution"); var pack = new SolutionPackagerTask(service, trace); pack.command = command; task = pack; break; case "import": trace.WriteLine("Packing & Import Solution"); var import = new SolutionPackagerTask(service, trace); import.command = command; task = import; break; case "compare": trace.WriteLine("Comparing Solution"); var compare = new SolutionPackagerTask(service, trace); compare.command = command; task = compare; break; } if (task != null) { if (arguments.Profile != null) { task.Profile = arguments.Profile; } task.Execute(arguments.Path); } else { throw new SparkleTaskException(SparkleTaskException.ExceptionTypes.NO_TASK_SUPPLIED, String.Format("Task '{0}' not recognised. Please consult help!", arguments.Task.ToLower())); } }
static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("spkl Task Runner v" + Assembly.GetEntryAssembly().GetName().Version + "\tTasks v" + Assembly.GetAssembly(typeof(SparkleXrm.Tasks.BaseTask)).GetName().Version); Console.ForegroundColor = ConsoleColor.Gray; bool error = false; CommandLineArgs arguments = null; try { arguments = CommandLine.Parse <CommandLineArgs>(); Run(arguments); } catch (CommandLineException exception) { Console.WriteLine(exception.ArgumentHelp.Message); Console.WriteLine(exception.ArgumentHelp.GetHelpText(Console.BufferWidth)); } catch (SparkleTaskException ex) { Console.WriteLine(ex.Message); error = true; } catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ex) { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("The application terminated with an error."); Console.WriteLine("Timestamp: {0}", ex.Detail.Timestamp); Console.WriteLine("Code: {0}", ex.Detail.ErrorCode); Console.WriteLine("Message: {0}", ex.Detail.Message); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine(ex.StackTrace); if (!string.IsNullOrEmpty(ex.Detail.TraceText)) { Console.WriteLine("Plugin Trace: {0}", ex.Detail.TraceText); } if (ex.Detail.InnerFault != null) { Console.WriteLine("Inner Fault: {0}", null == ex.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"); } error = true; Console.ForegroundColor = ConsoleColor.White; } catch (System.TimeoutException ex) { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("The application terminated with an error."); Console.WriteLine("Message: {0}", ex.Message); Console.WriteLine("Stack Trace: {0}", ex.StackTrace); if (ex.InnerException != null) { Console.WriteLine("Inner Fault: {0}", null == ex.InnerException.Message ? "No Inner Fault" : ex.InnerException.Message); } error = true; Console.ForegroundColor = ConsoleColor.White; } catch (System.Exception ex) { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("The application terminated with an error."); Console.WriteLine(ex.Message); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine(ex.StackTrace); // Display the details of the inner exception. if (ex.InnerException != null) { Console.WriteLine(ex.InnerException.Message); FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> fe = ex.InnerException as FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault>; if (fe != null) { Console.WriteLine("Timestamp: {0}", fe.Detail.Timestamp); Console.WriteLine("Code: {0}", fe.Detail.ErrorCode); Console.WriteLine("Message: {0}", fe.Detail.Message); if (!string.IsNullOrEmpty(fe.Detail.TraceText)) { Console.WriteLine("Plugin Trace: {0}", fe.Detail.TraceText); } if (fe.Detail.InnerFault != null) { Console.WriteLine("Inner Fault: {0}", null == fe.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"); } } } error = true; Console.ForegroundColor = ConsoleColor.White; } finally { if (error) { Environment.ExitCode = 1; } } if (arguments != null && arguments.WaitForKey == true) { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Press any key..."); Console.ReadKey(); } Console.ForegroundColor = ConsoleColor.Gray; }
private static void RunTask(CommandLineArgs arguments, IOrganizationService service, ITrace trace) { if (arguments.Path == null) { arguments.Path = Directory.GetCurrentDirectory(); } else { // Strip trailing \ arguments.Path = arguments.Path.TrimEnd('\\'); arguments.Path = Path.Combine(Directory.GetCurrentDirectory(), arguments.Path); } BaseTask task = null; switch (arguments.Task.ToLower()) { case "plugins": trace.WriteLine("Deploying Plugins"); task = new DeployPluginsTask(service, trace); break; case "workflow": trace.WriteLine("Deploying Custom Workflow Activities"); task = new DeployWorkflowActivitiesTask(service, trace); break; case "webresources": trace.WriteLine("Deploying WebResources"); task = new DeployWebResourcesTask(service, trace); break; case "instrument": trace.WriteLine("Downloading Plugin/Workflow Activity Metadata"); task = new DownloadPluginMetadataTask(service, trace); break; case "get-webresources": trace.WriteLine("Downloading Webresources"); task = new DownloadWebresourceConfigTask(service, trace); task.Prefix = arguments.Prefix; break; case "earlybound": trace.WriteLine("Generating early bound types"); var earlyBound = new EarlyBoundClassGeneratorTask(service, trace); task = earlyBound; earlyBound.ConectionString = arguments.Connection; break; } if (task != null) { if (arguments.Profile != null) { task.Profile = arguments.Profile; } task.Execute(arguments.Path); } else { throw new SparkleTaskException(SparkleTaskException.ExceptionTypes.NO_TASK_SUPPLIED, String.Format("Task '{0}' not recognised. Please consult help!", arguments.Task.ToLower())); } }
private static void Run(CommandLineArgs arguments) { try { if (arguments.Task.Length < 3) { throw new CommandLineException("Invalid Command"); } var trace = new TraceLogger(); if (arguments.Connection == null) { // No Connection is supplied to ask for connection on command line ServerConnection serverConnect = new ServerConnection(); ServerConnection.Configuration config = serverConnect.GetServerConfiguration(arguments.IgnoreLocalPrincipal); arguments.Connection = BuildConnectionString(config); using (var serviceProxy = new OrganizationServiceProxy(config.OrganizationUri, config.HomeRealmUri, config.Credentials, config.DeviceCredentials)) { // This statement is required to enable early-bound type support. serviceProxy.EnableProxyTypes(); serviceProxy.Timeout = new TimeSpan(1, 0, 0); RunTask(arguments, serviceProxy, trace); } } else if (arguments.Connection == "") { // Support for tasks that require no connection string such as pack RunTask(arguments, null, trace); } else { // Does the connection contain a password prompt? var passwordMatch = Regex.Match(arguments.Connection, "Password=[*]+", RegexOptions.IgnoreCase); if (passwordMatch.Success) { // Prompt for password Console.WriteLine("Password required for connection {0}", arguments.Connection); Console.Write("Password:"******"Password="******"Not Ready {0} {1}", serviceProxy.LastCrmError, serviceProxy.LastCrmException); throw new SparkleTaskException(SparkleTaskException.ExceptionTypes.AUTH_ERROR, String.Format("Error connecting to the Organization Service Proxy: {0}", serviceProxy.LastCrmError)); } else { IOrganizationService crmService = (IOrganizationService)serviceProxy.OrganizationWebProxyClient != null ? (IOrganizationService)serviceProxy.OrganizationWebProxyClient : (IOrganizationService)serviceProxy.OrganizationServiceProxy; RunTask(arguments, crmService, trace); } } } } catch (CommandLineException exception) { Console.WriteLine(exception.ArgumentHelp.Message); Console.WriteLine(exception.ArgumentHelp.GetHelpText(Console.BufferWidth)); } }
static void Main(string[] args) { bool error = false; CommandLineArgs arguments = null; try { arguments = CommandLine.Parse <CommandLineArgs>(); Run(arguments); } catch (SparkleTaskException ex) { Console.WriteLine(ex.Message); error = true; } catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ex) { Console.WriteLine("The application terminated with an error."); Console.WriteLine("Timestamp: {0}", ex.Detail.Timestamp); Console.WriteLine("Code: {0}", ex.Detail.ErrorCode); Console.WriteLine("Message: {0}", ex.Detail.Message); if (!string.IsNullOrEmpty(ex.Detail.TraceText)) { Console.WriteLine("Plugin Trace: {0}", ex.Detail.TraceText); } if (ex.Detail.InnerFault != null) { Console.WriteLine("Inner Fault: {0}", null == ex.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"); } error = true; } catch (System.TimeoutException ex) { Console.WriteLine("The application terminated with an error."); Console.WriteLine("Message: {0}", ex.Message); Console.WriteLine("Stack Trace: {0}", ex.StackTrace); if (ex.InnerException != null) { Console.WriteLine("Inner Fault: {0}", null == ex.InnerException.Message ? "No Inner Fault" : ex.InnerException.Message); } error = true; } catch (System.Exception ex) { Console.WriteLine("The application terminated with an error."); Console.WriteLine(ex.Message); // Display the details of the inner exception. if (ex.InnerException != null) { Console.WriteLine(ex.InnerException.Message); FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> fe = ex.InnerException as FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault>; if (fe != null) { Console.WriteLine("Timestamp: {0}", fe.Detail.Timestamp); Console.WriteLine("Code: {0}", fe.Detail.ErrorCode); Console.WriteLine("Message: {0}", fe.Detail.Message); if (!string.IsNullOrEmpty(fe.Detail.TraceText)) { Console.WriteLine("Plugin Trace: {0}", fe.Detail.TraceText); } if (fe.Detail.InnerFault != null) { Console.WriteLine("Inner Fault: {0}", null == fe.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"); } } } error = true; } finally { if (error) { Environment.ExitCode = 1; } } if (arguments != null && arguments.WaitForKey == true) { Console.WriteLine("Press any key..."); Console.ReadKey(); } }