private static void OnRenamed(object source, RenamedEventArgs e) { Program.ClientForm.addtoConsole("Event triggered:" + e.ChangeType); Program.ClientForm.addtoConsole("Event triggered on:" + e.FullPath); //MessageBox.Show("OnRenameed Event Raised", "Client"); //MessageBox.Show("File: " + e.OldFullPath + " renamed to " + e.FullPath); string eventType = "rename"; LocalFileSysAccess.getFileAttributes timestamp = new LocalFileSysAccess.getFileAttributes(e.FullPath); fileBeingUsed.eventDetails eventdet = new fileBeingUsed.eventDetails(); eventdet.datetime = timestamp.lastModified; eventdet.filepath = e.FullPath; eventdet.eventType = eventType; if (Client.Program.filesInUse.alreadyPresent(eventdet)) { return; } else { Client.Program.filesInUse.addToList(eventdet); } //Client.MessageClasses.changedFile renamedFile = new Client.MessageClasses.changedFile(e.OldFullPath, e.FullPath, e.OldName, e.Name); string renamedStr = "<" + e.OldFullPath + ">:<" + e.FullPath + ">:<" + e.OldName + ">:<" + e.Name + ">"; Uploader upload = new Uploader(); upload.start(e.OldFullPath, "rename", renamedStr,timestamp.lastModified); Program.ClientForm.addtoConsole("Uploader thread started"); }
// Define the event handlers. private static void OnChanged(object source, FileSystemEventArgs e) { if (Configuration.flag.polling == true) { return; } string eventType; Program.ClientForm.addtoConsole("Event triggered:" + e.ChangeType); Program.ClientForm.addtoConsole("Event triggered on:" + e.FullPath); /* if (onchnageToggler==true) { onchnageToggler = false; } else { onchnageToggler = true; return; } */ //MessageBox.Show("OnChanged Event Raised", "Client"); //Thread.Sleep(1000); try { //watcher.EnableRaisingEvents = false; //MessageBox.Show("OnChangedFun : File: " + e.FullPath + " " + e.ChangeType); if(File.Exists(e.FullPath)) { // let it sleep to avoid multiple "change" detection // b/c IO is much slower than thread! // but for large files, this needs to be patched //Thread.Sleep(500); if (e.ChangeType == WatcherChangeTypes.Changed) { eventType = "change"; } else { eventType = "create"; // add file metadata to file list Client.LocalFileSysAccess.FileListMaintain fileMaintain = new Client.LocalFileSysAccess.FileListMaintain(); fileMaintain.addSingleFileToFileList(e.FullPath); } LocalFileSysAccess.getFileAttributes timestamp = new LocalFileSysAccess.getFileAttributes(e.FullPath); fileBeingUsed.eventDetails eventdet = new fileBeingUsed.eventDetails(); eventdet.datetime = timestamp.lastModified; eventdet.filepath = e.FullPath; eventdet.eventType = eventType; if(Client.Program.filesInUse.alreadyPresent(eventdet)) { return; } else { Client.Program.filesInUse.addToList(eventdet); } Uploader upload = new Uploader(); //if (e.ChangeType == WatcherChangeTypes.Changed) //{ upload.start(e.FullPath, eventType, null, timestamp.lastModified); Program.ClientForm.addtoConsole("Uploader thread started"); //} //else //{ // upload.start(e.FullPath, "create", null); //} } else { Program.ClientForm.addtoConsole("File does not exist."); } } finally { //watcher.EnableRaisingEvents = true; } }
static void uploadeverything(string path) { string filepath = path; string[] files; string[] directories; files = Directory.GetFiles(path); foreach (string file in files) { // Process each file string eventType = "signUpStart"; LocalFileSysAccess.getFileAttributes timestamp = new LocalFileSysAccess.getFileAttributes(file); fileBeingUsed.eventDetails eventdet = new fileBeingUsed.eventDetails(); eventdet.datetime = timestamp.lastModified; eventdet.filepath = file; eventdet.eventType = eventType; if (Client.Program.filesInUse.alreadyPresent(eventdet)) { //return; } else { Client.Program.filesInUse.addToList(eventdet); Uploader upload = new Uploader(); upload.start(file, "signUpStart", null, timestamp.lastModified); } } directories = Directory.GetDirectories(path); foreach (string directory in directories) { // Process each directory recursively uploadeverything(directory); } }