/// <summary>
 /// 添加ServiceBus注册信息
 /// </summary>
 public bool RegisterToServiceBus(ServiceBusServerInfo serviceBus)
 {
     if (!serviceBusSet.Contains(serviceBus))
     {
         return(this.serviceBusSet.Add(serviceBus));
     }
     return(false);
 }
        /// <summary>
        /// 注册服务程序集
        /// </summary>
        /// <param name="serviceAssemblyName">服务程序集名</param>
        /// <param name="busInfo">servicebus信息</param>
        /// <returns></returns>
        public void RegisterServiceAssembly(string serviceAssemblyName, ServiceBusServerInfo busInfo)
        {
            if (serviceAssemblyName == null)
            {
                throw new ArgumentNullException("serviceAssemblyName");
            }
            if (busInfo == null)
            {
                throw new ArgumentNullException("busInfo");
            }

            ServiceAssemblyInfo serviceAssembly = null;
            bool isServiceAssemblyExists        = serviceAssemblyDic.TryGetValue(serviceAssemblyName, out serviceAssembly);

            if (!isServiceAssemblyExists)
            {
                serviceAssembly = new ServiceAssemblyInfo(serviceAssemblyName);
                serviceAssemblyDic.TryAdd(serviceAssemblyName, serviceAssembly);
            }

            //serviceAssembly挂载到busServer上
            serviceAssembly.RegisterToServiceBus(busInfo);
        }
        /// <summary>
        /// 根据配置文件初始化注册表
        /// </summary>
        /// <param name="serviceBusSection">配置节</param>
        public ServiceBusRegistry Initital(ServiceBusSection serviceBusSection)
        {
            if (serviceBusSection == null)
            {
                throw new ArgumentNullException("serviceBusSection");
            }

            lock (locker)
            {
                serviceBusDic.Clear();
                serviceAssemblyDic.Clear();

                //初始化serviceBus列表
                foreach (ServiceBusItemSection busSection in serviceBusSection.BusGroup)
                {
                    string serviceBusName        = busSection.Name.Trim();
                    ServiceBusServerInfo busInfo = new ServiceBusServerInfo(serviceBusName,
                                                                            //expo config
                                                                            new ServiceBusServerInfo.ExpoServer(
                                                                                busSection.ExpoServer.AppClassId,
                                                                                busSection.ExpoServer.CommandId,
                                                                                busSection.ExpoServer.CommandTimeout,
                                                                                busSection.ExpoServer.IsStart)
                                                                            //TODO: rabbitmq config...
                                                                            );
                    bool isSuccess = serviceBusDic.TryAdd(serviceBusName, busInfo);
                    if (isSuccess)
                    {
                        //当前ServiceBus
                        if (busSection.IsCurrent)
                        {
                            this.LocalBusServer = busInfo;
                        }
                    }
                    else
                    {
                        //TODO: serviceBus名称冲突处理
                        this.Logger.Error(string.Format("ServiceBus:[{0}] duplicated in configuration!", serviceBusName));
                    }
                }

                if (this.LocalBusServer == null)
                {
                    throw new WindServiceBusException("Can not located current busServer! Please set isCurrent attribute on busServer section.");
                }

                //初始化windService列表
                //遍历每个servicebus
                foreach (ServiceCollectionSection busServiceCollection in serviceBusSection.ServiceGroup)
                {
                    string serviceBusName = busServiceCollection.Name.Trim();

                    ServiceBusServerInfo busInfo = null;
                    bool isServiceBusExists      = this.serviceBusDic.TryGetValue(serviceBusName, out busInfo);
                    if (isServiceBusExists)
                    {
                        //遍历每个服务程序集申明
                        foreach (ServiceItemSection serviceAssemblyItem in busServiceCollection)
                        {
                            string serviceAssemblyName = serviceAssemblyItem.Name.Trim();
                            this.RegisterServiceAssembly(serviceAssemblyName, busInfo);
                        }
                    }
                    else
                    {
                        //TODO: 未找到serviceBus名称
                        this.Logger.Error(string.Format("ServiceBus:[{0}] not found in configuration!", serviceBusName));
                    }
                }
            }
            return(this);
        }