Example #1
0
        public override Task WriteRawAsync(char[] buffer, int index, int count)
        {
            CheckAsync();
            var task = _coreWriter.WriteRawAsync(buffer, index, count);

            _lastTask = task;
            return(task);
        }
        internal static async Task EncodeAsync(byte[] buffer, int index, int count, XmlWriter writer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }
            if (count > buffer.Length - index)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            char[] chars    = new char[(count * 2) < CharsChunkSize ? (count * 2) : CharsChunkSize];
            int    endIndex = index + count;

            while (index < endIndex)
            {
                int cnt = (count < CharsChunkSize / 2) ? count : CharsChunkSize / 2;
                HexConverter.EncodeToUtf16(buffer.AsSpan(index, cnt), chars);
                await writer.WriteRawAsync(chars, 0, cnt * 2).ConfigureAwait(false);

                index += cnt;
                count -= cnt;
            }
        }
Example #3
0
        internal static async Task EncodeAsync(byte[] buffer, int index, int count, XmlWriter writer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count");
            }
            if (count > buffer.Length - index)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            char[] chars = new char[(count * 2) < CharsChunkSize ? (count * 2) : CharsChunkSize];
            int endIndex = index + count;
            while (index < endIndex)
            {
                int cnt = (count < CharsChunkSize / 2) ? count : CharsChunkSize / 2;
                int charCount = Encode(buffer, index, cnt, chars);
                await writer.WriteRawAsync(chars, 0, charCount).ConfigureAwait(false);
                index += cnt;
                count -= cnt;
            }
        }
Example #4
0
            static async Task Core(byte[] buffer, int index, int count, XmlWriter writer)
            {
                char[] chars    = new char[(count * 2) < CharsChunkSize ? (count * 2) : CharsChunkSize];
                int    endIndex = index + count;

                while (index < endIndex)
                {
                    int cnt = (count < CharsChunkSize / 2) ? count : CharsChunkSize / 2;
                    HexConverter.EncodeToUtf16(buffer.AsSpan(index, cnt), chars);
                    await writer.WriteRawAsync(chars, 0, cnt * 2).ConfigureAwait(false);

                    index += cnt;
                    count -= cnt;
                }
            }
            internal async Task ReplayAsync(XmlWriter writer) {
                if (singleStringValue != null) {
                    await writer.WriteStringAsync(singleStringValue).ConfigureAwait(false);
                    return;
                }

                BufferChunk bufChunk;
                for (int i = firstItem; i <= lastItem; i++) {
                    Item item = items[i];
                    switch (item.type) {
                        case ItemType.EntityRef:
                            await writer.WriteEntityRefAsync((string)item.data).ConfigureAwait(false);
                            break;
                        case ItemType.CharEntity:
                            await writer.WriteCharEntityAsync((char)item.data).ConfigureAwait(false);
                            break;
                        case ItemType.SurrogateCharEntity:
                            char[] chars = (char[])item.data;
                            await writer.WriteSurrogateCharEntityAsync(chars[0], chars[1]).ConfigureAwait(false);
                            break;
                        case ItemType.Whitespace:
                            await writer.WriteWhitespaceAsync((string)item.data).ConfigureAwait(false);
                            break;
                        case ItemType.String:
                            await writer.WriteStringAsync((string)item.data).ConfigureAwait(false);
                            break;
                        case ItemType.StringChars:
                            bufChunk = (BufferChunk)item.data;
                            await writer.WriteCharsAsync(bufChunk.buffer, bufChunk.index, bufChunk.count).ConfigureAwait(false);
                            break;
                        case ItemType.Raw:
                            await writer.WriteRawAsync((string)item.data).ConfigureAwait(false);
                            break;
                        case ItemType.RawChars:
                            bufChunk = (BufferChunk)item.data;
                            await writer.WriteCharsAsync(bufChunk.buffer, bufChunk.index, bufChunk.count).ConfigureAwait(false);
                            break;
                        case ItemType.ValueString:
                            await writer.WriteStringAsync((string)item.data).ConfigureAwait(false);
                            break;
                        default:
                            Debug.Assert(false, "Unexpected ItemType value.");
                            break;
                    }
                }
            }
Example #6
0
        private async Task RenderPageNavigatorsAsync(XmlWriter writer)
        {
            await writer.WriteStartElementAsync("p");
            {
                var nextPageIndex = pageIndex + 1;
                var moreErrors = nextPageIndex*pageSize < totalCount;

                if (moreErrors)
                {
                    await writer.WriteStartElementAsync("a");
                    await writer.WriteAttributeStringAsync("href", $"{BasePageName}?page={nextPageIndex + 1}&size={pageSize}");
                    await writer.WriteAttributeStringAsync("rel", "next");
                    {
                        await writer.WriteStringAsync("Next errors");
                    }
                    await writer.WriteEndElementAsync();
                }

                // If not on the first page then render a link to the firs page.

                if (pageIndex > 0 && totalCount > 0)
                {
                    if (moreErrors)
                        await writer.WriteRawAsync("; ");

                    await writer.WriteStartElementAsync("a");
                    await writer.WriteAttributeStringAsync("href", $"{BasePageName}?page=1&size={pageSize}");
                    await writer.WriteAttributeStringAsync("rel", "start");
                    {
                        await writer.WriteStringAsync("Back to first page");
                    }
                    await writer.WriteEndElementAsync();
                }
            }
            await writer.WriteEndElementAsync();
        }
