Ejemplo n.º 1
0
 public static WebEventData Parse(WebEventDescriptor eventDescriptor, string eventArgsJson)
 {
     return(new WebEventData(
                eventDescriptor.BrowserRendererId,
                eventDescriptor.EventHandlerId,
                InterpretEventFieldInfo(eventDescriptor.EventFieldInfo),
                ParseEventArgsJson(eventDescriptor.EventHandlerId, eventDescriptor.EventArgsType, eventArgsJson)));
 }
Ejemplo n.º 2
0
 public static async Task DispatchEvent(WebEventDescriptor eventDescriptor, string eventArgsJson)
 {
     var webEvent = WebEventData.Parse(eventDescriptor, eventArgsJson);
     var renderer = ComponentsDesktop.DesktopRenderer;
     await renderer.DispatchEventAsync(
         webEvent.EventHandlerId,
         webEvent.EventFieldInfo,
         webEvent.EventArgs);
 }
Ejemplo n.º 3
0
 public static async Task DispatchEvent(WebEventDescriptor eventDescriptor, string eventArgsJson)
 {
     var webEvent = WebEventData.Parse(eventDescriptor, eventArgsJson);
     var renderer = BlazorWebViewHost.PlatformRenderer;
     await renderer.DispatchEventAsync(
         webEvent.EventHandlerId,
         webEvent.EventFieldInfo,
         webEvent.EventArgs);
 }
        /// <summary>
        /// For framework use only.
        /// </summary>
        //[JSInvokable(nameof(DispatchEvent))]
        private Task DispatchEventOriginal(WebEventDescriptor eventDescriptor, string eventArgsJson)
        {
            var webEvent = WebEventData.Parse(eventDescriptor, eventArgsJson);

            return(_renderer.DispatchEventAsync(
                       webEvent.EventHandlerId,
                       webEvent.EventFieldInfo,
                       webEvent.EventArgs));
        }
Ejemplo n.º 5
0
 public static async Task DispatchEvent(WebEventDescriptor eventDescriptor, string eventArgsJson)
 {
     var webEvent = WebEventData.Parse(eventDescriptor, eventArgsJson);
     var renderer = Launcher.ElectronRenderer;
     await renderer.DispatchEventAsync(
         webEvent.EventHandlerId,
         webEvent.EventFieldInfo,
         webEvent.EventArgs);
 }
Ejemplo n.º 6
0
        public static Task DispatchEvent(WebEventDescriptor eventDescriptor, string eventArgsJson)
        {
            var webEvent = WebEventData.Parse(eventDescriptor, eventArgsJson);
            var renderer = RendererRegistry.Find(eventDescriptor.BrowserRendererId);

            return(renderer.DispatchEventAsync(
                       webEvent.EventHandlerId,
                       webEvent.EventFieldInfo,
                       webEvent.EventArgs));
        }
Ejemplo n.º 7
0
        public static Task DispatchEvent(WebEventDescriptor eventDescriptor, string eventArgsJson)
        {
            var renderer = RendererRegistry.Find(eventDescriptor.BrowserRendererId);
            var jsonSerializerOptions = DefaultWebAssemblyJSRuntime.Instance.ReadJsonSerializerOptions();
            var webEvent = WebEventData.Parse(renderer, jsonSerializerOptions, eventDescriptor, eventArgsJson);

            return(renderer.DispatchEventAsync(
                       webEvent.EventHandlerId,
                       webEvent.EventFieldInfo,
                       webEvent.EventArgs));
        }
Ejemplo n.º 8
0
    public static WebEventData Parse(
        Renderer renderer,
        JsonSerializerOptions jsonSerializerOptions,
        WebEventDescriptor eventDescriptor,
        JsonElement eventArgsJson)
    {
        var parsedEventArgs = ParseEventArgsJson(renderer, jsonSerializerOptions, eventDescriptor.EventHandlerId, eventDescriptor.EventName, eventArgsJson);

        return(new WebEventData(
                   eventDescriptor.EventHandlerId,
                   eventDescriptor.EventFieldInfo,
                   parsedEventArgs));
    }
Ejemplo n.º 9
0
        public async Task DispatchEvent(WebEventDescriptor eventDescriptor, string eventArgsJson)
        {
            if (eventDescriptor is null)
            {
                throw new ArgumentNullException(nameof(eventDescriptor));
            }

            var webEvent = WebEventData.Parse(eventDescriptor, eventArgsJson);
            await _blazorHybridRenderer.DispatchEventAsync(
                webEvent.EventHandlerId,
                webEvent.EventFieldInfo,
                webEvent.EventArgs).ConfigureAwait(false);
        }
Ejemplo n.º 10
0
        public static Task DispatchEvent(WebEventDescriptor eventDescriptor, string eventArgsJson)
        {
            var renderer = RendererRegistry.Find(eventDescriptor.BrowserRendererId);

            // JsonSerializerOptions are tightly bound to the JsonContext. Cache it on first use using a copy
            // of the serializer settings.
            if (_jsonContext is null)
            {
                var jsonSerializerOptions = DefaultWebAssemblyJSRuntime.Instance.ReadJsonSerializerOptions();
                _jsonContext = new(new JsonSerializerOptions(jsonSerializerOptions));
            }

            var webEvent = WebEventData.Parse(renderer, _jsonContext, eventDescriptor, eventArgsJson);

            return(renderer.DispatchEventAsync(
                       webEvent.EventHandlerId,
                       webEvent.EventFieldInfo,
                       webEvent.EventArgs));
        }
Ejemplo n.º 11
0
    public Task ClickAsync(BlazorClient client)
    {
        if (!Events.TryGetValue("click", out var clickEventDescriptor))
        {
            throw new InvalidOperationException("Element does not have a click event.");
        }

        var mouseEventArgs = new TestMouseEventArgs
        {
            Type   = clickEventDescriptor.EventName,
            Detail = 1
        };
        var webEventDescriptor = new WebEventDescriptor
        {
            EventHandlerId = clickEventDescriptor.EventId,
            EventName      = "click",
        };

        return(DispatchEventCore(client, webEventDescriptor, mouseEventArgs));
    }
Ejemplo n.º 12
0
        public Task ClickAsync(HubConnection connection)
        {
            if (!Events.TryGetValue("click", out var clickEventDescriptor))
            {
                throw new InvalidOperationException("Element does not have a click event.");
            }

            var mouseEventArgs = new
            {
                Type   = clickEventDescriptor.EventName,
                Detail = 1
            };
            var webEventDescriptor = new WebEventDescriptor
            {
                BrowserRendererId = 0,
                EventHandlerId    = clickEventDescriptor.EventId,
                EventName         = "click",
            };

            return(DispatchEventCore(connection, Serialize(webEventDescriptor), Serialize(mouseEventArgs)));
        }
    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);
    }
Ejemplo n.º 14
0
 private static Task DispatchEventCore(BlazorClient client, WebEventDescriptor descriptor, EventArgs eventArgs) =>
 client.DispatchEventAsync(descriptor, eventArgs);