// 数据库是否已经存在? // return: // -1 error // 0 not exist // 1 exist // 2 其他类型的同名对象已经存在 int IsDatabaseExist( RmsChannel channel, string strDatabaseName, out string strError) { strError = ""; // 看看数据库是否已经存在 ResInfoItem[] items = null; long lRet = channel.DoDir("", "zh", "", // style out items, out strError); if (lRet == -1) { strError = "列服务器 " + channel.Url + " 下全部数据库目录的时候出错: " + strError; return -1; } for (int i = 0; i < items.Length; i++) { if (items[i].Name == strDatabaseName) { if (items[i].Type == ResTree.RESTYPE_DB) { strError = "数据库 " + strDatabaseName + " 已经存在。"; return 1; } else { strError = "和数据库 " + strDatabaseName + " 同名的非数据库类型对象已经存在。"; return 2; } } } return 0; }
// 递归 public int Fill(TreeNode node) { TreeNodeCollection children = null; if (node == null) { children = this.Nodes; } else { children = node.Nodes; } int i; // 填充根 if (node == null) { children.Clear(); TreeNode nodeNew = new TreeNode(this.ServerUrl, ResTree.RESTYPE_SERVER, ResTree.RESTYPE_SERVER); ResTree.SetLoading(nodeNew); NodeInfo nodeinfo = new NodeInfo(); nodeinfo.TreeNode = nodeNew; nodeinfo.Expandable = true; nodeinfo.DefElement = GetDefElementString(nodeNew.ImageIndex); nodeinfo.NodeState |= NodeState.Object; nodeNew.Tag = nodeinfo; if (EnabledIndices != null && StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false) nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor); children.Add(nodeNew); return 0; } // 根以下的节点类型 ResPath respath = new ResPath(node); string strPath = respath.Path; //if (node != null) // strPath = TreeViewUtil.GetPath(node); this.channel = Channels.GetChannel(this.ServerUrl); Debug.Assert(channel != null, "Channels.GetChannel() 异常"); ResInfoItem [] items = null; string strError = ""; DigitalPlatform.Stop stop = null; if (stopManager != null) { stop = new DigitalPlatform.Stop(); stop.Register(this.stopManager, true); // 和容器关联 stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在列目录: " + this.ServerUrl + "?" + strPath); stop.BeginLoop(); } long lRet = channel.DoDir(strPath, this.Lang, null, // 不需要列出全部语言的名字 out items, out strError); if (stopManager != null) { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); stop.Unregister(); // 和容器关联 } this.channel = null; if (lRet == -1) { try { MessageBox.Show(this, "Channel::DoDir() Error: " + strError); } catch { // this可能已经不存在 return -1; } if (node != null) { ResTree.SetLoading(node); // 出错的善后处理,重新出现+号 node.Collapse(); } return -1; } if (items != null) { children.Clear(); for(i=0;i<items.Length;i++) { // 忽略from类型节点 if (items[i].Type == ResTree.RESTYPE_FROM) continue; TreeNode nodeNew = new TreeNode(items[i].Name, items[i].Type, items[i].Type); NodeInfo nodeinfo = new NodeInfo(); nodeinfo.TreeNode = nodeNew; nodeinfo.Expandable = items[i].HasChildren; nodeinfo.DefElement = GetDefElementString(nodeNew.ImageIndex); nodeinfo.NodeState |= NodeState.Object; nodeinfo.Style = items[i].Style; nodeNew.Tag = nodeinfo; if (items[i].HasChildren) ResTree.SetLoading(nodeNew); if (EnabledIndices != null && StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false) nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor); children.Add(nodeNew); } } return 0; }
/* // 将内存对象创建为真正的服务器端对象 public int BuildRealObjects( string strDbName, DatabaseObject root, out string strError) { strError = ""; int nRet = 0; // 创建根 if (root.Type != -1) { if (root.Type == ResTree.RESTYPE_DB) goto DOCHILD; // 忽略本节点,但是继续作下级节点 // 缺省配置文件,忽略保存 if (root.IsDefaultFile() == true) return 0; MemoryStream stream = null; if (root.Type == ResTree.RESTYPE_FILE) stream = new MemoryStream(root.Content); string strPath = root.MakePath(strDbName); // 在服务器端创建对象 nRet = NewServerSideObject(strPath, root.Type, stream, root.TimeStamp, out strError); if (nRet == -1) return -1; } DOCHILD: // 递归 for(int i=0;i<root.Children.Count;i++) { DatabaseObject obj = (DatabaseObject)root.Children[i]; nRet = BuildRealObjects( strDbName, obj, out strError); if (nRet == -1) return -1; } return 0; } */ // 根据路径创建内存对象 public int CreateObject(DatabaseObject obj, string strPath, out string strError) { strError = ""; obj.Children.Clear(); if (obj.Type == ResTree.RESTYPE_FILE) { byte[] baTimeStamp = null; string strMetaData; string strOutputPath; this.channel = Channels.GetChannel(this.ServerUrl); Debug.Assert(channel != null, "Channels.GetChannel() 异常"); // string strStyle = "attachment,data,timestamp,outputpath"; string strStyle = "content,data,timestamp,outputpath"; using (MemoryStream stream = new MemoryStream()) { long lRet = channel.GetRes(strPath, stream, null, // stop, strStyle, null, // byte [] input_timestamp, out strMetaData, out baTimeStamp, out strOutputPath, out strError); if (lRet == -1) { // obj.SetData(null); obj.TimeStamp = null; return 0; // 继续处理 } obj.SetData(stream); obj.TimeStamp = baTimeStamp; } } if (obj.Type == ResTree.RESTYPE_DB || obj.Type == ResTree.RESTYPE_FOLDER) { this.channel = Channels.GetChannel(this.ServerUrl); Debug.Assert(channel != null, "Channels.GetChannel() 异常"); ResInfoItem[] items = null; DigitalPlatform.Stop stop = null; if (stopManager != null) { stop = new DigitalPlatform.Stop(); stop.Register(this.stopManager, true); // 和容器关联 stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在列目录: " + this.ServerUrl + "?" + strPath); stop.BeginLoop(); } long lRet = channel.DoDir(strPath, this.Lang, null, // 不需要返回全部语言的名字 out items, out strError); if (stopManager != null) { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); stop.Unregister(); // 和容器关联 } this.channel = null; if (lRet == -1) return -1; if (items == null) return 0; for (int i = 0; i < items.Length; i++) { // 忽略from类型节点 if (items[i].Type == ResTree.RESTYPE_FROM) continue; DatabaseObject child = new DatabaseObject(); child.Name = items[i].Name; child.Type = items[i].Type; child.Style = items[i].Style; child.Parent = obj; obj.Children.Add(child); int nRet = CreateObject(child, strPath + "/" + items[i].Name, out strError); if (nRet == -1) return -1; } } return 0; }
int GetDbStyle(string strDbName, out string strError) { strError = ""; this.channel = Channels.GetChannel(this.ServerUrl); Debug.Assert(channel != null, "Channels.GetChannel() 异常"); ResInfoItem[] items = null; DigitalPlatform.Stop stop = null; if (stopManager != null) { stop = new DigitalPlatform.Stop(); stop.Register(this.stopManager, true); // 和容器关联 stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在获得数据库 " + strDbName + "的风格参数"); stop.BeginLoop(); } long lRet = channel.DoDir("", // 列出全部数据库 this.Lang, null, // 不需要列出全部语言的名字 out items, out strError); if (stopManager != null) { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); stop.Unregister(); // 和容器关联 } this.channel = null; if (lRet == -1) return -1; if (items == null) return 0; // 数据库不存在 for (int i = 0; i < items.Length; i++) { // 忽略非数据库类型节点 if (items[i].Type != ResTree.RESTYPE_DB) continue; if (items[i].Name == strDbName) return items[i].Style; } return 0; // 数据库不存在 }
// 递归 public int Fill(TreeNode node, out string strError) { strError = ""; TreeNodeCollection children = null; if (node == null) { children = this.Nodes; } else { children = node.Nodes; } int i; // 填充根 if (node == null) { children.Clear(); for(i=0;i<Servers.Count;i++) { Server server = (Server)Servers[i]; TreeNode nodeNew = new TreeNode(server.Url, RESTYPE_SERVER, RESTYPE_SERVER); SetLoading(nodeNew); if (EnabledIndices != null && StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false) nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor); children.Add(nodeNew); } return 0; } // 根以下的节点类型 ResPath respath = new ResPath(node); this.channel = Channels.GetChannel(respath.Url); Debug.Assert(channel != null, "Channels.GetChannel() 异常"); /* int nStart = 0; int nPerCount = -1; int nCount = 0; */ ResInfoItem [] items = null; #if NO DigitalPlatform.Stop stop = null; if (stopManager != null) { stop = new DigitalPlatform.Stop(); stop.Register(this.stopManager, true); // 和容器关联 stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在列目录: " + respath.FullPath); stop.BeginLoop(); } #endif DigitalPlatform.Stop stop = PrepareStop("正在列目录: " + respath.FullPath); long lRet = 0; try { lRet = channel.DoDir(respath.Path, this.Lang, null, // 不需要列出全部语言的名字 out items, out strError); } finally { EndStop(stop); } #if NO if (stopManager != null) { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); stop.Unregister(); // 和容器关联 } #endif this.channel = null; if (lRet == -1) { #if NO try { MessageBox.Show(this, "Channel::DoDir() Error: " + strError); } catch { // this可能已经不存在 return -1; } #endif if (node != null) { SetLoading(node); // 出错的善后处理,重新出现+号 node.Collapse(); } return -1; } if (items != null) { children.Clear(); //for(i=0;i<items.Length;i++) foreach(ResInfoItem res_item in items) { // ResInfoItem res_item = items[i]; TreeNode nodeNew = new TreeNode(res_item.Name, res_item.Type, res_item.Type); if (res_item.Type == RESTYPE_DB) { DbProperty prop = new DbProperty(); prop.TypeString = res_item.TypeString; // 类型字符串 nodeNew.Tag = prop; List<string> column_names = null; int nRet = GetBrowseColumns( node.Text, res_item.Name, out column_names, out strError); if (nRet == -1) return -1; prop.ColumnNames = column_names; } else { ItemProperty prop = new ItemProperty(); prop.TypeString = res_item.TypeString; // 类型字符串 nodeNew.Tag = prop; } if (res_item.HasChildren) SetLoading(nodeNew); if (EnabledIndices != null && StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false) nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor); children.Add(nodeNew); } } return 0; }