Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ErrorLogEntry"/> class
        /// for a given unique error entry in an error log.
        /// </summary>
        public ErrorLogEntry(ErrorLog log, string id, Error error)
        {
            if (log == null)
                throw new ArgumentNullException("log");

            if (id == null)
                throw new ArgumentNullException("id");

            if (id.Length == 0)
                throw new ArgumentException(null, "id");

            if (error == null)
                throw new ArgumentNullException("error");

            _log = log;
            _id = id;
            _error = error;
        }
        /// <summary>
        /// Initializes a new instance of the 
        /// <see cref="ErrorLogDataSourceAdapter"/> class with the default
        /// error log implementation.
        /// </summary>

        public ErrorLogDataSourceAdapter()
        {
            _log = ErrorLog.GetDefault(HttpContext.Current);
        }
        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;
        }
        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();
        }