AppHarbor.Commands.LogAppCommand.InnerExecute C# (CSharp) Method

InnerExecute() protected method

protected InnerExecute ( string arguments ) : void
arguments string
return void
        protected override void InnerExecute(string[] arguments)
        {
            var request = new RestRequest("applications/{slug}/logsession", Method.POST)
            {
                RequestFormat = DataFormat.Json
            }
                .AddUrlSegment("slug", ApplicationId)
                .AddHeader("Authorization", string.Format("BEARER {0}", _accessToken))
                .AddBody(new
                {
                    tail = _tail,
                    limit = _limit - 1,
                    sourcefilter = _sourceFilter,
                    processFilter = _processFilter,
                });

            var response = _restClient.Execute(request);
            var locationHeader = response.Headers.FirstOrDefault(x =>
                string.Equals(x.Name, "location",StringComparison.InvariantCultureIgnoreCase));
            if (response.StatusCode != HttpStatusCode.Created || locationHeader.Value == null)
            {
                throw new CommandException("Couldn't create log session. Try again later.");
            }

            var sessionUrl = new Uri(locationHeader.Value.ToString());
            try
            {
                using (var webClient = new WebClient())
                {
                    using (var stream = webClient.OpenRead(sessionUrl))
                    using (var reader = new StreamReader(stream))
                    {
                        while (true)
                        {
                            var line = reader.ReadLine();
                            if (line != null)
                            {
                                WriteColorizedLine(line);
                            }

                            if (reader.EndOfStream)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            catch (WebException exception)
            {
                Console.WriteLine("Log session ended with message: {0}", exception.Message);
            }
        }