protected async Task LoadPluginBase <T>(T plugin, string ns, Dictionary <string, object> options) where T : class { bool mainThread = (bool)options["NKS.MainThread"]; bool remoteProcess = NKOptions.itemOrDefault(options, "NKS.RemoteProcess", false); NKScriptExportType bridge = (NKScriptExportType)options["NKS.PluginBridge"]; NKScriptChannelProtocol channel; switch (bridge) { case NKScriptExportType.NKScriptExport: if (remoteProcess) { channel = new NKScriptChannelRemote((NKScriptContext)this); } else if (mainThread) { channel = new NKScriptChannel((NKScriptContext)this, (TaskScheduler)options["NKS.MainThreadScheduler"]); } else { channel = new NKScriptChannel((NKScriptContext)this); } var scriptValue = await channel.bindPlugin <T>(plugin, ns); _injectedPlugins.Add(scriptValue); NKLogging.log("+NKScripting Plugin loaded at " + ns); break; case NKScriptExportType.NKScriptExportRemote: if (mainThread) { channel = new NKScriptChannelRemote((NKScriptContext)this, (TaskScheduler)options["NKS.MainThreadScheduler"]); } else { channel = new NKScriptChannelRemote((NKScriptContext)this); } var scriptValueRemote = await channel.bindPlugin <T>(plugin, ns); _injectedPlugins.Add(scriptValueRemote); NKLogging.log("+NKScripting Remote Plugin loaded at " + ns); break; default: throw new InvalidOperationException("Load Plugin Base called for non-handled bridge type"); } }
protected override Task LoadPlugin <T>(T plugin, string ns, Dictionary <string, object> options) { NKScriptExportType bridge = (NKScriptExportType)options["NKS.PluginBridge"]; switch (bridge) { case NKScriptExportType.JSExport: throw new NotSupportedException("JSExport option is for darwin platforms only"); case NKScriptExportType.WinRT: throw new NotSupportedException("WinRT option is for Windows Store Applications only"); default: throw new NotImplementedException("Unknown Scripting Plugin Bridge Option"); } }
protected override async Task LoadPlugin <T>(T plugin, string ns, Dictionary <string, object> options) { bool mainThread = (bool)options["NKS.MainThread"]; NKScriptExportType bridge = (NKScriptExportType)options["NKS.PluginBridge"]; switch (bridge) { case NKScriptExportType.JSExport: throw new NotSupportedException("JSExport option is for darwin platforms only"); case NKScriptExportType.WinRT: if (plugin == null) { switchContextifNeeded(); if (!_projectedNamespaces.Contains(ns)) { Native.ThrowIfError(Native.JsProjectWinRTNamespace(ns)); _projectedNamespaces.Add(ns); NKLogging.log("+Windows Unversal Component namespace loaded at " + ns); } } else if (typeof(T) != typeof(Type)) { throw new ArgumentException("Windows Universal Components can only be provided as a type"); } else { var t = (plugin as Type); var projectionNamespace = t.Namespace; var projectionName = t.Name; var projectionFullName = projectionNamespace + "." + projectionName; var targetNamespace = ns; switchContextifNeeded(); if (!_projectedNamespaces.Contains(projectionNamespace)) { Native.ThrowIfError(Native.JsProjectWinRTNamespace(projectionNamespace)); _projectedNamespaces.Add(projectionNamespace); } var cs = new NKScriptExportProxy <T>(plugin); var localstub = cs.rewriteGeneratedStub("", ".local"); var globalstubber = "(function(exports) {\n" + localstub + "})(NKScripting.createProjection('" + targetNamespace + "', " + projectionFullName + "));\n"; var globalstub = cs.rewriteGeneratedStub(globalstubber, ".global"); var script = new NKScriptSource(globalstub, targetNamespace + "/plugin/" + projectionName + ".js"); await this.NKinjectScript(script); await cs.initializeForContext(this); plugin.setNKScriptValue(this.NKgetScriptValue(targetNamespace)); NKLogging.log("+Windows Unversal Component Plugin with script loaded at " + targetNamespace); } break; default: throw new NotImplementedException("Unknown Scripting Plugin Bridge Option"); } }