/* // 将内存对象创建为真正的服务器端对象 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; }
/* // 把当前Real模式的对象全部构造为内存树 public int BuildMemoryTree( TreeNode treenode, out DatabaseObject root, out string strError) { Debug.Assert(false, "废止"); root = null; strError = ""; //if (this.StorageMode != StorageMode.Real) //{ // strError = "必须在Real存储模式下调用函数BuildMemoryTree()"; // return -1; //} root = new DatabaseObject(); return BuildMemoryTree( treenode, root, out strError); } */ int BuildMemoryTree( TreeNode parentTreeNode, DatabaseObject parentDatabaseObject, out string strError) { strError = ""; TreeNodeCollection children = null; if (parentTreeNode == null) { children = this.Nodes; } else { children = parentTreeNode.Nodes; } //DatabaseObject newObj = null; if (parentTreeNode != null) // 实根 { TreeNode treenode = parentTreeNode; parentDatabaseObject.Type = treenode.ImageIndex; parentDatabaseObject.Name = treenode.Text; if (treenode.ImageIndex == ResTree.RESTYPE_DB) { //newObj = parentDatabaseObject; } else if (treenode.ImageIndex == ResTree.RESTYPE_FOLDER) { /* newObj = DatabaseObject.BuildDirObject(treenode.Text); newObj.Type = treenode.ImageIndex; newObj.Parent = parentDatabaseObject; parentDatabaseObject.Children.Add(newObj); */ //newObj = parentDatabaseObject; } else if (treenode.ImageIndex == ResTree.RESTYPE_FILE) { this.channel = Channels.GetChannel(this.ServerUrl); Debug.Assert(channel != null, "Channels.GetChannel() 异常"); string strPath = ""; byte[] baTimeStamp = null; string strMetaData; string strOutputPath; strPath = this.GetPath(treenode); // 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) return -1; parentDatabaseObject.SetData(stream); parentDatabaseObject.TimeStamp = baTimeStamp; } return 0; } else { Debug.Assert(false, "意外的节点类型"); } } for (int i = 0; i < children.Count; i++) { TreeNode treenode = children[i]; DatabaseObject child = new DatabaseObject(); child.Parent = parentDatabaseObject; parentDatabaseObject.Children.Add(child); int nRet = BuildMemoryTree( treenode, child, out strError); if (nRet == -1) return -1; } return 0; }