예제 #1
0
        internal void TaskDaemonEntryPoint(Utilities.Daemon daemon)
        {
            if (ConfigurationManager.IsEnabled(nameof(FolderWatcher)))
            {
                Logging.Debug特("FolderWatcherTask for library {0} SKIPPED: disabled by advanced settings.", LibraryRef);
            }

            Logging.Debug特("FolderWatcherTask for library {0} START", LibraryRef);

            Dictionary <string, FolderWatcherRecord> folder_watchset = new Dictionary <string, FolderWatcherRecord>();

            // Get the new list of folders to watch
            string           folders_to_watch_batch = LibraryRef?.FolderToWatch;
            HashSet <string> folders_to_watch       = new HashSet <string>();

            if (null != folders_to_watch_batch)
            {
                foreach (var folder_to_watch_batch in folders_to_watch_batch.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    folders_to_watch.Add(folder_to_watch_batch);
                }
            }
            else
            {
                return;
            }

            //Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
            lock (folder_watcher_records_lock)
            {
                //l1_clk.LockPerfTimerStop();
                // Kill off any unwanted folders
                HashSet <string> folders_to_watch_deleted = new HashSet <string>(folder_watcher_records.Keys);
                foreach (var folder_to_watch in folders_to_watch)
                {
                    folders_to_watch_deleted.Remove(folder_to_watch);
                }
                foreach (var folder_to_watch_deleted in folders_to_watch_deleted)
                {
                    Logging.Info("Deleting FolderWatcher for '{0}'", folder_to_watch_deleted);

                    folder_watcher_records[folder_to_watch_deleted].folder_watcher.Dispose();
                    folder_watcher_records.Remove(folder_to_watch_deleted);
                }

                // Create any new folders
                foreach (var folder_to_watch in folders_to_watch)
                {
                    if (!folder_watcher_records.ContainsKey(folder_to_watch))
                    {
                        Logging.Info("Creating FolderWatcher for '{0}'", folder_to_watch);
                        string[] parts = folder_to_watch.Split(new char[] { ';' }, 2);

                        FolderWatcherRecord fwr = new FolderWatcherRecord();
                        fwr.path           = parts[0];
                        fwr.tags           = (1 < parts.Length) ? parts[1] : null;
                        fwr.folder_watcher = new FolderWatcher(this, LibraryRef, fwr.path, fwr.tags);

                        folder_watcher_records[folder_to_watch] = fwr;
                    }
                }

                // Copy the list to local dict:
                foreach (var folder_watcher_record in folder_watcher_records)
                {
                    folder_watchset.Add(folder_watcher_record.Key, folder_watcher_record.Value);
                }
            }

            // Do the actual folder processing
            foreach (var folder_watcher_record in folder_watchset)
            {
                try
                {
                    folder_watcher_record.Value.folder_watcher.ExecuteBackgroundProcess(daemon);
                }
                catch (Exception ex)
                {
                    Logging.Warn(ex, "There was an exception while processing the watched folder '{0}'.", folder_watcher_record.Value.path);
                }
            }
        }
예제 #2
0
        internal void TaskDaemonEntryPoint(Utilities.Daemon daemon)
        {
            Dictionary <string, FolderWatcherRecord> folder_watchset = new Dictionary <string, FolderWatcherRecord>();

            // Get the new list of folders to watch
            string           folders_to_watch_batch = library.WebLibraryDetail.FolderToWatch;
            HashSet <string> folders_to_watch       = new HashSet <string>();

            if (null != folders_to_watch_batch)
            {
                foreach (var folder_to_watch_batch in folders_to_watch_batch.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    folders_to_watch.Add(folder_to_watch_batch);
                }
            }

            Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
            lock (folder_watcher_records_lock)
            {
                l1_clk.LockPerfTimerStop();
                // Kill off any unwanted folders
                HashSet <string> folders_to_watch_deleted = new HashSet <string>(folder_watcher_records.Keys);
                foreach (var folder_to_watch in folders_to_watch)
                {
                    folders_to_watch_deleted.Remove(folder_to_watch);
                }
                foreach (var folder_to_watch_deleted in folders_to_watch_deleted)
                {
                    Logging.Info("Deleting FolderWatcher for '{0}'", folder_to_watch_deleted);

                    folder_watcher_records[folder_to_watch_deleted].folder_watcher.Dispose();
                    folder_watcher_records.Remove(folder_to_watch_deleted);
                }

                // Create any new folders
                foreach (var folder_to_watch in folders_to_watch)
                {
                    if (!folder_watcher_records.ContainsKey(folder_to_watch))
                    {
                        Logging.Info("Creating FolderWatcher for '{0}'", folder_to_watch);
                        string[] parts = folder_to_watch.Split(new char[] { ';' }, 2);

                        FolderWatcherRecord fwr = new FolderWatcherRecord();
                        fwr.path           = parts[0];
                        fwr.tags           = (1 < parts.Length) ? parts[1] : null;
                        fwr.folder_watcher = new FolderWatcher(this, library, fwr.path, fwr.tags);

                        folder_watcher_records[folder_to_watch] = fwr;
                    }
                }

                // Copy the list to local dict:
                foreach (var folder_watcher_record in folder_watcher_records)
                {
                    folder_watchset.Add(folder_watcher_record.Key, folder_watcher_record.Value);
                }
            }

            // Do the actual folder processing
            foreach (var folder_watcher_record in folder_watchset)
            {
                try
                {
                    folder_watcher_record.Value.folder_watcher.TaskDaemonEntryPoint(daemon);
                }
                catch (Exception ex)
                {
                    Logging.Warn(ex, "There was an exception while processing the watched folder '{0}'.", folder_watcher_record.Value.path);
                }
            }
        }