/// <summary>
 /// 注册服务命令
 /// </summary>
 /// <param name="cmdInfo">服务命令信息</param>
 /// <returns>是否注册成功</returns>
 public bool RegisterCommand(ServiceCommandTypeInfo cmdInfo)
 {
     lock (locker)
     {
         ServiceAssemblyInfo serviceAssembly = this.getServiceAssemblyInfo(cmdInfo.ServiceCommandUniqueName.ServiceAssemblyName);
         if (serviceAssembly != null)
         {
             return(serviceAssembly.RegisterCommand(cmdInfo));
         }
         return(false);
     }
 }
        private ServiceAssemblyInfo getServiceAssemblyInfo(string serviceAssemblyName)
        {
            if (string.IsNullOrWhiteSpace(serviceAssemblyName))
            {
                throw new ArgumentNullException("serviceAssemblyName");
            }

            ServiceAssemblyInfo serviceAssemblyInfo = null;
            bool isServiceAssemblyExists            = this.serviceAssemblyDic.TryGetValue(serviceAssemblyName.Trim(), out serviceAssemblyInfo);

            return(serviceAssemblyInfo);
        }
        /// <summary>
        /// 服务(程序集)发现
        /// </summary>
        /// <param name="serviceAssemblyName">目标服务程序集名称</param>
        /// <returns>目标ServiceBus</returns>
        public IList <ServiceBusServerInfo> DiscoverRemoteBusInfo(string serviceAssemblyName)
        {
            ServiceAssemblyInfo serviceAssemblyInfo = this.getServiceAssemblyInfo(serviceAssemblyName);

            if (serviceAssemblyInfo != null)
            {
                var busList = serviceAssemblyInfo.GetServiceBusInfo()
                              .Where(busInfo => !busInfo.Equals(LocalBusServer)) //发现的ServiceBus不能包括自身
                              .ToList();
                return(busList);
            }
            return(null);    //服务程序集未找到
        }
        /// <summary>
        /// 是否本地服务命令
        /// </summary>
        /// <param name="targetServiceName">服务名</param>
        /// <returns></returns>
        public bool IsLocalServiceCommand(ServiceUniqueNameInfo serviceUniqueName, out ServiceCommandTypeInfo localCommandInfo)
        {
            localCommandInfo = null;

            ServiceAssemblyInfo serviceAssemblyInfo = this.getServiceAssemblyInfo(serviceUniqueName.ServiceAssemblyName);

            if (serviceAssemblyInfo != null)
            {
                ////是否本地ServiceBus包括的服务程序集
                //bool isServiceAssemblyLocal = serviceAssemblyInfo.GetServiceBusInfo()
                //    .Any(busInfo => busInfo.Equals(this.LocalBusServer));

                //if (!isServiceAssemblyLocal)
                //    return false;

                localCommandInfo = serviceAssemblyInfo.TryGetCommand(serviceUniqueName);
                if (localCommandInfo != null)
                {
                    return(true);
                }
            }
            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);
        }