示例#1
0
 internal static void setNKScriptChannel(this object obj, NKScriptChannel value)
 {
     if (value != null)
     {
         dictionary[obj] = value;
     }
     else
     {
         dictionary.Remove(obj);
     }
 }
示例#2
0
        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");
            }
        }
 internal static void setNKScriptChannel(this object obj, NKScriptChannel value)
 {
     if (value != null)
         dictionary[obj] = value;
     else
         dictionary.Remove(obj);
 }