v 1.0.5-rc20-alpha5

in order to build 1.0.5-rc20-alpha5

* fixing dep graph, while moving as must as possible code from Yavsc to
Yavsc.Server
* impoved topmost Makefile
* cleaned the badly desined, ans system redondant "Action" definiton
This commit is contained in:
Paul Schneider 2018-06-11 14:43:18 +02:00
commit 781ce94edc
21 changed files with 24 additions and 8664 deletions

View file

@ -1,9 +0,0 @@
namespace Yavsc.Server.Helpers
{
public static class DbHelpers
{
// FIXME BUG [fr] DependencyInjection Pourquoi ce champ ne pourrait pas devenir une propriété ?
// : casse à l'execution d'un controlleur, se plaignant d'une valeur nule
public static string ConnectionString = "Server=Your-Server-Adress;Port=5432;Database=YourDadabaseName;Username=YourDatabaseUserName;Password=YourPassword;";
}
}

View file

@ -0,0 +1,28 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Yavsc.Interfaces.Workflow;
using Yavsc.Models.Google.Messaging;
using Yavsc.Models.Haircut;
using Yavsc.Models.Messaging;
namespace Yavsc.Services
{
public interface IGoogleCloudMessageSender
{
Task<MessageWithPayloadResponse> NotifyBookQueryAsync(
IEnumerable<string> registrationId,
RdvQueryEvent ev);
Task<MessageWithPayloadResponse> NotifyEstimateAsync(
IEnumerable<string> registrationId,
EstimationEvent ev);
Task<MessageWithPayloadResponse> NotifyHairCutQueryAsync(
IEnumerable<string> registrationId,
HairCutQueryEvent ev);
Task<MessageWithPayloadResponse> NotifyAsync(
IEnumerable<string> regids,
IEvent yaev);
}
}

View file

@ -0,0 +1,10 @@
using System.Threading.Tasks;
namespace Yavsc.Services
{
public interface ISmsSender
{
Task SendSmsAsync(TwilioSettings settings, string number, string message);
}
}

View file

@ -1,9 +0,0 @@
using System.Threading.Tasks;
namespace Yavsc.Models.Process
{
public abstract class Action<TResult,TInput>
{
public abstract Task<TResult> GetTask(TInput data);
}
}

View file

@ -1,3 +1,4 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace Yavsc.Models.Process
@ -5,7 +6,7 @@ namespace Yavsc.Models.Process
/// <summary>
/// An abstract, identified rule
/// </summary>
public class Rule<TResult,TInput>
public abstract class Rule<TResult,TInput>
{
[Key]
public string Id { get; set; }
@ -28,7 +29,7 @@ namespace Yavsc.Models.Process
public string Description { get; set; }
public Action<TResult,TInput> Execution { get; set; }
public abstract TResult Execute(TInput inputData);
}
}

View file

