using Microsoft.Cognitive.CustomVision.Prediction; using Microsoft.Cognitive.CustomVision.Training; ... using Microsoft.Rest; using System; using System.Linq; using System.Threading.Tasks; ... namespace VisionRacing.PredictingRacingImages { class Program { static void Main(string[] args) { var trainingKey = "Your Custom Vision training key."; var predictionKey = "Your Custom Vision prediction key."; Start(trainingKey, predictionKey).Wait(); } private static async Task Start(string trainingKey, string predictionKey) { var projectName = " "; var trainingApi = GetTrainingApi(trainingKey); var predictionEndpoint = GetPredictionEndpoint(predictionKey); while (!string.IsNullOrEmpty(projectName)) { try { Console.Clear(); await ListProjects(trainingApi); Console.WriteLine("Please enter a project name or press enter to exit:"); projectName = Console.ReadLine(); if (!string.IsNullOrEmpty(projectName)) { await WorkOnProject(trainingApi, predictionEndpoint, projectName); } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"An error occurred: {Environment.NewLine}{ex.Message}"); if (ex is HttpOperationException) { Console.WriteLine(((HttpOperationException)ex).Response.Content); } Console.ResetColor(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Press any key to continue"); Console.ReadLine(); } } } ... private static PredictionEndpoint GetPredictionEndpoint(string predictionKey) { return new PredictionEndpoint { ApiKey = predictionKey }; } private static TrainingApi GetTrainingApi(string trainingKey) { return new TrainingApi { ApiKey = trainingKey }; } private static async Task ListProjects(TrainingApi trainingApi) { var projects = await trainingApi.GetProjectsAsync(); if (projects.Any()) { Console.WriteLine($"Existing projects: {Environment.NewLine}{string.Join(Environment.NewLine, projects.Select(p => p.Name))}{Environment.NewLine}"); } } ... } }