protected async Task SendEventAsync([CallerMemberName] string methodName = null, bool usePreventDefault = false) { ThrowExceptionWhenMethodNameIsNull(methodName); var normalizedModuleName = Regex.Replace(this.GetType().Name, @"Module$", string.Empty).FirstCharacterToLower(); var normalizedEventName = Regex.Replace(methodName, @"Async$", string.Empty).InsertDashBeforeUpperCharacters().ToLower(); var action = new ElectronAction { Module = normalizedModuleName, Method = normalizedEventName, Type = ElectronRequestType.Event, UsePreventDefault = usePreventDefault }; await _handler.SendActionAsync(action); }
protected async Task <JToken> SendActionAsync([CallerMemberName] string methodName = null, params object[] arguments) { ThrowExceptionWhenMethodNameIsNull(methodName); var normalizedModuleName = Regex.Replace(this.GetType().Name, @"Module$", string.Empty).FirstCharacterToLower(); var normalizedMethodName = Regex.Replace(methodName, @"Async$", string.Empty).FirstCharacterToLower(); var action = new ElectronAction <object[]> { Module = normalizedModuleName, Method = normalizedMethodName, Type = ElectronRequestType.Method, Arguments = arguments }; var response = await _handler.SendActionAsync(action); return(response.Result); }
protected async Task <Guid> SubscribeEventAsync(Func <Task> handler, bool usePreventDefault = false, bool isPageEvent = true, [CallerMemberName] string methodName = null) { ThrowExceptionWhenMethodNameIsNull(methodName); var normalizedModuleName = Regex.Replace(this.GetType().Name, @"Module$", string.Empty).FirstCharacterToLower(); var normalizedEventName = Regex.Replace(Regex.Replace(methodName, @"Async$", string.Empty), @"^Subscribe", string.Empty) .InsertDashBeforeUpperCharacters() .ToLower(); var action = new ElectronAction <ElectronEventArguments> { Module = normalizedModuleName, Method = normalizedEventName, Type = ElectronRequestType.SubscribeEvent, Arguments = new ElectronEventArguments { UsePreventDefault = usePreventDefault, IsPageEvent = isPageEvent } }; await _handler.SubscribeToEventAsync(action, handler); return(action.Id); }