From 2e6d8ac33e56a9ebb4a75040a6ed3cad3ad7e749 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sun, 22 May 2011 18:37:36 +0100 Subject: [PATCH] repo, listener base: make syncdown queue handle multiple channels --- SparkleLib/SparkleListenerBase.cs | 33 +++++++++++++++---------------- SparkleLib/SparkleRepoBase.cs | 15 +++++++------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/SparkleLib/SparkleListenerBase.cs b/SparkleLib/SparkleListenerBase.cs index c46b8a6f..4107c25c 100644 --- a/SparkleLib/SparkleListenerBase.cs +++ b/SparkleLib/SparkleListenerBase.cs @@ -100,10 +100,10 @@ namespace SparkleLib { // Announcements that weren't sent off // because we were disconnected - protected List announce_queue = new List (); + protected List queue_up = new List (); + protected List queue_down = new List (); protected string server; protected List channels = new List (); - protected int changes_queue = 0; protected bool is_connecting; @@ -117,14 +117,6 @@ namespace SparkleLib { } - // Announcements of remote changes that we've received - public int ChangesQueue { - get { - return this.changes_queue; - } - } - - public bool IsConnecting { get { return this.is_connecting; @@ -138,14 +130,21 @@ namespace SparkleLib { Announce (announcement); } else { SparkleHelpers.DebugInfo ("Listener", "Not connected to " + this.server + ". Queuing message"); - this.announce_queue.Add (announcement); + this.queue_up.Add (announcement); } } - public void DecrementChangesQueue () + public bool HasQueueDownAnnouncement (string folder_identifier) { - this.changes_queue--; + foreach (SparkleAnnouncement announcement in this.queue_down) { + if (announcement.FolderIdentifier.Equals (folder_identifier)) { + this.queue_down.Remove (announcement); + return true; + } + } + + return false; } @@ -156,12 +155,12 @@ namespace SparkleLib { if (Connected != null) Connected (); - if (this.announce_queue.Count > 0) { + if (this.queue_up.Count > 0) { SparkleHelpers.DebugInfo ("Listener", "Delivering queued messages..."); - foreach (SparkleAnnouncement announcement in this.announce_queue) + foreach (SparkleAnnouncement announcement in this.queue_up) AnnounceBase (announcement); - this.announce_queue = new List (); + this.queue_up = new List (); } } @@ -179,7 +178,7 @@ namespace SparkleLib { { SparkleHelpers.DebugInfo ("Listener", "Got message from " + announcement.FolderIdentifier + " on " + this.server); - this.changes_queue++; + this.queue_down.Add (announcement); if (RemoteChange != null) RemoteChange (announcement); diff --git a/SparkleLib/SparkleRepoBase.cs b/SparkleLib/SparkleRepoBase.cs index 2e11a6a6..d84544c1 100644 --- a/SparkleLib/SparkleRepoBase.cs +++ b/SparkleLib/SparkleRepoBase.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; // remove using System.IO; using System.Text.RegularExpressions; using System.Timers; @@ -117,10 +116,10 @@ namespace SparkleLib { if (this.is_polling && !this.listener.IsConnecting) this.listener.Connect (); - if (HasUnsyncedChanges){ - Console.WriteLine ("!!!!!!!!!!!!!!!!!!!!!!!!!");Console.WriteLine ("!!!!!!!!!!!!!!!!!!!!!!!!!");Console.WriteLine ("!!!!!!!!!!!!!!!!!!!!!!!!!"); + // In the unlikely case that we haven't synced up our + // changes or the server was down, sync up again + if (HasUnsyncedChanges) SyncUpBase (); - } }; this.remote_timer.Start (); @@ -269,16 +268,16 @@ namespace SparkleLib { // Fetch changes when there is a message in the irc channel this.listener.RemoteChange += delegate (SparkleAnnouncement announcement) { - if (announcement.FolderIdentifier == Identifier && + string identifier = Identifier; + + if (announcement.FolderIdentifier == identifier && !announcement.Message.Equals (CurrentRevision)) { if ((Status != SyncStatus.SyncUp) && (Status != SyncStatus.SyncDown) && !this.is_buffering) { - while (this.listener.ChangesQueue > 0) { + while (this.listener.HasQueueDownAnnouncement (identifier)) SyncDownBase (); - this.listener.DecrementChangesQueue (); - } } } };