Beispiel #1
0
        static void Main(string[] args)
        {
            var connectionStr = "mongodb://localhost";
            var client        = new MongoClient(connectionStr);
            var server        = client.GetServer();
            var db            = server.GetDatabase("MongoDictionary");
            MongoCollection <Word> dictionaryCollection = db.GetCollection <Word>("Words");

            MongoDictionary mongoDictionary = new MongoDictionary(dictionaryCollection);

            UI.DrawMenu();

            mongoDictionary["asdf"] = "pe6enceto";

            while (true)
            {
                Console.Write("Please enter a command: ");
                string command = Console.ReadLine().Trim();

                if (command == "Exit")
                {
                    break;
                }

                Engine.ParseCommand(command, mongoDictionary);
            }
        }
Beispiel #2
0
 public static void ListAllFromDictionary(MongoDictionary mongoDictionary)
 {
     foreach (var item in mongoDictionary)
     {
         Console.WriteLine("{0}=>{1}", item.Key, item.Value);
     }
 }
Beispiel #3
0
        public static void ParseCommand(string command, MongoDictionary mongoDictCollection)
        {
            int commandEndIndex = command.IndexOf(' ');

            string parsedCommand = command.Substring(0, commandEndIndex).Trim();

            switch (parsedCommand)
            {
            case "Add": AddToDictionary(command, mongoDictCollection);
                Console.WriteLine("Word is added successfully.");
                break;

            case "Remove": RemoveFromDictionary(command, mongoDictCollection);
                Console.WriteLine("Word is removed successfully.");
                break;

            case "Find":
                string result = FindFromDictionary(command, mongoDictCollection);
                Console.WriteLine(result);
                break;

            case "List": ListAllFromDictionary(mongoDictCollection);
                break;

            default: Console.WriteLine("Wrong command. Try again.");
                break;
            }
        }
Beispiel #4
0
 public static void ListAllFromDictionary(MongoDictionary mongoDictionary)
 {
     foreach (var item in mongoDictionary)
     {
         Console.WriteLine("{0}=>{1}", item.Key, item.Value);
     }
 }
Beispiel #5
0
        static void Main(string[] args)
        {
            var connectionStr = "mongodb://localhost";
            var client = new MongoClient(connectionStr);
            var server = client.GetServer();
            var db = server.GetDatabase("MongoDictionary");
            MongoCollection<Word> dictionaryCollection = db.GetCollection<Word>("Words");

            MongoDictionary mongoDictionary = new MongoDictionary(dictionaryCollection);

            UI.DrawMenu();

            mongoDictionary["asdf"] = "pe6enceto";

            while (true)
            {
                Console.Write("Please enter a command: ");
                string command = Console.ReadLine().Trim();

                if (command == "Exit")
                {
                    break;
                }

                Engine.ParseCommand(command, mongoDictionary);
            }
        }
Beispiel #6
0
        public static string FindFromDictionary(string command, MongoDictionary mongoDictionary)
        {
            int wordStartIndex = command.IndexOf(' ') + 1;

            string word = command.Substring(wordStartIndex, command.Length - wordStartIndex).Trim();

            return(mongoDictionary[word]);
        }
Beispiel #7
0
        public static void RemoveFromDictionary(string command, MongoDictionary mongoDictionary)
        {
            int wordStartIndex = command.IndexOf(' ') + 1;

            string word = command.Substring(wordStartIndex, command.Length - wordStartIndex).Trim();

            mongoDictionary.Remove(word);
        }
Beispiel #8
0
        public static string FindFromDictionary(string command, MongoDictionary mongoDictionary)
        {
            int wordStartIndex = command.IndexOf(' ') + 1;

            string word = command.Substring(wordStartIndex, command.Length - wordStartIndex).Trim();

            return mongoDictionary[word];
        }
Beispiel #9
0
        public static void RemoveFromDictionary(string command, MongoDictionary mongoDictionary)
        {
            int wordStartIndex = command.IndexOf(' ') + 1;

            string word = command.Substring(wordStartIndex, command.Length - wordStartIndex).Trim();

            mongoDictionary.Remove(word);
        }
Beispiel #10
0
        public static void AddToDictionary(string command, MongoDictionary mongoDictionary)
        {
            int wordStartIndex = command.IndexOf(' ') + 1;
            int wordEndIndex   = command.IndexOf('-');

            string word        = command.Substring(wordStartIndex, wordEndIndex - wordStartIndex).Trim();
            string explination = command.Substring(wordEndIndex + 1, (command.Length - 1) - wordEndIndex);

            mongoDictionary.Add(word, explination);
        }
Beispiel #11
0
        public static void AddToDictionary(string command, MongoDictionary mongoDictionary)
        {
            int wordStartIndex = command.IndexOf(' ') + 1;
            int wordEndIndex = command.IndexOf('-');

            string word = command.Substring(wordStartIndex, wordEndIndex - wordStartIndex).Trim();
            string explination = command.Substring(wordEndIndex + 1, (command.Length - 1) - wordEndIndex);

            mongoDictionary.Add(word, explination);
        }
Beispiel #12
0
        public static void ParseCommand(string command, MongoDictionary mongoDictCollection)
        {
            int commandEndIndex = command.IndexOf(' ');

            string parsedCommand = command.Substring(0, commandEndIndex).Trim();

            switch (parsedCommand)
            {
                case "Add": AddToDictionary(command, mongoDictCollection);
                    Console.WriteLine("Word is added successfully.");
                    break;
                case "Remove": RemoveFromDictionary(command, mongoDictCollection);
                    Console.WriteLine("Word is removed successfully.");
                    break;
                case "Find":
                    string result = FindFromDictionary(command, mongoDictCollection);
                    Console.WriteLine(result);
                    break;
                case "List": ListAllFromDictionary(mongoDictCollection);
                    break;
                default: Console.WriteLine("Wrong command. Try again.");
                    break;
            }
        }