Skip to content

Instantly share code, notes, and snippets.

@dontpaniclabsgists
Created August 25, 2017 16:03
Show Gist options
  • Save dontpaniclabsgists/2ac60ccd72b30e94c069b98d7cc72f4b to your computer and use it in GitHub Desktop.
Save dontpaniclabsgists/2ac60ccd72b30e94c069b98d7cc72f4b to your computer and use it in GitHub Desktop.
azure_functions_4_5
class Program
 {
     static void Main(string[] args)
     {
         var endpoint = args[0];
         var key = args[1];
         Task.Run(async () =>
         {
             await Run(endpoint, key);
         }).GetAwaiter().GetResult();         
         Console.ReadLine();
     }
     static async Task Run(string endpoint, string key)
     {
         Console.WriteLine(endpoint);
         Console.WriteLine(key);
         var exit = false;
         while (!exit)
         {
             try
             {
                 WriteMenu();
                 var number = int.Parse(Console.ReadLine());
                 var factory = new AccessorFactory(endpoint, key);
                 var accessor = factory.CreateWardrobeAccessor();
                 switch (number)
                 {
                     case 1:
                         Console.WriteLine("COUNT: " + await accessor.Count());
                         break;
                     case 2:
                         {
                             Console.WriteLine("LIST: ");
                             var items = await accessor.Wardrobes();
                             var json = Newtonsoft.Json.JsonConvert.SerializeObject(items);
                             Console.WriteLine(json);
                         }
                         break;
                     case 3:
                         {
                             Console.WriteLine("CURRENT: ");
                             var item = await accessor.CurrentWardrobe();
                             var json = Newtonsoft.Json.JsonConvert.SerializeObject(item);
                             Console.WriteLine(json);
                         }
                         break;
                     case 4:
                         {
                             Console.WriteLine("Add: ");
                             var w = new Wardrobe()
                             {
                                 Id = Guid.NewGuid().ToString()
                             };
                             var item = await accessor.AddWardrobe(w);
                             var json = Newtonsoft.Json.JsonConvert.SerializeObject(item);
                             Console.WriteLine(json);
                         }
                         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. List");
         Console.WriteLine(" 3. Current");
         Console.WriteLine(" 4. Add");
         Console.WriteLine("99. Exit");
     }
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment