// Appelé lors de la détection de la création d'un fichier. private void folderWatcherObect_Created(object sender, FileSystemEventArgs e) { if (watchedFolderList.InvokeRequired) { DirectoryWatcherEventDelegate d = new DirectoryWatcherEventDelegate(folderWatcherObect_Created); Invoke(d, new object[] { sender, e }); } else { Debug.Assert(!InvokeRequired); UpdateSystemTrayIconTextAndIcon(); string watchedPath = ((FileSystemWatcher)sender).Path; string file = e.FullPath; if (Directory.Exists(file)) { file = file + Path.DirectorySeparatorChar; } // Prend en note le fichier ajouté. var newFile = new WatchedFile { Path = file, DateDetected = DateTime.Now, DirectoryWatched = watchedPath }; watchedFiles.Add(newFile); if (notificationType == NotificationType.TemporaryNotification) { // Faire apparaître une notification temporaire. String title = "Nouveaux fichiers"; String message = String.Format( "De nouveaux fichiers sont apparus dans le répertoire {0}.\n\n{1}", newFile.DirectoryName, newFile.FileName); notifyIcon.ShowBalloonTip(0, title, message, ToolTipIcon.Info); } else if (notificationType == NotificationType.PermanentNotification) { permanentNotificationForm.AddFile(newFile); } // Mise à jour des informations affichées. UpdateData(); } }
// Appelé lors de la détection de la création d'un fichier. private void manualFolderCheck(string path) { Debug.Assert(!InvokeRequired); UpdateSystemTrayIconTextAndIcon(); string[] fileEntries = Directory.GetFiles(path); string[] dirEntries = Directory.GetDirectories(path); List <string> allEntries = fileEntries.ToList(); foreach (string a in dirEntries) { allEntries.Add(a + Path.DirectorySeparatorChar); } foreach (string filename in allEntries) { // Prend en note le fichier ajouté. var newFile = new WatchedFile { Path = filename, DateDetected = DateTime.Now, DirectoryWatched = path }; watchedFiles.Add(newFile); if (notificationType == NotificationType.PermanentNotification) { permanentNotificationForm.AddFile(newFile); } } if (allEntries.Count() > 0 && notificationType == NotificationType.TemporaryNotification) { // Faire apparaître une notification temporaire. String title = "Fichiers détectés"; String message = String.Format( "Le répertoire {0} contient des fichiers.", path); notifyIcon.ShowBalloonTip(0, title, message, ToolTipIcon.Info); } // Mise à jour des informations affichées. UpdateData(); }
public void AddFile(WatchedFile f) { if (InvokeRequired) { AddFileDelegate d = new AddFileDelegate(AddFile); Invoke(d, new object[] { f }); } else { // On aura pas besoin du timer de recall, s'il est en fonction, puisqu'on // va popper la fenêtre. RecallTimer.Enabled = false; Show(); Activate(); //MakeFormVisible(this); //Application.DoEvents(); fileNotifications.Add(f); FilesDetectedBinding.ResetBindings(false); } }