Example #1
0
        public void OnAnnouncement(SparkleAnnouncement announcement)
        {
            SparkleHelpers.DebugInfo("Listener",
                                     "Got message " + announcement.Message + " from " +
                                     announcement.FolderIdentifier + " on " + Server);

            if (IsRecentAnnouncement(announcement))
            {
                SparkleHelpers.DebugInfo("Listener",
                                         "Ignoring previously processed message " + announcement.Message +
                                         " from " + announcement.FolderIdentifier + " on " + Server);

                return;
            }

            SparkleHelpers.DebugInfo("Listener",
                                     "Processing message " + announcement.Message + " from " +
                                     announcement.FolderIdentifier + " on " + Server);

            AddRecentAnnouncement(announcement);
            this.queue_down [announcement.FolderIdentifier] = announcement;

            if (Received != null)
            {
                Received(announcement);
            }
        }
Example #2
0
        private void ListenerAnnouncementReceivedDelegate(SparkleAnnouncement announcement)
        {
            string identifier = Identifier;

            if (!announcement.FolderIdentifier.Equals(identifier))
            {
                return;
            }

            if (!announcement.Message.Equals(CurrentRevision))
            {
                while (this.is_syncing)
                {
                    Thread.Sleep(100);
                }

                SparkleLogger.LogInfo(Name, "Syncing due to announcement");

                if (Status == SyncStatus.Paused)
                {
                    SparkleLogger.LogInfo(Name, "We're paused, skipping sync");
                }
                else
                {
                    SyncDownBase();
                }
            }
        }
Example #3
0
        public void Announce(SparkleAnnouncement announcement)
        {
            if (!IsRecentAnnouncement(announcement))
            {
                if (IsConnected)
                {
                    SparkleHelpers.DebugInfo("Listener",
                                             "Announcing message " + announcement.Message + " to " +
                                             announcement.FolderIdentifier + " on " + Server);

                    AnnounceInternal(announcement);
                    AddRecentAnnouncement(announcement);
                }
                else
                {
                    SparkleHelpers.DebugInfo("Listener",
                                             "Can't send message to " +
                                             Server + ". Queuing message");

                    this.queue_up [announcement.FolderIdentifier] = announcement;
                }
            }
            else
            {
                SparkleHelpers.DebugInfo("Listener",
                                         "Already processed message " + announcement.Message + " to " +
                                         announcement.FolderIdentifier + " from " + Server);
            }
        }
Example #4
0
        public void OnAnnouncement(SparkleAnnouncement announcement)
        {
            SparkleLogger.LogInfo("Listener", "Got message " + announcement.Message + " from " +
                                  announcement.FolderIdentifier + " on " + Server);

            if (IsRecentAnnouncement(announcement))
            {
                return;
            }

            AddRecentAnnouncement(announcement);
            AnnouncementReceived(announcement);
        }
        private void AddRecentAnnouncement(SparkleAnnouncement announcement)
        {
            List <SparkleAnnouncement> recent_announcements = this.GetRecentAnnouncements(announcement.FolderIdentifier);

            if (!IsRecentAnnounement(announcement))
            {
                recent_announcements.Add(announcement);
            }

            if (recent_announcements.Count > this.max_recent_announcements)
            {
                recent_announcements.RemoveRange(0, (recent_announcements.Count - this.max_recent_announcements));
            }
        }
        public override void Announce(SparkleAnnouncement announcement)
        {
            string to_send = "announce " + announcement.FolderIdentifier
                + " " + announcement.Message + "\n";

            try {

                lock (this.mutex) {
                    this.socket.Send (Encoding.UTF8.GetBytes (to_send));
                }
            } catch (SocketException e) {
              SparkleHelpers.DebugInfo ("ListenerTcp", "Could not connect to " + Server + ": " + e.Message);

              OnDisconnected ();
            }
        }
