public ClientInfo TryConnect(Guid extProcID, string address) { var info = new ClientInfo(); ServerExtensionClient client; try { client = new ServerExtensionClient(address); client.RegisterClient(); info.ExtensionID = client.ID; if (client.SingleInstanceOnly) { bool isNotUnique; lock (_clients) isNotUnique = _clients.Any(c => c.ExtensionID == info.ExtensionID); if (isNotUnique) { _logger.Warn("A second instance of the extension \"" + info.ExtensionID + "\" was found, but the extension has specified that only one instance is allowed to run at a time. The second instance will be stopped."); _extProcMgr.Stop(extProcID); return(null); } } info.ExtProcID = extProcID; info.Name = client.Name; info.Description = client.Description; info.Commands = client.GetCommands(); info.Client = client; _logger.Info("Connected to extension: " + info.Name); } catch (Exception ex) { _logger.ErrorException("Exception thrown while trying to connect to extension \"" + info.Name + "\"", ex); return(null); } client.Disconnected += c => { lock (_clients) _clients.Remove(info); _logger.Info("Lost connection to extension: " + info.Name); }; client.NotificationReceived += (src, msg, lvl) => { var handler = ExtensionNotificationReceived; if (handler != null) { handler(info.ExtProcID, info.ExtensionID, info.Name, src, msg, lvl); } }; lock (_clients) _clients.Add(info); return(info); }
public ClientInfo TryConnect(Guid extProcID, string address) { var info = new ClientInfo(); ServerExtensionClient client; try { client = new ServerExtensionClient(address); client.RegisterClient(); info.ExtensionID = client.ID; if(client.SingleInstanceOnly) { bool isNotUnique; lock(_clients) isNotUnique = _clients.Any(c => c.ExtensionID == info.ExtensionID); if(isNotUnique) { _logger.Warn("A second instance of the extension \"" + info.ExtensionID + "\" was found, but the extension has specified that only one instance is allowed to run at a time. The second instance will be stopped."); _extProcMgr.Stop(extProcID); return null; } } info.ExtProcID = extProcID; info.Name = client.Name; info.Description = client.Description; info.Commands = client.GetCommands(); info.Client = client; _logger.Info("Connected to extension: " + info.Name); } catch(Exception ex) { _logger.ErrorException("Exception thrown while trying to connect to extension \"" + info.Name + "\"", ex); return null; } client.Disconnected += c => { lock(_clients) _clients.Remove(info); _logger.Info("Lost connection to extension: " + info.Name); }; client.NotificationReceived += (src, msg, lvl) => { var handler = ExtensionNotificationReceived; if(handler != null) handler(info.ExtProcID, info.ExtensionID, info.Name, src, msg, lvl); }; lock(_clients) _clients.Add(info); return info; }