DisplayPageSizeAsync(string url, int line)
 {
     WebRequest webRequest = WebRequest.Create(url);
     WebRequestState state =
         new WebRequestState(webRequest, line);
     Write(state, url + " ");
     return Task<WebResponse>.Factory.FromAsync(
             webRequest.BeginGetResponse,
             GetResponseAsyncCompleted, state);
 }
Exemple #2
0
        DisplayPageSizeAsync(string url, int line)
        {
            WebRequest      webRequest = WebRequest.Create(url);
            WebRequestState state      =
                new WebRequestState(webRequest, line);

            Write(state, url + " ");
            return(Task <WebResponse> .Factory.FromAsync(
                       webRequest.BeginGetResponse,
                       GetResponseAsyncCompleted, state));
        }
Exemple #3
0
 private static void Write(
     WebRequestState completedState, string text)
 {
     lock (ConsoleSyncObject)
     {
         Console.SetCursorPosition(
             completedState.ConsoleColumn,
             completedState.ConsoleLine);
         Console.Write(text);
         completedState.ConsoleColumn +=
             text.Length;
     }
 }
 private static void Write(
     WebRequestState completedState, string text)
 {
     lock(ConsoleSyncObject)
     {
         Console.SetCursorPosition(
             completedState.ConsoleColumn,
             completedState.ConsoleLine);
         Console.Write(text);
         completedState.ConsoleColumn +=
             text.Length;
     }
 }
Exemple #5
0
        private static WebResponse GetResponseAsyncCompleted(
            IAsyncResult asyncResult)
        {
            WebRequestState completedState =
                (WebRequestState)asyncResult.AsyncState;
            HttpWebResponse response =
                (HttpWebResponse)completedState.WebRequest
                .EndGetResponse(asyncResult);
            Stream stream =
                response.GetResponseStream();

            using (StreamReader reader =
                       new StreamReader(stream))
            {
                int length = reader.ReadToEnd().Length;
                Write(
                    completedState, FormatBytes(length));
            }
            return(response);
        }
Exemple #6
0
        private static void DisplayProgress(
            WebRequestState state)
        {
            int left = state.ConsoleColumn;
            int top  = state.ConsoleLine;

            lock (ConsoleSyncObject)
            {
                if (left >= Console.BufferWidth -
                    int.MaxValue.ToString().Length)
                {
                    left = state.Url.Length;

                    Console.SetCursorPosition(left, top);
                    Console.Write("".PadRight(
                                      Console.BufferWidth -
                                      state.Url.Length));

                    state.ConsoleColumn = left;
                }

                Write(state, ".");
            }
        }
        private static void DisplayProgress(
            WebRequestState state)
        {
            int left = state.ConsoleColumn;
            int top = state.ConsoleLine;
            lock(ConsoleSyncObject)
            {
                if(left >= Console.BufferWidth -
                    int.MaxValue.ToString().Length)
                {
                    left = state.Url.Length;

                    Console.SetCursorPosition(left, top);
                    Console.Write("".PadRight(
                        Console.BufferWidth -
                            state.Url.Length));

                    state.ConsoleColumn = left;
                }

                Write(state, ".");
            }
        }