Example #7
0
        protected override void AnnounceInternal(SparkleAnnouncement announcement)
        {
            string to_send = "announce " + announcement.FolderIdentifier + " " + announcement.Message + "\n";

            try {
                if (this.socket != null)
                {
                    this.socket.Send(Encoding.UTF8.GetBytes(to_send));
                }

                this.last_ping = DateTime.Now;
            } catch (Exception e) {
                this.is_connected  = false;
                this.is_connecting = false;

                OnDisconnected(DisconnectReason.TimeOut, e.Message);
            }
        }
Example #8
0
        private bool IsRecentAnnouncement(SparkleAnnouncement announcement)
        {
            if (!this.recent_announcements.ContainsKey(announcement.FolderIdentifier))
            {
                return(false);
            }
            else
            {
                foreach (SparkleAnnouncement recent_announcement in GetRecentAnnouncements(announcement.FolderIdentifier))
                {
                    if (recent_announcement.Message.Equals(announcement.Message))
                    {
                        return(true);
                    }
                }

                return(false);
            }
        }
        public void Announce (SparkleAnnouncement announcement)
        {
            if (!IsRecentAnnouncement (announcement)) {
                if (IsConnected) {
                    SparkleLogger.LogInfo ("Listener", "Announcing message " + announcement.Message +
                        " to " + announcement.FolderIdentifier + " on " + Server);

                    AnnounceInternal (announcement);
                    AddRecentAnnouncement (announcement);

                } else {
                    SparkleLogger.LogInfo ("Listener", "Can't send message to " + Server + ". Queuing message");
                    this.queue_up [announcement.FolderIdentifier] = announcement;
                }

            } else {
                SparkleLogger.LogInfo ("Listener", "Already processed message " + announcement.Message +
                    " to " + announcement.FolderIdentifier + " from " + Server);
            }
        }
Example #10
0
        public void OnConnected()
        {
            foreach (string channel in this.channels.GetRange(0, this.channels.Count))
            {
                SparkleLogger.LogInfo("Listener", "Subscribing to channel " + channel + " on " + Server);
                AlsoListenToInternal(channel);
            }

            SparkleLogger.LogInfo("Listener", "Listening for announcements on " + Server);
            Connected();

            if (this.queue_up.Count > 0)
            {
                SparkleLogger.LogInfo("Listener", "Delivering " + this.queue_up.Count + " queued messages...");

                foreach (KeyValuePair <string, SparkleAnnouncement> item in this.queue_up)
                {
                    SparkleAnnouncement announcement = item.Value;
                    Announce(announcement);
                }
            }
        }
        public void OnConnected()
        {
            SparkleHelpers.DebugInfo("Listener", "Listening for announcements on " + Server);

            if (Connected != null)
            {
                Connected();
            }

            if (this.queue_up.Count > 0)
            {
                SparkleHelpers.DebugInfo("Listener", "Delivering " + this.queue_up.Count + " queued messages...");

                foreach (KeyValuePair <string, SparkleAnnouncement> item in this.queue_up)
                {
                    SparkleAnnouncement announcement = item.Value;
                    AnnounceBase(announcement);
                }

                this.queue_down.Clear();
            }
        }
Example #12
0
        // Fetch changes when there is an announcement
        private void ListenerAnnouncementReceivedDelegate(SparkleAnnouncement announcement)
        {
            string identifier = Identifier;

            if (announcement.FolderIdentifier.Equals(identifier) &&
                !announcement.Message.Equals(CurrentRevision))
            {
                while (this.is_syncing)
                {
                    Thread.Sleep(100);
                }

                SparkleLogger.LogInfo(Name, "Syncing due to announcement");
                SyncDownBase();
            }
            else
            {
                if (announcement.FolderIdentifier.Equals(identifier))
                {
                    SparkleLogger.LogInfo(Name, "Not syncing, message is for current revision");
                }
            }
        }
