refactoring messages

This commit is contained in:
2018-02-03 20:17:29 +01:00
parent edd91faa96
commit 6c18f32f61
44 changed files with 603 additions and 304 deletions

View File

@ -15,12 +15,7 @@ namespace Yavsc.Helpers
var yaev = new RdvQueryEvent(subtopic)
{
Sender = query.ClientId,
Message = string.Format(SR["RdvToPerf"],
query.Client.UserName,
query.EventDate.ToString("dddd dd/MM/yyyy à HH:mm"),
query.Location.Address,
query.ActivityCode)+
"\n"+query.Reason,
Reason = query.Reason,
Client = new ClientProviderInfo { 
UserName = query.Client.UserName ,
UserId = query.ClientId,
@ -46,21 +41,7 @@ namespace Yavsc.Helpers
var yaev = query.CreateEvent("NewHairCutQuery",
string.Format(Startup.GlobalLocalizer["HairCutQueryValidation"],query.Client.UserName),
$"{query.Client.UserName}",
$@"Un client vient de valider une demande de prestation à votre encontre:
Prestation: {strprestation}
Client : {query.Client.UserName}
Date: {evdate},
Adresse: {address}
-----
{query.AdditionalInfo}
Facture prévue (non réglée):
{query.GetBillText()}
") ;
$"{query.Client.UserName}") ;
return yaev;
}
@ -74,11 +55,7 @@ Facture prévue (non réglée):
var yaev = new HairCutQueryEvent("newCommand")
{
Sender = query.ClientId,
Message = string.Format(SR["RdvToPerf"],
query.Client.UserName,
query.EventDate.ToString("dddd dd/MM/yyyy à HH:mm"),
query.Location.Address,
query.ActivityCode),
Client = new ClientProviderInfo { 
UserName = query.Client.UserName ,
UserId = query.ClientId,

View File

@ -23,67 +23,29 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Data.Entity;
using Microsoft.AspNet.Identity.EntityFramework;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Compute.v1;
using Google.Apis.Auth.OAuth2.Flows;
using Google.Apis.Util.Store;
using Google.Apis.Auth.OAuth2.Responses;
using Google.Apis.Util;
namespace Yavsc.Helpers
{
using Models.Google.Messaging;
using Models.Messaging;
using Models;
using Interfaces.Workflow;
using Yavsc.Models.Calendar;
using Google.Apis.Auth.OAuth2;
using Microsoft.Data.Entity;
using Microsoft.AspNet.Identity.EntityFramework;
using Yavsc.Services;
using Google.Apis.Services;
using Google.Apis.Compute.v1;
using Google.Apis.Auth.OAuth2.Flows;
using Google.Apis.Util.Store;
using Google.Apis.Auth.OAuth2.Responses;
using Google.Apis.Util;
using Models.Calendar;
using Services;
/// <summary>
/// Google helpers.
/// </summary>
public static class GoogleHelpers
{
public static async Task <MessageWithPayloadResponse> NotifyEvent<Event>
(this GoogleAuthSettings googleSettings, IEnumerable<string> regids, Event ev)
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>()
{
notification = new Notification()
{
title = ev.Topic+" "+ev.Sender,
body = ev.Message,
icon = "icon"
},
data = ev,
registration_ids = regids.ToArray()
};
try {
using (var m = new SimpleJsonPostMethod("https://gcm-http.googleapis.com/gcm/send",$"key={googleSettings.ApiKey}")) {
return await m.Invoke<MessageWithPayloadResponse>(msg);
}
}
catch (Exception ex) {
throw new Exception ("Quelque chose s'est mal passé à l'envoi",ex);
}
}
public static ServiceAccountCredential OupsGetCredentialForApi(IEnumerable<string> scopes)
{
var initializer = new ServiceAccountCredential.Initializer(Startup.GoogleSettings.Account.client_email);