public static void Main(string[] args) { KeyValueBaseServiceClient client = new KeyValueBaseServiceClient(); while (true) { try { Console.Write("Enter command: "); string line = Console.ReadLine(); string[] parts = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 0) { continue; } string cmd = parts[0]; if (cmd == "init") { client.Init(line.Split(new char[] { ' ', '\t' }, 2, StringSplitOptions.RemoveEmptyEntries)[1]); } else if (cmd == "reset") { client.Reset(); } else if (cmd == "read") { KeyImpl key = ParseKey(parts[1]); PrintList(client.Read(key)); } else if (cmd == "insert") { KeyImpl key = ParseKey(parts[1]); ValueListImpl values = ParseList(parts, 2); client.Insert(key, values); } else if (cmd == "update") { KeyImpl key = ParseKey(parts[1]); ValueListImpl values = ParseList(parts, 2); client.Update(key, values); } else if (cmd == "delete") { KeyImpl key = ParseKey(parts[1]); client.Delete(key); } else if (cmd == "scan" || cmd == "atomicscan") { bool atomic = cmd == "atomicscan"; KeyImpl begin = ParseKey(parts[1]); KeyImpl end = ParseKey(parts[2]); string predicateString = line.Split(new char[] { ' ', '\t' }, 4, StringSplitOptions.RemoveEmptyEntries)[3]; object predicate = TokenizeAndParsePredicate(predicateString); ValueListImpl[] lists; if (atomic) { lists = client.AtomicScan(begin, end, predicate); } else { lists = client.Scan(begin, end, predicate); } foreach (ValueListImpl vl in lists) { PrintList(vl); } } else if (cmd == "close" || cmd == "quit" || cmd == "exit") { break; } else { Console.WriteLine("?"); } } catch (Exception e) { Console.WriteLine(e.ToString()); } } client.Close(); }
private static void PrintList(ValueListImpl valueListImpl) { Console.WriteLine(String.Join(", ", valueListImpl.List.Select(v => v.Value))); }