public static async Task DispatchEvent(byte[] eventInfo)
        {
            var payload         = GetJsonElements(eventInfo);
            var eventDescriptor = WebEventDescriptorReader.Read(payload.EventDescriptor);
            var renderer        = RendererRegistry.Find(eventDescriptor.BrowserRendererId);

            var webEvent = WebEventData.Parse(
                renderer,
                DefaultWebAssemblyJSRuntime.Instance.ReadJsonSerializerOptions(),
                eventDescriptor,
                payload.EventArgs);

            await renderer.DispatchEventAsync(
                webEvent.EventHandlerId,
                webEvent.EventFieldInfo,
                webEvent.EventArgs);
        }
Esempio n. 2
0
    public static WebEventData Parse(
        Renderer renderer,
        JsonSerializerOptions jsonSerializerOptions,
        JsonElement eventDescriptorJson,
        JsonElement eventArgsJson)
    {
        WebEventDescriptor eventDescriptor;

        try
        {
            eventDescriptor = WebEventDescriptorReader.Read(eventDescriptorJson);
        }
        catch (Exception e)
        {
            throw new InvalidOperationException("Error parsing the event descriptor", e);
        }

        return(Parse(renderer, jsonSerializerOptions, eventDescriptor, eventArgsJson));
    }
    public void Read_WithBoolValue_Works(bool value)
    {
        // Arrange
        var args = new WebEventDescriptor
        {
            EventFieldInfo = new EventFieldInfo
            {
                ComponentId = 89,
                FieldValue  = value,
            },
            EventHandlerId = 897,
            EventName      = "test1",
        };
        var jsonElement = GetJsonElement(args);

        // Act
        var result = WebEventDescriptorReader.Read(jsonElement);

        // Assert
        Assert.Equal(args.EventHandlerId, result.EventHandlerId);
        Assert.Equal(args.EventName, result.EventName);
        Assert.Equal(args.EventFieldInfo.ComponentId, result.EventFieldInfo.ComponentId);
        Assert.Equal(args.EventFieldInfo.FieldValue, result.EventFieldInfo.FieldValue);
    }