📄 directorycachemanager.cs
字号:
namespace FTP.Model.DataStructures.DirectoryCache
{
using System;
using System.Net;
using System.Collections;
using System.Windows.Forms;
public class DirectoryCacheManager
{
private DirectoryNode rootNode;
private Hashtable hashtableOfNodes;
private DirectoryNode currentDirectoryNode;
private bool newDirectoryAdded = false;
// Constructor (for ROOT node)
public DirectoryCacheManager(string pRootDirectory)
{
rootNode = new DirectoryNode(pRootDirectory, pRootDirectory);
// Add root node to the HashTable
hashtableOfNodes = new Hashtable();
hashtableOfNodes.Add(pRootDirectory, rootNode);
}
////////////////////////////////////////////////////////////////////
///////////////////// Exposed to ViewState /////////////////////////
////////////////////////////////////////////////////////////////////
public void addDirectoryData(string pFullDirectoryPath, ServerFileData[] pRootLISTData)
{
// To Do: Error handling
// Find the node (it must have been created by its parent)
DirectoryNode newDirectoryNode = (DirectoryNode)hashtableOfNodes[pFullDirectoryPath];
//System.Windows.Forms.MessageBox.Show("Add LIST Data " + pFullDirectoryPath + "<", "",
// System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
if (!newDirectoryNode.fullyPopulated)
{
// Add the Server LIST Data
newDirectoryNode.AddFilesAndCreateSubNodes(pRootLISTData);
// Add subnodes to Hashtable
for (int i=0; i<currentDirectoryNode.subNodes.Length; i++)
{
if (!hashtableOfNodes.ContainsKey(currentDirectoryNode.subNodes[i].fullDirectoryPath))
{
// System.Windows.Forms.MessageBox.Show("New HASH entry >" + currentDirectoryNode.subNodes[i].fullDirectoryPath + "<", "",
// System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
hashtableOfNodes.Add(currentDirectoryNode.subNodes[i].fullDirectoryPath, currentDirectoryNode.subNodes[i]);
newDirectoryAdded = true;
}
}
}
}
// Build TREE VIEW
public void getTreeViewData(ref TreeView pTreeView, string pFullDirectoryPath)
{
if (newDirectoryAdded)
{
// Reset the current data
pTreeView.Nodes.Clear();
// Build up a TreeView
pTreeView.Nodes.Add(recurseNodes(this.rootNode));
pTreeView.ExpandAll();
// pTreeView.SelectedNode = moveToNode;
newDirectoryAdded = false;
}
}
private TreeNode recurseNodes(DirectoryNode pWorkingNode)
{
TreeNode returnTreeNode = new TreeNode(pWorkingNode.directoryName);
if (pWorkingNode.subNodes != null)
{
for (int i=0; i<pWorkingNode.subNodes.Length; i++)
{
returnTreeNode.Nodes.Add(recurseNodes(pWorkingNode.subNodes[i]));
}
}
// if (pWorkingNode.directoryName == temp)
// moveToNode = returnTreeNode;
return returnTreeNode;
}
private TreeNode moveToNode;
public void getListViewData(ref ListView pListView, string pFullDirectoryPath)
{
// Find the node To Do: Error checking
DirectoryNode directoryNode = (DirectoryNode)hashtableOfNodes[pFullDirectoryPath];
if (directoryNode.fileData != null)
{
pListView.Items.Clear();
for (int i=0; i<directoryNode.fileData.Length; i++)
{
pListView.Items.Add(makeListViewItem(directoryNode.fileData[i],i));
}
}
}
private ListViewItem makeListViewItem(ServerFileData pfileData, int pPosition)
{
string[] itemArray = new string[6];
itemArray[0] = pfileData.fileName;
itemArray[1] = Convert.ToString(pfileData.size);
itemArray[2] = pfileData.date;
itemArray[3] = pfileData.permission;
itemArray[4] = pfileData.owner;
itemArray[5] = pfileData.group;
return (new ListViewItem(itemArray,pPosition));
}
public bool tryToSwitchDirectory(string pFullDirectoryPath)
{
// Find the node To Do: Error checking
DirectoryNode directoryNode = (DirectoryNode)hashtableOfNodes[pFullDirectoryPath];
this.currentDirectoryNode = directoryNode;
return directoryNode.fullyPopulated;
}
public string[] getFileNamesFromIntegerArray(int[] pSelectedFiles)
{
string[] fileNameArray = new string[pSelectedFiles.Length];
for (int i=0; i<pSelectedFiles.Length; i++)
fileNameArray[i] = this.currentDirectoryNode.fileData[pSelectedFiles[i]].fileName;
return fileNameArray;
}
public void flushCurrentDirectoryCache()
{
this.currentDirectoryNode.flushData();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -