private static void Run(CommandLineArgs arguments) { try { var executingDirectory = Environment.CurrentDirectory; var searchPath = arguments.Path ?? Path.Combine(executingDirectory, "..\\"); if (arguments.Connection == null) { if (arguments.LegacyLogin) { // 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); BuildProxy(serviceProxy, searchPath); } } else { var toolingConnector = new XrmToolingConnection(); var client = toolingConnector.Connect(); arguments.Connection = toolingConnector.ConnectionString; BuildProxy(client, searchPath); } } 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="******"Error connecting to the Organization Service Proxy: {0}", serviceProxy.LastCrmError)); } serviceProxy.OrganizationServiceProxy.Timeout = new TimeSpan(1, 0, 0); BuildProxy(serviceProxy, searchPath); } } } 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) { if (arguments.LegacyLogin) { Console.ForegroundColor = ConsoleColor.Blue; Console.Write("On-premises/Legacy Login"); Console.ForegroundColor = ConsoleColor.Gray; // This login code will not work with the latest versions of CDS // 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 { var toolingConnector = new XrmToolingConnection(); var client = toolingConnector.Connect(); arguments.Connection = toolingConnector.ConnectionString; RunTask(arguments, client, 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="******"Error connecting to the Organization Service: {0}", serviceProxy.LastCrmError)); } if (!serviceProxy.IsReady) { trace.WriteLine("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)); } }