Esempio n. 1
0
        private void ListConnections(SavedConnectionArguments arguments)
        {
            var connections = this.GetConnections(arguments);

            if (connections.Count() == 0)
            {
                if (!string.IsNullOrEmpty(arguments.Name))
                {
                    this.MessageService.WriteLine(
                        string.Format("There is no saved connection called \"{0}\".", arguments.Name));
                }
                else
                {
                    this.MessageService.WriteLine("There are no saved connections.");
                }
            }
            else
            {
                foreach (var connection in connections)
                {
                    this.MessageService.WriteLine(connection.Name + ":");
                    this.WriteConnectionInfo(connection);
                }
            }
        }
Esempio n. 2
0
        private void CreateFromTemplate(SavedConnectionArguments arguments)
        {
            var template = this.SavedConnectionService.SavedConnections.FirstOrDefault(
                c => c.Name == arguments.TemplateConnection);

            if (template != null)
            {
                var connectionString = !string.IsNullOrEmpty(arguments.ConnectionString)
                    ? arguments.ConnectionString : template.ConnectionString;
                var driverClass = !string.IsNullOrEmpty(arguments.DriverClass)
                    ? arguments.DriverClass : template.DriverClass;
                var dialect = !string.IsNullOrEmpty(arguments.Dialect)
                    ? arguments.Dialect : template.Dialect;
                var provider = !string.IsNullOrEmpty(arguments.ConnectionProvider)
                    ? arguments.ConnectionProvider : template.ConnectionProvider;

                var connection = this.SavedConnectionService.CreateSavedConnection(
                    arguments.Name,
                    connectionString,
                    provider,
                    driverClass,
                    dialect);
                this.SavedConnectionService.SaveConnections();

                this.MessageService.WriteLine(
                    string.Format(
                        "Created a new connection \"{0}\" based on \"{1}\".", arguments.Name, arguments.TemplateConnection));
                this.WriteConnectionInfo(connection);
            }
            else
            {
                this.MessageService.WriteLine(
                    string.Format("Template connection \"{0}\" could not be found.", arguments.TemplateConnection));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Parses the arguments.
        /// </summary>
        /// <param name='args'>
        /// The command line arguments.
        /// </param>
        /// <returns>
        /// The parsed arguments.
        /// </returns>
        private static SavedConnectionArguments ParseArguments(string[] args)
        {
            var arguments      = new SavedConnectionArguments();
            var parserSettings = new CommandLineParserSettings();

            parserSettings.CaseSensitive = true;
            parserSettings.HelpWriter    = System.Console.Out;

            var parser = new CommandLineParser(parserSettings);

            parser.ParseArguments(args, arguments);

            return(arguments);
        }
Esempio n. 4
0
 private void DeleteConnection(SavedConnectionArguments arguments)
 {
     if (this.SavedConnectionService.DeleteConnection(arguments.Name))
     {
         this.SavedConnectionService.SaveConnections();
         this.MessageService.WriteLine(
             string.Format("\"{0}\" has been deleted.", arguments.Name));
     }
     else
     {
         this.MessageService.WriteLine(
             string.Format("There is no saved connection called \"{0}\".", arguments.Name));
     }
 }
Esempio n. 5
0
 private void SetDefaultConnection(SavedConnectionArguments arguments)
 {
     if (this.SavedConnectionService.SetDefaultConnection(arguments.Name))
     {
         this.SavedConnectionService.SaveConnections();
         this.MessageService.WriteLine(
             string.Format("\"{0}\" is now the default connection.", arguments.Name));
     }
     else
     {
         this.MessageService.WriteLine(
             string.Format("There is no saved connection called \"{0}\".", arguments.Name));
     }
 }
Esempio n. 6
0
        private IEnumerable <SavedConnection> GetConnections(SavedConnectionArguments arguments)
        {
            if (!string.IsNullOrEmpty(arguments.Name))
            {
                return(this.SavedConnectionService.SavedConnections
                       .Where(c => c.Name == arguments.Name));
            }

            return(this.SavedConnectionService.SavedConnections
                   .Where(c => c.IsDefault)
                   .Union(
                       this.SavedConnectionService.SavedConnections
                       .Where(c => !c.IsDefault)
                       .OrderBy(c => c.Name)));
        }
Esempio n. 7
0
        /// <summary>
        /// Creates the new connection.
        /// </summary>
        /// <param name='arguments'>
        /// The arguments to create the connection with.
        /// </param>
        /// <returns>
        /// The new connection.
        /// </returns>
        private void CreateNewConnection(SavedConnectionArguments arguments)
        {
            var existingConnection =
                this.SavedConnectionService.SavedConnections.FirstOrDefault(c => c.Name == arguments.Name);

            string name;
            string connectionString;
            string connectionProvider;
            string driverClass;
            string dialect;

            if (existingConnection != null)
            {
                name             = existingConnection.Name;
                connectionString = !string.IsNullOrEmpty(arguments.ConnectionString)
                    ? arguments.ConnectionString : existingConnection.ConnectionString;
                connectionProvider = !string.IsNullOrEmpty(arguments.ConnectionProvider)
                    ? arguments.ConnectionProvider : existingConnection.ConnectionProvider;
                driverClass = !string.IsNullOrEmpty(arguments.DriverClass)
                    ? arguments.DriverClass : existingConnection.DriverClass;
                dialect = !string.IsNullOrEmpty(arguments.Dialect)
                    ? arguments.Dialect : existingConnection.Dialect;
            }
            else
            {
                name               = arguments.Name;
                connectionString   = arguments.ConnectionString;
                connectionProvider = arguments.ConnectionProvider;
                driverClass        = arguments.DriverClass;
                dialect            = arguments.Dialect;
            }

            var connection = this.SavedConnectionService.CreateSavedConnection(
                name,
                connectionString,
                connectionProvider,
                driverClass,
                dialect);

            this.SavedConnectionService.SaveConnections();

            this.MessageService.WriteLine(
                string.Format("Created new saved connection \"{0}\":", connection.Name));
            this.WriteConnectionInfo(connection);
        }