/SparkleLib/SparkleWatcher.cs
C# | 63 lines | 33 code | 15 blank | 15 comment | 0 complexity | bb2c6d1373f81564d729aa4b6200ba03 MD5 | raw file
1// SparkleShare, a collaboration and sharing tool. 2// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com> 3// 4// This program is free software: you can redistribute it and/or modify 5// it under the terms of the GNU Lesser General Public License as 6// published by the Free Software Foundation, either version 3 of the 7// License, or (at your option) any later version. 8// 9// This program is distributed in the hope that it will be useful, 10// but WITHOUT ANY WARRANTY; without even the implied warranty of 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12// GNU General Public License for more details. 13// 14// You should have received a copy of the GNU General Public License 15// along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 18using System; 19using System.IO; 20 21namespace SparkleLib { 22 23 public class SparkleWatcher : FileSystemWatcher { 24 25 public event ChangeEventEventHandler ChangeEvent = delegate { }; 26 public delegate void ChangeEventEventHandler (FileSystemEventArgs args); 27 28 private Object thread_lock = new Object (); 29 30 31 public SparkleWatcher (string path) : base (path) 32 { 33 IncludeSubdirectories = true; 34 EnableRaisingEvents = true; 35 Filter = "*"; 36 37 Changed += OnChanged; 38 Created += OnChanged; 39 Deleted += OnChanged; 40 Renamed += OnChanged; 41 } 42 43 44 private void OnChanged (object sender, FileSystemEventArgs args) 45 { 46 ChangeEvent (args); 47 } 48 49 50 public void Enable () 51 { 52 lock (this.thread_lock) 53 EnableRaisingEvents = true; 54 } 55 56 57 public void Disable () 58 { 59 lock (this.thread_lock) 60 EnableRaisingEvents = false; 61 } 62 } 63}