Exemplo n.º 1
0
 /// <summary>
 /// 获取Couchbase在配置文件中的节点
 /// </summary>
 /// <param name="doc"></param>
 /// <param name="couchbase"></param>
 /// <returns></returns>
 private static XmlElement GetCouchbaseElement(XmlDocument doc, CouchbaseConfig couchbase)
 {
     if (couchbase.MinPoolSize == default(int)) couchbase.MinPoolSize = 10;
     if (couchbase.MaxPoolSize == default(int)) couchbase.MaxPoolSize = 20;
     if (couchbase.ConnectionTimeout == default(TimeSpan)) couchbase.ConnectionTimeout = new TimeSpan(0, 0, 2);
     if (couchbase.DeadTimeout == default(TimeSpan)) couchbase.DeadTimeout = new TimeSpan(0, 0, 10);
     if (couchbase.ReceiveTimeout == default(TimeSpan)) couchbase.ReceiveTimeout = new TimeSpan(0, 0, 10);
     if (couchbase.QueueTimeout == default(TimeSpan)) couchbase.QueueTimeout = TimeSpan.Parse("00:00:00.1000000");
     var serverElement = doc.CreateElement("server");
     serverElement.SetAttribute("name", couchbase.Name);
     serverElement.SetAttribute("bucket", couchbase.Bucket ?? "default");
     serverElement.SetAttribute("password", couchbase.PassWord);
     if (couchbase.Uris != null && couchbase.Uris.Count > 0)
     {
         var urlsElement = doc.CreateElement("urls");
         foreach (var uri in couchbase.Uris)
         {
             var addElement = doc.CreateElement("add");
             addElement.SetAttribute("uri", uri.ToString());
             urlsElement.AppendChild(addElement);
         }
         serverElement.AppendChild(urlsElement);
     }
     var socketPoolElement = doc.CreateElement("socketPool");
     socketPoolElement.SetAttribute("minPoolSize", couchbase.MinPoolSize.ToString());
     socketPoolElement.SetAttribute("maxPoolSize", couchbase.MaxPoolSize.ToString());
     socketPoolElement.SetAttribute("connectionTimeout", couchbase.ConnectionTimeout.ToString());
     socketPoolElement.SetAttribute("deadTimeout", couchbase.DeadTimeout.ToString());
     socketPoolElement.SetAttribute("receiveTimeout", couchbase.ReceiveTimeout.ToString());
     socketPoolElement.SetAttribute("queueTimeout", couchbase.QueueTimeout.ToString());
     serverElement.AppendChild(socketPoolElement);
     return serverElement;
 }
Exemplo n.º 2
0
 /// <summary>
 /// 读取couchbase配置
 /// </summary>
 /// <param name="zone"></param>
 /// <returns></returns>
 public static List<CouchbaseConfig> GetCouchbaseConfig(int zone)
 {
     var result = new List<CouchbaseConfig>();
     var path = GetEndpointPath(zone);
     var doc = XmlHelper.GetXmlDocCache(path);
     var nodes = doc.SelectNodes("/configuration/couchbase/server");
     if (nodes == null || nodes.Count <= 0) return result;
     foreach (XmlNode node in nodes)
     {
         var couchbase = new CouchbaseConfig
         {
             Name = XmlHelper.GetXmlAttributeValue(node, "name", string.Empty),
             Bucket = XmlHelper.GetXmlAttributeValue(node, "bucket", string.Empty),
             PassWord = XmlHelper.GetXmlAttributeValue(node, "password", string.Empty),
             Uris = new List<Uri>()
         };
         foreach (XmlNode item in node.ChildNodes)
         {
             switch (item.Name)
             {
                 case "urls":
                     foreach (XmlNode uri in item.ChildNodes) couchbase.Uris.Add(new Uri(XmlHelper.GetXmlAttributeValue(uri, "uri", string.Empty)));
                     break;
                 case "socketPool":
                     couchbase.MinPoolSize = CoreParse.GetInt32((XmlHelper.GetXmlAttributeValue(item, "minPoolSize", string.Empty)), 20);
                     couchbase.MaxPoolSize = CoreParse.GetInt32((XmlHelper.GetXmlAttributeValue(item, "maxPoolSize", string.Empty)), 1000);
                     couchbase.ConnectionTimeout = TimeSpan.Parse(XmlHelper.GetXmlAttributeValue(item, "connectionTimeout", "00:00:02"));
                     couchbase.DeadTimeout = TimeSpan.Parse(XmlHelper.GetXmlAttributeValue(item, "deadTimeout", "00:00:10"));
                     couchbase.ReceiveTimeout = TimeSpan.Parse(XmlHelper.GetXmlAttributeValue(item, "receiveTimeout", "00:00:10"));
                     couchbase.QueueTimeout = TimeSpan.Parse(XmlHelper.GetXmlAttributeValue(item, "queueTimeout", "00:00:00.1000000"));
                     break;
             }
         }
         result.Add(couchbase);
     }
     return result;
 }
Exemplo n.º 3
0
 /// <summary>
 /// CouchBase 配置
 /// </summary>
 /// <param name="doc"></param>
 /// <param name="couchbase"></param>
 /// <returns></returns>
 public static XmlDocument SetCouchbaseConfig(XmlDocument doc, CouchbaseConfig couchbase)
 {
     doc = GetXmlDocument(doc, "configuration");
     if (couchbase == null) return doc;
     var couchbaseElement = doc.CreateElement("couchbase");
     var serverElement = GetCouchbaseElement(doc, couchbase);
     couchbaseElement.AppendChild(serverElement);
     doc.AppendChild(couchbaseElement);
     return doc;
 }