private void CreateListener() { this.listener = SparkleListenerFactory.CreateListener(Name, Identifier); if (this.listener.IsConnected) { this.poll_interval = PollInterval.Long; new Thread(() => { if (!this.is_syncing && !HasLocalChanges && HasRemoteChanges) { SyncDownBase(); } }).Start(); } this.listener.Connected += ListenerConnectedDelegate; this.listener.Disconnected += ListenerDisconnectedDelegate; this.listener.AnnouncementReceived += ListenerAnnouncementReceivedDelegate; // Start listening if (!this.listener.IsConnected && !this.listener.IsConnecting) { this.listener.Connect(); } }
private void CreateListener() { this.listener = SparkleListenerFactory.CreateListener(Name, Identifier); if (this.listener.IsConnected) { this.poll_interval = PollInterval.Long; } this.listener.Disconnected += ListenerDisconnectedDelegate; this.listener.AnnouncementReceived += ListenerAnnouncementReceivedDelegate; if (!this.listener.IsConnected && !this.listener.IsConnecting) { this.listener.Connect(); } }
public void CreateListener() { this.listener = SparkleListenerFactory.CreateListener(Name, Identifier); if (this.listener.IsConnected) { this.poll_interval = this.long_interval; new Thread(new ThreadStart(delegate { if (!IsSyncing && CheckForRemoteChanges()) { SyncDownBase(); } })).Start(); } // 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; if (!IsSyncing) { // 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 this.listener.Disconnected += delegate { this.poll_interval = this.short_interval; SparkleHelpers.DebugInfo(Name, "Falling back to polling"); }; // Fetch changes when there is a message in the irc channel this.listener.Announcement += delegate(SparkleAnnouncement announcement) { string identifier = Identifier; if (announcement.FolderIdentifier.Equals(identifier) && !announcement.Message.Equals(CurrentRevision)) { while (this.IsSyncing) { System.Threading.Thread.Sleep(100); } SparkleHelpers.DebugInfo("Listener", "Syncing due to announcement"); SyncDownBase(); } else { if (announcement.FolderIdentifier.Equals(identifier)) { SparkleHelpers.DebugInfo("Listener", "Not syncing, message is for current revision"); } } }; // Start listening if (!this.listener.IsConnected && !this.listener.IsConnecting) { this.listener.Connect(); } }