コード例 #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);
            }
        }
コード例 #2
0
 public static void ListAllFromDictionary(MongoDictionary mongoDictionary)
 {
     foreach (var item in mongoDictionary)
     {
         Console.WriteLine("{0}=>{1}", item.Key, item.Value);
     }
 }
コード例 #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;
            }
        }
コード例 #4
0
ファイル: Engine.cs プロジェクト: VesiBaleva/TelerikAcademy
 public static void ListAllFromDictionary(MongoDictionary mongoDictionary)
 {
     foreach (var item in mongoDictionary)
     {
         Console.WriteLine("{0}=>{1}", item.Key, item.Value);
     }
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: C3co0o0o/Databases
        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);
            }
        }
コード例 #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]);
        }
コード例 #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);
        }
コード例 #8
0
ファイル: Engine.cs プロジェクト: VesiBaleva/TelerikAcademy
        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];
        }
コード例 #9
0
ファイル: Engine.cs プロジェクト: VesiBaleva/TelerikAcademy
        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);
        }
コード例 #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);
        }
コード例 #11
0
ファイル: Engine.cs プロジェクト: VesiBaleva/TelerikAcademy
        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);
        }
コード例 #12
0
ファイル: Engine.cs プロジェクト: VesiBaleva/TelerikAcademy
        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;
            }
        }