Inheritance: IAsyncResult
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            if (_result != null)
                throw new InvalidOperationException("An asynchronous operation is already pending.");

            HttpRequest request = context.Request;
            NameValueCollection query = request.QueryString;

            //
            // Limit the download by some maximum # of records?
            //

            _maxDownloadCount = Math.Max(0, Convert.ToInt32(query["limit"], CultureInfo.InvariantCulture));

            //
            // Determine the desired output format.
            //

            string format = Mask.EmptyString(query["format"], "csv").ToLower(CultureInfo.InvariantCulture);

            switch (format)
            {
                case "csv": _format = new CsvFormat(context); break;
                case "jsonp": _format = new JsonPaddingFormat(context); break;
                case "html-jsonp": _format = new JsonPaddingFormat(context, /* wrapped */ true); break;
                default:
                    throw new Exception("Request log format is not supported.");
            }

            Debug.Assert(_format != null);

            //
            // Emit format header, initialize and then fetch results.
            //

            context.Response.BufferOutput = false;
            _format.Header();

            AsyncResult result = _result = new AsyncResult(extraData);
            _log = ErrorLog.GetDefault(context);
            _pageIndex = 0;
            _lastBeatTime = DateTime.Now;
            _context = context;
            _callback = cb;
            _errorEntryList = new ArrayList(_pageSize);

            _log.BeginGetErrors(_pageIndex, _pageSize, _errorEntryList,
                new AsyncCallback(GetErrorsCallback), null);

            return result;
        }
Exemple #2
0
 protected virtual void MakeCallback(
     AsyncCallback callback, AsyncResult result)
 {
     // If a callback method was set, call it
     if (callback != null)
         callback(result);
 }
        public void EndProcessRequest(IAsyncResult result)
        {
            if (result == null)
                throw new ArgumentNullException("result");

            if (result != _result)
                throw new ArgumentException(null, "result");

            _result = null;
            _log = null;
            _context = null;
            _callback = null;
            _errorEntryList = null;

            ((AsyncResult) result).End();
        }
Exemple #4
0
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (_result != null)
            {
                throw new InvalidOperationException("An asynchronous operation is already pending.");
            }

            HttpRequest         request = context.Request;
            NameValueCollection query   = request.QueryString;

            //
            // Limit the download by some maximum # of records?
            //

            _maxDownloadCount = Math.Max(0, Convert.ToInt32(query["limit"], CultureInfo.InvariantCulture));

            //
            // Determine the desired output format.
            //

            string format = Mask.EmptyString(query["format"], "csv").ToLower(CultureInfo.InvariantCulture);

            switch (format)
            {
            case "csv": _format = new CsvFormat(context); break;

            case "jsonp": _format = new JsonPaddingFormat(context); break;

            case "html-jsonp": _format = new JsonPaddingFormat(context, /* wrapped */ true); break;

            default:
                throw new Exception("Request log format is not supported.");
            }

            Debug.Assert(_format != null);

            //
            // Emit format header, initialize and then fetch results.
            //

            context.Response.BufferOutput = false;
            _format.Header();

            AsyncResult result = _result = new AsyncResult(extraData);

            _log            = ErrorLog.GetDefault(context);
            _pageIndex      = 0;
            _lastBeatTime   = DateTime.Now;
            _context        = context;
            _callback       = cb;
            _errorEntryList = new List <ErrorLogEntry>(_pageSize);

            _log.BeginGetErrors(_pageIndex, _pageSize, _errorEntryList,
                                new AsyncCallback(GetErrorsCallback), null);

            return(result);
        }