public MqttClientActivator GetClient(string name, bool flagRemove = false) { MqttClientActivator client = null; if (string.IsNullOrEmpty(name)) { throw new ArgumentException("Not valid service name"); } try { _rwl.AcquireReaderLock(TimeSpan.FromSeconds(60)); foreach (AppDomain appDomain in _appDomains) { List <MqttClientActivator> activators = appDomain.GetData(_key) as List <MqttClientActivator>; if (activators != null) { MqttClientActivator activator = activators.Find(delegate(MqttClientActivator a) { return(a.Name == name); }); if (activator != null) { client = activator; if (flagRemove) { activators.Remove(activator); } } } } } finally { _rwl.ReleaseReaderLock(); } return(client); }
public static MqttClientActivator Create(AppDomain appDomain, ConfigData config) { string _assemblyName = Assembly.GetAssembly(typeof(MqttClientActivator)).FullName; MqttClientActivator activator = appDomain.CreateInstanceAndUnwrap(_assemblyName, typeof(MqttClientActivator).ToString()) as MqttClientActivator; activator.SetClient(config); return(activator); }
private void RemoveFromStorage(MqttClientActivator activator) { List <MqttClientActivator> activators = this.GetStorage(); if (activators.Exists(delegate(MqttClientActivator host) { return(host.Name == activator.Name); })) { activators.Remove(activator); } }
private void AddToStorage(MqttClientActivator activator) { List <MqttClientActivator> activators = this.GetStorage(); if (activators.Exists(delegate(MqttClientActivator host) { return(host.Name == activator.Name); })) { LogMessage($"[{this.Name}] Internal Error during add appDomain {AppDomain.CurrentDomain.FriendlyName} to storage, activator alredy exist it", "Error"); throw new InvalidOperationException(string.Format("The client '{0}' is already hosted in the appDomain '{1}'", activator.Name, AppDomain.CurrentDomain.FriendlyName)); } activators.Add(this); }
public void Add(string appDomainName, ConfigData config) { try { _rwl.AcquireWriterLock(TimeSpan.FromSeconds(60)); appDomainName = ValidateAppDomainName(appDomainName); AppDomain appDomain = this.CreateDomainHost(appDomainName); MqttClientActivator.Create(appDomain, config); } finally { _rwl.ReleaseWriterLock(); } }