SENARIO : FTP 서버에 폴더가 거의없고 특정 사용자에게 속합니다. 총 공간이 10GB이고 각 사용자에게 1GB를 할당한다고 가정합니다. 즉 각 사용자가 1GB 인 10 명의 사용자를 수용 할 수 있습니다.asp.net (C#)을 사용하여 FileSystemWatcher를 사용하는 방법
사용자는 저장 공간을 활용하기 위해 모든 유형의 파일을 추가/삭제/편집 할 수 있습니다. 내가해야 할 일은 파일 저장을 위해 1 기가 바이트 공간을 초과하지 않도록 사용자를 제한하는 것입니다. 이것을 위해 FileSystemWatcher를 사용하여 사용자가 파일을 생성/삭제/편집 할 수 있도록 파일을 만들 때 1GB의 공간을 최소화하거나 삭제 공간을 추가 할 수 있도록 파일을 작성/삭제/편집했음을 알리려고합니다.
이것은 FSW를 사용하는 코딩 조각입니다. 사용자가 적절한 ID 및 암호로 로그인하면 각 폴더가 열리고 (FTP 서버에 있음) 모든 유형의 파일을 추가/삭제/편집 할 수 있으며 그에 따라 i가 ulitilized 된 공간을 모니터링 할 수 있습니다.
하지만 문제는 콘솔에서 작성된 이벤트 핸들러입니다. 나는이 코드가 실행될 때 어떤 일이 일어나는지 이해하지 못한다 ... 나는 FSW 클래스를 사용하여 사용자가 그의 폴더에서 변경 한 내용을 모니터링 할 수있는 방법을 모르겠다.
도와주세요 ... 고맙습니다
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
public class _Default: System.Web.UI.Page {
public class ClsFileSystemWatcher {
public static void OnChanged(object source, FileSystemEventArgs e) {
Console.WriteLine("File "+e.FullPath+" :"+e.ChangeType);
}
public static void OnDeleted(object source, FileSystemEventArgs e) {
Console.WriteLine("File "+e.FullPath+" :"+e.ChangeType);
}
public static void OnCreated(object source, FileSystemEventArgs e) {
Console.WriteLine("File "+e.FullPath+" :"+e.ChangeType);
}
public static void OnRenamed(object source, RenamedEventArgs e) {
Console.WriteLine("File "+e.OldFullPath+" [Changed to] "+e.FullPath);
}
public static void OnError(object source, ErrorEventArgs e) {
Console.WriteLine("Error "+e);
}
public void FileWatcher(string InputDir) {
using (FileSystemWatcher fsw = new FileSystemWatcher()) {
fsw.Path = InputDir;
fsw.Filter = @"*";
fsw.IncludeSubdirectories = true;
fsw.NotifyFilter = NotifyFilters.FileName|NotifyFilters.Attributes|NotifyFilters.LastAccess|NotifyFilters.LastWrite|NotifyFilters.Security|NotifyFilters.Size|NotifyFilters.CreationTime|NotifyFilters.DirectoryName;
fsw.Changed += OnChanged;
fsw.Created += OnCreated;
fsw.Deleted += OnDeleted;
fsw.Renamed += OnRenamed;
fsw.Error += OnError;
fsw.EnableRaisingEvents = true;
//string strOldFile = InputDir + "OldFile.txt";
//string strNewFile = InputDir + "CreatedFile.txt";
//// Making changes in existing file
//using (FileStream stream = File.Open(strOldFile, FileMode.Append))
//{
// StreamWriter sw = new StreamWriter(stream);
// sw.Write("Appending new line in Old File");
// sw.Flush();
// sw.Close();
//}
//// Writing new file on FileSystem
//using (FileStream stream = File.Create(strNewFile))
//{
// StreamWriter sw = new StreamWriter(stream);
// sw.Write("Writing First line into the File");
// sw.Flush();
// sw.Close();
//}
//File.Delete(strOldFile);
//File.Delete(strNewFile);
// Minimum time given to event handler to track new events raised by the filesystem.
Thread.Sleep(1000);
}
}
}
private DAL conn;
private string connection;
private string id = string.Empty;
protected void Page_Load(object sender, EventArgs e) {
connection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\project\\Desktop\\BE prj\\dbsan.mdb;Persist Security Info=False";
conn = new DAL(connection);
////*** Opening Respective Folder of a User ***////
DirectoryInfo directories = new DirectoryInfo(@"C:\\Inetpub\\ftproot\\san\\");
DirectoryInfo[] folderList = directories.GetDirectories();
if (Request.QueryString["id"] != null) {
id = Request.QueryString["id"];
}
string path = Path.Combine(@"C:\\Inetpub\\ftproot\\san\\", id);
int folder_count = folderList.Length;
for (int j = 0; j < folder_count; j++) {
if (Convert.ToString(folderList[j]) == id) {
Process p = new Process();
p.StartInfo.FileName = path;
p.Start();
}
}
ClsFileSystemWatcher FSysWatcher = new ClsFileSystemWatcher();
FSysWatcher.FileWatcher(path);
}
}
NTFS 디스크 할당량 사용은 어떻습니까? http://technet.microsoft.com/en-us/library/cc781892(WS.10).aspx – Lucero