コード例 #1
0
ファイル: HostServices.cs プロジェクト: msft-gerry/MqttIotHub
        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);
        }
コード例 #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);
        }
コード例 #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);
            }
        }
コード例 #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);
        }
コード例 #5
0
ファイル: HostServices.cs プロジェクト: msft-gerry/MqttIotHub
 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();
     }
 }