static async Task Main(string[] args) { //API request params string accessToken = "PLACEHOLDER"; string requestUrl = "https://dev.azure.com/ViewpointVSO/_apis/work/processes/lists/2b075466-b4fa-4b5b-8013-f3bbd27c6a20?api-version=6.0-preview.1"; //Get json from api and deserialize it into an object string currentListJson = await GetJson(accessToken, requestUrl); ListObj currentList = JsonConvert.DeserializeObject <ListObj>(currentListJson); //Print current options to the console Console.WriteLine("Current target releases:"); if (currentList.items.Count == 0) { Console.WriteLine("The list is empty."); } for (int i = 0; i < currentList.items.Count; i++) { Console.WriteLine(currentList.items[i]); } Console.WriteLine(""); await Menu(accessToken, requestUrl); }
private static async Task AddOption(string accessToken, string requestUrl) { //Get json from api and deserialize it into an object string currentListJson = await GetJson(accessToken, requestUrl); ListObj currentList = JsonConvert.DeserializeObject <ListObj>(currentListJson); //Get the option to be added Console.WriteLine("Type the option you would like to add:"); string addItem = Console.ReadLine(); //Make sure a value was entered if (addItem == "") { Console.WriteLine("You must enter a value.\n"); return; } //Add the option currentList.items.Add(addItem); //Re-serialize to json string updatedListJson = JsonConvert.SerializeObject(currentList); //Send the request await PutJson(accessToken, requestUrl, updatedListJson); Console.WriteLine("\nSuccessfuly updated the list in Azure DevOps.\n"); }
private static async Task RemoveOption(string accessToken, string requestUrl) { //Get json from api and deserialize it into an object string currentListJson = await GetJson(accessToken, requestUrl); ListObj currentList = JsonConvert.DeserializeObject <ListObj>(currentListJson); //Make sure the list isn't empty if (currentList.items.Count == 0) { Console.WriteLine("The list is empty."); return; } //List the items that are available to delete Console.WriteLine("Select an item to remove by typing a number, then pressing 'Enter':"); for (int i = 0; i < currentList.items.Count; i++) { Console.WriteLine($"{i + 1} - {currentList.items[i]}"); } //Grab the index of the item to delete string consoleRead = Console.ReadLine(); if (consoleRead == "") { Console.WriteLine("You must enter a value.\n"); return; } //Ensure a numerical value was entered try { Int32.Parse(consoleRead); } catch { Console.WriteLine("\nYou must enter a numerical value\n."); return; } int deleteIndex = Int32.Parse(consoleRead); //Delete the item try { currentList.items.RemoveAt(deleteIndex - 1); } catch (ArgumentOutOfRangeException) { Console.WriteLine("\nThe number you entered was invalid.\n"); return; } //Re-serialize to json string updatedListJson = JsonConvert.SerializeObject(currentList); //Send the request await PutJson(accessToken, requestUrl, updatedListJson); Console.WriteLine("\n\nSuccessfuly updated the list in Azure DevOps.\n"); }
private static async Task EditOption(string accessToken, string requestUrl) { //Get json from api and deserialize it into an object string currentListJson = await GetJson(accessToken, requestUrl); ListObj currentList = JsonConvert.DeserializeObject <ListObj>(currentListJson); //Make sure the list isn't empty if (currentList.items.Count == 0) { Console.WriteLine("The list is empty."); return; } //List the items that are available to edit Console.WriteLine("Select an item to edit by typing a number, then pressing 'Enter':"); for (int i = 0; i < currentList.items.Count; i++) { Console.WriteLine($"{i + 1} - {currentList.items[i]}"); } //Grab the index of the item to edit string consoleRead = Console.ReadLine(); //Make sure a value was entered if (consoleRead == "") { Console.WriteLine("You must enter a value.\n"); return; } //Make sure the value entered is a number try { Int32.Parse(consoleRead); } catch { Console.WriteLine("\nYou must enter a numerical value.\n"); return; } int editIndex = Int32.Parse(consoleRead); //Grab the text to change it to try { Console.WriteLine($"\nEnter what you would like to change '{currentList.items[editIndex - 1]}' to:"); } catch (ArgumentOutOfRangeException) { Console.WriteLine("\nThe number you entered was out of range.\n"); return; } string editedOption = Console.ReadLine(); //Make sure a value was actually entered. if (editedOption == "") { Console.WriteLine("You must enter a value.\n"); return; } //Make the change currentList.items[editIndex - 1] = editedOption; //Re-serialize to json string updatedListJson = JsonConvert.SerializeObject(currentList); //Send the request await PutJson(accessToken, requestUrl, updatedListJson); Console.WriteLine("\nSuccessfuly updated the list in Azure DevOps.\n"); }