public void MoveChildToTop(MapNode node) { lock (_childrenList) { int index = _childrenList.IndexOf(node); if (index != -1 && index != 0) { while (index != 0) { _childrenList.Reverse(index - 1, 2); index--; } } } }
public void MoveChildToBottom(MapNode node) { lock (_childrenList) { int index = _childrenList.IndexOf(node); if (index != -1 && index < _childrenList.Count - 1) { while (index != _childrenList.Count - 1) { _childrenList.Reverse(index, 2); index++; } } } }
public void MoveChildForward(MapNode node) { lock (_childrenList) { int index = _childrenList.IndexOf(node); if (index != -1 && index != 0) { _childrenList.Reverse(index - 1, 2); } } }
public void MoveChildBackward(MapNode node) { lock (_childrenList) { int index = _childrenList.IndexOf(node); if (index != -1 && index < _childrenList.Count - 1) { _childrenList.Reverse(index, 2); } } }
public void AddChild(MapNode node) { lock (_childrenList) { _childrenList.Add(node); node.Index = _childrenList.Count - 1; node.Parent = this; } }
public void RemoveChild(MapNode node) { lock (_childrenList) { _childrenList.Remove(node); node.Parent = null; } }
public MapNode(int id, ServerMap.ServerMapType type, int flag, string name, int mapServerId, int index, MapNode parent) { _id = id; _type = type; _flag = flag; _name = name; _mapServerId = mapServerId; _index = index; _parent = parent; }
/// <summary> /// 记得捕捉异常 /// </summary> /// <param name="index"></param> /// <param name="node"></param> public void InsertChild(int index, MapNode node) { lock (_childrenList) { _childrenList.Insert(index, node); node.Parent = this; } }
/// <summary> /// 根据MapNode获取其对应的GameServers(不含重复的) /// </summary> /// <param name="selNodes">MapNodes</param> public GameServer[] GetGameServerFromMapNodes(MapNode[] selNodes) { try { if (selNodes != null) { List<GameServer> serverList = new List<GameServer>(); for (int index = 0; index < selNodes.Length; ++index) { MapNode node = selNodes[index]; if (node != null) { switch (node.MapType) { case ServerMapType.Net: { foreach (MapNode regionNode in node.Children) { foreach (MapNode serverNode in regionNode.Children) { GameServer server = AdminServer.TheInstance.GameServerManager.GetGameServer(serverNode.MapServerId); if (server != null && !serverList.Contains(server)) { serverList.Add(server); } } } } break; case ServerMapType.Region: { foreach (MapNode serverNode in node.Children) { GameServer server = AdminServer.TheInstance.GameServerManager.GetGameServer(serverNode.MapServerId); if (server != null && !serverList.Contains(server)) { serverList.Add(server); } } } break; case ServerMapType.Server: { GameServer server = AdminServer.TheInstance.GameServerManager.GetGameServer(node.MapServerId); if (server != null && !serverList.Contains(server)) { serverList.Add(server); } } break; } } } return serverList.ToArray(); } else { return null; } } catch (Exception ex) { FSEye.Util.DebugLog(ex.ToString()); return null; } }
/// <summary> /// 保存整体配置 /// </summary> /// <param name="netList">配置</param> public bool SaveServerMapList(List<MapNode> netList) { IBlazeDatabase db = null; try { db = DbFactory.GetDatabase(); db.BeginTrans(); IBlazeTable serverTable = db.GetTable(TableString.ServerMapTableName); DataSet dataSet = new DataSet(); serverTable.Get(dataSet); DataTable serverMapTable = dataSet.Tables[TableString.ServerMapTableName]; //删除所有行 //为什么用serverMapTable.Rows.Clear()就删不掉?!?! foreach (DataRow row in serverMapTable.Rows) { row.Delete(); } for (int netIndex = 0; netIndex < netList.Count; ++netIndex) { MapNode netNode = netList[netIndex]; DataRow netRow = serverMapTable.NewRow(); netRow[TableString.ServerMapFieldId] = netNode.ID; netRow[TableString.ServerMapFieldParentId] = 0; netRow[TableString.ServerMapFieldName] = netNode.Name; netRow[TableString.ServerMapFieldMapType] = (int)netNode.MapType; netRow[TableString.ServerMapFieldIndex] = netIndex; netRow[TableString.ServerMapFieldFlag] = netNode.Flag; netRow[TableString.ServerMapFieldMapServerId] = netNode.MapServerId; serverMapTable.Rows.Add(netRow); for (int regionIndex = 0; regionIndex < netNode.Children.Length; ++regionIndex) { MapNode regionNode = netNode.Children[regionIndex]; DataRow regionRow = serverMapTable.NewRow(); regionRow[TableString.ServerMapFieldId] = regionNode.ID; regionRow[TableString.ServerMapFieldParentId] = regionNode.Parent.ID; regionRow[TableString.ServerMapFieldName] = regionNode.Name; regionRow[TableString.ServerMapFieldMapType] = (int)regionNode.MapType; regionRow[TableString.ServerMapFieldIndex] = regionIndex; regionRow[TableString.ServerMapFieldFlag] = regionNode.Flag; regionRow[TableString.ServerMapFieldMapServerId] = regionNode.MapServerId; serverMapTable.Rows.Add(regionRow); for (int serverIndex = 0; serverIndex < regionNode.Children.Length; ++serverIndex) { MapNode serverNode = regionNode.Children[serverIndex]; DataRow serverRow = serverMapTable.NewRow(); serverRow[TableString.ServerMapFieldId] = serverNode.ID; serverRow[TableString.ServerMapFieldParentId] = serverNode.Parent.ID; serverRow[TableString.ServerMapFieldName] = serverNode.Name; serverRow[TableString.ServerMapFieldMapType] = (int)serverNode.MapType; serverRow[TableString.ServerMapFieldIndex] = serverIndex; serverRow[TableString.ServerMapFieldFlag] = serverNode.Flag; serverRow[TableString.ServerMapFieldMapServerId] = serverNode.MapServerId; serverMapTable.Rows.Add(serverRow); } } } serverTable.Set(serverMapTable); db.CommitTrans(); //下面一行为之前的代码,这样做的问题是: //页面内的netList与这里的_netList将指向相同的对象, //于是在同一次页面的访问内,只要调用这个函数保存过一次修改, //之后同一次的页面内的修改将直接作用于这里的_netList, //这将使得"察看系统配置"和"察看当前配置"的结果没有区别 //_netList = netList; //下面的代码是为了解决之前为浅拷贝的问题,重新从数据库生成新的_netList //这样,在同一次打开的ServerListConfig.aspx内,未保存的修改不会影响这里的_netList //因为是完全不同的两份List<MapNode>了 List<MapNode> resultList = new List<MapNode>(); IBlazeTable serverTable1 = db.GetTable(TableString.ServerMapTableName); DataSet data = new DataSet(); serverTable1.Get(data); DataTable mapServerTable = data.Tables[TableString.ServerMapTableName]; string condition = string.Format("{0}={1}", TableString.ServerMapFieldMapType, (int)ServerMapType.Net); string order = string.Format("{0} ASC", TableString.ServerMapFieldIndex); DataRow[] netData = mapServerTable.Select(condition, order); if (netData.Length > 0) { foreach (DataRow netRow in netData) { int nodeId = (int)netRow[TableString.ServerMapFieldId]; int parentId = (int)netRow[TableString.ServerMapFieldParentId]; string name = netRow[TableString.ServerMapFieldName] as string; int nodeIndex = (int)netRow[TableString.ServerMapFieldIndex]; ServerMapType type = (ServerMap.ServerMapType)netRow[TableString.ServerMapFieldMapType]; int flag = (int)netRow[TableString.ServerMapFieldFlag]; int mapServerId = (int)netRow[TableString.ServerMapFieldMapServerId]; MapNode node = new MapNode(nodeId, type, flag, name, mapServerId, nodeIndex); BuildMapNode(node, data.Tables[TableString.ServerMapTableName]); resultList.Insert(nodeIndex, node); } } _netList = resultList; return true; } catch (Exception ex) { if (db != null) { db.RollbackTrans(); } FSEye.Util.DebugLog(ex.ToString()); return false; } finally { if (db != null) { db.Close(); } } }
/// <summary> /// 构建结点 /// </summary> /// <param name="rootNode">被构建的结点</param> /// <param name="dataTable">数据表</param> public void BuildMapNode(MapNode rootNode, DataTable dataTable) { try { if (rootNode != null) { DataRow[] childData = dataTable.Select(TableString.ServerMapFieldParentId + "=" + rootNode.ID, TableString.ServerMapFieldIndex + " ASC"); foreach (DataRow childRow in childData) { int nodeId = (int)childRow[TableString.ServerMapFieldId]; int parentId = (int)childRow[TableString.ServerMapFieldParentId]; string name = childRow[TableString.ServerMapFieldName] as string; int nodeIndex = (int)childRow[TableString.ServerMapFieldIndex]; ServerMapType type = (ServerMap.ServerMapType)childRow[TableString.ServerMapFieldMapType]; int flag = (int)childRow[TableString.ServerMapFieldFlag]; int mapServerId = (int)childRow[TableString.ServerMapFieldMapServerId]; MapNode node = new MapNode(nodeId, type, flag, name, mapServerId); BuildMapNode(node, dataTable); rootNode.InsertChild(nodeIndex, node); } } } catch (Exception ex) { FSEye.Util.DebugLog(ex.ToString()); } }
/// <summary> /// 从数据库中生成配置 /// </summary> /// <param name="netList">配置(ref)</param> public bool LoadServerMap(ref List<MapNode> netList) { IBlazeDatabase db = null; try { db = DbFactory.GetDatabase(); db.BeginTrans(); List<MapNode> resultList = new List<MapNode>(); IBlazeTable serverTable = db.GetTable(TableString.ServerMapTableName); DataSet data = new DataSet(); serverTable.Get(data); DataTable mapServerTable = data.Tables[TableString.ServerMapTableName]; string condition = string.Format("{0}={1}", TableString.ServerMapFieldMapType, (int)ServerMapType.Net); string order = string.Format("{0} ASC", TableString.ServerMapFieldIndex); DataRow[] netData = mapServerTable.Select(condition, order); if (netData.Length > 0) { foreach (DataRow netRow in netData) { int nodeId = (int)netRow[TableString.ServerMapFieldId]; int parentId = (int)netRow[TableString.ServerMapFieldParentId]; string name = netRow[TableString.ServerMapFieldName] as string; int nodeIndex = (int)netRow[TableString.ServerMapFieldIndex]; ServerMapType type = (ServerMap.ServerMapType)netRow[TableString.ServerMapFieldMapType]; int flag = (int)netRow[TableString.ServerMapFieldFlag]; int mapServerId = (int)netRow[TableString.ServerMapFieldMapServerId]; MapNode node = new MapNode(nodeId, type, flag, name, mapServerId, nodeIndex); BuildMapNode(node, data.Tables[TableString.ServerMapTableName]); resultList.Insert(nodeIndex, node); } } netList = resultList; return true; } catch (Exception ex) { FSEye.Util.DebugLog(ex.ToString()); return false; } finally { if (db != null) { db.Close(); } } }
/// <summary> /// 得到服务器名字描述 /// </summary> /// <param name="serverNode">服务器映射结点</param> public string GetServerNameDesc(MapNode serverNode) { StringBuilder serverNameBuilder = new StringBuilder(); serverNameBuilder.Append("【" + serverNode.Name + "】"); if (serverNode.New) { serverNameBuilder.Append(StringDef.ServerFlagNew); } if (serverNode.Recommend) { //只生成1个flag,因为客户端会显示不下 //这里New的优先级高于Recommand //如果这两个flag都有,则只生成New //if (serverNode.New == false) //{ serverNameBuilder.Append(StringDef.ServerFlagRecommend); //} } return serverNameBuilder.ToString(); }