public MongoProfileContext(uint id) { var dbNode = MongoCache.GetTreeNode(id); Database = MongoCache.GetMongoObject(id) as MongoDatabaseModel; var serverNode = MongoCache.GetTreeNode(dbNode.PID); Server = MongoCache.GetMongoObject(serverNode.ID) as MongoServerModel; }
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 MongoCollectionInfo(uint id) { var tbNode = MongoCache.GetTreeNode(id); Table = MongoCache.GetMongoObject(id) as MongoCollectionModel; var dbNode = MongoCache.GetTreeNode(tbNode.PID); Database = MongoCache.GetMongoObject(dbNode.ID) as MongoDatabaseModel; var serverNode = MongoCache.GetTreeNode(dbNode.PID); Server = MongoCache.GetMongoObject(serverNode.ID) as MongoServerModel; }
/// <summary> /// 获取索引信息 /// </summary> /// <returns></returns> public List <MongoIndexModel> GetIndexes() { var list = MongoCache.GetTreeNodes().Where(node => node.PID == ID).ToList(); var indexes = new List <MongoIndexModel>(); foreach (var item in list) { indexes.Add(MongoCache.GetMongoObject(item.ID) as MongoIndexModel); } return(indexes); }
public List <MongoFieldModel> GetFields() { var fieldNodes = MongoCache.GetTreeNodes().Where(n => n.PID == ID).ToList(); var list = new List <MongoFieldModel>(); foreach (var node in fieldNodes) { list.Add(MongoCache.GetMongoObject(node.ID) as MongoFieldModel); } return(list); }
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(); }
public MongoIndexContext(uint id) { ID = id; var idxNode = MongoCache.GetTreeNode(ID); var tbNode = MongoCache.GetTreeNode(idxNode.PID); Table = MongoCache.GetMongoObject(tbNode.ID) as MongoCollectionModel; var dbNode = MongoCache.GetTreeNode(tbNode.PID); Database = MongoCache.GetMongoObject(dbNode.ID) as MongoDatabaseModel; var serverNode = MongoCache.GetTreeNode(dbNode.PID); Server = MongoCache.GetMongoObject(serverNode.ID) as MongoServerModel; }
/// <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(); }
public MongoReplicationContext(uint id) { var serverNode = MongoCache.GetTreeNode(id); Server = MongoCache.GetMongoObject(serverNode.ID) as MongoServerModel; }
/// <summary> /// 获取字段节点信息 /// </summary> /// <returns></returns> public List <MongoTreeNode> GetFieldNodes() { var fieldFiller = MongoCache.GetTreeNodes().Where(n => n.PID == Table.ID && n.Type == MongoTreeNodeType.TableFiller).First(); return(MongoCache.GetTreeNodes().Where(n => n.PID == fieldFiller.ID).ToList()); }
public MongoServerInfo(uint id) { Server = MongoCache.GetMongoObject(id) as MongoServerModel; }