Example #13
0
        // Fetch changes when there is an announcement
        private void ListenerAnnouncementReceivedDelegate (SparkleAnnouncement announcement)
        {
            string identifier = Identifier;

            if (announcement.FolderIdentifier.Equals (identifier) &&
                !announcement.Message.Equals (CurrentRevision)) {

                while (this.is_syncing)
                    Thread.Sleep (100);

                SparkleLogger.LogInfo (Name, "Syncing due to announcement");
                SyncDownBase ();

            } else {
                if (announcement.FolderIdentifier.Equals (identifier))
                    SparkleLogger.LogInfo (Name, "Not syncing, message is for current revision");
            }
        }
Example #14
0
        public override void Announce(SparkleAnnouncement announcement)
        {
            string channel = announcement.FolderIdentifier;
            byte [] message = Encoding.UTF8.GetBytes (
               "{\"folder\": \"" + channel + "\", \"command\": \"publish\"}");
            this.socket.Send (message);

            // Also announce to ourselves for debugging purposes
            // base.OnAnnouncement (announcement);
        }
        public override void Announce(SparkleAnnouncement announcement)
        {
            string channel = "#" + announcement.FolderIdentifier;
            this.client.SendMessage (SendType.Message, channel, announcement.Message);

            // Also announce to ourselves for debugging purposes
            //OnRemoteChange (announcement);
        }
        private void AddRecentAnnouncement (SparkleAnnouncement announcement)
        {
            List<SparkleAnnouncement> recent_announcements =
                GetRecentAnnouncements (announcement.FolderIdentifier);

            if (!IsRecentAnnouncement (announcement))
                recent_announcements.Add (announcement);

            if (recent_announcements.Count > this.max_recent_announcements)
                recent_announcements.RemoveRange (0, recent_announcements.Count - this.max_recent_announcements);
        }
 protected abstract void AnnounceInternal (SparkleAnnouncement announcent);
        public override void Announce(SparkleAnnouncement announcement)
        {
            string to_send = "announce " + announcement.FolderIdentifier
                + " " + announcement.Message + "\n";

            lock (this.mutex) {
                this.socket.Send (Encoding.UTF8.GetBytes (to_send));
            }
        }
        private bool IsRecentAnnouncement (SparkleAnnouncement announcement)
        {
            if (!this.recent_announcements.ContainsKey (announcement.FolderIdentifier)) {
                return false;

            } else {
                foreach (SparkleAnnouncement recent_announcement in GetRecentAnnouncements (announcement.FolderIdentifier)) {
                    if (recent_announcement.Message.Equals (announcement.Message))
                        return true;
                }

                return false;
            }
        }
Example #20
0
        private void ListenerAnnouncementReceivedDelegate (SparkleAnnouncement announcement)
        {
            string identifier = Identifier;

            if (!announcement.FolderIdentifier.Equals (identifier))
                return;
                
            if (!announcement.Message.Equals (CurrentRevision)) {
                while (this.is_syncing)
                    Thread.Sleep (100);

                SparkleLogger.LogInfo (Name, "Syncing due to announcement");

                if (Status == SyncStatus.Paused)
                    SparkleLogger.LogInfo (Name, "We're paused, skipping sync");
                else
                    SyncDownBase ();
            }
        }
        protected override void AnnounceInternal(SparkleAnnouncement announcement)
        {
            string to_send = "announce " + announcement.FolderIdentifier + " " + announcement.Message + "\n";

            try {
                if (this.socket != null)
                    this.socket.Send (Encoding.UTF8.GetBytes (to_send));

                this.last_ping = DateTime.Now;

            } catch (Exception e) {
                this.is_connected  = false;
                this.is_connecting = false;

                OnDisconnected (e.Message);
            }
        }
Example #22
0
        public override void SyncUpNotes()
        {
            while (Status != SyncStatus.Idle) {
                System.Threading.Thread.Sleep (5 * 20);
            }

            SparkleGit git_push = new SparkleGit (LocalPath, "push origin refs/notes/*");
            git_push.Start ();
            git_push.WaitForExit ();

            if (git_push.ExitCode == 0) {
                SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Notes pushed");

            } else {
                HasUnsyncedChanges = true;
                SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing notes failed, trying again later");
            }

            SparkleAnnouncement announcement = new SparkleAnnouncement (Identifier, SHA1 (DateTime.Now.ToString ()));
            base.listener.Announce (announcement);
        }
