Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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();
                }
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 5
0
        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));
            }
        }
Ejemplo n.º 6
0
        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 ();
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 9
0
        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);
            }
        }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 11
0
        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();
            }
        }
Ejemplo n.º 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");
                }
            }
        }
Ejemplo n.º 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");
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
 protected abstract void AnnounceInternal (SparkleAnnouncement announcent);
Ejemplo n.º 18
0
        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));
            }
        }
Ejemplo n.º 19
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;
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 24
0
 public abstract void Announce(SparkleAnnouncement announcent);
Ejemplo n.º 25
0
        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);
            }
        }
Ejemplo n.º 26
0
 protected abstract void AnnounceInternal(SparkleAnnouncement announcent);
Ejemplo n.º 27
0
        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 ();
            }
        }
Ejemplo n.º 28
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);
        }
Ejemplo n.º 29
0
 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);
        }
Ejemplo n.º 31
0
        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);
        }
Ejemplo n.º 32
0
        public override void Announce(SparkleAnnouncement announcement)
        {
            this.SendCommand(new TcpMessagePacket(announcement.FolderIdentifier, "new_version"));

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