Exemplo n.º 1
0
        //Used to send a Post Request to VideoInderAPI and returns id of breakdown
        static async Task MakeRequest(VideoIndexerUpload uploadRequest)
        {
            //Define Request body


            using (var client = new HttpClient())
            {
                var content = new MultipartFormDataContent();

                content.Add(new StreamContent(File.Open(uploadRequest.filePath, FileMode.Open)), uploadRequest.name,
                            uploadRequest.fileName);


                client.Timeout = TimeSpan.FromMinutes(30);

                var queryString = HttpUtility.ParseQueryString(string.Empty);

                //Define Request headers
                client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", uploadRequest.ocpKey);


                //Define Request parameters
                queryString["name"]    = uploadRequest.name;
                queryString["privacy"] = uploadRequest.privacy;
                var uri = $"https://videobreakdown.azure-api.net/Breakdowns/Api/Partner/Breakdowns?{queryString}";

                HttpResponseMessage response;

                try
                {
                    response = await client.PostAsync(uri, content);

                    Console.WriteLine(response.ToString());
                    Console.WriteLine("Parsing response body...");
                    Console.WriteLine("The Id is: ");
                    await ParseJson(response);
                }
                catch (Exception e)
                {
                    Console.WriteLine("There was an Error with your Upload!");
                    Console.WriteLine(e);
                }
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            bool isRunning = true;


            VideoIndexerUpload upload = new VideoIndexerUpload("{apiKey}",
                                                               "{NameUpload}",
                                                               "Private", "{pathToFile}", "{NameFile}");


            while (isRunning)
            {
                Console.WriteLine();
                Console.WriteLine("Enter q to finish, u for upload,b for breakdown or enter w for a widget url!");
                var input = Console.ReadLine();
                if (input == "q")
                {
                    isRunning = false;
                }
                else if (input == "u")
                {
                    Console.WriteLine("Hit enter to start Upload!");
                    Console.ReadKey();

                    Console.WriteLine("Upload started!");
                    MakeRequest(upload).Wait();
                }
                else if (input == "b")
                {
                    var idBreakdown = GetIdValue();
                    GetBreakdown(idBreakdown).Wait();
                    Console.ReadKey();
                }
                else if (input == "w")
                {
                    var idWidget = GetIdValue();
                    GetBreakdownUrl(idWidget).Wait();
                    Console.ReadKey();
                }
            }
        }