From 1100fa205b0087151c738a151a8abb28150e2da6 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sun, 13 Nov 2011 00:27:25 +0000 Subject: [PATCH] repo: When listening, make poll interval long for every repo --- SparkleLib/SparkleListenerBase.cs | 4 +-- SparkleLib/SparkleRepoBase.cs | 49 +++++++++++++++++++------------ 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/SparkleLib/SparkleListenerBase.cs b/SparkleLib/SparkleListenerBase.cs index ef27895e..4ef34a4d 100755 --- a/SparkleLib/SparkleListenerBase.cs +++ b/SparkleLib/SparkleListenerBase.cs @@ -165,7 +165,7 @@ namespace SparkleLib { public void OnConnected () { - SparkleHelpers.DebugInfo ("Listener", "Connected to " + Server); + SparkleHelpers.DebugInfo ("Listener", "Listening for announcements on " + Server); if (Connected != null) Connected (); @@ -185,7 +185,7 @@ namespace SparkleLib { public void OnDisconnected () { - SparkleHelpers.DebugInfo ("Listener", "Disonnected from " + Server); + SparkleHelpers.DebugInfo ("Listener", "Signal of " + Server + " lost"); if (Disconnected != null) Disconnected (); diff --git a/SparkleLib/SparkleRepoBase.cs b/SparkleLib/SparkleRepoBase.cs index 7cb2ca73..67dfd2d0 100755 --- a/SparkleLib/SparkleRepoBase.cs +++ b/SparkleLib/SparkleRepoBase.cs @@ -126,6 +126,7 @@ namespace SparkleLib { while (HasUnsyncedChanges) SyncUpBase (); + EnableWatching (); } @@ -232,18 +233,28 @@ namespace SparkleLib { { 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 this.listener.Connected += delegate { this.poll_interval = this.long_interval; this.last_poll = DateTime.Now; - // Check for changes manually one more time - if (CheckForRemoteChanges ()) - SyncDownBase (); + if (!IsSyncing) { - // Push changes that were made since the last disconnect - if (HasUnsyncedChanges) - SyncUpBase (); + // Check for changes manually one more time + if (CheckForRemoteChanges ()) + SyncDownBase (); + + // Push changes that were made since the last disconnect + if (HasUnsyncedChanges) + SyncUpBase (); + } }; // Start polling when the connection to the irc channel is lost @@ -259,30 +270,30 @@ namespace SparkleLib { if (announcement.FolderIdentifier.Equals (identifier) && !announcement.Message.Equals (CurrentRevision)) { - while (this.IsSyncing ()) { + while (this.IsSyncing) System.Threading.Thread.Sleep (100); - } - SparkleHelpers.DebugInfo ("Listener", "Syncing due to Announcement"); - if (!announcement.Message.Equals (CurrentRevision)) - SyncDownBase (); + + SparkleHelpers.DebugInfo ("Listener", "Syncing due to announcement"); + SyncDownBase (); + } else { 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 - if (!this.listener.IsConnected && !this.listener.IsConnecting) { + if (!this.listener.IsConnected && !this.listener.IsConnecting) this.listener.Connect (); - } } - private bool IsSyncing () - { - if (Status == SyncStatus.SyncUp || Status == SyncStatus.SyncDown || this.is_buffering) - return true; - return false; + private bool IsSyncing { + get { + return (Status == SyncStatus.SyncUp || + Status == SyncStatus.SyncDown || + this.is_buffering); + } }