code format & exception matters

This commit is contained in:
2017-02-22 22:57:07 +01:00
parent 1fba85fb47
commit f0a94ef3d8

View File

@ -29,6 +29,8 @@ namespace Yavsc.Helpers
using Models.Google.Messaging; using Models.Google.Messaging;
using Models.Messaging; using Models.Messaging;
using Models; using Models;
using Interfaces.Workflow;
/// <summary> /// <summary>
/// Google helpers. /// Google helpers.
@ -73,6 +75,16 @@ namespace Yavsc.Helpers
(this GoogleAuthSettings googleSettings, IEnumerable<string> regids, Event ev) (this GoogleAuthSettings googleSettings, IEnumerable<string> regids, Event ev)
where Event : IEvent where Event : IEvent
{ {
if (ev == null)
throw new Exception("Spécifier un évènement");
if (ev.Message == null)
throw new Exception("Spécifier un message");
if (ev.Sender == null)
throw new Exception("Spécifier un expéditeur");
if (regids == null)
throw new NotImplementedException("Notify & No GCM reg ids");
var msg = new MessageWithPayload<Event>() var msg = new MessageWithPayload<Event>()
{ {
notification = new Notification() notification = new Notification()
@ -84,12 +96,14 @@ namespace Yavsc.Helpers
data = ev, data = ev,
registration_ids = regids.ToArray() registration_ids = regids.ToArray()
}; };
try {
if (regids == null)
throw new NotImplementedException("Notify & No GCM reg ids");
using (var m = new SimpleJsonPostMethod("https://gcm-http.googleapis.com/gcm/send",$"key={googleSettings.ApiKey}")) { using (var m = new SimpleJsonPostMethod("https://gcm-http.googleapis.com/gcm/send",$"key={googleSettings.ApiKey}")) {
return m.Invoke<MessageWithPayloadResponse>(msg); return m.Invoke<MessageWithPayloadResponse>(msg);
} }
}
catch (Exception ex) {
throw new Exception ("Quelque chose s'est mal passé à l'envoi",ex);
}
} }
public static async Task<UserCredential> GetCredentialForGoogleApiAsync(this UserManager<ApplicationUser> userManager, ApplicationDbContext context, string uid) public static async Task<UserCredential> GetCredentialForGoogleApiAsync(this UserManager<ApplicationUser> userManager, ApplicationDbContext context, string uid)
{ {