Example #1
0
    internal static void AppendEpilogue(IHtmlContentBuilder htmlContentBuilder, ServerComponentMarker record)
    {
        var endRecord = JsonSerializer.Serialize(
            record.GetEndRecord(),
            ServerComponentSerializationSettings.JsonSerializationOptions);

        htmlContentBuilder.AppendHtml("<!--Blazor:");
        htmlContentBuilder.AppendHtml(endRecord);
        htmlContentBuilder.AppendHtml("-->");
    }
Example #2
0
    /// <remarks>
    /// Remember to update <see cref="PreambleBufferSize"/> if the number of entries being appended in this function changes.
    /// </remarks>
    internal static void AppendPreamble(IHtmlContentBuilder htmlContentBuilder, ServerComponentMarker record)
    {
        var serializedStartRecord = JsonSerializer.Serialize(
            record,
            ServerComponentSerializationSettings.JsonSerializationOptions);

        htmlContentBuilder.AppendHtml("<!--Blazor:");
        htmlContentBuilder.AppendHtml(serializedStartRecord);
        htmlContentBuilder.AppendHtml("-->");
    }
        private (ComponentDescriptor, ServerComponent) DeserializeServerComponent(ServerComponentMarker record)
        {
            string unprotected;

            try
            {
                unprotected = _dataProtector.Unprotect(record.Descriptor);
            }
            catch (Exception e)
            {
                Log.FailedToUnprotectDescriptor(_logger, e);
                return(default);
Example #4
0
        private ServerComponentMarker[] CreateMarkers(params Type[] types)
        {
            var serializer = new ServerComponentSerializer(_ephemeralDataProtectionProvider);
            var markers    = new ServerComponentMarker[types.Length];

            for (var i = 0; i < types.Length; i++)
            {
                markers[i] = serializer.SerializeInvocation(_invocationSequence, types[i], ParameterView.Empty, false);
            }

            return(markers);
        }
        private (ComponentDescriptor, ServerComponent) DeserializeServerComponent(ServerComponentMarker record)
        {
            string unprotected;

            try
            {
                var payload          = Convert.FromBase64String(record.Descriptor);
                var unprotectedBytes = _dataProtector.Unprotect(payload);
                unprotected = Encoding.UTF8.GetString(unprotectedBytes);
            }
            catch (Exception e)
            {
                Log.FailedToUnprotectDescriptor(_logger, e);
                return(default);
    internal IEnumerable <string> GetPreamble(ServerComponentMarker record)
    {
        var serializedStartRecord = JsonSerializer.Serialize(
            record,
            ServerComponentSerializationSettings.JsonSerializationOptions);

        if (record.PrerenderId != null)
        {
            return(PrerenderedStart(serializedStartRecord));
        }
        else
        {
            return(NonPrerenderedSequence(serializedStartRecord));
        }
Example #7
0
 public ServerComponentMarker SerializeInvocation(ServerComponentInvocationSequence invocationId, Type type, ParameterView parameters, bool prerendered)
 {
     var(sequence, serverComponent) = CreateSerializedServerComponent(invocationId, type, parameters);
     return(prerendered ? ServerComponentMarker.Prerendered(sequence, serverComponent) : ServerComponentMarker.NonPrerendered(sequence, serverComponent));
 }