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.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(); RunTask(arguments, serviceProxy, 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); } RunTask(arguments, serviceProxy, trace); } } } catch (CommandLineException exception) { Console.WriteLine(exception.ArgumentHelp.Message); Console.WriteLine(exception.ArgumentHelp.GetHelpText(Console.BufferWidth)); } }
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)); } }