public async Task DispatchEvent(string eventDescriptorJson, string eventArgsJson) { WebEventData webEventData; try { AssertInitialized(); webEventData = WebEventData.Parse(eventDescriptorJson, eventArgsJson); } catch (Exception ex) { Log.DispatchEventFailedToParseEventData(_logger, ex); return; } try { await Renderer.Dispatcher.InvokeAsync(() => { SetCurrentCircuitHost(this); return(Renderer.DispatchEventAsync( webEventData.EventHandlerId, webEventData.EventFieldInfo, webEventData.EventArgs)); }); } catch (Exception ex) { Log.DispatchEventFailedToDispatchEvent(_logger, webEventData.EventHandlerId.ToString(), ex); UnhandledException?.Invoke(this, new UnhandledExceptionEventArgs(ex, isTerminating: false)); } }
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); }
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); }
public Task DispatchEventAsync(JsonElement eventDescriptor, JsonElement eventArgs) { var webEventData = WebEventData.Parse(_renderer, _jsonOptions, eventDescriptor, eventArgs); return(_renderer.DispatchEventAsync( webEventData.EventHandlerId, webEventData.EventFieldInfo, webEventData.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)); }
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); }
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)); }
private Task DispatchBrowserEventAsync(PageContext pageContext, JsonElement eventDescriptor, JsonElement eventArgs) { var renderer = pageContext.Renderer; var webEventData = WebEventData.Parse(renderer, pageContext.JSRuntime.ReadJsonSerializerOptions(), eventDescriptor, eventArgs); return(renderer.DispatchEventAsync( webEventData.EventHandlerId, webEventData.EventFieldInfo, webEventData.EventArgs)); }
private Task DispatchBrowserEventAsync(PageContext pageContext, string eventDescriptor, string eventArgs) { var renderer = pageContext.Renderer; var webEventData = WebEventData.Parse(renderer, eventDescriptor, eventArgs); return(renderer.DispatchEventAsync( webEventData.EventHandlerId, webEventData.EventFieldInfo, webEventData.EventArgs)); }
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)); }
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); }
// DispatchEvent is used in a fire-and-forget context, so it's responsible for its own // error handling. public async Task DispatchEvent(string eventDescriptorJson, string eventArgsJson) { AssertInitialized(); AssertNotDisposed(); WebEventData webEventData; try { // JsonSerializerOptions are tightly bound to the JsonContext. Cache it on first use using a copy // of the serializer settings. if (_jsonContext is null) { _jsonContext = new(new JsonSerializerOptions(JSRuntime.ReadJsonSerializerOptions())); } webEventData = WebEventData.Parse(Renderer, _jsonContext, eventDescriptorJson, eventArgsJson); } catch (Exception ex) { // Invalid event data is fatal. We expect a well-behaved client to send valid JSON. Log.DispatchEventFailedToParseEventData(_logger, ex); await TryNotifyClientErrorAsync(Client, GetClientErrorMessage(ex, "Bad input data.")); UnhandledException?.Invoke(this, new UnhandledExceptionEventArgs(ex, isTerminating: false)); return; } try { await Renderer.Dispatcher.InvokeAsync(() => { return(Renderer.DispatchEventAsync( webEventData.EventHandlerId, webEventData.EventFieldInfo, webEventData.EventArgs)); }); } catch (Exception ex) { // A failure in dispatching an event means that it was an attempt to use an invalid event id. // A well-behaved client won't do this. Log.DispatchEventFailedToDispatchEvent(_logger, webEventData.EventHandlerId.ToString(CultureInfo.InvariantCulture), ex); await TryNotifyClientErrorAsync(Client, GetClientErrorMessage(ex, "Failed to dispatch event.")); UnhandledException?.Invoke(this, new UnhandledExceptionEventArgs(ex, isTerminating: false)); } }
// DispatchEvent is used in a fire-and-forget context, so it's responsible for its own // error handling. public async Task DispatchEvent(string eventDescriptorJson, string eventArgsJson) { AssertInitialized(); AssertNotDisposed(); WebEventData webEventData; try { AssertInitialized(); webEventData = WebEventData.Parse(eventDescriptorJson, eventArgsJson); } catch (Exception ex) { // Invalid event data is fatal. We expect a well-behaved client to send valid JSON. Log.DispatchEventFailedToParseEventData(_logger, ex); if (Client.Connected) { await NotifyClientError(Client, "Invalid event data."); } UnhandledException?.Invoke(this, new UnhandledExceptionEventArgs(ex, isTerminating: false)); return; } try { await Renderer.Dispatcher.InvokeAsync(() => { SetCurrentCircuitHost(this); return(Renderer.DispatchEventAsync( webEventData.EventHandlerId, webEventData.EventFieldInfo, webEventData.EventArgs)); }); } catch (Exception ex) { // A failure in dispatching an event means that it was an attempt to use an invalid event id. // A well-behaved client won't do this. Log.DispatchEventFailedToDispatchEvent(_logger, webEventData.EventHandlerId.ToString(), ex); if (Client.Connected) { await NotifyClientError(Client, "Failed to dispatch event."); } UnhandledException?.Invoke(this, new UnhandledExceptionEventArgs(ex, isTerminating: false)); } }
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); }
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)); }
private Task DispatchBrowserEventAsync(PageContext pageContext, string eventDescriptor, string eventArgs) { var renderer = pageContext.Renderer; // 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 = pageContext.JSRuntime.ReadJsonSerializerOptions(); _jsonContext = new(new JsonSerializerOptions(jsonSerializerOptions)); } var webEventData = WebEventData.Parse(renderer, _jsonContext, eventDescriptor, eventArgs); return(renderer.DispatchEventAsync( webEventData.EventHandlerId, webEventData.EventFieldInfo, webEventData.EventArgs)); }