Exemplo n.º 1
0
        /// <summary>
        ///  根据节点添加缩略图
        /// </summary>
        /// <param name="dataServiceGroups"></param>
        /// <param name="endPoints"></param>
        /// <param name="node"></param>
        protected virtual void AddDataServiceByXmlNode(IList <DataServiceGroupInfo> dataServiceGroups, IList <EndPointInfo> endPoints, XmlNode node)
        {
            var dsp = new DataServiceGroupInfo {
                DataServices = new List <DataServiceInfo>()
            };

            if (node != null && node.Attributes != null)
            {
                dsp.Path      = node.Attributes["Path"] == null ? null : node.Attributes["Path"].Value;
                dsp.Name      = node.Attributes["Name"] == null ? null : node.Attributes["Name"].Value;
                dsp.IsClose   = node.Attributes["IsClose"] != null && Convert.ToBoolean(node.Attributes["IsClose"].Value);
                dsp.Addresses = node.Attributes["Addresses"] == null ? null : node.Attributes["Addresses"].Value.Split(',');
                XmlNodeList dsNodes = node.SelectNodes("DataService");
                if (dsNodes != null && dsNodes.Count > 0)
                {
                    foreach (XmlNode dsNode in dsNodes)
                    {
                        var ds = new DataServiceInfo
                        {
                            Type = dsNode.Attributes["Type"] == null
                                           ? DataServiceType.Master
                                           : (DataServiceType)
                                   Enum.Parse(typeof(DataServiceType), dsNode.Attributes["Type"].Value),
                            EndPoint =
                                endPoints.FirstOrDefault(it => it.Name.Equals(dsNode.Attributes["EndPointName"].Value))
                        };
                        dsp.DataServices.Add(ds);
                    }
                }
            }
            dataServiceGroups.Add(dsp);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 得到写的服务器
        /// </summary>
        /// <param name="dataServiceGroup"></param>
        /// <param name="hashValue"></param>
        /// <returns></returns>
        protected virtual DataServiceInfo GetMasterDataService(DataServiceGroupInfo dataServiceGroup, long hashValue)
        {
            var dataServices = dataServiceGroup.DataServices.Where(it => it.Type == DataServiceType.Master).ToList();

            if (dataServices.Count == 0)
            {
                return(null);
            }
            return(dataServices[(int)(hashValue % dataServices.Count)]);
        }