/// <summary> /// Führt die Nutzerbenachrichtigung über eine eingegangene Push Nachricht und die /// damit verbundene Aktion durch. /// </summary> /// <param name="pushController">Referenz auf die Instanz des PushNotificationController.</param> /// <param name="pushMsg">Die eingegangene Push-Nachricht, für die /// die Benutzerbenachrichtigung durchgeführt wird.</param> private void performUserNotification(PushNotificationController pushController, PushMessage pushMsg) { string headline = null; string resourceKey = null; string resourceAppendix = null; switch (pushMsg.PushType) { case PushType.ANNOUNCEMENT_NEW: // Ermittle Überschrift und Ressourcen-Schlüssel für Nachrichteninhalt. headline = pushController.GetUserNotificationHeadline(pushMsg); resourceKey = pushController.GetUserNotificationContentLocalizationKey(pushMsg); // Toast mit Ankündigung. showToastNotification(headline, resourceKey); break; case PushType.CONVERSATION_MESSAGE_NEW: // Ermittle Überschrift und Ressourcen-Schlüssel für Nachrichteninhalt. headline = pushController.GetUserNotificationHeadline(pushMsg); resourceKey = pushController.GetUserNotificationContentLocalizationKey(pushMsg); // Toast mit Ankündigung. showToastNotification(headline, resourceKey); break; default: // Ermittle Überschrift und Ressourcen-Schlüssel für Nachrichteninhalt. headline = pushController.GetUserNotificationHeadline(pushMsg); resourceKey = pushController.GetUserNotificationContentLocalizationKey(pushMsg); resourceAppendix = pushController.GetResourceAppendix(pushMsg); // Ghost Toast. showSilentToastNotification(headline, resourceKey, resourceAppendix); break; } }
/// <summary> /// https://devdocs.line.me/en/#push-message /// Send messages to a user, group, or room at any time. /// INFO Use of the Push Message API is limited to certain plans. /// </summary> /// <param name="pushMessage"></param> public async Task PushAsync(PushMessage pushMessage) { using (HttpClient client = GetClient()) { JsonSerializerSettings settings = new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore }; settings.Converters.Add(new StringEnumConverter(true)); StringContent content = new StringContent( JsonConvert.SerializeObject(pushMessage, settings), Encoding.UTF8, "application/json"); var result = await client.PostAsync(pushEndpoint, content); if (result.IsSuccessStatusCode) { return; } else { throw new Exception(await result.Content.ReadAsStringAsync()); } //200 OK Request successful //400 Bad Request Problem with the request //401 Unauthorized Valid Channel access token is not specified //403 Forbidden Not authorized to use the API.Confirm that your account or plan is authorized to used the API. //429 Too Many Requests Exceeded the rate limit for API calls //500 Internal Server Error Error on the internal server } }
/// <summary> /// enque a message by taking our PushMessage, serializing it and adding its type to the front of the message /// </summary> /// <param name="msg"></param> public void Enque(PushMessage msg) { string msgStr = ToString(msg); var queueMsg = new CloudQueueMessage(msgStr); this.queue.AddMessage(queueMsg); }
private void Send() { try { // 產生 push playload PushMessage msg = new PushMessage(); msg.Aps.Badge = 1; msg.Aps.Sound = "default"; msg.Aps.Alert = "有一則推播通知"; // msg.Aps.ContentAvailable = 0; PushSender sender = new PushSender(); sender.PushMessage ( this.record.DeviceTokens, // device token msg, // push message, 不可超過2kb this.record.CertificateFilePath, // p12授權檔路徑 this.record.CertificatePassword, // 授權檔密碼 this.record.ServerMode // 推送到測試(false)或正式(true)server ); } catch (Exception ex) { MessageBox.Show("error happen:" + ex.ToString()); } }
/// <summary> /// Enque either a common or WP7 message to be sent to MPNS. Get message components and send it to the device /// </summary> /// <param name="devices">Devices to send the message to</param> /// <param name="msg">Message to send</param> public override void EnqueMessage(IEnumerable <DeviceDataModel> devices, PushMessage msg) { try { if (msg.MessageType == (short)PushMessageType.Toast) { this.EnqueWP7ToastNotification(devices, msg.Message["toast"]); } else if (msg.MessageType == (short)PushMessageType.Raw) { this.EnqueWP7RawNotification(devices, msg.Message["raw"]); } else if (msg.MessageType == (short)PushMessageType.Tile || msg.MessageType == (short)PushMessageType.Common) { this.EnqueWP7TileNotification(devices, msg.Message["title"], int.Parse(msg.Message["count"], CultureInfo.InvariantCulture), msg.Message["url"]); } else { return; } } catch (Exception) { if (this.NotificationFormatError != null) { this.NotificationFormatError(this, new NotificationEventArgs(new NotificationFormatException(msg))); } } }
public static async Task Push(string to, IEnumerable <IMessageObject> messages) { var accessToken = Environment.GetEnvironmentVariable("LINE_CHANNEL_ACCESS_TOKEN"); var client = new ServiceCollection().AddHttpClient().BuildServiceProvider().GetService <IHttpClientFactory>() .CreateClient(); client.DefaultRequestHeaders.Add("ContentType", "application/json"); client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}"); var requestItem = new PushMessage(to, messages); var bodyJson = JsonConvert.SerializeObject(requestItem, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); var content = new StringContent(bodyJson, Encoding.UTF8, "application/json"); var result = await client.PostAsync("https://api.line.me/v2/bot/message/push", content); if (result.IsSuccessStatusCode) { return; } var errorBodyTask = result.Content.ReadAsStringAsync(); throw new Exception(errorBodyTask.Result); }
private static string ToString(PushMessage o) { JavaScriptSerializer jser = new JavaScriptSerializer(); string contents = jser.Serialize(o); return(contents); }
bool HandlePush(PushMessage message) { try { JSONObject customJson = new JSONObject(message.CustomData); if (customJson.Has("r") && customJson.Has("g") && customJson.Has("b")) { int r = customJson.GetInt("r"); int g = customJson.GetInt("g"); int b = customJson.GetInt("b"); if (CurrentActivity != null) { CurrentActivity.Window.DecorView.FindViewById <View>(Android.Resource.Id.Content).SetBackgroundColor(Android.Graphics.Color.Rgb(r, g, b)); } } if (customJson.Has("id")) { Intent intent = new Intent(ApplicationContext, typeof(SecondActivity)); intent.SetFlags(ActivityFlags.NewTask); intent.PutExtra(SecondActivity.PUSH_MESSAGE_KEY, message.ToJson().ToString()); ApplicationContext.StartActivity(intent); return(true); } } catch (Exception) {} return(false); }
public async Task <bool> NotifyUser(string userId, string title, string body, string target, string image, NotificationOptions notificationType) { _logger.LogDebug($"Sending email messages to {userId} - {target}"); using var scope = _provider.CreateScope(); // this is called from a rabbitmq service so we're on a different scope // DI has to be manually constucted var subscriptionStore = scope.ServiceProvider.GetRequiredService <IPushSubscriptionStore>(); await _sendEmail(userId, title, body, target, image, notificationType); var pushMessage = new PushMessage(body) { Topic = title, Urgency = PushMessageUrgency.Normal }; try { //TODO: Adding PushSubscriptionContext as Singleton is a recipe for disaster //TODO: but this gets f****d if I don't _logger.LogDebug($"Sending GCM messages to {userId}"); _logger.LogDebug($"Using store {subscriptionStore.GetType()}"); await subscriptionStore.ForEachSubscriptionAsync(userId, (WP.PushSubscription subscription) => { _logger.LogInformation($"Sending to {target}"); _notificationService.SendNotificationAsync(subscription, pushMessage, target); }); return(true); } catch (Exception ex) { _logger.LogError(ex.Message); } return(false); }
public async Task TriggerPush(PushMessage pushMessage) { pushMessage.Message += $"-{DateTime.Now:dddd HH:mm:ss}"; var subscriptions = await _subscriptionsRepository.GetSubscriptionsAsync(); foreach (var sub in subscriptions) { var subscription = new PushSubscription(sub.Endpoint, sub.Key, sub.AuthSecret); var webPushClient = new WebPushClient(); try { webPushClient.SendNotification(subscription, JsonConvert.SerializeObject(pushMessage, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }), _vapidDetails); } catch (WebPushException exception) { Console.WriteLine("Http STATUS code" + exception.StatusCode); } catch (Exception exception) { await _subscriptionsRepository.RemoveSubscription(sub); Console.WriteLine(exception); } } }
protected override void StartActivityForPushMessage(PushMessage message) { if (!HandlePush(message)) { base.StartActivityForPushMessage(message); } }
public async Task SendNotificationsAsync() { SetNotificationProperties(new SubscriptionService(DataUnitOfWork, ObjectLocator), new PushServiceClient()); AngularPushNotification _notification = new AngularPushNotification { Title = "Test Notification", Body = $"This is test notification", Icon = "" }; string topic = null; int? timeToLive = null; PushMessageUrgency urgency = PushMessageUrgency.Normal; PushMessage notification = new PushMessage(WRAPPER_START + JsonConvert.SerializeObject(_notification, _jsonSerializerSettings) + WRAPPER_END) { Topic = topic, TimeToLive = timeToLive, Urgency = urgency }; try { var allSupscriptions = await _subscriptionsService.getAllSubscriptions(); foreach (MBPushSubscription subscription in allSupscriptions) { // fire-and-forget await _pushClient.RequestPushMessageDeliveryAsync(subscription.PushSubscription, notification); } } catch (Exception e) { } }
private async Task PushTransactions(IClientProxy clientsCaller, SubscribeModel subscribeModel, BlockRpcEntity model, BlockOperations operations) { foreach (var transaction in operations.Transactions) { var content = transaction.contents.Where(c => c.kind == TezosBlockOperationConstants.Transaction && c.metadata.operation_result.status == TezosBlockOperationConstants.OperationResultStatusApplied).ToList(); foreach (var transactionContent in content) { // Babylon upgrade - KT1 transactions are smart contract operations var txSource = transactionContent.GetTransactionSource(); var txDestination = transactionContent.GetTransactionDestination(); var txContent = transactionContent.GetInternalTransactionContent(); if (subscribeModel.TransactionAddresses.Contains("all") || subscribeModel.TransactionAddresses.Contains(txSource) || subscribeModel.TransactionAddresses.Contains(txDestination)) { var message = new PushMessage(new TransactionModel(model, transaction, txContent)); await clientsCaller.SendAsync("transactions", message); _log.LogDebug($"History Block {model.header.level} | " + $"Operation hash {transaction.hash} has been sent. TxSource={txSource}, TxDestination={txDestination}"); } } } }
public async Task <bool> InitiateSupportRequest(ChatViewModel message) { if (!string.IsNullOrEmpty(_chatSettings.CurrentChatUser)) { var user = await _userManager.FindByEmailAsync(_chatSettings.CurrentChatUser); if (!string.IsNullOrEmpty(user?.Id)) { //send firebase message to notify via web worker var pushMessage = new PushMessage(message.Message) { Topic = "New support chat message", Urgency = PushMessageUrgency.Normal }; await _subscriptionStore.ForEachSubscriptionAsync(user.Id, (PushSubscription subscription) => { _notificationService.SendNotificationAsync(subscription, pushMessage, string.Empty); }); // await _hub.SendUserAsync(user.Id, "support-message", new object[] { message }); //send slack message var slackResult = await _slackSupport.NotifyUser(message); return(true); } } return(false); }
public static async Task Invia() { FlurlClient _client; PushMessage pushMessage = new PushMessage(); pushMessage.notification_content = new NotificationContent(); try { var flurClient = Utils.GetBaseUrlForOperations("risorsa"); // News news = (News)contentService.GetById(node.Id); //pushMessage.notification_target.type = ""; pushMessage.notification_content.name = "A2"; // pushMessage.notification_content.title = node.GetValue("TitoloNews").ToString(); pushMessage.notification_content.title = "Titolo"; pushMessage.notification_content.body = "Contenuto"; var jobInJson = JsonConvert.SerializeObject(pushMessage); var json = new StringContent(jobInJson, Encoding.UTF8); json.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); dynamic data2 = await flurClient.PostAsync(json).ReceiveJson(); var expandoDic = (IDictionary <string, object>)data2; var name = expandoDic["notification_id"]; Console.WriteLine(name); } catch (FlurlHttpTimeoutException ex) { Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType + " " + ex); } catch (FlurlHttpException ex) { Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType + " " + ex); if (ex.Call.Response != null) { Console.WriteLine("Failed with response code " + ex.Call.Response.StatusCode); } else { Console.WriteLine("Totally failed before getting a response! " + ex.Message); } } catch (Exception ex) { Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType + " " + ex); }; }
// Based on the type of message, it is sent to appropriate connection private void ProcessMessage(PushMessage pushMsg) { // Check if APNS and MPNS support a given type bool ifAPNSSupportsType = this.apnsSupportedMessages[(PushMessageType)pushMsg.MessageType]; bool ifMPNSSupportsType = this.mpnsSupportedMessages[(PushMessageType)pushMsg.MessageType]; bool ifC2DMSupportsType = this.c2dmSupportedMessages[(PushMessageType)pushMsg.MessageType]; if (ifAPNSSupportsType) { // If APNS supports it, get the list of devices of the type APNS supports. IEnumerable <DeviceDataModel> ddmList = this.sds.SelectByDeviceTypeAndSubscription(pushMsg.SubscriptionName, this.apnsDevType); this.apnsConnection.EnqueMessage(ddmList, pushMsg); } if (ifMPNSSupportsType) { // If MPNS supports the message type, get the list of devices of MPNS type and subscribed to a given subscription IEnumerable <DeviceDataModel> ddmList = this.sds.SelectByDeviceTypeAndSubscription(pushMsg.SubscriptionName, this.mpnsDevType); this.mpnsConnection.EnqueMessage(ddmList, pushMsg); } if (ifC2DMSupportsType) { // If APNS supports it, get the list of devices of the type APNS supports. IEnumerable <DeviceDataModel> ddmList = this.sds.SelectByDeviceTypeAndSubscription(pushMsg.SubscriptionName, this.c2dmDevType); this.c2dmConnection.EnqueMessage(ddmList, pushMsg); } }
private async Task PushTransactions(BlockRpcEntity model, BlockOperations operations) { foreach (var transaction in operations.Transactions) { var content = transaction.contents.Where(c => c.kind == TezosBlockOperationConstants.Transaction && c.metadata.operation_result.status == TezosBlockOperationConstants.OperationResultStatusApplied).ToList(); foreach (var transactionContent in content) { // Babylon upgrade - KT1 transactions are smart contract operations var txSource = transactionContent.GetTransactionSource(); var txDestination = transactionContent.GetTransactionDestination(); var txContent = transactionContent.GetInternalTransactionContent(); var message = new PushMessage(new TransactionModel(model, transaction, txContent)); await _hubContext.Clients.Groups( $"transactions_{txSource}", $"transactions_{txDestination}", "transactions_all" ) .SendAsync("transactions", message); _log.LogDebug($"Block {model.header.level} | " + $"Operation hash {transaction.hash} has been sent to the following groups [transactions_{transactionContent.source}, transactions_{transactionContent.destination}, transactions_all]"); } } }
public async Task <Unit> UpdateOrder(CryptoOrder cryptoOrder) { try { Console.WriteLine($"Closed order {cryptoOrder.Uuid} as {cryptoOrder.OrderType} at {cryptoOrder.Limit}"); switch (cryptoOrder.OrderType) { case CryptoOrderType.LimitSell: Budget.Available += cryptoOrder.Price; var tradeForSellOrder = Trades.FirstOrDefault(t => t.SellOrder.Uuid == cryptoOrder.Uuid); if (tradeForSellOrder != null) { if (cryptoOrder.Canceled) { tradeForSellOrder.Status = TradeStatus.Bought; tradeForSellOrder.SellOrder.IsOpened = false; return(await Task.FromResult(Unit.Default)); } var tradeProfit = tradeForSellOrder.BuyOrder.Price.GetReadablePercentageChange(tradeForSellOrder.SellOrder.Price); Budget.Profit += tradeProfit; Budget.Earned += tradeForSellOrder.SellOrder.Price - tradeForSellOrder.BuyOrder.Price; Console.WriteLine($"{cryptoOrder.Uuid}: SELL - {tradeProfit}"); await _pushManager.TriggerPush(PushMessage.FromMessage($"Sold {Market} for profit {tradeProfit}%")); tradeForSellOrder.Profit = tradeProfit; tradeForSellOrder.Status = TradeStatus.Completed; tradeForSellOrder.SellOrder = cryptoOrder; } break; case CryptoOrderType.LimitBuy: var tradeForBuyOrder = Trades.FirstOrDefault(t => t.BuyOrder.Uuid == cryptoOrder.Uuid); if (tradeForBuyOrder != null) { await _pushManager.TriggerPush(PushMessage.FromMessage($"Bought {Market} at {cryptoOrder.Limit} BTC")); if (cryptoOrder.Canceled) { tradeForBuyOrder.Status = TradeStatus.Empty; tradeForBuyOrder.BuyOrder = new CryptoOrder(); return(await Task.FromResult(Unit.Default)); } tradeForBuyOrder.Status = TradeStatus.Bought; tradeForBuyOrder.BuyOrder = cryptoOrder; } break; } } finally { if (!IsInTestMode) { var traderData = await _traderGrain.GetTraderData(); traderData.CurrentTicker = Ticker; await _hubNotifier.UpdateTrader(traderData); } } return(await Task.FromResult(Unit.Default)); }
private void DoWork(object state) { DataContext context = new DataContext(); // get all subscribers for which the trigger datetime is within 30 seconds var dateOfNextDay = GetNextWeekday(DayOfWeekToNotify); var dateToNotify = new DateTime(dateOfNextDay.Year, dateOfNextDay.Month, dateOfNextDay.Day, TimeToNotify.Hour, TimeToNotify.Minute, TimeToNotify.Second); double totalMinutesSeperation = dateToNotify.Subtract(DateTime.UtcNow).TotalMinutes; IEnumerable <DataAccess.PushSubscription> subscribers = new List <DataAccess.PushSubscription>(); if (Math.Abs(totalMinutesSeperation) < (15 * 60)) { var hoursSeperation = totalMinutesSeperation / 60; // less than 15 hours either side of UTC, so lets start checking subscribers = context.PushSubscriptions.Where(ps => Math.Abs(ps.TimeOffset.TotalHours - hoursSeperation) < (1D / 60D)); } var pushNotificationManager = new PushNotificationManager(); var pushMessage = new PushMessage("ITS BEER TIME") { Topic = "Beer", Urgency = PushMessageUrgency.Normal, }; foreach (var pushSubscription in subscribers) { pushNotificationManager.SendNotificationAsync(pushSubscription.ToPushSubscription(context.PushSubscriptionKeys.Where(psk => psk.Endpoint == pushSubscription.Endpoint)), pushMessage, CancellationToken.None).Wait(); } }
/// <summary> /// Stores specified message item /// </summary> /// <param name="item">PushMessage instance</param> public void Save(PushMessage item) { try { _lock.EnterWriteLock(); List <PushMessage> messages; _storage.TryGetValue(item.Topic, out messages); if (messages != null) { messages.Add(item); } else { _storage.Add(item.Topic, new List <PushMessage>() { item }); } } finally { if (_lock.IsWriteLockHeld) { _lock.ExitWriteLock(); } } }
public void SendMessage(PushMessage msg) { lock (syncObject) { msgSendQueue.Enqueue(msg); } }
private static StartSerialResponse StartSerial(PushMessage message) { SerialInfo serialInfo = null; string user = null; string password = null; string equipment = null; string workarea = null; lock (_clientMessagesLock) { if (clients.ContainsKey(message.ClientUniqueID)) { var client = clients[message.ClientUniqueID]; user = client.UserName; password = client.Password; equipment = client.Equipment; workarea = client.WorkArea; if (client.Messages.ContainsKey(message.ServerMessageId)) { serialInfo = GetMessageData <SerialInfo>(client.Messages[message.ServerMessageId]); } } } if (user == null || password == null || serialInfo == null || workarea == null) { return new StartSerialResponse { Succeeded = false, Error = "Unknown Client or Serial" } } ; return(StartSerial(serialInfo, user, password, equipment, workarea)); }
public void MessageResponseReceived(string messageType, PushMessage messagePayload, string responseType, IDictionary <string, string> responsePayload, Java.Lang.Ref.WeakReference activityHolder) { // Handle a message response Log.Debug("MessageResponseReceived", messageType); if (messagePayload != null) { Log.Debug("MessageResponseReceived", messagePayload.ToJson()); } Log.Debug("MessageResponseReceived", responseType); if (responsePayload != null) { foreach (KeyValuePair <string, string> keypair in responsePayload) { Log.Debug("MessageResponseReceived", keypair.Key + " - " + keypair.Value); } } if (messageType == "push" && !string.IsNullOrEmpty(messagePayload.Url)) { Log.Debug("Debug: MessageResponseReceived Deeplinking with ", messagePayload.Url); ((AnnexioWebAppPage)App.Current.MainPage).ConfigureDeeplink(messagePayload.Url); } Dictionary <string, string> dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(messagePayload.ToJson()); if (messageType == "push" && dict.ContainsKey("deeplink")) { ((AnnexioWebAppPage)App.Current.MainPage).ConfigureDeeplink(dict["deeplink"]); } }
public static AbstractNotificationBuilder CreateNotification( Context context, BuildVersionCodes sdkInt, PushMessage pushMessage) { return(sdkInt >= 26 ? (AbstractNotificationBuilder) new OreoNotificationBuilder(context, pushMessage) : (AbstractNotificationBuilder) new NotificationBuilder(context, pushMessage)); }
public static async Task <bool> SendPush(PushMessage message) { try { Hub = NotificationHubClient.CreateClientFromConnectionString("Endpoint=sb://iot-tdc-2014hub-ns.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=YOXL/NF+JPM+VERp2d6LU95mQ0T0YfTj7C8fZ+PcXUU=", "iot-tdc-2014hub"); var user = HttpContext.Current.User.Identity.Name; var userTag = "username:"******"<toast><visual><binding template=\"ToastText01\"><text id=\"1\">" + message.Mensagem + "</text></binding></visual></toast>"; //Encoding Utf8 = new UTF8Encoding(false); //byte[] bytes = Encoding.Default.GetBytes(toast); //toast = Utf8.GetString(bytes); var result = await Hub.SendMpnsNativeNotificationAsync(prepareToastPayload(message.Mensagem, ""), userTag); } //if (message.Android) //{ // await Hub.SendGcmNativeNotificationAsync("{ \"data\" : {\"msg\":\"" + message.Mensagem + "\"}}"); //} } catch (System.Exception ex) { var text = ex.Message; return(false); } return(true); }
public JsonResult pushTags(PushMessage PushMessageModle) { HttpReSultMode result = new HttpReSultMode(); try { PushMessageModle.Id = Guid.NewGuid(); PushMessageModle.AddTime = DateTime.Now; PushMessageModle.UpdateTime = DateTime.Now; //rol.RoleDescription = PushMessageModle.RoleDescription; //rol.RoleOrder = PushMessageModle.RoleOrder; OPBiz.Add(PushMessageModle); JpushHelp jh = new JpushHelp(); string[] tags = { PushMessageModle.Tags }; jh.SendTagMsg(PushMessageModle.Title, PushMessageModle.Contents, tags); result.Code = 11; result.Data = "ok"; result.Msg = "发送成功"; } catch (Exception e) { result.Code = -11; result.Data = "Nok"; result.Msg = "发送失败" + e.ToString(); } return(Json(JsonHelper.ToJson(result, true), JsonRequestBehavior.AllowGet)); }
public async Task Publish_ShouldThrowArgumentExceptionWhenExpoTokenIsInvalid(string token) { var pushClient = new PushClient(); var message = new PushMessage(token); await Assert.ThrowsAsync <ArgumentException>(async() => await pushClient.Publish(message)); }
public async Task SendNotificationsAsync(Notification notificationObject) { var allSupscriptions = await _subscriptionsService.getAllSubscriptions(); foreach (MBSubscription subscription in allSupscriptions) { try { AngularPushNotification _notification = new AngularPushNotification { Title = notificationObject.Title, Body = $"{notificationObject.Body}", Icon = (notificationObject.Image != null) ? notificationObject.Image : "" }; string topic = null; int? timeToLive = null; PushMessageUrgency urgency = PushMessageUrgency.Normal; PushMessage notification = new PushMessage(WRAPPER_START + JsonConvert.SerializeObject(_notification, _jsonSerializerSettings) + WRAPPER_END) { Topic = topic, TimeToLive = timeToLive, Urgency = urgency }; // fire-and-forget var result = _pushClient.RequestPushMessageDeliveryAsync(subscription.PushSubscription, notification, CancellationToken.None); } catch (Exception e) { } } }
private static void CheckDPI(PushMessage message) { string user = string.Empty; string password = string.Empty; string equipment = string.Empty; lock (_clientMessagesLock) { if (clients[message.ClientUniqueID].Messages.Any(m => IsDPI(m.Value))) { return; } else { user = clients[message.ClientUniqueID].UserName; password = clients[message.ClientUniqueID].Password; equipment = clients[message.ClientUniqueID].Equipment; } } if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(equipment)) { return; } RefreshSerials(user, password, equipment); }
//4、调用推送方法 public void Send(string CoursePackID, string CourseGroupDiscussionID, string GroupID, string UserID, string UserType, string content, string UserName) { //int UserCounts = Convert.ToInt32(content); //int UserCounts = _userInfoBll.GetUserCount(new Entities.SearchUserinfo(){ ClassIdEqual="1"}); //聊天方法 //获取到各个具体参数的项目的数量 //Clients.Group("").onSend(content); //给所有的注册页面推送消息 PushMessage pushMessageModel = new PushMessage() { CoursePackID = Convert.ToInt32(CoursePackID), CourseGroupDiscussionID = Convert.ToInt32(CourseGroupDiscussionID), GroupID = Convert.ToInt32(GroupID), UserID = Convert.ToInt32(UserID), UserType = Convert.ToInt32(UserType), Content = content, CreateDate = DateTime.Now, UserName = UserName }; Clients.Group(GroupID).onSend(pushMessageModel); //HubContext.Clients.All.onSend(toDbChatMessage); //消息保存到数据库 // _PushMessageBLL.AddPushMessage(PushMessageModel); }
private async Task <PushMessage> RecordPushMessageResult(GoogleFCMResponseModel result, PushMessage pushValue) { FPS_PushHistory pushMessage = new FPS_PushHistory(); pushMessage.MessageSN = DateTime.Now.ToString("yyyyMMddhhmmss") + _serialAndEncryption.CreateUniqueSN(); pushMessage.DeviceID = pushValue.TargetDeviceID; pushMessage.Message_Data = pushValue.Data.isNull()? "" : pushValue.Data.ToString(); pushMessage.Message_Noti = pushValue.Notification.isNull()? "" : pushValue.Notification.ToString(); //目前僅使用單Device推播 pushMessage.Status = 1.Equals(result.success) ? "S" : "F"; pushMessage.Error = 1.Equals(result.success) ? "" : (result.results.FirstOrDefault().error); pushMessage.FCMAuth = pushValue.FCMAuth; pushMessage.PushID = result.multicast_id.ToString(); pushMessage.PushTime = DateTime.Now; var addRes = await _pushHistoryRepository.AddFPS_PushHistory(pushMessage); PushMessage apiBack = new PushMessage(); apiBack.MessageSN = pushMessage.MessageSN; apiBack.Status = pushMessage.Status; apiBack.ErrorMsg = pushMessage.Error; apiBack.DataTime = pushMessage.PushTime.ToString("yyyy/MM/dd HH:mm:ss"); return(apiBack); }
private static AcceptMaterialCallResponse AnswerMaterialCall(PushMessage message) { CallInfo callInfo = null; string user = null; string password = null; lock (_clientMessagesLock) { if (clients.ContainsKey(message.ClientUniqueID)) { var client = clients[message.ClientUniqueID]; user = client.UserName; password = client.Password; if (client.Messages.ContainsKey(message.ServerMessageId)) { callInfo = GetMessageData <CallInfo>(client.Messages[message.ServerMessageId]); } } } if (user == null || password == null || callInfo == null) { return new AcceptMaterialCallResponse { Succeeded = false, Error = "Unknown Client or CallId" } } ; return(AnswerMaterialCall(callInfo, user, password)); }
void OnPushReceived(PushMessage message) { Debug.Log ("Received push! " + message.Alert); if (message.Extras != null) { foreach (KeyValuePair<string, string> kvp in message.Extras) { Debug.Log (string.Format ("Extras Key = {0}, Value = {1}", kvp.Key, kvp.Value)); } } }
private static void MessageCallback(PushMessage msg) { foreach (var subscriber in _subscribers) { try { subscriber.Value.WriteLine("data:" + JsonConvert.SerializeObject(msg) + "\n"); subscriber.Value.Flush(); } catch(Exception ex) { StreamWriter sw; _subscribers.TryRemove(subscriber.Key, out sw); continue; } } }
public ActionResult Add(PushMessage model, bool isRedirect = false) { ViewData.Model = model; if (Request.HttpMethod == "POST") { model.IsUserSend = true; //這個必須設置為true if (pushMsgService.AddMessage(model, userId)) { if (isRedirect) { return RedirectToAction("index"); } else { AddAlertMsg("消息已发送"); } } } return View(model); }
/// <summary> /// Sendet ein Event an alle interessierten Abonnenten des Events. Die Abonnenten /// sind Views, welche über Änderungen informiert werden wollen, so dass die Views /// ihren Zustand aktualisieren können. /// </summary> /// <param name="pushMsg">Die eingegangene Push Nachricht aufgrund derer /// das zu versendende Event bestimmt wird.</param> private void sendViewUpdateEvent(PushMessage pushMsg) { // Benachrichtige View, so dass diese sich aktualisieren können. if (pushMsg != null) { switch (pushMsg.PushType) { case PushType.ANNOUNCEMENT_NEW: // Sende Event an Listener. // Sende ReceivedAnnouncement Event mit Kanal-Id des betroffenen Kanals. ReceivedAnnouncement?.Invoke(this, new AnnouncementReceivedEventArgs(pushMsg.Id1)); break; case PushType.CHANNEL_DELETED: // Sende ChannelDeleted Event mit Kanal-Id des betroffenen Kanals. ChannelDeleted?.Invoke(this, new ChannelDeletedEventArgs(pushMsg.Id1)); break; case PushType.CHANNEL_CHANGED: // Sende ChannelDeleted Event mit Kanal-Id des betroffenen Kanals. ChannelChanged?.Invoke(this, new ChannelChangedEventArgs(pushMsg.Id1)); break; case PushType.CONVERSATION_MESSAGE_NEW: // Sende ReceivedConverstionMessage Event. ReceivedConversationMessage?.Invoke(this, new ConversationRelatedEventArgs(pushMsg.Id1, pushMsg.Id2)); break; case PushType.GROUP_DELETED: GroupDeleted?.Invoke(this, new GroupRelatedEventArgs(pushMsg.Id1)); break; case PushType.PARTICIPANT_NEW: ParticipantNew?.Invoke(this, new GroupRelatedEventArgs(pushMsg.Id1)); break; case PushType.PARTICIPANT_LEFT: ParticipantLeft?.Invoke(this, new GroupRelatedEventArgs(pushMsg.Id1)); break; case PushType.PARTICIPANT_REMOVED: ParticipantLeft?.Invoke(this, new GroupRelatedEventArgs(pushMsg.Id1)); break; case PushType.CONVERSATION_NEW: ConversationNew?.Invoke(this, new ConversationRelatedEventArgs(pushMsg.Id1, pushMsg.Id2)); break; case PushType.CONVERSATION_DELETED: ConversationDeleted?.Invoke(this, new ConversationRelatedEventArgs(pushMsg.Id1, pushMsg.Id2)); break; case PushType.BALLOT_NEW: BallotNew?.Invoke(this, new BallotRelatedEventArgs(pushMsg.Id1, pushMsg.Id2)); break; case PushType.BALLOT_OPTION_NEW: BallotOptionNew?.Invoke(this, new BallotRelatedEventArgs(pushMsg.Id1, pushMsg.Id2)); break; case PushType.BALLOT_OPTION_ALL: BallotOptionNew?.Invoke(this, new BallotRelatedEventArgs(pushMsg.Id1, pushMsg.Id2)); break; case PushType.BALLOT_OPTION_VOTE: BallotOptionVote?.Invoke(this, new BallotRelatedEventArgs(pushMsg.Id1, pushMsg.Id2)); break; case PushType.BALLOT_OPTION_VOTE_ALL: BallotOptionVote?.Invoke(this, new BallotRelatedEventArgs(pushMsg.Id1, pushMsg.Id2)); break; case PushType.BALLOT_DELETED: BallotDeleted?.Invoke(this, new BallotRelatedEventArgs(pushMsg.Id1, pushMsg.Id2)); break; default: break; } } }
private async void PushMessage(string url, PushMessage msg) { using (HttpClient client = new HttpClient()) { HttpResponseMessage response = await client.PostAsJsonAsync(url, msg); } }
/// <summary> /// Behandelt eine eingehende Nachricht vom Typ PARTICIPANT_NEW. Fragt die Teilnehmer /// vom Server ab. Fügt den neuen Teilnehmer auch lokal der Gruppe hinzu. /// </summary> /// <param name="msg">Die empfangene Push Nachricht.</param> /// <returns>Liefert true, wenn Behandlung erfolgreich, ansonsten false.</returns> private async Task<bool> handleParticipantNewPushMsgAsync(PushMessage msg) { int groupId = msg.Id1; int participantId = msg.Id2; try { // Frage zunächst die Teilnehmer der Gruppe ab. List<User> participants = await groupController.GetParticipantsOfGroupAsync(groupId, false); if (participants != null && participants.Count > 0) { User addedParticipant = participants.Find(item => item.Id == participantId); // Füge Nutzer der Gruppe hinzu. if (addedParticipant != null) { groupController.AddParticipantToGroup(groupId, addedParticipant); // Setze HasNewEvent Flag. groupController.SetHasNewEventFlag(groupId, true); } } } catch (ClientException ex) { // Keine weitere Fehlerbehandlung hier, da dies Operationen im Hintergrund ablaufen. Debug.WriteLine("Handling of ParticipantNew push message failed. Message is {0}.", ex.Message); return false; } return true; }
/// <summary> /// Behandelt eine eingehende Push-Nachricht vom Typ GROUP_DELETED. Markiert /// die entsprechende Gruppe als gelöscht in den lokalen Datensätzen. /// </summary> /// <param name="msg">Die empfangene Push Nachricht.</param> /// <returns>Liefert true, wenn Behandlung erfolgreich, ansonsten false.</returns> private bool handleGroupDeletedPushMsg(PushMessage msg) { int groupId = msg.Id1; try { // Markiere Gruppe als gelöscht. groupController.MarkGroupAsDeleted(groupId); } catch (ClientException ex) { // Keine weitere Fehlerbehandlung hier, da dies Operationen im Hintergrund ablaufen. Debug.WriteLine("Handling of GroupDeleted push message failed. Message is {0}.", ex.Message); return false; } return true; }
public void PushMessage(PushMessage msg) { msg.Dt = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"); MessageCallback(msg); }
/// <summary> /// Behandelt eine eingehende Push Nachricht vom Typ MODERATOR_REMOVED. Entfernt den /// betroffenen Moderator aus Liste der Verantwortlichen für den angegebenen Kanal. /// </summary> /// <param name="msg">Die empfangene Push Nachricht.</param> /// <returns>Liefert true, wenn Behandlung erfolgreich, ansonsten false.</returns> private bool handleModeratorRemovedPushMsgAsync(PushMessage msg) { // Lese die Kanal-Id des betroffenen Kanals aus. int channelId = msg.Id1; // Lese die Moderator-Id des betroffenene Moderator aus. int moderatorId = msg.Id2; try { channelController.RemoveModeratorFromChannel(channelId, moderatorId); } catch (ClientException ex) { // Keine weitere Fehlerbehandlung hier, da dies Operationen im Hintergrund ablaufen. Debug.WriteLine("Handling of Moderator_Removed push message failed. Message is {0}.", ex.Message); return false; } return true; }
/// <summary> /// Behandelt eine eingehende Nachricht vom Typ GROUP_CHANGED. Fragt die neusten Gruppendaten /// vom Server ab. Aktualisiert den lokalen Datensatz der Gruppe. /// </summary> /// <param name="msg">Die empfangene Push Nachricht.</param> /// <returns>Liefert true, wenn Behandlung erfolgreich, ansonsten false.</returns> private async Task<bool> handleGroupChangedPushMsgAsync(PushMessage msg) { int groupId = msg.Id1; try { // Frage neuste Gruppendaten ab. Group newGroup = await groupController.GetGroupAsync(groupId, false); if (newGroup != null) { // Aktualisiere den Datensatz der Gruppe. groupController.UpdateGroup(newGroup, false); // Setze das HasNewEvent Flag. groupController.SetHasNewEventFlag(groupId, true); } } catch (ClientException ex) { // Keine weitere Fehlerbehandlung hier, da dies Operationen im Hintergrund ablaufen. Debug.WriteLine("Handling of GroupChanged push message failed. Message is {0}.", ex.Message); return false; } return true; }
/// <summary> /// Behandelt eine eingehende Push Nachricht vom Typ CHANNEL_DELETED. Markiert den /// Kanal lokal als gelöscht. /// </summary> /// <param name="msg">Die empfangene Push Nachricht.</param> /// <returns>Liefert true, wenn Behandlung erfolgreich, ansonsten false.</returns> private bool handleChannelDeletedPushMsg(PushMessage msg) { // Lese die Kanal-Id des betroffenen Kanals aus. int channelId = msg.Id1; try { channelController.MarkChannelAsDeleted(channelId); } catch (ClientException ex) { // Keine weitere Fehlerbehandlung hier, da dies Operationen im Hintergrund ablaufen. Debug.WriteLine("Handling of Channel_Deleted push message failed. Message is {0}.", ex.Message); return false; } return true; }
/// <summary> /// Behandelt eine eingehende Push Nachricht vom Typ CONVERSATION_MESSAGE_NEW. Ruft die /// empfange Nachricht vom Server ab und speichert sie in den lokalen Datensätzen ab. /// </summary> /// <param name="msg">Die empfangene Push Nachricht.</param> /// <returns>Liefert true, wenn Behandlung erfolgreich, ansonsten false.</returns> private async Task<bool> handleConversationMessageNewPushMsgAsync(PushMessage msg) { // Extrahiere Parameter. int groupId = msg.Id1; int conversationId = msg.Id2; try { // Frage höchste Nachrichtennummer für Kanal ab. int highestMsgNr = groupController.GetHighestMessageNumberOfConversation(conversationId); // Frage Nachrichten ab. List<ConversationMessage> messages = await groupController.GetConversationMessagesAsync( groupId, conversationId, highestMsgNr, false); if (messages != null) { if (messages.Count == 1) { bool successful = groupController.StoreConversationMessage(messages.First()); if (!successful) { Debug.WriteLine("handleConversationMessageNewPushMsgAsync: Trying to retrieve the missing data."); // Versuche Nachricht mit Abruf der notwendigen Daten zu speichern. await groupController.SynchronizeConversationsWithServerAsync(groupId, true); groupController.StoreConversationMessage(messages.First()); } else { // Setze HasNewEvent Flag. groupController.SetHasNewEventFlag(groupId, true); } } else { // Speichere die Nachrichten ab. groupController.StoreConversationMessages(groupId, conversationId, messages); // Setze HasNewEvent Flag. groupController.SetHasNewEventFlag(groupId, true); } } } catch (ClientException ex) { // Keine weitere Fehlerbehandlung hier, da dies Operationen im Hintergrund ablaufen. Debug.WriteLine("Handling of ConversationMessageNew push message failed. Message is {0}.", ex.Message); return false; } return true; }
/// <summary> /// Behandelt eine eingehende Push Nachricht vom Typ ANNOUNCEMENT_NEW. Ruft für den betroffenen Kanal /// die neusten Announcements vom Server ab und speichert diese in der lokalen Datenbank ab. /// </summary> /// <param name="msg">Die empfangende Push Nachricht.</param> /// <returns>Liefert true, wenn die PushNachricht erfolgreich behandelt wurde, ansonsten false.</returns> private async Task<bool> handleAnnouncementNewPushMsgAsync(PushMessage msg) { // Lese die Kanal-Id des betroffenen Kanals aus. int channelId = msg.Id1; // Frage ab, was aktuell die höchste MessageNumber ist für diesen Kanal. int highestMsgNr = channelController.GetHighestMsgNrForChannel(channelId); try { // Frage die Announcements für diesen Kanal ab. List<Announcement> announcements = await channelController.GetAnnouncementsOfChannelAsync(channelId, highestMsgNr, false); if (announcements != null) { // Speichere die abgerufenen Announcements ab. if (announcements.Count == 1) { await channelController.StoreReceivedAnnouncementAsync(announcements[0]); } else { await channelController.StoreReceivedAnnouncementsAsync(announcements); } } } catch(ClientException ex) { // Keine weitere Fehlerbehandlung hier, da dies Operationen im Hintergrund ablaufen. Debug.WriteLine("Handling of Announcement_New push message failed. Message is {0}.", ex.Message); return false; } return true; }
/// <summary> /// Behandelt eine eingehende Push Nachricht vom Typ MODERATOR_ADDED. Fügt den /// betroffenen Moderator als Verantwortlichen zu dem angegebenen Kanal hinzu. /// </summary> /// <param name="msg">Die empfangene Push Nachricht.</param> /// <returns>Liefert true, wenn Behandlung erfolgreich, ansonsten false.</returns> private async Task<bool> handleModeratorAddedPushMsgAsync(PushMessage msg) { // Lese die Kanal-Id des betroffenen Kanals aus. int channelId = msg.Id1; // Lese die Moderator-Id des betroffenene Moderator aus. int moderatorId = msg.Id2; try { // Frage Moderatorendatensätze des Kanals ab. List<Moderator> moderators = await channelController.GetResponsibleModeratorsAsync(channelId); if (moderators != null) { foreach (Moderator moderator in moderators) { if (moderator.Id == moderatorId) { ModeratorController moderatorController = new ModeratorController(); if (!moderatorController.IsModeratorStored(moderatorId)) { Debug.WriteLine("handleModeratorAddedPushMsgAsync: Need to store moderator with id {0} first.", moderator.Id); // Speichere den Moderator zunächst ab. moderatorController.StoreModerator(moderator); } // Füge den Moderator dem Kanal hinzu. channelController.AddModeratorToChannel(channelId, moderator); } } } } catch (ClientException ex) { // Keine weitere Fehlerbehandlung hier, da dies Operationen im Hintergrund ablaufen. Debug.WriteLine("handleModeratorAddedPushMsgAsync: Handling of Moderator_Added push message failed. Message is {0}.", ex.Message); return false; } return true; }
/// <summary> /// Gibt einen von der bevorzugten Sprache unabhängigen String zurück, der an die /// Beschreibung der Benachrichtigung angehängt wird. /// </summary> /// <param name="msg">Die empfangene Push Nachricht.</param> /// <returns>Den anzuhängenden String.</returns> public string GetResourceAppendix(PushMessage msg) { string resourceAppendix = string.Empty; switch (msg.PushType) { case PushType.PARTICIPANT_NEW: // Id2 ist die Id des betroffenen Teilnehmers. int participantId = msg.Id2; resourceAppendix = getParticipantName(participantId); break; case PushType.PARTICIPANT_LEFT: // Id2 ist die Id des betroffenen Teilnehmers. resourceAppendix = getParticipantName(msg.Id2); break; case PushType.PARTICIPANT_REMOVED: // Id2 ist die Id des betroffenen Teilnehmers. resourceAppendix = getParticipantName(msg.Id2); break; case PushType.CONVERSATION_NEW: // Id2 ist die Id der neuen Konversation. resourceAppendix = getConversationTitle(msg.Id2); break; case PushType.BALLOT_NEW: // Id2 ist die Id der neuen Abstimmung. resourceAppendix = getBallotTitle(msg.Id2); break; case PushType.BALLOT_OPTION_NEW: // Id2 ist die Id der betroffenen Abstimmung. resourceAppendix = getBallotTitle(msg.Id2); break; case PushType.BALLOT_OPTION_ALL: // Id2 ist die Id der betroffenen Abstimmung. resourceAppendix = getBallotTitle(msg.Id2); break; } return resourceAppendix; }
/// <summary> /// Behandelt eine eingehende Push Nachricht vom Typ CHANNEL_CHANGED. Ruft die Kanalinformationen /// des betroffenen Kanals ab und aktualisiert die lokalen Datensätze. /// </summary> /// <param name="msg">Die empfangene Push Nachricht.</param> /// <returns>Liefert true, wenn Behandlung erfolgreich, ansonsten false.</returns> private async Task<bool> handleChannelChangedPushMsgAsync(PushMessage msg) { // Lese die Kanal-Id des betroffenen Kanals aus. int channelId = msg.Id1; try { // Rufe die neuesten Informationen zum Kanal ab. Channel newChannel = await channelController.GetChannelInfoAsync(channelId); // Rufe aktuelle Instanz ab. Channel currentChannel = channelController.GetChannel(channelId); // Prüfe, ob Aktualisierung erforderlich. Es könnte sein der Nutzer dieser App selbst hat die // Aktualisierung ausgelöst, dann wäre der lokale Datensatz schon auf dem aktuellsten Stand. if (newChannel != null && DateTimeOffset.Compare(currentChannel.ModificationDate, newChannel.ModificationDate) < 0) { Debug.WriteLine("handleChannelChangedPushMsgAsync: Update required."); // Speichere die neusten Kanalinformationen lokal ab. channelController.ReplaceLocalChannelWhileKeepingNotificationSettings(newChannel); } else { Debug.WriteLine("handleChannelChangedPushMsgAsync: No update required."); return false; } } catch (ClientException ex) { // Keine weitere Fehlerbehandlung hier, da dies Operationen im Hintergrund ablaufen. Debug.WriteLine("Handling of Channel_Changed push message failed. Message is {0}.", ex.Message); return false; } return true; }
/// <summary> /// Gibt die Überschrift für die Nachricht zurück, mittels der dem Nutzer /// die eingetroffene Push Nachricht angekündigt wird. /// </summary> /// <param name="msg">Die eingegangene Push Nachricht als PushMessage Instanz.</param> /// <returns>Die Überschrift für die Nutzerbenachrichtigung.</returns> public string GetUserNotificationHeadline(PushMessage msg) { string headline = string.Empty; switch (msg.PushType) { case PushType.ANNOUNCEMENT_NEW: // Id1 ist die Kanal-Id in diesem Kontext. headline = getChannelName(msg.Id1); break; case PushType.CHANNEL_DELETED: // Id1 ist die Kanal-Id in diesem Kontext. headline = getChannelName(msg.Id1); break; case PushType.CONVERSATION_MESSAGE_NEW: string groupName = getGroupName(msg.Id1); string conversationTitle = getConversationTitle(msg.Id2); headline = groupName + ": " + conversationTitle; break; case PushType.GROUP_DELETED: headline = getGroupName(msg.Id1); break; case PushType.PARTICIPANT_NEW: headline = getGroupName(msg.Id1); break; case PushType.PARTICIPANT_LEFT: headline = getGroupName(msg.Id1); break; case PushType.PARTICIPANT_REMOVED: headline = getGroupName(msg.Id1); break; case PushType.CONVERSATION_NEW: headline = getGroupName(msg.Id1); break; case PushType.BALLOT_NEW: headline = getGroupName(msg.Id1); break; case PushType.BALLOT_OPTION_NEW: headline = getGroupName(msg.Id1); break; case PushType.BALLOT_OPTION_ALL: headline = getGroupName(msg.Id1); break; } return headline; }
/// <summary> /// Behandelt eine vom WNS empfangene RawNotification. Die Push Nachricht wird geparset und abhängig /// von ihrem Typ behandelt. /// </summary> /// <param name="receivedNotificationMessage">Die empfangene Notification in Form einer PushMessage Instanz.</param> /// <returns>Liefert true, wenn die PushNachricht erfolgreich behandelt wurde, ansonsten false.</returns> public async Task<bool> HandlePushNotificationAsync(PushMessage receivedNotificationMessage) { bool handledSuccessfully = false; if(receivedNotificationMessage == null) { return handledSuccessfully; } Debug.WriteLine("HandlePushNotificationAsync: Received message: \n {0}.", receivedNotificationMessage.ToString()); // Lese als erstes den Typ der empfangenen Push Nachricht aus. Behandle die PushNachricht nach Typ. PushType pushType = receivedNotificationMessage.PushType; switch (pushType) { case PushType.ANNOUNCEMENT_NEW: handledSuccessfully = await handleAnnouncementNewPushMsgAsync(receivedNotificationMessage); break; case PushType.ANNOUNCEMENT_DELETED: // Aktuell nicht unterstützt. break; case PushType.CHANNEL_CHANGED: handledSuccessfully = await handleChannelChangedPushMsgAsync(receivedNotificationMessage); break; case PushType.CHANNEL_DELETED: handledSuccessfully = handleChannelDeletedPushMsg(receivedNotificationMessage); break; case PushType.MODERATOR_ADDED: handledSuccessfully = await handleModeratorAddedPushMsgAsync(receivedNotificationMessage); break; case PushType.MODERATOR_CHANGED: // Aktuell nicht unterstützt. break; case PushType.MODERATOR_REMOVED: handledSuccessfully = handleModeratorRemovedPushMsgAsync(receivedNotificationMessage); break; case PushType.GROUP_DELETED: handledSuccessfully = handleGroupDeletedPushMsg(receivedNotificationMessage); break; case PushType.GROUP_CHANGED: handledSuccessfully = await handleGroupChangedPushMsgAsync(receivedNotificationMessage); break; case PushType.PARTICIPANT_NEW: handledSuccessfully = await handleParticipantNewPushMsgAsync(receivedNotificationMessage); break; case PushType.PARTICIPANT_LEFT: handledSuccessfully = handleParticipantLeftPushMsg(receivedNotificationMessage); break; case PushType.PARTICIPANT_REMOVED: handledSuccessfully = handleParticipantLeftPushMsg(receivedNotificationMessage); break; case PushType.PARTICIPANT_CHANGED: // Aktuell nicht unterstützt. break; case PushType.CONVERSATION_NEW: handledSuccessfully = await handleConversationNewPushMsgAsync(receivedNotificationMessage); break; case PushType.CONVERSATION_CHANGED: handledSuccessfully = await handleConversationChangedPushMsgAsync(receivedNotificationMessage); break; case PushType.CONVERSATION_CHANGED_ALL: handledSuccessfully = await handleConversationChangedAllPushMsgAsync(receivedNotificationMessage); break; case PushType.CONVERSATION_CLOSED: // Aktuell nicht unterstützt. Wird über CONVERSATION_CHANGED abgedeckt. break; case PushType.CONVERSATION_DELETED: handledSuccessfully = handleConversationDeletedPushMsgAsync(receivedNotificationMessage); break; case PushType.CONVERSATION_MESSAGE_NEW: handledSuccessfully = await handleConversationMessageNewPushMsgAsync(receivedNotificationMessage); break; case PushType.BALLOT_NEW: handledSuccessfully = await handleBallotNewPushMsgAsync(receivedNotificationMessage); break; case PushType.BALLOT_CHANGED: handledSuccessfully = await handleBallotChangedPushMsgAsync(receivedNotificationMessage); break; case PushType.BALLOT_CHANGED_ALL: handledSuccessfully = await handleBallotChangedAllPushMsgAsync(receivedNotificationMessage); break; case PushType.BALLOT_OPTION_NEW: handledSuccessfully = await handleOptionNewPushMsgAsync(receivedNotificationMessage); break; case PushType.BALLOT_OPTION_ALL: handledSuccessfully = await handleOptionAllPushMsgAsync(receivedNotificationMessage); break; case PushType.BALLOT_OPTION_DELETED: handledSuccessfully = handleOptionDeletedPushMsg(receivedNotificationMessage); break; case PushType.BALLOT_OPTION_VOTE: handledSuccessfully = await handleOptionVotePushMsgAsync(receivedNotificationMessage); break; case PushType.BALLOT_OPTION_VOTE_ALL: handledSuccessfully = await handleOptionVoteAllPushMsgAsync(receivedNotificationMessage); break; case PushType.BALLOT_CLOSED: // Aktuell nicht unterstützt. Wird über BALLOT_CHANGED abgedeckt. break; case PushType.BALLOT_DELETED: handledSuccessfully = handleBallotDeletedPushMsg(receivedNotificationMessage); break; case PushType.USER_CHANGED: handledSuccessfully = await handleUserChangedPushMsgAsync(receivedNotificationMessage); break; default: break; } return handledSuccessfully; }
/// <summary> /// Behandelt eine eingehende Nachricht vom Typ USER_CHANGED. /// Ruft den neusten Datensatz des Nutzers ab und aktualisiert die lokalen Datensätze. /// </summary> /// <param name="msg">Die empfangene Push Nachricht.</param> /// <returns>Liefert true, wenn Behandlung erfolgreich, ansonsten false.</returns> private async Task<bool> handleUserChangedPushMsgAsync(PushMessage msg) { int userId = msg.Id1; try { UserController userController = new UserController(); User affectedUser = await userController.GetUserAsync(userId); if (affectedUser != null) { List<User> tmpUsers = new List<User>(); tmpUsers.Add(affectedUser); // Verwende Operation, die abhängig von den lokalen Datensätzen entweder den // Nutzer einfügt oder den Datensatz aktualisiert. userController.AddOrUpdateUsers(tmpUsers); } } catch (ClientException ex) { // Keine weitere Fehlerbehandlung hier, da dies Operationen im Hintergrund ablaufen. Debug.WriteLine("Handling of UserChanged push message failed. Message is {0}.", ex.Message); return false; } return true; }
/// <summary> /// Liefert den Schlüssel mittels dem der Inhalt der Nutzerbenachrichtigung über die /// eingegangene Push Nachricht aus den Resource Dateien extrahiert werden kann. Mittels /// diesem Schlüssel kann man also den anzuzeigenden Inhalt der Nutzerbenachrichtigung in der /// vom Nutzer bevorzugten Sprache ermitteln. /// </summary> /// <param name="msg">Die eingegangene Push Nachricht in Form einer PushMessage Instanz.</param> /// <returns>Den Schlüssel mittels dem der Inhalt der Nutzerbenachrichtigung extrahiert werden kann.</returns> public string GetUserNotificationContentLocalizationKey(PushMessage msg) { string localizationKey = string.Empty; switch (msg.PushType) { case PushType.ANNOUNCEMENT_NEW: localizationKey = "PushNotificationReceivedAnnouncementNew"; break; case PushType.CHANNEL_DELETED: localizationKey = "PushNotificationReceivedChannelDeleted"; break; case PushType.CONVERSATION_MESSAGE_NEW: localizationKey = "PushNotificationReceivedConversationMessageNew"; break; case PushType.GROUP_DELETED: localizationKey = "PushNotificationReceivedGroupDeleted"; break; case PushType.PARTICIPANT_NEW: localizationKey = "PushNotificationParticipantNew"; break; case PushType.PARTICIPANT_LEFT: localizationKey = "PushNotificationParticipantLeft"; break; case PushType.PARTICIPANT_REMOVED: localizationKey = "PushNotificationParticipantRemoved"; break; case PushType.CONVERSATION_NEW: localizationKey = "PushNotificationConversationNew"; break; case PushType.BALLOT_NEW: localizationKey = "PushNotificationBallotNew"; break; case PushType.BALLOT_OPTION_NEW: localizationKey = "PushNotificationOptionNew"; break; case PushType.BALLOT_OPTION_ALL: localizationKey = "PushNotificationOptionAll"; break; } return localizationKey; }
/// <summary> /// Behandelt eine eingehende Nachricht vom Typ BALLOT_OPTION_VOTE_ALL. /// Stößt eine Synchronisation der Votes für jede der Optionen der Abstimmung an. /// </summary> /// <param name="msg">Die empfangene Push Nachricht.</param> /// <returns>Liefert true, wenn Behandlung erfolgreich, ansonsten false.</returns> private async Task<bool> handleOptionVoteAllPushMsgAsync(PushMessage msg) { int groupId = msg.Id1; int ballotId = msg.Id2; try { // Frage Options und zugehörige Votes für diese Abstimmung ab. List<Option> options = await groupController.GetOptionsForBallotAsync(groupId, ballotId, true, false); if (options != null && options.Count > 0) { // Gehe Optionen durch und Synchronisiere die Votes für jede Option. foreach (Option option in options) { List<int> referenceVotes = null; if (option.VoterIds == null) { // Leere Liste. referenceVotes = new List<int>(); } else { referenceVotes = option.VoterIds; } // Synchronisiere die Votes für die betroffene Abstimmungsoption. groupController.SynchronizeLocalVotesForOption(groupId, ballotId, option.Id, referenceVotes); } } } catch (ClientException ex) { // Keine weitere Fehlerbehandlung hier, da dies Operationen im Hintergrund ablaufen. Debug.WriteLine("Handling of OptionVoteAll push message failed. Message is {0}.", ex.Message); return false; } return true; }
/// <summary> /// Bestimmt für eine gegebene PushMessage anhand der lokalen Einstellungen des Nutzers /// und anhand des Typs der Push Nachricht, ob eine Benachrichtigung des Benutzers erforderlich /// ist. /// </summary> /// <param name="pm">Die Push Nachricht in Form eines PushMessage Objekts.</param> /// <returns>Liefert true, wenn der Benutzer benachrichtigt werden soll, ansonsten false.</returns> public bool IsUserNotificationRequired(PushMessage pm) { if (pm == null) return false; AppSettings appSettings = GetApplicationSettings(); bool notificationRequired = false; switch(pm.PushType) { case PushType.ANNOUNCEMENT_NEW: // Prüfe Anwendungseinstellungen ab. Soll der Nutzer über die eingetroffene Announcement informiert werden? int channelId = pm.Id1; Debug.WriteLine("It will be checked whether the user needs to be notified about the received announcement" + " for the channel with id {0}.", channelId); notificationRequired = checkNotificationRequiredForNewAnnouncement(appSettings, channelId); break; case PushType.CONVERSATION_MESSAGE_NEW: // Prüfe Anwendungseinstellungen ab. Soll der Nutzer über die eingetroffene Konversationsnachricht informiert werden? int groupId = pm.Id1; int conversationId = pm.Id2; Debug.WriteLine("It will be checked whether the user needs to be notified about the received conversation message" + " for the group with id {0} and the conversation with id {1}.", groupId, conversationId); notificationRequired = checkNotificationRequiredForConversationMessage(appSettings, groupId, conversationId); break; case PushType.CHANNEL_DELETED: // Informieren bei Kanal-Löschung. notificationRequired = true; break; case PushType.GROUP_DELETED: // Informieren bei Gruppen-Löschung. notificationRequired = true; break; case PushType.PARTICIPANT_NEW: // Informieren bei Teilnehmer hinzugefügt. notificationRequired = true; break; case PushType.PARTICIPANT_LEFT: // Informiere bei Teilnehmer ausgetreten. notificationRequired = true; break; case PushType.PARTICIPANT_REMOVED: // Informiere bei Teilnehmer ausgetreten. notificationRequired = true; break; case PushType.CONVERSATION_NEW: // Informiere bei neuer Konversation. notificationRequired = true; break; case PushType.BALLOT_NEW: // Informiere bei neuer Abstimmung. notificationRequired = true; break; case PushType.BALLOT_OPTION_NEW: // Informiere bei neuer Abstimmungsoption. notificationRequired = true; break; case PushType.BALLOT_OPTION_ALL: // Informiere bei großer Anzahl geänderter Abstimmungsoptionen. notificationRequired = true; break; } return notificationRequired; }
/// <summary> /// Behandelt eine eingehende Nachricht vom Typ BALLOT_OPTION_ALL. Stößt eine Synchronisation /// der betroffenen Abstimmung an. /// </summary> /// <param name="msg">Die empfangene Push Nachricht.</param> /// <returns>Liefert true, wenn Behandlung erfolgreich, ansonsten false.</returns> private async Task<bool> handleOptionAllPushMsgAsync(PushMessage msg) { int groupId = msg.Id1; int ballotId = msg.Id2; try { // Stoße Synchronisation der gesamten Abstimmung an. await groupController.SynchronizeBallotWithServerAsync(groupId, ballotId); } catch (ClientException ex) { // Keine weitere Fehlerbehandlung hier, da dies Operationen im Hintergrund ablaufen. Debug.WriteLine("Handling of OptionAll push message failed. Message is {0}.", ex.Message); return false; } return true; }
/// <summary> /// Behandelt eine eingehende Nachricht vom Typ BALLOT_DELETED. /// Löscht die angegebene Abstimmung aus den lokalen Datensätzen. /// </summary> /// <param name="msg">Die empfangene Push Nachricht.</param> /// <returns>Liefert true, wenn Behandlung erfolgreich, ansonsten false.</returns> private bool handleBallotDeletedPushMsg(PushMessage msg) { int groupId = msg.Id1; int ballotId = msg.Id2; try { // Lösche Abstimmung aus den lokalen Datensätzen. groupController.DeleteBallot(ballotId); // Setze das HasNewEvent Flag. groupController.SetHasNewEventFlag(groupId, true); } catch (ClientException ex) { // Keine weitere Fehlerbehandlung hier, da dies Operationen im Hintergrund ablaufen. Debug.WriteLine("Handling of BallotDeleted push message failed. Message is {0}.", ex.Message); return false; } return true; }
/// <summary> /// Behandelt eine eingehende Nachricht vom Typ BALLOT_CHANGED. Ruft die Daten der geänderten /// Abstimmung ab. Aktualisiert die lokalen Datensätze. /// </summary> /// <param name="msg">Die empfangene Push Nachricht.</param> /// <returns>Liefert true, wenn Behandlung erfolgreich, ansonsten false.</returns> private async Task<bool> handleBallotChangedPushMsgAsync(PushMessage msg) { int groupId = msg.Id1; int ballotId = msg.Id2; try { // Frage zunächst die Daten der Abstimmung ab. Ballot ballot = await groupController.GetBallotAsync(groupId, ballotId, false, false); if (ballot != null) { bool successful = groupController.UpdateBallot(ballot); if (!successful) { Debug.WriteLine("handleBallotChangedPushMsgAsync: Fallback behavior."); await groupController.SynchronizeBallotsWithServerAsync(groupId, true); } else { // Setze HasNewEvent Flag. groupController.SetHasNewEventFlag(groupId, true); } } } catch (ClientException ex) { // Keine weitere Fehlerbehandlung hier, da dies Operationen im Hintergrund ablaufen. Debug.WriteLine("Handling of BallotChanged push message failed. Message is {0}.", ex.Message); return false; } return true; }
/// <summary> /// Behandelt eine eingehende Nachricht vom Typ BALLOT_OPTION_VOTE. Fragt die Nutzer ab, /// die für die betroffene Abstimmungsoption gestimmt haben. Synchronisiert dann die lokalen Datensätze /// für diese Abstimmungsoption. /// </summary> /// <param name="msg">Die empfangene Push Nachricht.</param> /// <returns>Liefert true, wenn Behandlung erfolgreich, ansonsten false.</returns> private async Task<bool> handleOptionVotePushMsgAsync(PushMessage msg) { int groupId = msg.Id1; int ballotId = msg.Id2; int optionId = msg.Id3; try { // Frage Liste von Nutzern ab, die für diese Abstimmungsoption gestimmt haben. List<User> voters = await groupController.GetVotersForOptionAsync(groupId, ballotId, optionId); if (voters != null && voters.Count > 0) { List<int> voterIds = new List<int>(); foreach (User voter in voters) { voterIds.Add(voter.Id); } // Synchronisiere die Votes für die betroffene Abstimmungsoption. groupController.SynchronizeLocalVotesForOption(groupId, ballotId, optionId, voterIds); } } catch (ClientException ex) { // Keine weitere Fehlerbehandlung hier, da dies Operationen im Hintergrund ablaufen. Debug.WriteLine("Handling of OptionVote push message failed. Message is {0}.", ex.Message); return false; } return true; }
/// <summary> /// Behandelt eine eingehende Nachricht vom Typ CONVERSATION_CHANGED_ALL. Stößt eine Synchronisation /// der Konversationen der betroffenen Gruppe an. /// </summary> /// <param name="msg">Die empfangene Push Nachricht.</param> /// <returns>Liefert true, wenn Behandlung erfolgreich, ansonsten false.</returns> private async Task<bool> handleConversationChangedAllPushMsgAsync(PushMessage msg) { int groupId = msg.Id1; try { // Führe Synchronisation der Konversationen der Gruppe aus. await groupController.SynchronizeConversationsWithServerAsync(groupId, true); } catch (ClientException ex) { // Keine weitere Fehlerbehandlung hier, da dies Operationen im Hintergrund ablaufen. Debug.WriteLine("Handling of ConversationChangedAll push message failed. Message is {0}.", ex.Message); return false; } return true; }
/// <summary> /// Behandelt eine eingehende Nachricht vom Typ BALLOT_OPTION_NEW. Fragt die Daten /// der neuen Abstimmungsoption ab und speichert diese lokal. /// </summary> /// <param name="msg">Die empfangene Push Nachricht.</param> /// <returns>Liefert true, wenn Behandlung erfolgreich, ansonsten false.</returns> private async Task<bool> handleOptionNewPushMsgAsync(PushMessage msg) { int groupId = msg.Id1; int ballotId = msg.Id2; int optionId = msg.Id3; try { // Frage Daten der Abstimmungsoption vom Server ab. Option option = await groupController.GetOptionAsync(groupId, ballotId, optionId); if (option != null) { // Speichere die Abstimmungsoption lokal ab. bool successful = groupController.StoreOption(ballotId, option, false); if (!successful) { Debug.WriteLine("handleOptionNewPushMsgAsync: Fallback behavior."); // Synchronisiere die betroffene Abstimmung komplett. await groupController.SynchronizeBallotWithServerAsync(groupId, ballotId); } else { // Setze das HasNewEventFlag für die Gruppe. groupController.SetHasNewEventFlag(groupId, true); } } } catch (ClientException ex) { // Keine weitere Fehlerbehandlung hier, da dies Operationen im Hintergrund ablaufen. Debug.WriteLine("Handling of OptionNew push message failed. Message is {0}.", ex.Message); return false; } return true; }