idem
This commit is contained in:
parent
35b3480837
commit
aee54b48c3
1 changed files with 10 additions and 29 deletions
|
|
@ -30,40 +30,20 @@ namespace Yavsc.Services
|
||||||
/// <returns>a MessageWithPayloadResponse,
|
/// <returns>a MessageWithPayloadResponse,
|
||||||
/// <c>bool somethingsent = (response.failure == 0 && response.success > 0)</c>
|
/// <c>bool somethingsent = (response.failure == 0 && response.success > 0)</c>
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public async Task<MessageWithPayloadResponse>
|
public async Task<MessageWithPayloadResponse>
|
||||||
NotifyAsync(GoogleAuthSettings googleSettings, IEnumerable<string> registrationIds, YaEvent ev)
|
NotifyAsync(GoogleAuthSettings googleSettings, IEnumerable<string> registrationIds, YaEvent ev)
|
||||||
{
|
{
|
||||||
MessageWithPayloadResponse response;
|
MessageWithPayloadResponse response = null;
|
||||||
try
|
await Task.Run(()=>{
|
||||||
{
|
response = googleSettings.NotifyEvent(registrationIds, ev);
|
||||||
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);
|
|
||||||
}
|
|
||||||
return response;
|
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();
|
MimeMessage msg = new MimeMessage();
|
||||||
msg.From.Add(new MailboxAddress(
|
msg.From.Add(new MailboxAddress(
|
||||||
siteSettings.Owner.Name,
|
siteSettings.Owner.Name,
|
||||||
|
|
@ -83,7 +63,8 @@ namespace Yavsc.Services
|
||||||
sc.Send(msg);
|
sc.Send(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception) {
|
catch (Exception)
|
||||||
|
{
|
||||||
return Task.FromResult(false);
|
return Task.FromResult(false);
|
||||||
}
|
}
|
||||||
return Task.FromResult(true);
|
return Task.FromResult(true);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue