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); } }
public static void ListAllFromDictionary(MongoDictionary mongoDictionary) { foreach (var item in mongoDictionary) { Console.WriteLine("{0}=>{1}", item.Key, item.Value); } }
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; } }
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); } }
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]); }
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); }
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]; }
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); }