public async Task <IActionResult> SendNotification([FromBody] NotificationHubs.Notification newNotification) { var content = JsonConvert.SerializeObject(new { Message = new { Token = "", Notification = new { Body = "This is an FCM notification message!", Title = "FCM Message", } } }); newNotification.Content = content; HubResponse <NotificationOutcome> pushDeliveryResult = await _notificationHubProxy.SendNotification(newNotification); if (pushDeliveryResult.CompletedWithSuccess) { return(Ok()); } return(BadRequest("An error occurred while sending push notification: " + pushDeliveryResult.FormattedErrorMessages)); }
private Task SendToConnection <T>(T message, Constants.Enums.MessageReponseKey action, string connectionId, bool isMySelf) { if (!string.IsNullOrEmpty(connectionId)) { HubResponse <T> result = new HubResponse <T>() { IsSucceed = true, Data = message, ResponseKey = GetResponseKey(action) }; if (isMySelf) { return(Clients.Client(connectionId).SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result))); } else { return(Clients.OthersInGroup(connectionId).SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result))); } } else { return(SendToCaller(Constants.HubMessages.UnknowErrorMsg, Constants.Enums.MessageReponseKey.Error)); } }
private async Task SendToGroup <T>(T message, Constants.Enums.MessageReponseKey action, string groupName, bool isMySelf = false) { if (!string.IsNullOrEmpty(groupName)) { HubResponse <T> result = new HubResponse <T>() { IsSucceed = true, Data = message, ResponseKey = GetResponseKey(action) }; if (isMySelf) { await Clients.Group(groupName).SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result).ToString(Newtonsoft.Json.Formatting.None)); } else { await Clients.OthersInGroup(groupName).SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result).ToString(Newtonsoft.Json.Formatting.None)); } } else { await SendToCaller(Constants.HubMessages.UnknowErrorMsg, Constants.Enums.MessageReponseKey.Error); } }
private Task SendToGroup <T>(T message, MessageReponseKey action, string groupName, bool isMySelf = false) { if (!string.IsNullOrEmpty(groupName)) { HubResponse <T> result = new HubResponse <T>() { IsSucceed = true, Data = message, ResponseKey = GetResponseKey(action) }; if (isMySelf) { return(Clients.Group(groupName).SendAsync(MixConstants.ServiceHub.ReceiveMethod, JObject.FromObject(result))); } else { return(Clients.OthersInGroup(groupName).SendAsync(MixConstants.ServiceHub.ReceiveMethod, JObject.FromObject(result))); } } else { return(SendToCaller(MixConstants.ServiceHub.UnknowErrorMsg, MessageReponseKey.Error)); } }
public async Task <IActionResult> Edit(Guid id, [FromForm] Plant plant) { if (id != plant.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var plantDb = await _context.Plants .FirstOrDefaultAsync(m => m.Id == id); plantDb.Name = plant.Name; plantDb.PlantFileUrl = plant.PlantFileUrl; plantDb.Points = plant.Points; plantDb.DeviceId = plant.DeviceId; plantDb.ScientificName = plant.ScientificName; plantDb.Family = plant.Family; plantDb.Description = plant.Description; plantDb.Surrounding = plant.Surrounding; plantDb.EndangeredLevel = plant.EndangeredLevel; _context.Update(plantDb); await _context.SaveChangesAsync(); var deviceId = await _context.PushRegistrations.FirstOrDefaultAsync(f => f.DeviceId == plantDb.DeviceId); if (deviceId != null) { HubResponse <NotificationOutcome> pushDeliveryResult = await _notificationHubProxy.SendNotification(new NotificationHubs.PushNotification { Content = $"One of your plants is updated: {plantDb.Points} points", Tags = new string[1] { deviceId.Tag }, Platform = deviceId.MobilePlatform }); } } catch (DbUpdateConcurrencyException) { if (!PlantExists(plant.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(plant)); }
private async Task SendToCaller <T>(T message, Constants.Enums.MessageReponseKey action) { HubResponse <T> result = new HubResponse <T>() { IsSucceed = true, Data = message, ResponseKey = GetResponseKey(action) }; await Clients.Caller.SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result).ToString(Newtonsoft.Json.Formatting.None)); }
public async Task <IActionResult> Create(NotificationHubs.Notification newNotification) { HubResponse <NotificationOutcome> pushDeliveryResult = await _notificationHubProxy.SendNotification(newNotification); if (pushDeliveryResult.CompletedWithSuccess) { return(RedirectToAction(nameof(Index))); } return(BadRequest("An error occurred while sending push notification: " + pushDeliveryResult.FormattedErrorMessages)); }
private Task SendToCaller <T>(T message, MessageReponseKey action) { HubResponse <T> result = new HubResponse <T>() { IsSucceed = true, Data = message, ResponseKey = GetResponseKey(action) }; return(Clients.Caller.SendAsync(MixConstants.ServiceHub.ReceiveMethod, JObject.FromObject(result))); }
public HubResponse CreateDraft(string name, int roundLimits, bool requireWatchers) { var user = _db.Users.Find(Context.User.GetUserId()); //Should never happen, but an additional check just in case var broadcaster = _db.Broadcasters.FirstOrDefault(b => b.Name == user.TwitchUsername); if (broadcaster == null) { throw new Exception("Sorry, this feature is only for broadcasters on twitch.tv (With a valid mtgbot.tv client application)."); } var newCubeDraft = new CubeDraft { BroadcasterId = broadcaster.Id, Created = DateTime.Now, Name = name, RoundTime = roundLimits, RequireWatchers = requireWatchers }; try { _db.CubeDrafts.Add(newCubeDraft); _db.SaveChanges(); } catch (DbEntityValidationException) { return(HubResponse.ErrorResponse("There was a problem saving this cube draft. If this problem persists, please contact the developer.")); } string username = null; try { username = BotService.StartCubeDraft(newCubeDraft.Id); } catch (Exception ex) { Log.Error("Error calling BotService.StartCubeDraft(" + newCubeDraft.Id + ")", ex); } if (username == null) { return(HubResponse.ErrorResponse("Unable to create draft. There is no bot available to support this draft. Please try again later.")); } Groups.Add(Context.ConnectionId, String.Format("draft/{0}/clients", newCubeDraft.Id)); return(HubResponse.SuccessResponse(new { Username = username, DraftId = newCubeDraft.Id })); }
private void SendToCaller <T>(T message, Constants.Enums.MessageReponseKey action) { HubResponse <T> result = new HubResponse <T>() { IsSucceed = true, Data = message, ResponseKey = GetResponseKey(action) }; Clients.Caller.SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result)); }
public async Task <IActionResult> SendNotification([FromBody] Common.Notification.Notification newNotification) { HubResponse <NotificationOutcome> pushDeliveryResult = await _notificationHubProxy.SendNotification(newNotification, _hubSignalRContext); if (pushDeliveryResult.CompletedWithSuccess) { return(Ok()); } return(StatusCode((int)HttpStatusCode.NoContent)); }
public async Task <IActionResult> SendNotification([FromBody] Notification newNotification) { HubResponse <NotificationOutcome> pushDeliveryResult = await _notificationHubProxy.SendNotification(newNotification); if (pushDeliveryResult.CompletedWithSuccess) { return(Ok()); } return(BadRequest("An error occurred while sending push notification: " + pushDeliveryResult.FormattedErrorMessages)); }
public async Task <IActionResult> RegisterForPushNotifications(string id, [FromBody] DeviceRegistration deviceUpdate) { HubResponse registrationResult = await _notificationHubProxy.RegisterForPushNotifications(id, deviceUpdate); if (registrationResult.CompletedWithSuccess) { return(Ok()); } return(BadRequest("An error occurred while sending push notification: " + registrationResult.FormattedErrorMessages)); }
public async Task <IActionResult> RegisterForPushNotifications(DeviceRegistration deviceUpdate) { HubResponse registrationResult = await _notificationHubProxy.RegisterForPushNotifications(deviceUpdate); if (registrationResult.CompletedWithSuccess) { return(Ok()); } return(StatusCode((int)HttpStatusCode.ExpectationFailed)); }
public HubResponse PairNextRound(int draftId) { try { var user = _db.Users.Find(Context.User.GetUserId()); var draft = _db.CubeDrafts .Include("Broadcaster").Single(c => c.Id == draftId); _draftService.EnsureBroadcaster(draft, user); Log.DebugFormat("Attempting to pair next round for draftId='{0}'", draftId); var tournament = GetTournament(draftId); //TODO: Remove //tournament.Matches.Clear(); //tournament.CurrentRound = 0; var pairings = tournament.PairNextRound(); Log.DebugFormat("Parings {0}", String.Join(", ", pairings)); foreach (var match in pairings) { match.ToDB(_db, draftId); } try { BotService.NotifyPairings(draftId, pairings); } catch (Exception ex) { Console.WriteLine(ex.Message); return (HubResponse.ErrorResponse("There was a problem notifiying players of the next round. Please try again later.")); } Clients.Group(String.Format("draft/{0}/clients", draftId)) .newPairings(tournament.CurrentRound, pairings); return(HubResponse.SuccessResponse()); } catch (InvalidOperationException ex) { return(HubResponse.ErrorResponse(ex.Message)); } catch (Exception ex) { return(HubResponse.ErrorResponse("An unhandled exception occurred: " + ex.Message)); } }
public HubResponse EndTournament(int draftId) { var user = _db.Users.Find(Context.User.GetUserId()); var draft = _db.CubeDrafts .Include("Broadcaster").Single(c => c.Id == draftId); _draftService.EndTournament(draft, user); Clients.Group(String.Format("draft/{0}/clients", draftId)).statusUpdate(CubeDraftStatus.ProductHandIn); BotService.UpdateCubeStatus(draft.Id); return(HubResponse.SuccessResponse()); }
private void SendToAll <T>(T message, Constants.Enums.MessageReponseKey action, bool isMySelf) { HubResponse <T> result = new HubResponse <T>() { IsSucceed = true, Data = message, ResponseKey = GetResponseKey(action) }; if (isMySelf) { Clients.All.SendAsync(Constants.HubMethods.ReceiveMethod, result); } else { Clients.Others.SendAsync(Constants.HubMethods.ReceiveMethod, result); } }
private async Task SendToAll <T>(T message, Constants.Enums.MessageReponseKey action, bool isMySelf) { HubResponse <T> result = new HubResponse <T>() { IsSucceed = true, Data = message, ResponseKey = GetResponseKey(action) }; if (isMySelf) { await Clients.All.SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result).ToString(Newtonsoft.Json.Formatting.None)); } else { await Clients.Others.SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result).ToString(Newtonsoft.Json.Formatting.None)); } }
private Task SendToAll <T>(T message, MessageReponseKey action, bool isMySelf) { HubResponse <T> result = new HubResponse <T>() { IsSucceed = true, Data = message, ResponseKey = GetResponseKey(action) }; if (isMySelf) { return(Clients.All.SendAsync(MixConstants.ServiceHub.ReceiveMethod, result)); } else { return(Clients.Others.SendAsync(MixConstants.ServiceHub.ReceiveMethod, result)); } }
public async Task <IActionResult> SendNotification() { var notification = new Notification() { Content = "{\"notification\":{\"title\":\"Notification Hub Test Notification\"," + "\"body\":\"This is a sample notification delivered by Azure Notification Hubs.\"}" + ",\"data\":{\"property1\":\"value1\",\"property2\":42}}" }; HubResponse <NotificationOutcome> pushDeliveryResult = await _notificationHubProxy.SendNotification(notification); if (pushDeliveryResult.CompletedWithSuccess) { return(Ok()); } return(BadRequest("An error occurred while sending push notification: " + pushDeliveryResult.FormattedErrorMessages)); }
private void SendToGroup <T>(T message, Constants.Enums.MessageReponseKey action, string groupName, bool isMySelf) { if (!string.IsNullOrEmpty(groupName)) { HubResponse <T> result = new HubResponse <T>() { IsSucceed = true, Data = message, ResponseKey = GetResponseKey(action) }; if (isMySelf) { Clients.Group(groupName).SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result)); } else { Clients.OthersInGroup(groupName).SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result)); } } }
private void SendToConnection <T>(T message, MessageReponseKey action, string connectionId, bool isMySelf) { if (!string.IsNullOrEmpty(connectionId)) { HubResponse <T> result = new HubResponse <T>() { IsSucceed = true, Data = message, ResponseKey = GetResponseKey(action) }; if (isMySelf) { Clients.Client(connectionId).SendAsync(receiveMethod, JObject.FromObject(result)); } else { Clients.OthersInGroup(connectionId).SendAsync(receiveMethod, JObject.FromObject(result)); } } }
public async Task <ActionResult <User> > PostUser(User user) { _context.Users.Add(user); await _context.SaveChangesAsync(); await _context.SaveChangesAsync(); NotificationHubProxy _notificationHubProxy = new NotificationHubProxy(standardNotificationHubConfiguration); NotificationHubs.Notification newNotification = new NotificationHubs.Notification(); newNotification.Content = "New user created: id = " + user.Id; newNotification.Title = "New user"; HubResponse <NotificationOutcome> pushDeliveryResult = await _notificationHubProxy.SendNotification(newNotification); if (pushDeliveryResult.CompletedWithSuccess) { Console.WriteLine("Push Message Succesful"); } return(CreatedAtAction("GetUser", new { id = user.Id }, user)); }
private async void SendNotification(PushNotificationIntegrationEvent newNotification) { HubResponse <NotificationOutcome> pushDeliveryResult = await _notificationHubProxy.SendNotification(newNotification); }