public static void SendPushNotification(Notification notification, ApiServices services) { try { Dictionary <string, string> data = new Dictionary <string, string>() { { "message", notification.Content } }; GooglePushMessage googleMessage = new GooglePushMessage(data, TimeSpan.FromHours(1)); var result = services.Push.SendAsync(googleMessage).Result; services.Log.Info(result.State.ToString()); data = new Dictionary <string, string>() { { "alert", notification.Content } }; ApplePushMessage appleMessage = new ApplePushMessage(notification.Content, TimeSpan.FromHours(1)); result = services.Push.SendAsync(appleMessage).Result; services.Log.Info(result.State.ToString()); } catch (Exception ex) { services.Log.Error(ex.Message, null, "Push.SendAsync Error"); } }
public async Task <HttpResponseMessage> Post() { var data = await this.Request.Content.ReadAsAsync <JObject>(); var method = (string)data["method"]; if (method == null) { return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest)); } if (method == "send") { var serialize = new JsonSerializer(); var token = (string)data["token"]; var payload = (JObject)data["payload"]; var type = (string)data["type"]; if (payload == null || token == null) { return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest)); } if (type == "template") { TemplatePushMessage message = new TemplatePushMessage(); var keys = payload.Properties(); foreach (JProperty key in keys) { Services.Log.Info("Key: " + key.Name); message.Add(key.Name, (string)key.Value); } var result = await Services.Push.SendAsync(message, "World"); } else if (type == "gcm") { GooglePushMessage message = new GooglePushMessage(); message.JsonPayload = payload.ToString(); var result = await Services.Push.SendAsync(message); } else { ApplePushMessage message = new ApplePushMessage(); Services.Log.Info(payload.ToString()); message.JsonPayload = payload.ToString(); var result = await Services.Push.SendAsync(message); } } else { return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest)); } return(new HttpResponseMessage(System.Net.HttpStatusCode.OK)); }
public void Serializes_AlertString() { // Arrange ApplePushMessage apsNot = new ApplePushMessage(); apsNot.Aps.Alert = "Message received from Bob"; apsNot["acme2"] = new Collection<string> { "bang", "whiz" }; // Act string actual = apsNot.ToString(); // Assert Assert.Equal(Templates["AlertString"], actual); }
public void Serializes_CloseAndViewButtons() { ApplePushMessage apsNot = new ApplePushMessage(); apsNot.Aps.Alert = "You got your emails."; apsNot.Aps.Badge = 9; apsNot.Aps.Sound = "bingbong.aiff"; apsNot["acme1"] = "bar"; apsNot["acme2"] = 42; // Act string actual = apsNot.ToString(); // Assert Assert.Equal(Templates["CloseAndViewButtons"], actual); }
public void Serializes_AlertProperties() { ApplePushMessage apsNot = new ApplePushMessage(); apsNot.Aps.AlertProperties.Body = "Bob wants to play poker"; apsNot.Aps.AlertProperties.ActionLocKey = "PLAY"; apsNot.Aps.Badge = 5; apsNot["acme1"] = "bar"; apsNot["acme2"] = new Collection<string> { "bang", "whiz" }; // Act string actual = apsNot.ToString(); // Assert Assert.Equal(Templates["AlertProperties"], actual); }
public static AutomaticNotification SendPushNotification(CurrencyRate rate, NotificationType notificationType, ApiServices services) { try { var now = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("Argentina Standard Time")); var category = notificationType == NotificationType.Hourly ? "Hourly" : "OpenClose"; var msj = notificationType == NotificationType.Hourly ? string.Empty : notificationType == NotificationType.OpenMarket ? "Apertura " : "Cierre "; msj += rate.Name + ": $" + decimal.Round(rate.Buy, 2, MidpointRounding.AwayFromZero) + " / $" + decimal.Round(rate.Sell, 2, MidpointRounding.AwayFromZero); var automaticNotification = new AutomaticNotification { Id = Guid.NewGuid().ToString(), NotificationType = notificationType, DateSent = now, Content = msj }; Dictionary <string, string> data = new Dictionary <string, string>() { { "message", msj }, { "category", category } }; GooglePushMessage googleMessage = new GooglePushMessage(data, TimeSpan.FromHours(1)); var result = services.Push.SendAsync(googleMessage, category).Result; services.Log.Info(result.State.ToString()); ApplePushMessage appleMessage = new ApplePushMessage(msj, TimeSpan.FromHours(1)); result = services.Push.SendAsync(appleMessage, category == "OpenClose" ? "OpenAndClose" : category).Result; services.Log.Info(result.State.ToString()); return(automaticNotification); } catch (Exception ex) { services.Log.Error(ex.Message, null, "Push.SendAsync Error"); return(null); } }
private void Btn_submit_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(textBox_device_token.Text)) { MessageBox.Show("Please Input Device Token!"); return; } if (String.IsNullOrEmpty(textBox_file_p12.Text)) { MessageBox.Show("Please Choice *.p12 File!"); return; } if (String.IsNullOrEmpty(textBox_key.Text)) { MessageBox.Show("Please Input p12 password!"); return; } if (String.IsNullOrEmpty(textBox_message.Text)) { MessageBox.Show("Please Input Message!"); return; } textBox_rs.Text = "Processing..."; ApplePushMessage applePushMessage = new ApplePushMessage(); applePushMessage.SetDeviceToken(textBox_device_token.Text); applePushMessage.SetP12FileName(textBox_file_p12.Text); applePushMessage.SetP12Key(textBox_key.Text); applePushMessage.SetSandBox(radioButton_sandbox.Checked); applePushMessage.SetMessage(textBox_message.Text); applePushMessage.Send(); textBox_rs.Text = applePushMessage.GetResponse(); //清除資料 textBox_file_p12.Text = ""; textBox_key.Text = ""; }
public async Task<HttpResponseMessage> Post() { var data = await this.Request.Content.ReadAsAsync<JObject>(); var method = (string)data["method"]; if (method == null) { return new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); } if (method == "send") { var serialize = new JsonSerializer(); var token = (string)data["token"]; if (data["payload"] == null || token == null) { return new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); } // Payload could be a string or a dictionary var payloadString = data["payload"].ToString(); var type = (string)data["type"]; var tag = (string)data["tag"]; if (type == "template") { TemplatePushMessage message = new TemplatePushMessage(); var payload = JObject.Parse(payloadString); var keys = payload.Properties(); foreach (JProperty key in keys) { this.traceWriter.Info("Key: " + key.Name); message.Add(key.Name, (string)key.Value); } var result = await this.pushClient.SendAsync(message); } else if (type == "gcm") { GooglePushMessage message = new GooglePushMessage(); message.JsonPayload = payloadString; var result = await this.pushClient.SendAsync(message); } else if (type == "apns") { ApplePushMessage message = new ApplePushMessage(); this.traceWriter.Info(payloadString.ToString()); message.JsonPayload = payloadString.ToString(); var result = await this.pushClient.SendAsync(message); } else if (type == "wns") { var wnsType = (string)data["wnsType"]; WindowsPushMessage message = new WindowsPushMessage(); message.XmlPayload = payloadString; message.Headers.Add("X-WNS-Type", type + '/' + wnsType); if (tag != null) { await this.pushClient.SendAsync(message, tag); } else { await this.pushClient.SendAsync(message); } } } else { return new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); } return new HttpResponseMessage(System.Net.HttpStatusCode.OK); }
public async Task <HttpResponseMessage> Post() { var data = await this.Request.Content.ReadAsAsync <JObject>(); var method = (string)data["method"]; if (method == null) { return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest)); } if (method == "send") { var serialize = new JsonSerializer(); var token = (string)data["token"]; if (data["payload"] == null || token == null) { return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest)); } // Payload could be a string or a dictionary var payloadString = data["payload"].ToString(); var type = (string)data["type"]; var tag = (string)data["tag"]; if (type == "template") { TemplatePushMessage message = new TemplatePushMessage(); var payload = JObject.Parse(payloadString); var keys = payload.Properties(); foreach (JProperty key in keys) { this.traceWriter.Info("Key: " + key.Name); message.Add(key.Name, (string)key.Value); } var result = await this.pushClient.SendAsync(message, "World"); } else if (type == "gcm") { GooglePushMessage message = new GooglePushMessage(); message.JsonPayload = payloadString; var result = await this.pushClient.SendAsync(message); } else if (type == "apns") { ApplePushMessage message = new ApplePushMessage(); this.traceWriter.Info(payloadString.ToString()); message.JsonPayload = payloadString.ToString(); var result = await this.pushClient.SendAsync(message); } else if (type == "wns") { var wnsType = (string)data["wnsType"]; WindowsPushMessage message = new WindowsPushMessage(); message.XmlPayload = payloadString; message.Headers.Add("X-WNS-Type", type + '/' + wnsType); if (tag != null) { await this.pushClient.SendAsync(message, tag); } else { await this.pushClient.SendAsync(message); } } } else { return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest)); } return(new HttpResponseMessage(System.Net.HttpStatusCode.OK)); }
public void Serializes_LocKeyAndArgs() { ApplePushMessage apsNot = new ApplePushMessage(); apsNot.Aps.AlertProperties.LocKey = "GAME_PLAY_REQUEST_FORMAT"; apsNot.Aps.AlertProperties.LogArgs.Add("Jenna"); apsNot.Aps.AlertProperties.LogArgs.Add("Frank"); apsNot.Aps.Sound = "chime"; apsNot["acme"] = "foo"; // Act string actual = apsNot.ToString(); // Assert Assert.Equal(Templates["LocKeyAndArgs"], actual); }
public void JsonPayload_TakesOverSerialization() { // Arrange ApplePushMessage apsNot = new ApplePushMessage() { JsonPayload = "text" }; // Act string actual = apsNot.ToString(); // Assert Assert.Equal("text", actual); }
public void ApplePushMessage_AlertExpiration_SetsAlertAndExpiration(string alert, TimeSpan? expiration) { // Act ApplePushMessage apsNot = new ApplePushMessage(alert, expiration); // Assert Assert.Equal(alert, apsNot.Aps.Alert); if (expiration != null) { Assert.True(apsNot.Expiration.HasValue); Assert.True(DateTimeOffset.UtcNow < apsNot.Expiration); } else { Assert.Null(apsNot.Expiration); } }