Example #23
0
        public void AnnounceBase(SparkleAnnouncement announcement)
        {
            if (!this.IsRecentAnnounement (announcement)) {
                if (IsConnected) {
                    SparkleHelpers.DebugInfo ("Listener",
                        "Announcing message " + announcement.Message + " to " + announcement.FolderIdentifier + " on " + this.server);

                    Announce (announcement);
                    this.AddRecentAnnouncement (announcement);
                } else {
                    SparkleHelpers.DebugInfo ("Listener", "Can't send message to " + this.server + ". Queuing message");
                    this.queue_up [announcement.FolderIdentifier] = announcement;
                }

            } else {
                SparkleHelpers.DebugInfo ("Listener",
                    "Already processed message " + announcement.Message + " to " + announcement.FolderIdentifier + " from " + this.server);
            }
        }
 public abstract void Announce(SparkleAnnouncement announcent);
        public void AnnounceBase(SparkleAnnouncement announcement)
        {
            if (IsConnected) {
                SparkleHelpers.DebugInfo ("Listener",
                    "Announcing to " + announcement.FolderIdentifier + " on " + this.server);

                Announce (announcement);

            } else {
                SparkleHelpers.DebugInfo ("Listener", "Not connected to " + this.server + ". Queuing message");
                this.queue_up.Add (announcement);
            }
        }
Example #26
0
 protected abstract void AnnounceInternal(SparkleAnnouncement announcent);
        public override void Announce(SparkleAnnouncement announcement)
        {
            string to_send = "announce " + announcement.FolderIdentifier
                + " " + announcement.Message + "\n";

            try {

                lock (this.mutex) {
                    this.socket.Send (Encoding.UTF8.GetBytes (to_send));
                }
            } catch (SocketException e) {
              SparkleHelpers.DebugInfo ("ListenerTcp", "Could not connect to " + Server + ": " + e.Message);

              OnDisconnected ();
            }
        }
        public void OnAnnouncement (SparkleAnnouncement announcement)
        {
            SparkleLogger.LogInfo ("Listener", "Got message " + announcement.Message + " from " +
                announcement.FolderIdentifier + " on " + Server);

            if (IsRecentAnnouncement (announcement))
                return;

            AddRecentAnnouncement (announcement);
            AnnouncementReceived (announcement);
        }
 public abstract void Announce(SparkleAnnouncement announcent);
        public void OnAnnouncement (SparkleAnnouncement announcement)
        {
            SparkleHelpers.DebugInfo ("Listener",
                "Got message " + announcement.Message + " from " +
                announcement.FolderIdentifier + " on " + Server);

            if (IsRecentAnnouncement (announcement)) {
                SparkleHelpers.DebugInfo ("Listener", "Ignoring previously processed message " + announcement.Message +
                    " from " + announcement.FolderIdentifier + " on " + Server);
                
                  return;
            }

            SparkleHelpers.DebugInfo ("Listener", "Processing message " + announcement.Message + " from " +
                announcement.FolderIdentifier + " on " + Server);

            AddRecentAnnouncement (announcement);
            this.queue_down [announcement.FolderIdentifier] = announcement;

            AnnouncementReceived (announcement);
        }
        public void OnAnnouncement(SparkleAnnouncement announcement)
        {
            SparkleHelpers.DebugInfo ("Listener", "Got message from " + announcement.FolderIdentifier + " on " + this.server);

            this.queue_down.Add (announcement);

            if (Announcement != null)
                Announcement (announcement);
        }
        public override void Announce(SparkleAnnouncement announcement)
        {
            this.SendCommand(new TcpMessagePacket(announcement.FolderIdentifier, "new_version"));

            // Also announce to ourselves for debugging purposes
            // base.OnAnnouncement (announcement);
        }