internal object Invoke(object evt) { var eventArgs = new HtmlEventArgs(); if (evt != null) { var dict = (IDictionary <string, object>)((object[])evt)[0]; ScriptObjectHelper.DictionaryToScriptableType(dict, eventArgs); } EventHandlers?.Invoke(this.Source, eventArgs); if (EventHandlers == null) { try { var eventDelegate = (MulticastDelegate)Source.GetType().GetTypeInfo().GetField(EventName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(Source); eventDelegate.DynamicInvoke(new object[] { Source, EventArgs.Empty }); } catch (Exception exc) { // We get an exception if there is nothing to invoke Console.WriteLine($"exception {exc.Message}"); } } return(null); }
public static async Task <BrowserInformation> GetBrowserInformation() { if (browserInfoFunction == null) { browserInfoFunction = await WebSharp.CreateJavaScriptFunction( @"return function (data, callback) { try { let browserInfo = {}; browserInfo['appName'] = navigator.appName; //browserInfo['appVersion'] = navigator.appVersion; browserInfo['appVersion'] = process.versions.chrome; browserInfo['userAgent'] = navigator.userAgent; browserInfo['platform'] = navigator.platform; browserInfo['cookieEnabled'] = navigator.cookieEnabled; browserInfo['appCodeName'] = navigator.appCodeName; callback(null, browserInfo); } catch (e) { callback(e, null); } }"); } var eval = await browserInfoFunction(null); if (eval != null) { var bi = new BrowserInformation(); ScriptObjectHelper.DictionaryToScriptableType((IDictionary <string, object>)eval, bi); return(bi); } return(default(BrowserInformation)); }
public async Task <LoginItemSettings> GetLoginItemSettings() { var settings = await Invoke <object>("getLoginItemSettings"); var lis = new LoginItemSettings(); ScriptObjectHelper.DictionaryToScriptableType((System.Collections.Generic.IDictionary <string, object>)settings, lis); return(lis); }
public async Task <Location> GetLocation() { var location = await GetProperty <object>("location"); if (location != null) { var loc = new Location(); ScriptObjectHelper.DictionaryToScriptableType((IDictionary <string, object>)location, loc); return(loc); } return(default(Location)); }
public async Task <Bookmark> ReadBookmark(ClipboardType type = ClipboardType.None) { var result = await Invoke <object>("readBookmark", type == ClipboardType.Selection? "selection" : string.Empty); var bm = new Bookmark(); if (result != null) { ScriptObjectHelper.DictionaryToScriptableType((System.Collections.Generic.IDictionary <string, object>)result, bm); } return(bm); }
internal object Invoke(object evt) { var eventArgs = new HtmlEventArgs(); defaultPrevented = false; cancelBubble = false; eventArgs.PreventDefaultAction = () => { defaultPrevented = true; }; eventArgs.StopPropagationAction = () => { cancelBubble = true; }; if (evt != null) { try { var dict = (IDictionary <string, object>)((object[])evt)[0]; ScriptObjectHelper.DictionaryToScriptableType(dict, eventArgs); if (eventArgs.DataTransfer != null) { dropEffect = eventArgs.DataTransfer.DropEffectValue; eventArgs.DataTransfer.DropEffectAction = (eff) => { dropEffect = eff; }; } } catch (Exception evtExc) { Console.WriteLine($"Error parsing HtmlEventArgs: {evtExc.Message}"); } } EventHandlers?.Invoke(this.Source, eventArgs); if (EventHandlers == null) { try { var eventDelegate = (MulticastDelegate)Source.GetType().GetTypeInfo().GetField(EventName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(Source); eventDelegate.DynamicInvoke(new object[] { Source, EventArgs.Empty }); } catch (Exception exc) { // We get an exception if there is nothing to invoke Console.WriteLine($"WebSharpHtmlEvent Invoke Exception {exc.Message}"); } } return(null); }