internal bool CheckIsAlive() { try { Target.Ping(); return(true); } catch (Exception ex) { Logger.Error(ex, $"Could not ping {ServiceName}"); Target = null; return(false); } }
// COM Endpoint from IDvcChannelBroker public IBrokeredDvcServiceRegistration RegisterService(string name, IBrokeredDvcService service) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } if (service == null) { throw new ArgumentNullException(nameof(service)); } ServiceRegistration existingRegistration; lock (syncRegisteredServices) { RegisteredServices.TryGetValue(name, out existingRegistration); } if (existingRegistration != null) { if (existingRegistration.CheckIsAlive()) { throw new InvalidOperationException($"Service '{name}' is already registered"); } else { KillRegistration(existingRegistration); } } // May leak if TOCTOU existingRegistration = new ServiceRegistration(name, service); lock (syncRegisteredServices) { // May throw if TOCTOU... I'm fine with that. RegisteredServices.Add(name, existingRegistration); } return(new UnregisterProxy(this, existingRegistration)); }
public void Dispose() { Target = null; }
public ServiceRegistration(string name, IBrokeredDvcService service) { this.ServiceName = name; this.Target = service; }