private bool HandleFeedUpdated(FeedUpdatedMessage fm) { List<FeedContent> fromFeed = fm.FeedItems; // Gets news balloons to be displayed Dictionary<string, ServerBalloon> fromServer = m_bubbles; int old = fromServer.Count, popped = 0, added = 0; foreach(ServerBalloon b in fromServer.Values) { // Check if the bubble need to be keept, or deleted if(fromFeed.Find(c => c.ContentID == b.ID) == null) { // Pop the balloon in the server not present in the feed EnqueueMessage(new PopObjectMessage(b.ID), fm.Sender); popped++; } } foreach(FeedContent i in fromFeed) { if(!fromServer.ContainsKey(i.ContentID)) { // Add the new balloon to the server and send content and state EnqueueMessage(new NewBalloonMessage(i.ContentID, Direction.Any, 0.2f, Vector2D.Zero), fm.Sender); EnqueueMessage(new BalloonContentUpdateMessage(i.ContentID, (BalloonType)i.Type, i.Title, i.Excerpt, i.URL, i.ImageURL), fm.Sender); EnqueueMessage(new BalloonStateUpdateMessage(i.ContentID, 0, Colour.Parse(i.BalloonColour), i.Votes), fm.Sender); added++; } } // remove all existing planes foreach (ServerPlane plane in m_planes.Values) { if (plane.Screen != null) { plane.Screen.Connection.SendMessage(new PopObjectMessage(plane.ID)); } } m_planes.Clear(); // add a new plane string planeID = String.Format("PLANE-{0}", m_nextPlaneID++); PlaneType planeType = (PlaneType)m_random.Next((int)PlaneType.InvalidType); Direction screenSide; Vector2D velocity; if (m_random.Next(2) == 0) { screenSide = Direction.Left; velocity = Configuration.PlaneVelocityRight; } else { screenSide = Direction.Right; velocity = Configuration.PlaneVelocityLeft; } EnqueueMessage(new PopObjectMessage(planeID)); EnqueueMessage(new NewPlaneMessage(planeID, planeType, screenSide, Configuration.PlaneInitialY, velocity, 0.0f)); Trace.WriteLine(String.Format("Server had {0} balloons, popped {1}, added {2}", old, popped, added)); return true; }
private bool HandleFeedUpdated(FeedUpdatedMessage fm) { List<FeedContent> fromFeed = fm.FeedItems; // Gets news balloons to be displayed Dictionary<string, ServerBalloon> fromServer = m_bubbles; int old = fromServer.Count, popped = 0, added = 0; foreach(KeyValuePair<string, ServerBalloon> i in fromServer) { ServerBalloon b = i.Value; // Check if the bubble need to be keept, or deleted if(fromFeed.Find(c => c.ContentID == b.ID) == null) { // Pop the balloon in the server not present in the feed EnqueueMessage(new PopBalloonMessage(b.ID), fm.Sender); popped++; } } foreach(FeedContent i in fromFeed) { if(!fromServer.ContainsKey(i.ContentID)) { // Add the new balloon to the server and send content and state EnqueueMessage(new NewBalloonMessage(i.ContentID, Direction.Any, 0.2f, Configuration.VelocityLeft), fm.Sender); EnqueueMessage(new BalloonContentUpdateMessage(i.ContentID, (BalloonType)i.Type, i.Title, i.Excerpt, i.URL, i.ImageURL), fm.Sender); EnqueueMessage(new BalloonStateUpdateMessage(i.ContentID, 0, Colour.Parse(i.BalloonColour), i.Votes), fm.Sender); added++; } } Trace.WriteLine(String.Format("Server had {0} balloons, popped {1}, added {2}", old, popped, added)); return true; }