public IAsyncResult BeginProcessRequests(AsyncCallback callback, object extraData) {
     if (DEBUG) {
         m_logWriter.WriteLine("Beginning async HTTP request process...");
     }
     NuxleusAsyncResult nuxleusAsyncResult = new NuxleusAsyncResult(callback, extraData);
     ProcessRequests(nuxleusAsyncResult);
     return nuxleusAsyncResult;
 }
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData) {

            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            NuxleusAsyncResult nuxleusAsyncResult = new NuxleusAsyncResult(cb, extraData);

            nuxleusAsyncResult.CompleteCall();
            return nuxleusAsyncResult;
        }
        private void ProcessRequests(NuxleusAsyncResult asyncResult) {

            int queryArrayLength = m_httpRequestArrayLength;
            TextWriter logWriter = m_logWriter;
            bool DEBUG = m_DEBUG;
            List<long> elaspedTimeList = m_elapsedTimeList;

            Encoding encoding = Encoding.UTF8;

            foreach (string r in m_httpRequestArray) {
                Stopwatch stopwatch = new Stopwatch();
                if (DEBUG) {
                    stopwatch.Start();
                }
                string requestString = r;
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(requestString));

                new AsyncHttpRequest(request, logWriter, DEBUG, stopwatch,
                        delegate(Stream stream, Stopwatch myStopwatch) {
                            //logWriter.WriteLine("The stopwatch objects are the same: {0}", stopwatch.Equals(myStopwatch));
                            long elapsedTime = 0;
                            if (DEBUG) {
                                myStopwatch.Stop();
                                elapsedTime = stopwatch.ElapsedMilliseconds;
                                elaspedTimeList.Add(elapsedTime);
                                myStopwatch.Reset();
                                logWriter.WriteLine("Current thread id: {0} for current request: {1}", Thread.CurrentThread.ManagedThreadId, requestString);
                            }

                            try {
                                using (stream) {
                                    StreamReader reader = new StreamReader(stream);
                                    m_responseStreamDictionary.Add(requestString.GetHashCode(), new MemoryStream(encoding.GetBytes(reader.ReadToEnd())));
                                }
                            } catch (Exception e) {
                                logWriter.WriteLine("Exception: {0}", e.Message);
                            }

                            if (m_responseStreamDictionary.Count == queryArrayLength) {
                                if (DEBUG) {
                                    logWriter.WriteLine("Elapsed time of this request:\t {0}ms", elapsedTime);
                                    logWriter.WriteLine("Completing call.");
                                }
                                asyncResult.CompleteCall();
                            } else {
                                if (DEBUG) {
                                    logWriter.WriteLine("Elapsed time of this request:\t {0}ms", elapsedTime);
                                    logWriter.WriteLine("Continuing process...");
                                }
                            }

                        });
            }
        }
Esempio n. 4
0
 public IAsyncResult BeginCallWebService(ITask task, NuxleusAsyncResult asyncResult)
 {
     HttpWebRequest request = GetHttpWebRequest(task, GetDefaultSettings());
     AsyncCallback callback = new AsyncCallback(EndCallWebService);
     return request.BeginGetResponse(callback,
         new HttpWebOperationCallbackContainer
         {
             AsyncResult = asyncResult,
             Callback = callback,
             Request = request,
             Task = task
         });
 }