using
System;
using System.Collections.Generic;
using System.Text;
using System.Security;
using System.Security.Permissions;
using System.IO;
using System.Data.SqlClient;
using WNSS.InfoCollection;
namespace WNSS
{
class FileWatcher
{
private FileWatcher()
{
throw new System.NotImplementedException();
}
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public static void StartWatcher(string Filepath, string strFilter, int flag)
{
FileSystemWatcher watcher = new FileSystemWatcher();
if (flag == 0)
{
watcher.Filter = strFilter;
watcher.Path = Filepath;
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Add event handlers.
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
watcher.EnableRaisingEvents = true;
}
else
{
watcher.EnableRaisingEvents = false;
}
//throw new System.NotImplementedException();
}//WatcherFile
private static void OnChanged(object source, FileSystemEventArgs e)
{
// Specify what is done when a file is changed, created, or deleted.
//Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
WNSSDataSetTableAdapters.FileTableAdapter fileAdapter = new WNSS.WNSSDataSetTableAdapters.FileTableAdapter();
fileAdapter.Insert(Client.testClientIP,
DateTime.Now,
e.ChangeType.ToString(),
e.FullPath);
}
private static void OnRenamed(object source, RenamedEventArgs e)
{
// Specify what is done when a file is renamed.
//Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
WNSSDataSetTableAdapters.FileTableAdapter fileAdapter = new WNSS.WNSSDataSetTableAdapters.FileTableAdapter();
fileAdapter.Insert(Client.testClientIP,
DateTime.Now,
"Rename",
e.OldFullPath + "," + e.FullPath);
}
public static void StopWatcher()
{
//watcher.EnableRaisingEvents = false;
//throw new System.NotImplementedException();
}
}//class
} // namesapce
using System.Collections.Generic;
using System.Text;
using System.Security;
using System.Security.Permissions;
using System.IO;
using System.Data.SqlClient;
using WNSS.InfoCollection;
namespace WNSS
{
class FileWatcher
{
private FileWatcher()
{
throw new System.NotImplementedException();
}
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public static void StartWatcher(string Filepath, string strFilter, int flag)
{
FileSystemWatcher watcher = new FileSystemWatcher();
if (flag == 0)
{
watcher.Filter = strFilter;
watcher.Path = Filepath;
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Add event handlers.
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
watcher.EnableRaisingEvents = true;
}
else
{
watcher.EnableRaisingEvents = false;
}
//throw new System.NotImplementedException();
}//WatcherFile
private static void OnChanged(object source, FileSystemEventArgs e)
{
// Specify what is done when a file is changed, created, or deleted.
//Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
WNSSDataSetTableAdapters.FileTableAdapter fileAdapter = new WNSS.WNSSDataSetTableAdapters.FileTableAdapter();
fileAdapter.Insert(Client.testClientIP,
DateTime.Now,
e.ChangeType.ToString(),
e.FullPath);
}
private static void OnRenamed(object source, RenamedEventArgs e)
{
// Specify what is done when a file is renamed.
//Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
WNSSDataSetTableAdapters.FileTableAdapter fileAdapter = new WNSS.WNSSDataSetTableAdapters.FileTableAdapter();
fileAdapter.Insert(Client.testClientIP,
DateTime.Now,
"Rename",
e.OldFullPath + "," + e.FullPath);
}
public static void StopWatcher()
{
//watcher.EnableRaisingEvents = false;
//throw new System.NotImplementedException();
}
}//class
} // namesapce