Improve the monitoring/adding algorithm to copy with lots/large files being added

Hopefully this simplifies the code and logic a little too
This commit is contained in:
Simon Pither 2010-06-14 10:42:04 +01:00
parent 10ff054edb
commit bec261198a

View file

@ -33,6 +33,8 @@ namespace SparkleShare {
private Timer FetchTimer; private Timer FetchTimer;
private Timer BufferTimer; private Timer BufferTimer;
private FileSystemWatcher Watcher; private FileSystemWatcher Watcher;
private bool HasChanged = false;
private DateTime LastChange;
public string Name; public string Name;
public string Domain; public string Domain;
@ -118,10 +120,19 @@ namespace SparkleShare {
}; };
FetchTimer.Start (); FetchTimer.Start ();
BufferTimer = new Timer ();
BufferTimer = new Timer ();
BufferTimer.Interval = 4000;
BufferTimer.Elapsed += delegate (object o, ElapsedEventArgs args) { BufferTimer.Elapsed += delegate (object o, ElapsedEventArgs args) {
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Done waiting."); SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Checking for changes.");
if (HasChanged) {
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Changes found, checking if settled.");
DateTime now = DateTime.UtcNow;
TimeSpan changed = new TimeSpan (now.Ticks - LastChange.Ticks);
if (changed.TotalMilliseconds > 5000) {
HasChanged = false;
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Changes have settled, adding.");
Add (); Add ();
string Message = FormatCommitMessage (); string Message = FormatCommitMessage ();
if (!Message.Equals ("")) { if (!Message.Equals ("")) {
@ -129,8 +140,12 @@ namespace SparkleShare {
Fetch (); Fetch ();
Push (); Push ();
} }
}
}
}; };
BufferTimer.Start ();
// Add everything that changed // Add everything that changed
// since SparkleShare was stopped // since SparkleShare was stopped
Add (); Add ();
@ -145,42 +160,10 @@ namespace SparkleShare {
WatcherChangeTypes wct = args.ChangeType; WatcherChangeTypes wct = args.ChangeType;
if (!ShouldIgnore (args.Name)) { if (!ShouldIgnore (args.Name)) {
SparkleHelpers.DebugInfo ("Event", "[" + Name + "] " + wct.ToString () + " '" + args.Name + "'"); SparkleHelpers.DebugInfo ("Event", "[" + Name + "] " + wct.ToString () + " '" + args.Name + "'");
StartBufferTimer ();
}
}
// A buffer that will fetch changes after
// file activity has settles down
public void StartBufferTimer ()
{
FetchTimer.Stop (); FetchTimer.Stop ();
int Interval = 4000; LastChange = DateTime.UtcNow;
if (!BufferTimer.Enabled) { HasChanged = true;
// Delay for a few seconds to see if more files change
BufferTimer.Interval = Interval;
BufferTimer.Elapsed += delegate (object o, ElapsedEventArgs args) {
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Done waiting.");
Add ();
};
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] " + "Waiting for more changes...");
BufferTimer.Start ();
} else {
// Extend the delay when something changes
BufferTimer.Close ();
BufferTimer = new Timer ();
BufferTimer.Interval = Interval;
FetchTimer.Start ();
BufferTimer.Start ();
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] " + "Waiting for more changes...");
} }
} }
// Clones a remote repo // Clones a remote repo
@ -209,6 +192,7 @@ namespace SparkleShare {
// SparkleUI.NotificationIcon.SetSyncingState (); // SparkleUI.NotificationIcon.SetSyncingState ();
// SparkleUI.NotificationIcon.SetIdleState (); // SparkleUI.NotificationIcon.SetIdleState ();
FetchTimer.Start (); FetchTimer.Start ();
BufferTimer.Start ();
} }
// Commits the made changes // Commits the made changes