示例#1
0
        public async Task <bool> OnPluginConnected(IImportPluginService pluginSvc, string channelName)
        {
            if (pluginSvc == null)
            {
                return(false);
            }

            using (await _pluginSvcLock.LockAsync())
            {
                try
                {
                    var resp = pluginSvc.ConnectBrowser(_extensionId, _userAgent, channelName);

                    if (resp == null)
                    {
                        LogTo.Warning($"{_extensionId} failed to connect to Plugin");
                        return(false);
                    }

                    LogTo.Debug($"Connected to plugin, version {resp.Version}");

                    await _host.Write(resp);

                    PluginSvc = pluginSvc;

                    return(true);
                }
                catch (EndOfStreamException) { }

                return(false);
            }
        }
示例#2
0
        public async Task OnPluginDisconnected()
        {
            using (await _pluginSvcLock.LockAsync())
                if (PluginSvc != null)
                {
                    PluginSvc = null;

                    try
                    {
                        await _host.Write(new RespDisconnect());
                    }
                    catch (EndOfStreamException) { }
                }

            _ipcService.OnDisconnected().RunAsync();
        }
示例#3
0
        private async Task KeepAlive(IImportPluginService pluginSvc)
        {
            try
            {
                while (true)
                {
                    pluginSvc.KeepAlive();

                    await Task.Delay(RetryDelayMs);
                }
            }
            catch (RemotingException)
            {
                await _hostService.OnPluginDisconnected();
            }
            catch (Exception ex)
            {
                LogTo.Error(ex, "Exception caught in KeepAlive");
                throw;
            }
        }