/// <summary> /// Default constructor. /// </summary> /// <param name="owner">Owner UserFolderCollection collection that owns this object.</param> /// <param name="user">Owner user.</param> /// <param name="parent">Gets parent folder.</param> /// <param name="folderPath">Folder path where folder belongs to.</param> /// <param name="folderName">Folder name.</param> internal UserFolder(UserFolderCollection owner,User user,UserFolder parent,string folderPath,string folderName) { m_pOwner = owner; m_pUser = user; m_pParent = parent; m_Path = folderPath; m_FolderName = folderName; m_pChildFolders = new UserFolderCollection(false,this,m_pUser); }
/// <summary> /// Default constructor. /// </summary> /// <param name="owner">Owner UserFolderCollection collection that owns this object.</param> /// <param name="user">Owner user.</param> /// <param name="parent">Gets parent folder.</param> /// <param name="folderPath">Folder path where folder belongs to.</param> /// <param name="folderName">Folder name.</param> internal UserFolder(UserFolderCollection owner, User user, UserFolder parent, string folderPath, string folderName) { m_pOwner = owner; m_pUser = user; m_pParent = parent; m_Path = folderPath; m_FolderName = folderName; m_pChildFolders = new UserFolderCollection(false, this, m_pUser); }
/// <summary> /// Renames/moves folder name. /// </summary> /// <param name="newFolderName">Full folder path, path + folder name.</param> public void Rename(string newFolderName) { // Find root folder collection UserFolderCollection root = m_pOwner; while (root.Parent != null) { root = root.Parent.Owner; } // Find new folderfolder collection string folderName = ""; string[] path_name = newFolderName.Replace('\\', '/').Split(new char[] { '/' }); if (path_name.Length == 1) { folderName = newFolderName; } else { folderName = path_name[path_name.Length - 1]; } UserFolderCollection newFolderCollection = root; for (int i = 0; i < path_name.Length - 1; i++) { newFolderCollection = newFolderCollection[path_name[i]].ChildFolders; } /* RenameUserFolder <virtualServerID> "<folderOwnerUser>" "<folder>" "<newFolder>" * Responses: +OK * -ERR <errorText> */ string id = Guid.NewGuid().ToString(); // Call TCP RenameUserFolder m_pUser.VirtualServer.Server.TcpClient.TcpStream.WriteLine("RenameUserFolder " + m_pUser.VirtualServer.VirtualServerID + " " + TextUtils.QuoteString(m_pUser.UserName) + " " + TextUtils.QuoteString(this.FolderFullPath) + " " + TextUtils.QuoteString(newFolderName) ); string response = m_pUser.VirtualServer.Server.ReadLine(); if (!response.ToUpper().StartsWith("+OK")) { throw new Exception(response); } // Move folder to right hierarchy m_pOwner.List.Remove(this); newFolderCollection.List.Add(this); }
/// <summary> /// Gets server user folders and binds them to this, if not binded already. /// </summary> private void Bind() { /* GetUserFolders <virtualServerID> <userID> * Responses: +OK <sizeOfData> * <data> * + ERR <errorText> */ lock (m_pUser.VirtualServer.Server.LockSynchronizer){ // Call TCP GetUserEmailAddresses m_pUser.VirtualServer.Server.TcpClient.TcpStream.WriteLine("GetUserFolders " + m_pUser.VirtualServer.VirtualServerID + " " + m_pUser.UserID); string response = m_pUser.VirtualServer.Server.ReadLine(); if (!response.ToUpper().StartsWith("+OK")) { throw new Exception(response); } int sizeOfData = Convert.ToInt32(response.Split(new char[] { ' ' }, 2)[1]); MemoryStream ms = new MemoryStream(); m_pUser.VirtualServer.Server.TcpClient.TcpStream.ReadFixedCount(ms, sizeOfData); // Decompress dataset DataSet ds = Utils.DecompressDataSet(ms); if (ds.Tables.Contains("Folders")) { foreach (DataRow dr in ds.Tables["Folders"].Rows) { string[] folderPathParts = dr["Folder"].ToString().Split('/'); UserFolderCollection current = this; string currentPath = ""; foreach (string pathPart in folderPathParts) { if (!current.Contains(pathPart)) { UserFolder f = new UserFolder(current, m_pUser, current.Parent, currentPath, pathPart); current.List.Add(f); } current = current[pathPart].ChildFolders; if (currentPath == "") { currentPath = pathPart; } else { currentPath += "/" + pathPart; } } } } } }