@ -0,0 +1,154 @@
using System.Threading.Tasks;
using MailKit.Net.Smtp;
using MimeKit;
using MailKit.Security;
using System;
using Yavsc.Models.Messaging;
using Microsoft.AspNet.Identity;
using Yavsc.Models;
using Yavsc.Models.Google.Messaging;
using System.Collections.Generic;
using Yavsc.Models.Haircut;
using Yavsc.Interfaces.Workflow;
using System.Linq;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Yavsc.Server.Helpers;
using Microsoft.Extensions.OptionsModel;
namespace Yavsc.Services
{
// This class is used by the application to send Email and SMS
// when you turn on two-factor authentication in ASP.NET Identity.
// For more details see this link http://go.microsoft.com/fwlink/?LinkID=532713
public class MessageSender : IEmailSender, IGoogleCloudMessageSender
{
private ILogger _logger;
SiteSettings siteSettings;
SmtpSettings smtpSettings;
GoogleAuthSettings googleSettings;
public MessageSender(
ILoggerFactory loggerFactory,
IOptions<SiteSettings> sitesOptions,
IOptions<SmtpSettings> smtpOptions,
IOptions<GoogleAuthSettings> googleOptions
)
{
_logger = loggerFactory.CreateLogger<MessageSender>();
siteSettings = sitesOptions.Value;
smtpSettings = smtpOptions.Value;
googleSettings = googleOptions.Value;
}
public async Task <MessageWithPayloadResponse> NotifyEvent<Event>
( IEnumerable<string> regids, Event ev)
where Event : IEvent
{
if (ev == null)
throw new Exception("Spécifier un évènement");
if (ev.Sender == null)
throw new Exception("Spécifier un expéditeur");
if (regids == null )
throw new NotImplementedException("Notify & No GCM reg ids");
var raa = regids.ToArray();
if (raa.Length<1)
throw new NotImplementedException("No GCM reg ids");
var msg = new MessageWithPayload<Event>()
{
data = ev,
registration_ids = regids.ToArray()
};
_logger.LogInformation("Sendding to Google : "+JsonConvert.SerializeObject(msg));
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);
}
}
/// <summary>
///
/// </summary>
/// <param name="googleSettings"></param>
/// <param name="registrationId"></param>
/// <param name="ev"></param>
/// <returns>a MessageWithPayloadResponse,
/// <c>bool somethingsent = (response.failure == 0 &amp;&amp; response.success > 0)</c>
/// </returns>
public async Task<MessageWithPayloadResponse> NotifyBookQueryAsync( IEnumerable<string> registrationIds, RdvQueryEvent ev)
{
return await NotifyEvent<RdvQueryEvent>(registrationIds, ev);
}
public async Task<MessageWithPayloadResponse> NotifyEstimateAsync(IEnumerable<string> registrationIds, EstimationEvent ev)
{
return await NotifyEvent<EstimationEvent>(registrationIds, ev);
}
public async Task<MessageWithPayloadResponse> NotifyHairCutQueryAsync(
IEnumerable<string> registrationIds, HairCutQueryEvent ev)
{
return await NotifyEvent<HairCutQueryEvent>(registrationIds, ev);
}
public Task<bool> SendEmailAsync(string username, string email, string subject, string message)
{
try
{
MimeMessage msg = new MimeMessage();
msg.From.Add(new MailboxAddress(
siteSettings.Owner.Name,
siteSettings.Owner.EMail));
msg.To.Add(new MailboxAddress(username, email));
msg.Body = new TextPart("plain")
{
Text = message
};
msg.Subject = subject;
using (SmtpClient sc = new SmtpClient())
{
sc.Connect(
smtpSettings.Host,
smtpSettings.Port,
SecureSocketOptions.None);
sc.Send(msg);
}
}
catch (Exception)
{
return Task.FromResult(false);
}
return Task.FromResult(true);
}
public Task<bool> ValidateAsync(string purpose, string token, UserManager<ApplicationUser> manager, ApplicationUser user)
{
throw new NotImplementedException();
}
public Task<MessageWithPayloadResponse> NotifyAsync(
IEnumerable<string> regids, IEvent yaev)
{
throw new NotImplementedException();
}
/* SMS with Twilio:
public Task SendSmsAsync(TwilioSettings twilioSettigns, string number, string message)
{
var Twilio = new TwilioRestClient(twilioSettigns.AccountSID, twilioSettigns.Token);
var result = Twilio.SendMessage( twilioSettigns.SMSAccountFrom, number, message);
// Status is one of Queued, Sending, Sent, Failed or null if the number is not valid
Trace.TraceInformation(result.Status);
// Twilio doesn't currently have an async API, so return success.
return Task.FromResult(result.Status != "Failed");
} */
}
}

View file

@ -0,0 +1,6 @@
namespace Yavsc
{
public class CompanyInfoSettings {
public string ApiKey { get; set; }
}
}

View file

@ -0,0 +1,14 @@
using Yavsc.Models.Relationship;
namespace Yavsc
{
public class Contact
{
public string Name { get; set; }
public string EMail { get; set; }
public PostalAddress PostalAddress { get; set; }
}
}

View file

@ -0,0 +1,26 @@
namespace Yavsc
{
public class GoogleAuthSettings
{
public string ApiKey { get; set; }
public string ClientSecret { get; set; }
public string ClientId { get; set; }
public string BrowserApiKey { get; set; }
public class ServiceAccount
{
public string project_id { get; set; }
public string private_key_id { get; set; }
public string private_key { get; set; }
public string client_email { get; set; }
public string client_id { get; set; }
public string auth_uri { get; set; }
public string token_uri { get; set; }
public string auth_provider_x509_cert_url { get; set; }
public string client_x509_cert_url { get; set; }
}
public ServiceAccount Account { get; set; }
}
}

