Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        private void RemoveFromStorage(MqttClientActivator activator)
        {
            List <MqttClientActivator> activators = this.GetStorage();

            if (activators.Exists(delegate(MqttClientActivator host) { return(host.Name == activator.Name); }))
            {
                activators.Remove(activator);
            }
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
 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();
     }
 }