Example #1
0
 public static void ListAllFromDictionary(MongoDictionary mongoDictionary)
 {
     foreach (var item in mongoDictionary)
     {
         Console.WriteLine("{0}=>{1}", item.Key, item.Value);
     }
 }
    private static void Main()
    {
        // The default console's font doesn't support Cyrillic letters.
        // We should find a font with Unicode support and change the
        // default font.
        Console.OutputEncoding = Encoding.UTF8;
        ConsoleHelper.SetConsoleFont(6);

        var dictionary = new MongoDictionary(
            "mongodb://localhost/?safe=true",
            "dictionary",
            "entries");

        //dictionary.InsertEntry("humongous", "огромен");

        string translation = dictionary.FindTranslationByName("humongous");

        Console.WriteLine(translation);

        var entries = dictionary.GetAllEntries();

        foreach (var entry in entries)
        {
            Console.WriteLine(entry);
        }
    }
Example #3
0
    /* 01. Write a simple "Dictionary" application in C# or JavaScript to perform the following in MongoDB:
           Add a dictionary entry (word + translation)
           List all words and their translations
           Find the translation of given word*/

    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();

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

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

            Engine.ParseCommand(command, mongoDictionary);
        }
    }
Example #4
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];
    }
Example #5
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);
    }
Example #6
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);
    }
Example #7
0
        static void Main(string[] args)
        {
            mongoDictionary = new MongoDictionary<Word>("collection", "collection");

            string[] command = { " " };
            while (command[0] != "end")
            {
                PrintMenu();
                command = Console.ReadLine().Split(
                    new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                switch (command[0])
                {
                    case "add": AddWord(command[1], JoinTranslation(command, 2)); break;
                    case "translate": Translate(command[1]); break;
                    case "list": ListAllWords(); break;
                    case "end": break;
                }
            }
        }
Example #8
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;
        }
    }