|
|
|
|
@ -30,40 +30,20 @@ namespace Yavsc.Services
|
|
|
|
|
/// <returns>a MessageWithPayloadResponse,
|
|
|
|
|
/// <c>bool somethingsent = (response.failure == 0 && response.success > 0)</c>
|
|
|
|
|
/// </returns>
|
|
|
|
|
public async Task<MessageWithPayloadResponse>
|
|
|
|
|
public async Task<MessageWithPayloadResponse>
|
|
|
|
|
NotifyAsync(GoogleAuthSettings googleSettings, IEnumerable<string> registrationIds, YaEvent ev)
|
|
|
|
|
{
|
|
|
|
|
MessageWithPayloadResponse response;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (var web = new HttpClient())
|
|
|
|
|
{
|
|
|
|
|
response = await web.NotifyEvent(googleSettings, registrationIds, ev);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (WebException ex)
|
|
|
|
|
{
|
|
|
|
|
string errorMsgGCM;
|
|
|
|
|
using (var respstream = ex.Response.GetResponseStream())
|
|
|
|
|
{
|
|
|
|
|
using (StreamReader rdr = new StreamReader(respstream))
|
|
|
|
|
{
|
|
|
|
|
errorMsgGCM = rdr.ReadToEnd();
|
|
|
|
|
rdr.Close();
|
|
|
|
|
}
|
|
|
|
|
respstream.Close();
|
|
|
|
|
}
|
|
|
|
|
if (errorMsgGCM == null)
|
|
|
|
|
throw;
|
|
|
|
|
|
|
|
|
|
throw new Exception(errorMsgGCM, ex);
|
|
|
|
|
}
|
|
|
|
|
MessageWithPayloadResponse response = null;
|
|
|
|
|
await Task.Run(()=>{
|
|
|
|
|
response = googleSettings.NotifyEvent(registrationIds, ev);
|
|
|
|
|
});
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<bool> SendEmailAsync(SiteSettings siteSettings, SmtpSettings smtpSettings, string email, string subject, string message)
|
|
|
|
|
public Task<bool> SendEmailAsync(SiteSettings siteSettings, SmtpSettings smtpSettings, string email, string subject, string message)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
MimeMessage msg = new MimeMessage();
|
|
|
|
|
msg.From.Add(new MailboxAddress(
|
|
|
|
|
siteSettings.Owner.Name,
|
|
|
|
|
@ -83,7 +63,8 @@ namespace Yavsc.Services
|
|
|
|
|
sc.Send(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception) {
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult(false);
|
|
|
|
|
}
|
|
|
|
|
return Task.FromResult(true);
|
|
|
|
|
|