Exemplo n.º 1
0
 /// <summary>
 /// 组件logfactory
 /// </summary>
 /// <returns></returns>
 private static IBalance BuildBalance(BalanceConfigProvider provider)
 {
     try
     {
         if (provider == null || string.IsNullOrEmpty(provider.Type) || provider.IsEnabled == false)
         {
             if (NDComponentConfig.Instance.IsThrowConfigException)
             {
                 throw new ArgumentNullException("Invalid_Config_BalanceProvider");
             }
             return(new RandomBalance());
         }
         string assemblyName = provider.Type.Split(',')[0];
         string typeName     = provider.Type.Split(',')[1];
         Type   type         = Type.GetType(typeName + "," + assemblyName);
         return((IBalance)Activator.CreateInstance(type));
     }
     catch (Exception ex)
     {
         if (NDComponentConfig.Instance.IsThrowConfigException)
         {
             throw new ArgumentNullException("Invalid_Config_BalanceProvider");
         }
         return(new RandomBalance());
     }
 }
Exemplo n.º 2
0
        //组建负载均衡
        #region BuildBlanceProvider
        public BalanceConfigProvider BuildBlanceProvider(XElement root)
        {
            BalanceConfigProvider provider = null;
            XElement root2 = root.Element("balanceprovider");

            if (root2 != null)
            {
                provider           = new BalanceConfigProvider();
                provider.Type      = root2.Attribute("type").Value;
                provider.IsEnabled = Convert.ToBoolean(root2.Attribute("isenabled").Value.NotEmpty("false"));
                provider.Balance   = BuildBalance(provider);
            }
            return(provider);
        }