View file

@ -0,0 +1,21 @@
namespace Yavsc
{
/// <summary>
/// OAuth2 client application sensitive settings.
/// </summary>
public class OAuth2AppSettings {
public string ClientId { get; set; }
public string ClientSecret { get; set; }
}
/// <summary>
/// Facebook's class, so class
/// </summary>
public class FacebookOAuth2AppSettings : OAuth2AppSettings {
}
}

View file

@ -0,0 +1,57 @@
namespace Yavsc
{
/// <summary>
/// PayPal NV/SOAP API Credentials
/// </summary>
public class PayPalSettings {
/// <summary>
/// supported values: <c>sandbox</c> or <c>production</c>
/// </summary>
/// <returns></returns>
public string Mode { get; set; }
/// <summary>
/// Client Id using the REST API
/// </summary>
public string ClientId { get; set; }
/// <summary>
/// Client Secret using the REST API
/// </summary>
/// <returns></returns>
public string ClientSecret { get; set; }
/// <summary>
/// Application Id using the REST API
/// </summary>
/// <returns></returns>
public string ApplicationId { get; set; }
/// <summary>
/// Get it from your PayPal Business profile settings
/// </summary>
/// <returns></returns>
public string MerchantAccountId { get; set; }
/// <summary>
/// Merchant PayPal Classic Api user name
/// </summary>
/// <returns></returns>
public string MerchantAccountUserName { get; set; }
/// <summary>
/// PayPal Classic Api credentials model
/// </summary>
public class ClassicPayPalAccountApiCredential {
public string Signature { get; set; }
public string ApiUsername { get; set; }
public string ApiPassword { get; set; }
}
/// <summary>
/// Live access is configured at:
/// https://www.paypal.com/businessprofile/mytools/apiaccess
/// </summary>
public ClassicPayPalAccountApiCredential[] Accounts { get; set; }
}
}

View file

@ -0,0 +1,67 @@
namespace Yavsc
{
public class SiteSettings
{
public string Title { get; set; }
public string Slogan { get; set; }
public string Banner { get; set; }
public string FavIcon { get; set; }
public string Icon { get; set; }
/// <summary>
/// Conceptually,
/// This authorisation server only has this present site as unique audience.
/// </summary>
/// <returns></returns>
public string Audience { get; set; }
/// <summary>
/// it's a very small company, with one domaine name only,
/// so let it be the same as in the Audience field.
/// </summary>
/// <returns></returns>
public string Authority { get; set; }
/// <summary>
/// Owner's email
/// </summary>
/// <returns></returns>
public Contact Owner { get; set; }
/// <summary>
/// Administrator's email
/// </summary>
/// <returns></returns>
public Contact Admin { get; set; }
public string DataDir { get; set; }
public string Avatars { get; set; }
public long Quota { get; set; }
public string Blog { get; set; }
public string Bills { get; set; }
public string GitRepository { get; set; } = "sources";
public string BusinessName { get; set; }
public string Street { get; set; }
public string PostalCode { get; set; }
public string CountryCode { get; set; }
public string HomeViewName { get; set; }
/// <summary>
/// Specifies the directory where should be
/// generated pdf files using pandoc
/// </summary>
/// <returns>The temporary directory to use</returns>
public string TempDir { get; set; } = "Temp";
/// <summary>
/// Only one performer will capture payments
/// </summary>
/// <returns>user capturing payments id</returns>
public string OnlyOnePerformerId { get; set; }
/// <summary>
/// Only one activity will be supported
/// </summary>
/// <returns>the supported activity code</returns>
public string OnlyOneActivityCode { get; set; }
}
}

View file

@ -0,0 +1,12 @@
namespace Yavsc
{
public class SmtpSettings
{
public string Host { get; set; }
public int Port { get; set; }
public bool EnableSSL { get; set; }
}
}

View file

@ -0,0 +1,7 @@
namespace Yavsc
{
public class ThirdPartyFiles {
}
}

View file

@ -0,0 +1,10 @@
namespace Yavsc
{
public class TwilioSettings {
public string AccountSID { get; set; }
public string Token { get; set; }
public string SMSAccountFrom { get; set; }
}
}