Created
August 23, 2017 15:18
-
-
Save dontpaniclabsgists/1068966e3c3918ab5b6f42df3d13e999 to your computer and use it in GitHub Desktop.
Cosmos1_11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var endpoint = args[0]; | |
var key = args[1]; | |
var databaseId = args[2]; | |
Task.Run(async () => | |
{ | |
await Run(endpoint, key, databaseId); | |
}).GetAwaiter().GetResult(); | |
Console.ReadLine(); | |
} | |
static async Task Run(string endpoint, string key, string databaseId) | |
{ | |
Console.WriteLine(endpoint); | |
Console.WriteLine(key); | |
Console.WriteLine(databaseId); | |
var exit = false; | |
Note added = null; | |
while (!exit) | |
{ | |
try | |
{ | |
WriteMenu(); | |
var number = int.Parse(Console.ReadLine()); | |
var accessor = new NotesAccessor(endpoint, key, databaseId); | |
switch (number) | |
{ | |
case 1: | |
Console.WriteLine("COUNT: " + await accessor.Count()); | |
break; | |
case 2: | |
{ | |
Console.WriteLine("READ: " + JsonConvert.SerializeObject(await accessor.All())); | |
} | |
break; | |
case 3: | |
{ | |
added = new Note() | |
{ | |
Id = Guid.NewGuid().ToString(), | |
CustomerId = "test", | |
Text = "Something" | |
}; | |
Console.WriteLine("CREATE: " + JsonConvert.SerializeObject(added)); | |
await accessor.Create(added); | |
} | |
break; | |
case 4: | |
{ | |
if (added != null) | |
{ | |
added.Text = "updated"; | |
Console.WriteLine("UPDATE: " + JsonConvert.SerializeObject(added)); | |
await accessor.Update(added); | |
} | |
else | |
{ | |
Console.WriteLine("add item first"); | |
} | |
} | |
break; | |
case 5: | |
{ | |
if (added != null) | |
{ | |
Console.WriteLine("DELETE: " + added.Id); | |
await accessor.Delete(added.Id, added.CustomerId); | |
} | |
else | |
{ | |
Console.WriteLine("add item first"); | |
} | |
} | |
break; | |
case 99: | |
exit = true; | |
break; | |
} | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.ToString()); | |
exit = true; | |
} | |
} | |
} | |
static void WriteMenu() | |
{ | |
Console.WriteLine(""); | |
Console.WriteLine("###### Menu ######"); | |
Console.WriteLine(" 1. Count"); | |
Console.WriteLine(" 2. Read"); | |
Console.WriteLine(" 3. Create"); | |
Console.WriteLine(" 4. Update"); | |
Console.WriteLine(" 5. Delete"); | |
Console.WriteLine("99. Exit"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment