repo: Move watcher to its own subclass
This commit is contained in:
parent
b1eef089d8
commit
9cfc42e812
|
@ -24,7 +24,8 @@ SOURCES = \
|
|||
SparkleListenerIrc.cs \
|
||||
SparkleOptions.cs \
|
||||
SparklePaths.cs \
|
||||
SparkleRepoBase.cs
|
||||
SparkleRepoBase.cs \
|
||||
SparkleWatcher.cs
|
||||
|
||||
|
||||
SMARTIRC4NET_FILES_EXPANDED = $(foreach file, $(SMARTIRC4NET_FILES), $(top_builddir)/$(file))
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
<Compile Include="SparkleListenerIrc.cs" />
|
||||
<Compile Include="SparkleBackend.cs" />
|
||||
<Compile Include="SparkleConfig.cs" />
|
||||
<Compile Include="SparkleWatcher.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ProjectExtensions>
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace SparkleLib {
|
|||
private TimeSpan short_interval = new TimeSpan (0, 0, 3, 0);
|
||||
private TimeSpan long_interval = new TimeSpan (0, 0, 10, 0);
|
||||
|
||||
private FileSystemWatcher watcher;
|
||||
private SparkleWatcher watcher;
|
||||
private SparkleListenerBase listener;
|
||||
private TimeSpan poll_interval;
|
||||
private Timer local_timer = new Timer () { Interval = 0.25 * 1000 };
|
||||
|
@ -211,16 +211,10 @@ namespace SparkleLib {
|
|||
|
||||
private void CreateWatcher ()
|
||||
{
|
||||
this.watcher = new FileSystemWatcher (LocalPath) {
|
||||
IncludeSubdirectories = true,
|
||||
EnableRaisingEvents = true,
|
||||
Filter = "*"
|
||||
this.watcher = new SparkleWatcher (LocalPath);
|
||||
this.watcher.ChangeEvent += delegate (FileSystemEventArgs args) {
|
||||
OnFileActivity (args);
|
||||
};
|
||||
|
||||
this.watcher.Changed += new FileSystemEventHandler (OnFileActivity);
|
||||
this.watcher.Created += new FileSystemEventHandler (OnFileActivity);
|
||||
this.watcher.Deleted += new FileSystemEventHandler (OnFileActivity);
|
||||
this.watcher.Renamed += new RenamedEventHandler (OnFileActivity);
|
||||
}
|
||||
|
||||
|
||||
|
@ -301,7 +295,7 @@ namespace SparkleLib {
|
|||
|
||||
|
||||
// Starts a timer when something changes
|
||||
public void OnFileActivity (object o, FileSystemEventArgs args)
|
||||
public void OnFileActivity (FileSystemEventArgs args)
|
||||
{
|
||||
if (args.FullPath.Contains (Path.DirectorySeparatorChar + "."))
|
||||
return;
|
||||
|
|
57
SparkleLib/SparkleWatcher.cs
Normal file
57
SparkleLib/SparkleWatcher.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
// SparkleShare, a collaboration and sharing tool.
|
||||
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace SparkleLib {
|
||||
|
||||
public class SparkleWatcher : FileSystemWatcher {
|
||||
|
||||
public delegate void ChangeEventEventHandler (FileSystemEventArgs args);
|
||||
public event ChangeEventEventHandler ChangeEvent;
|
||||
|
||||
|
||||
public SparkleWatcher (string path) : base (path)
|
||||
{
|
||||
IncludeSubdirectories = true;
|
||||
EnableRaisingEvents = true;
|
||||
Filter = "*";
|
||||
|
||||
Changed += delegate (object o, FileSystemEventArgs args) {
|
||||
if (ChangeEvent != null)
|
||||
ChangeEvent (args);
|
||||
};
|
||||
|
||||
Created += delegate (object o, FileSystemEventArgs args) {
|
||||
if (ChangeEvent != null)
|
||||
ChangeEvent (args);
|
||||
};
|
||||
|
||||
Deleted += delegate (object o, FileSystemEventArgs args) {
|
||||
if (ChangeEvent != null)
|
||||
ChangeEvent (args);
|
||||
};
|
||||
|
||||
Renamed += delegate (object o, RenamedEventArgs args) {
|
||||
if (ChangeEvent != null)
|
||||
ChangeEvent (args);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -57,7 +57,7 @@ namespace SparkleShare {
|
|||
|
||||
foreach (SparkleRepoBase repo in Repositories) {
|
||||
if (repo.Name.Equals (repo_name))
|
||||
repo.OnFileActivity (this, args);
|
||||
repo.OnFileActivity (args);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue