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,19 +120,32 @@ 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.");
Add ();
string Message = FormatCommitMessage (); if (HasChanged) {
if (!Message.Equals ("")) { SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Changes found, checking if settled.");
Commit (Message); DateTime now = DateTime.UtcNow;
Fetch (); TimeSpan changed = new TimeSpan (now.Ticks - LastChange.Ticks);
Push (); if (changed.TotalMilliseconds > 5000) {
HasChanged = false;
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Changes have settled, adding.");
Add ();
string Message = FormatCommitMessage ();
if (!Message.Equals ("")) {
Commit (Message);
Fetch ();
Push ();
}
}
} }
}; };
BufferTimer.Start ();
// Add everything that changed // Add everything that changed
// since SparkleShare was stopped // since SparkleShare was stopped
Add (); Add ();
@ -145,44 +160,12 @@ 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 (); FetchTimer.Stop ();
LastChange = DateTime.UtcNow;
HasChanged = true;
} }
} }
// A buffer that will fetch changes after
// file activity has settles down
public void StartBufferTimer ()
{
FetchTimer.Stop ();
int Interval = 4000;
if (!BufferTimer.Enabled) {
// 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
public void Clone () public void Clone ()
{ {
@ -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