public void AddServer(string ip, int port) { // 添加需要新增的XElement对象 var element = new XElement("Server", new XAttribute("IP", ip), new XAttribute("Port", port)); XML.Root.Add(element); XML.Save(ConfigFile); MongoCache.Clear(); }
public void DeleteServer(string ip, int port) { // 添加需要新增的XElement对象 var server = XML.Descendants("Server").ToList().Find(p => p.Attribute("IP").Value == ip && p.Attribute("Port").Value == port.ToString()); if (server != null) { server.Remove(); XML.Save(ConfigFile); MongoCache.Clear(); } }
/// <summary> /// 删除索引 /// </summary> /// <param name="name"></param> public void DeleteIndex(uint id) { var mongo = new MongoClient(string.Format(MongoConst.ConnString, Server.Name)); var server = mongo.GetServer(); var db = server.GetDatabase(Database.Name); var idx = MongoCache.GetMongoObject(id) as MongoIndexModel; var tbl = db.GetCollection(Table.Name); tbl.DropIndex(idx.Keys.Select(k => k.FieldName).ToArray()); MongoCache.Clear(); }
/// <summary> /// 新建索引 /// </summary> /// <param name="jsonData"></param> public void CreateIndex(string jsonData) { var model = JsonConvert.DeserializeObject <SaveIndexModel>(jsonData); var idxDoc = ToDoc(model.Keys); var idxOption = new IndexOptionsDocument(); idxOption.Add("background", model.Background); idxOption.Add("dropdups", model.Dropdups); var mongo = new MongoClient(string.Format(MongoConst.ConnString, Server.Name)); var server = mongo.GetServer(); var db = server.GetDatabase(Database.Name); var tbl = db.GetCollection(Table.Name); var rst = tbl.CreateIndex(idxDoc, idxOption); MongoCache.Clear(); }