Ejemplo n.º 1
0
        /// <summary>
        /// Creates an Database Profile
        /// </summary>
        public static void CreateProfile()
        {
            DBConfiguration profile = new DBConfiguration();
            profile.Name = InputHelper.RequestInput("Profile Name: ");
            //profile.LiveUsername = InputHelper.RequestInput("Live Account (Username): ");
            //profile.LiveAPIKey = InputHelper.RequestInput("Live API Key: ");
            //profile.LiveAPIPassword = InputHelper.RequestInput("Live API Password: "******"Live URL (without db): ", "https://" + profile.LiveUsername + ".cloudant.com/");
            //profile.LocalURL = InputHelper.RequestInput("Local URL (without db): ", "http://localhost:5984/");
            ////config.ViewNames

            //Security Checks
            if (SettingManager.Settings.Databases.Where(x => x.Name.Equals(profile.Name, StringComparison.InvariantCultureIgnoreCase)).Count() > 0)
            {
                Console.WriteLine("There already exists an profile with the name: " + profile.Name);
                Console.WriteLine("Do you want to override it? ( Y/N )");
                ConsoleKeyInfo anwser = Console.ReadKey(true);
                if (anwser.KeyChar == 'y')
                {
                    //Override!!!
                    SettingManager.Update(profile);

                    //Load Profile.
                    DBManager = new DatabaseManager(profile);
                    return;
                }
                else
                {
                    Console.WriteLine("Create aborted!");
                    return;
                }
                //END OF THIS OPTION. (We don't want to save double!)
            }
            else if (String.IsNullOrEmpty(profile.Name))
            {
                Console.WriteLine("Database name can't be empty!");
                return;
            }

            //Add the new configuration
            SettingManager.Settings.Databases.Add(profile);

            //Load Profile.
            DBManager = new DatabaseManager(profile);

            //Save the configuration to the file.
            SettingManager.Save();

            Console.WriteLine("Profile \"" + profile.Name + "\" Saved and Loaded!");
            Console.WriteLine("Please call /add-env to add environments to this profile!");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Let's the user choose between the available database profiles.
        /// </summary>
        public static void LoadProfile()
        {
            //Load Settings File
            SettingManager.Load();

            if (SettingManager.Settings.Databases.Count() > 0)
            {
                //Check if we can autload an profile.
                if (SettingManager.Settings.Databases.Count() == 1)
                {
                    DBManager = new DatabaseManager(SettingManager.Settings.Databases.FirstOrDefault());
                    Console.WriteLine("Database Configuration for: " + DBManager.Profile.Name + " automatically loaded!");
                    return;
                }

                //Communicate with user.
                Console.WriteLine("Which profile do you want to load?");

                //Build string with configuration profiles values
                StringBuilder builder = new StringBuilder();
                builder.Append("Profile options: ");
                foreach (DBConfiguration config in SettingManager.Settings.Databases)
                {
                    builder.Append(config.Name);
                    builder.Append(", ");
                }

                Console.WriteLine(builder.ToString().TrimEnd(' ', ','));

                //Get profile choice
                Console.Write("Profile: ");
                string profileName = Console.ReadLine();
                DBConfiguration profile = SettingManager.Settings.Databases.Where(x => x.Name.Equals(profileName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

                //Select profile
                Console.WriteLine();

                //Check if Database is selected
                if (profile == null)
                {
                    Console.WriteLine("No Database found with the name: " + profileName);
                    LoadProfile();
                }
                else
                {
                    DBManager = new DatabaseManager(profile);
                    Console.WriteLine("Database Configuration for: " + profileName + " SuccessFully loaded!");
                }

                //End of load flow
            }
            else
            {
                Console.WriteLine("No database profiles found! Profile Creation started:");
                CreateProfile();
                //End of Create flow.
            }
            //End of handling. New Command expected.
        }