Beispiel #1
0
    public static WebAssemblyComponentMarker SerializeInvocation(Type type, ParameterView parameters, bool prerendered)
    {
        var assembly     = type.Assembly.GetName().Name;
        var typeFullName = type.FullName;

        var(definitions, values) = ComponentParameter.FromParameterView(parameters);

        // We need to serialize and Base64 encode parameters separately since they can contain arbitrary data that might
        // cause the HTML comment to be invalid (like if you serialize a string that contains two consecutive dashes "--").
        var serializedDefinitions = Convert.ToBase64String(JsonSerializer.SerializeToUtf8Bytes(definitions, WebAssemblyComponentSerializationSettings.JsonSerializationOptions));
        var serializedValues      = Convert.ToBase64String(JsonSerializer.SerializeToUtf8Bytes(values, WebAssemblyComponentSerializationSettings.JsonSerializationOptions));

        return(prerendered ? WebAssemblyComponentMarker.Prerendered(assembly, typeFullName, serializedDefinitions, serializedValues) :
               WebAssemblyComponentMarker.NonPrerendered(assembly, typeFullName, serializedDefinitions, serializedValues));
    }
Beispiel #2
0
        private (int sequence, string payload) CreateSerializedServerComponent(
            ServerComponentInvocationSequence invocationId,
            Type rootComponent,
            ParameterView parameters)
        {
            var sequence = invocationId.Next();

            var(definitions, values) = ComponentParameter.FromParameterView(parameters);

            var serverComponent = new ServerComponent(
                sequence,
                rootComponent.Assembly.GetName().Name,
                rootComponent.FullName,
                definitions,
                values,
                invocationId.Value);

            var serializedServerComponent = JsonSerializer.Serialize(serverComponent, ServerComponentSerializationSettings.JsonSerializationOptions);

            return(serverComponent.Sequence, _dataProtector.Protect(serializedServerComponent, ServerComponentSerializationSettings.DataExpiration));
        }