Exemplo n.º 1
0
        public async Task PublishZipDeploy(Site functionApp, Func <Task <Stream> > zipFileFactory)
        {
            await RetryHelper.Retry(async() =>
            {
                using (var handler = new ProgressMessageHandler(new HttpClientHandler()))
                    using (var client = GetRemoteZipClient(new Uri($"https://{functionApp.ScmUri}"), handler))
                        using (var request = new HttpRequestMessage(HttpMethod.Post, new Uri("api/zipdeploy", UriKind.Relative)))
                        {
                            request.Headers.IfMatch.Add(EntityTagHeaderValue.Any);

                            ColoredConsole.WriteLine("Creating archive for current directory...");

                            (var content, var length) = CreateStreamContentZip(await zipFileFactory());
                            request.Content           = content;

                            HttpResponseMessage response = null;
                            using (var pb = new SimpleProgressBar($"Uploading {Utilities.BytesToHumanReadable(length)}"))
                            {
                                handler.HttpSendProgress += (s, e) => pb.Report(e.ProgressPercentage);
                                response = await client.SendAsync(request);
                            }

                            if (response == null || !response.IsSuccessStatusCode)
                            {
                                throw new CliException($"Error uploading archive ({response.StatusCode}).");
                            }

                            ColoredConsole.WriteLine("Upload completed successfully.");
                        }
            }, 2);
        }
Exemplo n.º 2
0
        public static async Task <HttpResponseMessage> InvokeLongRunningRequest(HttpClient client,
                                                                                ProgressMessageHandler handler, HttpRequestMessage request, long requestSize = 0, string prompt = null)
        {
            if (prompt == null)
            {
                prompt = string.Empty;
            }

            string message = string.Empty;

            if (requestSize > 0)
            {
                message = Utilities.BytesToHumanReadable(requestSize);
            }

            using (var pb = new SimpleProgressBar($"{prompt} {message}"))
            {
                handler.HttpSendProgress += (s, e) => pb.Report(e.ProgressPercentage);
                return(await client.SendAsync(request));
            }
        }