repo: When listening, make poll interval long for every repo

This commit is contained in:
Hylke Bons 2011-11-13 00:27:25 +00:00
parent 478ff8b33d
commit 1100fa205b
2 changed files with 32 additions and 21 deletions

View file

@ -165,7 +165,7 @@ namespace SparkleLib {
public void OnConnected () public void OnConnected ()
{ {
SparkleHelpers.DebugInfo ("Listener", "Connected to " + Server); SparkleHelpers.DebugInfo ("Listener", "Listening for announcements on " + Server);
if (Connected != null) if (Connected != null)
Connected (); Connected ();
@ -185,7 +185,7 @@ namespace SparkleLib {
public void OnDisconnected () public void OnDisconnected ()
{ {
SparkleHelpers.DebugInfo ("Listener", "Disonnected from " + Server); SparkleHelpers.DebugInfo ("Listener", "Signal of " + Server + " lost");
if (Disconnected != null) if (Disconnected != null)
Disconnected (); Disconnected ();

View file

@ -126,6 +126,7 @@ namespace SparkleLib {
while (HasUnsyncedChanges) while (HasUnsyncedChanges)
SyncUpBase (); SyncUpBase ();
EnableWatching (); EnableWatching ();
} }
@ -232,18 +233,28 @@ namespace SparkleLib {
{ {
this.listener = SparkleListenerFactory.CreateListener (Name, Identifier); this.listener = SparkleListenerFactory.CreateListener (Name, Identifier);
if (this.listener.IsConnected) {
this.poll_interval = this.long_interval;
if (!IsSyncing && CheckForRemoteChanges ())
SyncDownBase ();
}
// Stop polling when the connection to the irc channel is succesful // Stop polling when the connection to the irc channel is succesful
this.listener.Connected += delegate { this.listener.Connected += delegate {
this.poll_interval = this.long_interval; this.poll_interval = this.long_interval;
this.last_poll = DateTime.Now; this.last_poll = DateTime.Now;
// Check for changes manually one more time if (!IsSyncing) {
if (CheckForRemoteChanges ())
SyncDownBase ();
// Push changes that were made since the last disconnect // Check for changes manually one more time
if (HasUnsyncedChanges) if (CheckForRemoteChanges ())
SyncUpBase (); SyncDownBase ();
// Push changes that were made since the last disconnect
if (HasUnsyncedChanges)
SyncUpBase ();
}
}; };
// Start polling when the connection to the irc channel is lost // Start polling when the connection to the irc channel is lost
@ -259,30 +270,30 @@ namespace SparkleLib {
if (announcement.FolderIdentifier.Equals (identifier) && if (announcement.FolderIdentifier.Equals (identifier) &&
!announcement.Message.Equals (CurrentRevision)) { !announcement.Message.Equals (CurrentRevision)) {
while (this.IsSyncing ()) { while (this.IsSyncing)
System.Threading.Thread.Sleep (100); System.Threading.Thread.Sleep (100);
}
SparkleHelpers.DebugInfo ("Listener", "Syncing due to Announcement"); SparkleHelpers.DebugInfo ("Listener", "Syncing due to announcement");
if (!announcement.Message.Equals (CurrentRevision)) SyncDownBase ();
SyncDownBase ();
} else { } else {
if (announcement.FolderIdentifier.Equals (identifier)) if (announcement.FolderIdentifier.Equals (identifier))
SparkleHelpers.DebugInfo ("Listener", "Not syncing message is for current revision"); SparkleHelpers.DebugInfo ("Listener", "Not syncing, message is for current revision");
} }
}; };
// Start listening // Start listening
if (!this.listener.IsConnected && !this.listener.IsConnecting) { if (!this.listener.IsConnected && !this.listener.IsConnecting)
this.listener.Connect (); this.listener.Connect ();
}
} }
private bool IsSyncing () private bool IsSyncing {
{ get {
if (Status == SyncStatus.SyncUp || Status == SyncStatus.SyncDown || this.is_buffering) return (Status == SyncStatus.SyncUp ||
return true; Status == SyncStatus.SyncDown ||
return false; this.is_buffering);
}
} }