Example #7
0
        private async Task RenderErrorsAsync(XmlWriter writer)
        {
            //
            // Create a table to display error information in each row.
            //

            await writer.WriteStartElementAsync("table");
            await writer.WriteAttributeStringAsync("id", "ErrorLog");
            await writer.WriteAttributeStringAsync("style", "border-spacing: 0;");
            {

                //
                // Create the table row for headings.
                //

                await writer.WriteStartElementAsync("tr");
                {
                    await RenderCellAsync(writer, "th", "Host", "host-col");
                    await RenderCellAsync(writer, "th", "Code", "code-col");
                    await RenderCellAsync(writer, "th", "Type", "type-col");
                    await RenderCellAsync(writer, "th", "Error", "error-col");
                    await RenderCellAsync(writer, "th", "User", "user-col");
                    await RenderCellAsync(writer, "th", "Date", "date-col");
                    await RenderCellAsync(writer, "th", "Time", "time-col");
                }
                await writer.WriteEndElementAsync();

                //
                // Generate a table body row for each error.
                //

                for (int index = 0; index < errorLogEntries.Count; index++)
                {
                    var errorLogEntry = errorLogEntries[index];

                    await writer.WriteStartElementAsync("tr");
                    await writer.WriteAttributeStringAsync("class", index % 2 == 0 ? "even-row" : "odd-row");
                    {
                        // Format host and status code cells.

                        var error = errorLogEntry.Error;

                        await RenderCellAsync(writer, "td", error.HostName, "host-col");
                        await RenderCellAsync(writer, "td", error.StatusCode.ToString(), "code-col", HttpCodeParser.GetstatusDescription(error.StatusCode));
                        await RenderCellAsync(writer, "td", ErrorShortName(error.TypeName), "host-col", error.TypeName);

                        //
                        // Format the message cell, which contains the message 
                        // text and a details link pointing to the page where
                        // all error details can be viewed.
                        //

                        await writer.WriteStartElementAsync("td");
                        await writer.WriteAttributeStringAsync("class", "error-col");
                        {
                            await writer.WriteStartElementAsync("label");
                            {
                                await writer.WriteStringAsync(error.Message);
                            }
                            await writer.WriteEndElementAsync();

                            await writer.WriteStartElementAsync("a");
                            await writer.WriteAttributeStringAsync("href", $"{BasePageName}/detail?id={errorLogEntry.Id}");
                            {
                                await writer.WriteRawAsync("Details&hellip;");
                            }
                            await writer.WriteEndElementAsync();
                        }
                        await writer.WriteEndElementAsync();

                        // Format the user, date and time cells.
                        await RenderCellAsync(writer, "td", error.User, "user-col");
                        await RenderCellAsync(writer, "td", error.Time.DateTime.ToShortDateString(), "date-col", error.Time.DateTime.ToLongDateString());
                        await RenderCellAsync(writer, "td", error.Time.DateTime.ToShortTimeString(), "time-col", error.Time.DateTime.ToLongTimeString());

                    }
                    await writer.WriteEndElementAsync();
                }
            }
            await writer.WriteEndElementAsync();
        }
Example #8
0
        private static async Task RenderCellAsync(XmlWriter writer, string cellType, string contents, string cssClassName, string tooltip = "")
        {
            await writer.WriteStartElementAsync(cellType);
            await writer.WriteAttributeStringAsync("class", cssClassName);

            if (string.IsNullOrEmpty(contents?.Trim()))
            {
                await writer.WriteRawAsync("&nbsp;");
            }
            else
            {
                if (string.IsNullOrEmpty(tooltip?.Trim()))
                {
                    await writer.WriteStringAsync(contents);
                }
                else
                {
                    await writer.WriteStartElementAsync("label");
                    await writer.WriteAttributeStringAsync("title", tooltip);
                    await writer.WriteStringAsync(contents);
                    await writer.WriteEndElementAsync();
                }
            }

            await writer.WriteEndElementAsync();
        }
            internal async Task ReplayAsync(XmlWriter writer)
            {
                if (_singleStringValue != null)
                {
                    await writer.WriteStringAsync(_singleStringValue).ConfigureAwait(false);

                    return;
                }

                BufferChunk bufChunk;

                for (int i = _firstItem; i <= _lastItem; i++)
                {
                    Item item = _items[i];
                    switch (item.type)
                    {
                    case ItemType.EntityRef:
                        await writer.WriteEntityRefAsync((string)item.data).ConfigureAwait(false);

                        break;

                    case ItemType.CharEntity:
                        await writer.WriteCharEntityAsync((char)item.data).ConfigureAwait(false);

                        break;

                    case ItemType.SurrogateCharEntity:
                        char[] chars = (char[])item.data;
                        await writer.WriteSurrogateCharEntityAsync(chars[0], chars[1]).ConfigureAwait(false);

                        break;

                    case ItemType.Whitespace:
                        await writer.WriteWhitespaceAsync((string)item.data).ConfigureAwait(false);

                        break;

                    case ItemType.String:
                        await writer.WriteStringAsync((string)item.data).ConfigureAwait(false);

                        break;

                    case ItemType.StringChars:
                        bufChunk = (BufferChunk)item.data;
                        await writer.WriteCharsAsync(bufChunk.buffer, bufChunk.index, bufChunk.count).ConfigureAwait(false);

                        break;

                    case ItemType.Raw:
                        await writer.WriteRawAsync((string)item.data).ConfigureAwait(false);

                        break;

                    case ItemType.RawChars:
                        bufChunk = (BufferChunk)item.data;
                        await writer.WriteCharsAsync(bufChunk.buffer, bufChunk.index, bufChunk.count).ConfigureAwait(false);

                        break;

                    case ItemType.ValueString:
                        await writer.WriteStringAsync((string)item.data).ConfigureAwait(false);

                        break;

                    default:
                        Debug.Assert(false, "Unexpected ItemType value.");
                        break;
                    }
                }
            }