public ActionResult Create(FormCollection collection) { try { // Process the form Utilities.UpdateType type = Utilities.UpdateType.News; if(string.Compare(collection["UpdateType"], Utilities.UpdateType.Event.ToString()) == 0) { type = Utilities.UpdateType.Event; } else if(string.Compare(collection["UpdateType"], Utilities.UpdateType.News.ToString()) == 0) { type = Utilities.UpdateType.News; } // Create update to be sent to the client Update update = new Update() { Name = collection["Name"], UpdateType = type.ToString(), PublishDate = DateTime.Now }; UpdateList.Add(update); BroadcastUpdate(update); return RedirectToAction("Create"); } catch { return View(); } }
/// <summary> /// Broadcasts the update to all connected clients. I've done this directly in the controller to /// demonstrate server -> client pushing, rather than client -> client pushing. /// </summary> /// <param name="updateItem">The update item.</param> internal static void BroadcastUpdate(Update updateItem) { // Fetch the hub's context to broadcast IHubContext context = GlobalHost.ConnectionManager.GetHubContext<LiveUpdate.Hubs.LiveUpdateHub>(); // Call the hub's feedUpdated method with our news / event item. context.Clients.feedUpdated(updateItem); }