principalement du format de code
This commit is contained in:
parent
222a0f96d1
commit
ff1444d664
87 changed files with 510 additions and 550 deletions
|
|
@ -18,10 +18,8 @@ namespace Yavsc.Controllers
|
|||
[Route("api/live")]
|
||||
public class LiveApiController : Controller
|
||||
{
|
||||
|
||||
ILiveProcessor _liveProcessor;
|
||||
private ApplicationDbContext _dbContext;
|
||||
ILogger _logger;
|
||||
readonly ILiveProcessor _liveProcessor;
|
||||
private readonly ApplicationDbContext _dbContext;
|
||||
|
||||
/// <summary>
|
||||
/// Live Api Controller
|
||||
|
|
@ -30,13 +28,11 @@ namespace Yavsc.Controllers
|
|||
/// <param name="context"></param>
|
||||
|
||||
public LiveApiController(
|
||||
ILoggerFactory loggerFactory,
|
||||
ApplicationDbContext context,
|
||||
ILiveProcessor liveProcessor)
|
||||
{
|
||||
_liveProcessor = liveProcessor;
|
||||
_dbContext = context;
|
||||
_logger = loggerFactory.CreateLogger<LiveApiController>();
|
||||
}
|
||||
|
||||
[HttpGet("filenamehint/{id}")]
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ namespace Yavsc.ApiControllers
|
|||
[Route("~/api/bug")]
|
||||
public class BugApiController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
ILogger _logger;
|
||||
private readonly ApplicationDbContext _context;
|
||||
readonly ILogger _logger;
|
||||
|
||||
public BugApiController(ApplicationDbContext context, ILoggerFactory factory)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -32,4 +32,4 @@ namespace Yavsc.AuthorizationHandlers
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace Yavsc.AuthorizationHandlers
|
|||
{
|
||||
public class SendMessageHandler : AuthorizationHandler<PrivateChatEntryRequirement, string>
|
||||
{
|
||||
ApplicationDbContext _dbContext ;
|
||||
readonly ApplicationDbContext _dbContext ;
|
||||
|
||||
public SendMessageHandler(ApplicationDbContext dbContext)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@ using Yavsc.ViewModels.Auth;
|
|||
namespace Yavsc.AuthorizationHandlers {
|
||||
|
||||
public class ViewFileHandler : AuthorizationHandler<ViewRequirement, ViewFileContext> {
|
||||
|
||||
IFileSystemAuthManager _authManager;
|
||||
readonly IFileSystemAuthManager _authManager;
|
||||
|
||||
public ViewFileHandler (IFileSystemAuthManager authManager) {
|
||||
_authManager = authManager;
|
||||
|
|
@ -28,4 +27,4 @@ namespace Yavsc.AuthorizationHandlers {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace Yavsc.Auth
|
|||
{
|
||||
internal class GoogleHandler : OAuthHandler<YavscGoogleOptions>
|
||||
{
|
||||
private ILogger _logger;
|
||||
private readonly ILogger _logger;
|
||||
public GoogleHandler(HttpClient httpClient,ILogger logger)
|
||||
: base(httpClient)
|
||||
{
|
||||
|
|
@ -92,9 +92,11 @@ namespace Yavsc.Auth
|
|||
{
|
||||
|
||||
var scope = FormatScope();
|
||||
var queryStrings = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
queryStrings.Add("response_type", "code");
|
||||
queryStrings.Add("client_id", Options.ClientId);
|
||||
var queryStrings = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
{ "response_type", "code" },
|
||||
{ "client_id", Options.ClientId }
|
||||
};
|
||||
// this runtime may not known this value,
|
||||
// it should be get from config,
|
||||
// And always be using a secure sheme ... since Google won't support anymore insecure ones.
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ namespace Yavsc.Auth
|
|||
/// </summary>
|
||||
public class GoogleMiddleware : OAuthMiddleware<YavscGoogleOptions>
|
||||
{
|
||||
private RequestDelegate _next;
|
||||
private ILogger _logger;
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="GoogleMiddleware"/>.
|
||||
|
|
|
|||
|
|
@ -15,8 +15,9 @@ namespace Yavsc.Auth {
|
|||
_googleUserId = googleUserId;
|
||||
Principal = ticket.Principal;
|
||||
}
|
||||
AuthenticationTicket _ticket;
|
||||
string _googleUserId;
|
||||
|
||||
readonly AuthenticationTicket _ticket;
|
||||
readonly string _googleUserId;
|
||||
|
||||
public AuthenticationTicket Ticket { get { return _ticket; } }
|
||||
|
||||
|
|
@ -24,4 +25,4 @@ namespace Yavsc.Auth {
|
|||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,6 @@ namespace Yavsc.Controllers
|
|||
[Authorize(Roles = Constants.AdminGroupName)]
|
||||
public IActionResult Index(string page, string len)
|
||||
{
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
|
|
@ -262,7 +261,7 @@ namespace Yavsc.Controllers
|
|||
// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
|
||||
// Send an email with this link
|
||||
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
||||
var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: "https", host: Startup.Authority);
|
||||
var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code }, protocol: "https", host: Startup.Authority);
|
||||
var emailSent = await _emailSender.SendEmailAsync(model.UserName, model.Email, _localizer["ConfirmYourAccountTitle"],
|
||||
string.Format(_localizer["ConfirmYourAccountBody"], _siteSettings.Title, callbackUrl, _siteSettings.Slogan, _siteSettings.Audience));
|
||||
// No, wait for more than a login pass submission:
|
||||
|
|
@ -317,7 +316,7 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
||||
var callbackUrl = Url.Action("ConfirmEmail", "Account",
|
||||
new { userId = user.Id, code = code }, protocol: "https", host: Startup.Authority);
|
||||
new { userId = user.Id, code }, protocol: "https", host: Startup.Authority);
|
||||
var res = await _emailSender.SendEmailAsync(user.UserName, user.Email,
|
||||
this._localizer["ConfirmYourAccountTitle"],
|
||||
string.Format(this._localizer["ConfirmYourAccountBody"],
|
||||
|
|
|
|||
|
|
@ -29,18 +29,18 @@ namespace Yavsc.Controllers
|
|||
private readonly SignInManager<ApplicationUser> _signInManager;
|
||||
private readonly IEmailSender _emailSender;
|
||||
private readonly ILogger _logger;
|
||||
private SiteSettings _siteSettings;
|
||||
private readonly SiteSettings _siteSettings;
|
||||
|
||||
private ApplicationDbContext _dbContext;
|
||||
private readonly ApplicationDbContext _dbContext;
|
||||
|
||||
private GoogleAuthSettings _googleSettings;
|
||||
private readonly GoogleAuthSettings _googleSettings;
|
||||
|
||||
private PayPalSettings _payPalSettings;
|
||||
private IYavscMessageSender _GCMSender;
|
||||
private SIRENChecker _cchecker;
|
||||
private IStringLocalizer _SR;
|
||||
private CompanyInfoSettings _cinfoSettings;
|
||||
ICalendarManager _calendarManager;
|
||||
private readonly PayPalSettings _payPalSettings;
|
||||
private readonly IYavscMessageSender _GCMSender;
|
||||
private readonly SIRENChecker _cchecker;
|
||||
private readonly IStringLocalizer _SR;
|
||||
private readonly CompanyInfoSettings _cinfoSettings;
|
||||
readonly ICalendarManager _calendarManager;
|
||||
|
||||
|
||||
public ManageController(
|
||||
|
|
@ -300,7 +300,7 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
var uid = User.GetUserId();
|
||||
|
||||
var calendars = await _calendarManager.GetCalendarsAsync(uid, pageToken);
|
||||
var calendars = await _calendarManager.GetCalendarsAsync(pageToken);
|
||||
return View(new SetGoogleCalendarViewModel {
|
||||
ReturnUrl = returnUrl,
|
||||
Calendars = calendars
|
||||
|
|
|
|||
|
|
@ -20,12 +20,10 @@ namespace Yavsc.Controllers
|
|||
[AllowAnonymous]
|
||||
public class OAuthController : Controller
|
||||
{
|
||||
ApplicationDbContext _context;
|
||||
UserManager<ApplicationUser> _userManager;
|
||||
|
||||
SiteSettings _siteSettings;
|
||||
|
||||
ILogger _logger;
|
||||
readonly ApplicationDbContext _context;
|
||||
readonly UserManager<ApplicationUser> _userManager;
|
||||
readonly SiteSettings _siteSettings;
|
||||
readonly ILogger _logger;
|
||||
private readonly SignInManager<ApplicationUser> _signInManager;
|
||||
|
||||
public OAuthController(ApplicationDbContext context, SignInManager<ApplicationUser> signInManager, IKeyManager keyManager,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace Yavsc.Controllers
|
|||
[Authorize("AdministratorOnly")]
|
||||
public class UsersController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public UsersController(ApplicationDbContext context)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace Yavsc.Controllers
|
|||
[Authorize("AdministratorOnly")]
|
||||
public class MailingTemplateController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public MailingTemplateController(ApplicationDbContext context)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,11 +21,10 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
public class BlogspotController : Controller
|
||||
{
|
||||
ILogger _logger;
|
||||
private ApplicationDbContext _context;
|
||||
private IAuthorizationService _authorizationService;
|
||||
|
||||
RequestLocalizationOptions _localisationOptions;
|
||||
readonly ILogger _logger;
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
readonly RequestLocalizationOptions _localisationOptions;
|
||||
|
||||
public BlogspotController(
|
||||
ApplicationDbContext context,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
public class CircleController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public CircleController(ApplicationDbContext context)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
public class CircleMembersController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public CircleMembersController(ApplicationDbContext context)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace Yavsc.Controllers
|
|||
/// </summary>
|
||||
public class CommentsController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public CommentsController(ApplicationDbContext context)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Yavsc.Controllers
|
|||
using Models.Identity;
|
||||
public class DevicesController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public DevicesController(ApplicationDbContext context)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace Yavsc.Controllers
|
|||
[Authorize("AdministratorOnly")]
|
||||
public class HyperLinkController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public HyperLinkController(ApplicationDbContext context)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
public class LiveFlowController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public LiveFlowController(ApplicationDbContext context)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ namespace Yavsc.Controllers
|
|||
[Authorize()]
|
||||
public class MyFSRulesController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private ILogger _logger;
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public MyFSRulesController(ApplicationDbContext context,
|
||||
ILoggerFactory loggerFactory)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
public class NotificationsController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public NotificationsController(ApplicationDbContext context)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ namespace Yavsc.Controllers
|
|||
[Authorize("AdministratorOnly")]
|
||||
public class ActivityController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
IStringLocalizer<Yavsc.YavscLocalisation> SR;
|
||||
ILogger logger;
|
||||
private readonly ApplicationDbContext _context;
|
||||
readonly IStringLocalizer<Yavsc.YavscLocalisation> SR;
|
||||
readonly ILogger logger;
|
||||
|
||||
public ActivityController(ApplicationDbContext context,
|
||||
IStringLocalizer<Yavsc.YavscLocalisation> SR,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
public class ClientController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public ClientController(ApplicationDbContext context)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ namespace Yavsc.Controllers
|
|||
[Authorize]
|
||||
public class DoController : Controller
|
||||
{
|
||||
private ApplicationDbContext dbContext;
|
||||
ILogger logger;
|
||||
IBillingService billing;
|
||||
private readonly ApplicationDbContext dbContext;
|
||||
readonly ILogger logger;
|
||||
readonly IBillingService billing;
|
||||
public DoController(
|
||||
ApplicationDbContext context,
|
||||
IBillingService billing,
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ namespace Yavsc.Models
|
|||
builder.Entity<UserActivity>().HasKey(u => new { u.DoesCode, u.UserId });
|
||||
builder.Entity<Instrumentation>().HasKey(u => new { u.InstrumentId, u.UserId });
|
||||
builder.Entity<CircleAuthorizationToBlogPost>().HasKey(a => new { a.CircleId, a.BlogPostId });
|
||||
builder.Entity<CircleMember>().HasKey(c => new { MemberId = c.MemberId, CircleId = c.CircleId });
|
||||
builder.Entity<CircleMember>().HasKey(c => new { c.MemberId, c.CircleId });
|
||||
builder.Entity<DimissClicked>().HasKey(c => new { uid = c.UserId, notid = c.NotificationId });
|
||||
builder.Entity<HairTaintInstance>().HasKey(ti => new { ti.TaintId, ti.PrestationId });
|
||||
builder.Entity<HyperLink>().HasKey(l => new { l.HRef, l.Method });
|
||||
|
|
@ -79,9 +79,9 @@ namespace Yavsc.Models
|
|||
}
|
||||
|
||||
// this is not a failback procedure.
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured) return;
|
||||
if (!string.IsNullOrWhiteSpace(Startup.ConnectionString))
|
||||
{
|
||||
optionsBuilder.UseNpgsql(Startup.ConnectionString);
|
||||
|
|
@ -161,12 +161,6 @@ namespace Yavsc.Models
|
|||
public DbSet<Service> Services { get; set; }
|
||||
public DbSet<Product> Products { get; set; }
|
||||
|
||||
Client FindApplication(string clientId)
|
||||
{
|
||||
return Applications.FirstOrDefault(
|
||||
app => app.Id == clientId);
|
||||
}
|
||||
|
||||
public DbSet<ExceptionSIREN> ExceptionsSIREN { get; set; }
|
||||
|
||||
public DbSet<Location> Locations { get; set; }
|
||||
|
|
@ -231,7 +225,7 @@ namespace Yavsc.Models
|
|||
public async Task<int> SaveChangesAsync(string userId, CancellationToken ctoken = default(CancellationToken))
|
||||
{
|
||||
AddTimestamps(userId);
|
||||
return await base.SaveChangesAsync();
|
||||
return await base.SaveChangesAsync(ctoken);
|
||||
}
|
||||
|
||||
public DbSet<Circle> Circle { get; set; }
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ namespace Yavsc.Services
|
|||
public class BillingService : IBillingService
|
||||
{
|
||||
public ApplicationDbContext DbContext { get; private set; }
|
||||
private ILogger logger;
|
||||
public static Dictionary<string,Func<ApplicationDbContext,long,IDecidableQuery>> Billing =
|
||||
new Dictionary<string,Func<ApplicationDbContext,long,IDecidableQuery>> ();
|
||||
public static List<PropertyInfo> UserSettings = new List<PropertyInfo>();
|
||||
|
|
@ -25,9 +24,8 @@ namespace Yavsc.Services
|
|||
get { return GlobalBillingMap; }
|
||||
}
|
||||
|
||||
public BillingService(ILoggerFactory loggerFactory, ApplicationDbContext dbContext)
|
||||
public BillingService(ApplicationDbContext dbContext)
|
||||
{
|
||||
logger = loggerFactory.CreateLogger<BillingService>();
|
||||
DbContext = dbContext;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,24 +31,24 @@ namespace Yavsc.Services
|
|||
/// <typeparam name="string"></typeparam>
|
||||
/// <returns></returns>
|
||||
|
||||
static ConcurrentDictionary<string, string> ChatUserNames = new ConcurrentDictionary<string, string>();
|
||||
static readonly ConcurrentDictionary<string, string> ChatUserNames = new ConcurrentDictionary<string, string>();
|
||||
/// <summary>
|
||||
/// by user name
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
static ConcurrentDictionary<string, List<string>> ChatCxIds = new ConcurrentDictionary<string, List<string>>();
|
||||
static readonly ConcurrentDictionary<string, List<string>> ChatCxIds = new ConcurrentDictionary<string, List<string>>();
|
||||
|
||||
/// <summary>
|
||||
/// by user name,
|
||||
/// the list of its chat rooms
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
static ConcurrentDictionary<string, List<string>> ChatRoomPresence = new ConcurrentDictionary<string, List<string>>();
|
||||
static ConcurrentDictionary<string, bool> _isCop = new ConcurrentDictionary<string, bool>();
|
||||
static readonly ConcurrentDictionary<string, List<string>> ChatRoomPresence = new ConcurrentDictionary<string, List<string>>();
|
||||
static readonly ConcurrentDictionary<string, bool> _isCop = new ConcurrentDictionary<string, bool>();
|
||||
|
||||
public static ConcurrentDictionary<string, ChatRoomInfo> Channels = new ConcurrentDictionary<string, ChatRoomInfo>();
|
||||
ApplicationDbContext _dbContext;
|
||||
IStringLocalizer _localizer;
|
||||
readonly ApplicationDbContext _dbContext;
|
||||
readonly IStringLocalizer _localizer;
|
||||
|
||||
public HubConnectionManager()
|
||||
{
|
||||
|
|
@ -97,7 +97,7 @@ namespace Yavsc.Services
|
|||
return ChatRoomPresence[userName].Contains(roomName);
|
||||
}
|
||||
|
||||
public bool isCop(string userName)
|
||||
public bool IsCop(string userName)
|
||||
{
|
||||
return _isCop[userName];
|
||||
}
|
||||
|
|
@ -179,7 +179,7 @@ namespace Yavsc.Services
|
|||
}
|
||||
else
|
||||
{
|
||||
if (isCop(userName))
|
||||
if (IsCop(userName))
|
||||
{
|
||||
chanInfo.Ops.Add(cxId);
|
||||
}
|
||||
|
|
@ -320,7 +320,7 @@ namespace Yavsc.Services
|
|||
_errorHandler(roomName, _localizer.GetString(ChatHubConstants.HopWontKickOp).ToString());
|
||||
return false;
|
||||
}
|
||||
if (isCop(userName))
|
||||
if (IsCop(userName))
|
||||
{
|
||||
_errorHandler(roomName, _localizer.GetString(ChatHubConstants.NoKickOnCop).ToString());
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -27,14 +27,12 @@ namespace Yavsc.Lib
|
|||
const string DefaultBaseClassName = "ATemplate";
|
||||
const string DefaultBaseClass = nameof(UserOrientedTemplate);
|
||||
const string DefaultNamespace = "CompiledRazorTemplates";
|
||||
|
||||
RazorTemplateEngine razorEngine;
|
||||
IStringLocalizer<EMailer> stringLocalizer;
|
||||
|
||||
ApplicationDbContext dbContext;
|
||||
IEmailSender mailSender;
|
||||
RazorEngineHost host;
|
||||
ILogger logger;
|
||||
readonly RazorTemplateEngine razorEngine;
|
||||
readonly IStringLocalizer<EMailer> stringLocalizer;
|
||||
readonly ApplicationDbContext dbContext;
|
||||
readonly IEmailSender mailSender;
|
||||
readonly RazorEngineHost host;
|
||||
readonly ILogger logger;
|
||||
|
||||
public EMailer(ApplicationDbContext context, IEmailSender sender,
|
||||
IStringLocalizer<EMailer> localizer,
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ namespace Yavsc.Services
|
|||
{
|
||||
public class FileSystemAuthManager : IFileSystemAuthManager
|
||||
{
|
||||
ApplicationDbContext _dbContext;
|
||||
ILogger _logger;
|
||||
readonly ApplicationDbContext _dbContext;
|
||||
readonly ILogger _logger;
|
||||
|
||||
public FileSystemAuthManager(ApplicationDbContext dbContext, ILoggerFactory loggerFactory)
|
||||
{
|
||||
|
|
@ -70,4 +70,4 @@ namespace Yavsc.Services
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,45 +43,22 @@ namespace Yavsc.Services
|
|||
/// <summary>
|
||||
/// Google Calendar API client.
|
||||
/// </summary>
|
||||
public class CalendarManager : ICalendarManager
|
||||
public class CalendarManager : ICalendarManager
|
||||
{
|
||||
public class ExpiredTokenException : Exception { }
|
||||
protected static string [] scopesCalendar =
|
||||
protected static string[] scopesCalendar =
|
||||
{ "https://www.googleapis.com/auth/calendar",
|
||||
"https://www.googleapis.com/auth/calendar.events"
|
||||
};
|
||||
private string _ApiKey;
|
||||
private IAuthorizationCodeFlow _flow;
|
||||
ApplicationDbContext _dbContext;
|
||||
readonly ILogger _logger;
|
||||
readonly string _client_id;
|
||||
readonly string _client_secret;
|
||||
|
||||
IDataStore _dataStore;
|
||||
ILogger _logger;
|
||||
string _client_id;
|
||||
string _client_secret;
|
||||
|
||||
public CalendarManager(
|
||||
ApplicationDbContext dbContext,
|
||||
IDataStore dataStore,
|
||||
ILoggerFactory loggerFactory,
|
||||
IOptions<GoogleAuthSettings> settings)
|
||||
public CalendarManager(ILoggerFactory loggerFactory)
|
||||
{
|
||||
_client_id = Startup.GoogleWebClientConfiguration["web:cient_id"];
|
||||
_client_secret = Startup.GoogleWebClientConfiguration["web:cient_secret"];
|
||||
|
||||
_ApiKey = settings.Value.ApiKey;
|
||||
_dbContext = dbContext;
|
||||
_client_id = Startup.GoogleWebClientConfiguration["web:cient_id"];
|
||||
_client_secret = Startup.GoogleWebClientConfiguration["web:cient_secret"];
|
||||
_logger = loggerFactory.CreateLogger<CalendarManager>();
|
||||
_dataStore = dataStore;
|
||||
_flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
|
||||
{
|
||||
ClientSecrets = new ClientSecrets
|
||||
{
|
||||
ClientId = _client_id,
|
||||
ClientSecret = _client_secret
|
||||
},
|
||||
Scopes = scopesCalendar ,
|
||||
DataStore = dataStore
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -98,29 +75,27 @@ namespace Yavsc.Services
|
|||
/// </summary>
|
||||
/// <returns>The calendars.</returns>
|
||||
/// <param name="userId">Yavsc user id</param>
|
||||
public async Task<CalendarList> GetCalendarsAsync(string userId, string pageToken)
|
||||
public async Task<CalendarList> GetCalendarsAsync(string pageToken)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(userId))
|
||||
throw new Exception("the user id is not specified");
|
||||
var service = await CreateUserCalendarServiceAsync(userId);
|
||||
var service = await CreateUserCalendarServiceAsync();
|
||||
#if Debug
|
||||
if (service==null) throw new Exception("Could not get service");
|
||||
#endif
|
||||
_logger.LogInformation("Got a service");
|
||||
_logger.LogInformation("Got a service");
|
||||
|
||||
#if Debug
|
||||
if (service.CalendarList==null) throw new Exception("Could not get calendar list");
|
||||
#endif
|
||||
CalendarListResource.ListRequest calListReq = service.CalendarList.List ();
|
||||
CalendarListResource.ListRequest calListReq = service.CalendarList.List();
|
||||
|
||||
#if Debug
|
||||
if (calListReq==null) throw new Exception ("list is null");
|
||||
#endif
|
||||
|
||||
calListReq.PageToken = pageToken;
|
||||
return calListReq.Execute ();
|
||||
calListReq.PageToken = pageToken;
|
||||
return calListReq.Execute();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a calendar event list, between the given dates.
|
||||
/// </summary>
|
||||
|
|
@ -158,16 +133,17 @@ namespace Yavsc.Services
|
|||
|
||||
foreach (var ev in eventList.Items)
|
||||
{
|
||||
if (ev.Start.DateTime.HasValue && ev.End.DateTime.HasValue ) {
|
||||
DateTime start = ev.Start.DateTime.Value;
|
||||
DateTime end = ev.End.DateTime.Value;
|
||||
|
||||
if (ev.Transparency == "transparent")
|
||||
if (ev.Start.DateTime.HasValue && ev.End.DateTime.HasValue)
|
||||
{
|
||||
DateTime start = ev.Start.DateTime.Value;
|
||||
DateTime end = ev.End.DateTime.Value;
|
||||
|
||||
free.Add(new Period { Start = start, End = end });
|
||||
}
|
||||
else busy.Add(new Period { Start = start, End = end });
|
||||
if (ev.Transparency == "transparent")
|
||||
{
|
||||
|
||||
free.Add(new Period { Start = start, End = end });
|
||||
}
|
||||
else busy.Add(new Period { Start = start, End = end });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -200,7 +176,7 @@ namespace Yavsc.Services
|
|||
|
||||
if (string.IsNullOrWhiteSpace(calid))
|
||||
throw new Exception("the calendar identifier is not specified");
|
||||
|
||||
|
||||
var service = await GetServiceAsync();
|
||||
Event ev = new Event
|
||||
{
|
||||
|
|
@ -217,15 +193,16 @@ namespace Yavsc.Services
|
|||
CalendarService _service = null;
|
||||
public async Task<CalendarService> GetServiceAsync()
|
||||
{
|
||||
if (_service==null) {
|
||||
if (_service == null)
|
||||
{
|
||||
GoogleCredential credential = await GoogleCredential.GetApplicationDefaultAsync();
|
||||
var baseClientService = new BaseClientService.Initializer()
|
||||
{
|
||||
HttpClientInitializer = credential
|
||||
};
|
||||
{
|
||||
HttpClientInitializer = credential
|
||||
};
|
||||
if (credential.IsCreateScopedRequired)
|
||||
{
|
||||
credential = credential.CreateScoped( scopesCalendar );
|
||||
credential = credential.CreateScoped(scopesCalendar);
|
||||
}/*
|
||||
var credential = await GoogleHelpers.GetCredentialForApi(new string [] { scopeCalendar });
|
||||
if (credential.IsCreateScopedRequired)
|
||||
|
|
@ -239,26 +216,26 @@ namespace Yavsc.Services
|
|||
});
|
||||
}*/
|
||||
_service = new CalendarService(new BaseClientService.Initializer()
|
||||
{
|
||||
HttpClientInitializer = credential,
|
||||
ApplicationName = "Yavsc"
|
||||
});
|
||||
{
|
||||
HttpClientInitializer = credential,
|
||||
ApplicationName = "Yavsc"
|
||||
});
|
||||
}
|
||||
return _service;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates Google User Credential
|
||||
/// </summary>
|
||||
/// <param name="userId">Yavsc use id</param>
|
||||
/// <returns></returns>
|
||||
public async Task<CalendarService> CreateUserCalendarServiceAsync(string userId)
|
||||
/// <summary>
|
||||
/// Creates Google User Credential
|
||||
/// </summary>
|
||||
/// <param name="userId">Yavsc use id</param>
|
||||
/// <returns></returns>
|
||||
public async Task<CalendarService> CreateUserCalendarServiceAsync()
|
||||
{
|
||||
GoogleCredential credential = await GoogleCredential.GetApplicationDefaultAsync();
|
||||
|
||||
if (credential.IsCreateScopedRequired)
|
||||
{
|
||||
credential = credential.CreateScoped( scopesCalendar);
|
||||
credential = credential.CreateScoped(scopesCalendar);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -268,25 +245,32 @@ namespace Yavsc.Services
|
|||
ApplicationName = "yavsc-001"
|
||||
});
|
||||
|
||||
return service;
|
||||
}
|
||||
return service;
|
||||
}
|
||||
|
||||
public async Task<TokenResponse> RefreshToken(TokenResponse oldResponse)
|
||||
{
|
||||
string ep = " https://www.googleapis.com/oauth2/v4/token";
|
||||
_logger.LogInformation($"rt:{oldResponse.RefreshToken}");
|
||||
// refresh_token client_id client_secret grant_type=refresh_token
|
||||
try {
|
||||
using (var m = new SimpleJsonPostMethod(ep)) {
|
||||
try
|
||||
{
|
||||
using (var m = new SimpleJsonPostMethod(ep))
|
||||
{
|
||||
return await m.Invoke<TokenResponse>(
|
||||
new { refresh_token= oldResponse.RefreshToken, client_id=_client_id,
|
||||
client_secret=_client_secret,
|
||||
grant_type="refresh_token" }
|
||||
new
|
||||
{
|
||||
refresh_token = oldResponse.RefreshToken,
|
||||
client_id = _client_id,
|
||||
client_secret = _client_secret,
|
||||
grant_type = "refresh_token"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new Exception ("Quelque chose s'est mal passé à l'envoi",ex);
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Quelque chose s'est mal passé à l'envoi", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,14 +21,15 @@ using Newtonsoft.Json;
|
|||
namespace Yavsc.Services
|
||||
{
|
||||
|
||||
public class LiveProcessor : ILiveProcessor {
|
||||
IHubContext _hubContext;
|
||||
private ILogger _logger;
|
||||
ApplicationDbContext _dbContext;
|
||||
public PathString LiveCastingPath {get; set;} = Constants.LivePath;
|
||||
public class LiveProcessor : ILiveProcessor
|
||||
{
|
||||
readonly IHubContext _hubContext;
|
||||
private readonly ILogger _logger;
|
||||
readonly ApplicationDbContext _dbContext;
|
||||
public PathString LiveCastingPath { get; set; } = Constants.LivePath;
|
||||
|
||||
|
||||
public ConcurrentDictionary<string, LiveCastHandler> Casters {get;} = new ConcurrentDictionary<string, LiveCastHandler>();
|
||||
public ConcurrentDictionary<string, LiveCastHandler> Casters { get; } = new ConcurrentDictionary<string, LiveCastHandler>();
|
||||
|
||||
public LiveProcessor(ApplicationDbContext dbContext, ILoggerFactory loggerFactory)
|
||||
{
|
||||
|
|
@ -37,7 +38,7 @@ namespace Yavsc.Services
|
|||
_logger = loggerFactory.CreateLogger<LiveProcessor>();
|
||||
}
|
||||
|
||||
public async Task<bool> AcceptStream (HttpContext context)
|
||||
public async Task<bool> AcceptStream(HttpContext context)
|
||||
{
|
||||
// TODO defer request handling
|
||||
var liveId = long.Parse(context.Request.Path.Value.Substring(LiveCastingPath.Value.Length + 1));
|
||||
|
|
@ -51,22 +52,23 @@ namespace Yavsc.Services
|
|||
context.Response.StatusCode = 400;
|
||||
return false;
|
||||
}
|
||||
_logger.LogInformation("flow : "+flow.Title+" for "+uname);
|
||||
|
||||
_logger.LogInformation("flow : " + flow.Title + " for " + uname);
|
||||
|
||||
|
||||
LiveCastHandler liveHandler = null;
|
||||
if (Casters.ContainsKey(uname))
|
||||
{
|
||||
_logger.LogWarning($"Casters.ContainsKey({uname})");
|
||||
liveHandler = Casters[uname];
|
||||
if (liveHandler.Socket.State == WebSocketState.Open || liveHandler.Socket.State == WebSocketState.Connecting )
|
||||
if (liveHandler.Socket.State == WebSocketState.Open || liveHandler.Socket.State == WebSocketState.Connecting)
|
||||
{
|
||||
_logger.LogWarning($"Closing cx");
|
||||
_logger.LogWarning($"Closing cx");
|
||||
// FIXME loosed connexion should be detected & disposed else where
|
||||
await liveHandler.Socket.CloseAsync( WebSocketCloseStatus.EndpointUnavailable, "one by user", CancellationToken.None);
|
||||
|
||||
await liveHandler.Socket.CloseAsync(WebSocketCloseStatus.EndpointUnavailable, "one by user", CancellationToken.None);
|
||||
|
||||
}
|
||||
if (!liveHandler.TokenSource.IsCancellationRequested) {
|
||||
if (!liveHandler.TokenSource.IsCancellationRequested)
|
||||
{
|
||||
liveHandler.TokenSource.Cancel();
|
||||
}
|
||||
liveHandler.Socket.Dispose();
|
||||
|
|
@ -81,7 +83,7 @@ namespace Yavsc.Services
|
|||
}
|
||||
_logger.LogInformation("Accepted web socket");
|
||||
// Dispatch the flow
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if (liveHandler.Socket != null && liveHandler.Socket.State == WebSocketState.Open)
|
||||
|
|
@ -90,33 +92,33 @@ namespace Yavsc.Services
|
|||
// TODO: Handle the socket here.
|
||||
// Find receivers: others in the chat room
|
||||
// send them the flow
|
||||
var buffer = new byte[Constants.WebSocketsMaxBufLen+16];
|
||||
var buffer = new byte[Constants.WebSocketsMaxBufLen];
|
||||
var sBuffer = new ArraySegment<byte>(buffer);
|
||||
_logger.LogInformation("Receiving bytes...");
|
||||
|
||||
WebSocketReceiveResult received = await liveHandler.Socket.ReceiveAsync(sBuffer, liveHandler.TokenSource.Token);
|
||||
int count = (received.Count<4)? 0 : buffer[0]*256*1024 +buffer[1]*1024+buffer[2]*256 + buffer[3];
|
||||
|
||||
_logger.LogInformation($"Received bytes : {count}");
|
||||
_logger.LogInformation($"Received bytes : {received.Count}");
|
||||
_logger.LogInformation($"Is the end : {received.EndOfMessage}");
|
||||
const string livePath = "live";
|
||||
|
||||
string destDir = context.User.InitPostToFileSystem(livePath);
|
||||
_logger.LogInformation($"Saving flow to {destDir}");
|
||||
|
||||
string fileName = flow.GetFileName();
|
||||
|
||||
string fileName = flow.GetFileName();
|
||||
FileInfo destFileInfo = new FileInfo(Path.Combine(destDir, fileName));
|
||||
// this should end :-)
|
||||
while (destFileInfo.Exists) {
|
||||
while (destFileInfo.Exists)
|
||||
{
|
||||
flow.SequenceNumber++;
|
||||
fileName = flow.GetFileName();
|
||||
fileName = flow.GetFileName();
|
||||
destFileInfo = new FileInfo(Path.Combine(destDir, fileName));
|
||||
}
|
||||
var fsInputQueue = new Queue<ArraySegment<byte>>();
|
||||
|
||||
bool endOfInput=false;
|
||||
|
||||
bool endOfInput = false;
|
||||
fsInputQueue.Enqueue(sBuffer);
|
||||
var taskWritingToFs = liveHandler.ReceiveUserFile(user, _logger, destDir, fsInputQueue, fileName, flow.MediaType, ()=> endOfInput);
|
||||
var taskWritingToFs = liveHandler.ReceiveUserFile(user, _logger, destDir, fsInputQueue, fileName, flow.MediaType, () => endOfInput);
|
||||
var hubContext = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();
|
||||
|
||||
hubContext.Clients.All.addPublicStream(new PublicStreamInfo
|
||||
|
|
@ -132,15 +134,18 @@ namespace Yavsc.Services
|
|||
|
||||
try
|
||||
{
|
||||
do {
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
_logger.LogInformation($"Echoing {received.Count} bytes received in a {received.MessageType} message; Fin={received.EndOfMessage}");
|
||||
// Echo anything we receive
|
||||
// and send to all listner found
|
||||
_logger.LogInformation($"{liveHandler.Listeners.Count} listeners");
|
||||
foreach (var cliItem in liveHandler.Listeners)
|
||||
{
|
||||
var listenningSocket = cliItem.Value;
|
||||
if (listenningSocket.State == WebSocketState.Open) {
|
||||
if (listenningSocket.State == WebSocketState.Open)
|
||||
{
|
||||
_logger.LogInformation(cliItem.Key);
|
||||
await listenningSocket.SendAsync(
|
||||
sBuffer, received.MessageType, received.EndOfMessage, liveHandler.TokenSource.Token);
|
||||
|
|
@ -150,43 +155,47 @@ namespace Yavsc.Services
|
|||
ToClose.Push(cliItem.Key);
|
||||
}
|
||||
}
|
||||
buffer = new byte[Constants.WebSocketsMaxBufLen+16];
|
||||
|
||||
if (!received.CloseStatus.HasValue)
|
||||
{
|
||||
_logger.LogInformation("try and receive new bytes");
|
||||
|
||||
buffer = new byte[Constants.WebSocketsMaxBufLen];
|
||||
sBuffer = new ArraySegment<byte>(buffer);
|
||||
received = await liveHandler.Socket.ReceiveAsync(sBuffer, liveHandler.TokenSource.Token);
|
||||
count = (received.Count<4)? 0 : buffer[0]*256*1024 +buffer[1]*1024+buffer[2]*256 + buffer[3];
|
||||
_logger.LogInformation($"Received bytes : {count}");
|
||||
|
||||
_logger.LogInformation($"Received bytes : {received.Count}");
|
||||
_logger.LogInformation($"Is the end : {received.EndOfMessage}");
|
||||
if (received.Count<=4 || count > Constants.WebSocketsMaxBufLen) {
|
||||
if (received.CloseStatus.HasValue) {
|
||||
_logger.LogInformation($"received a close status: {received.CloseStatus.Value.ToString()}: {received.CloseStatusDescription}");
|
||||
}
|
||||
else {
|
||||
_logger.LogError("Wrong packet size: "+count.ToString());
|
||||
_logger.LogError(JsonConvert.SerializeObject(received));
|
||||
}
|
||||
fsInputQueue.Enqueue(sBuffer);
|
||||
if (received.CloseStatus.HasValue)
|
||||
{
|
||||
endOfInput=true;
|
||||
_logger.LogInformation($"received a close status: {received.CloseStatus.Value}: {received.CloseStatusDescription}");
|
||||
}
|
||||
else fsInputQueue.Enqueue(sBuffer);
|
||||
while (ToClose.Count >0)
|
||||
}
|
||||
else endOfInput=true;
|
||||
while (ToClose.Count > 0)
|
||||
{
|
||||
string no = ToClose.Pop();
|
||||
_logger.LogInformation("Closing follower connection");
|
||||
WebSocket listenningSocket;
|
||||
if (liveHandler.Listeners.TryRemove(no, out listenningSocket)) {
|
||||
if (liveHandler.Listeners.TryRemove(no, out listenningSocket))
|
||||
{
|
||||
await listenningSocket.CloseAsync(WebSocketCloseStatus.EndpointUnavailable,
|
||||
"State != WebSocketState.Open", CancellationToken.None);
|
||||
listenningSocket.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!received.CloseStatus.HasValue);
|
||||
_logger.LogInformation("Closing connection");
|
||||
endOfInput=true;
|
||||
taskWritingToFs.Wait();
|
||||
await liveHandler.Socket.CloseAsync(WebSocketCloseStatus.NormalClosure, received.CloseStatusDescription,liveHandler.TokenSource.Token );
|
||||
while (liveHandler.Socket.State == WebSocketState.Open);
|
||||
|
||||
_logger.LogInformation("Closing connection");
|
||||
taskWritingToFs.Wait();
|
||||
await liveHandler.Socket.CloseAsync(WebSocketCloseStatus.NormalClosure, received.CloseStatusDescription, liveHandler.TokenSource.Token);
|
||||
|
||||
liveHandler.TokenSource.Cancel();
|
||||
liveHandler.Dispose();
|
||||
_logger.LogInformation("Resulting file : " +JsonConvert.SerializeObject(taskWritingToFs.Result));
|
||||
_logger.LogInformation("Resulting file : " + JsonConvert.SerializeObject(taskWritingToFs.Result));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -200,16 +209,16 @@ namespace Yavsc.Services
|
|||
else
|
||||
{
|
||||
// Socket was not accepted open ...
|
||||
// not (meta.Socket != null && meta.Socket.State == WebSocketState.Open)
|
||||
// not (meta.Socket != null && meta.Socket.State == WebSocketState.Open)
|
||||
if (liveHandler.Socket != null)
|
||||
{
|
||||
_logger.LogError($"meta.Socket.State not Open: {liveHandler.Socket.State.ToString()} ");
|
||||
_logger.LogError($"meta.Socket.State not Open: {liveHandler.Socket.State} ");
|
||||
liveHandler.Socket.Dispose();
|
||||
}
|
||||
else
|
||||
_logger.LogError("socket object is null");
|
||||
}
|
||||
|
||||
|
||||
RemoveLiveInfo(uname);
|
||||
}
|
||||
catch (IOException ex)
|
||||
|
|
@ -231,11 +240,11 @@ namespace Yavsc.Services
|
|||
void RemoveLiveInfo(string userName)
|
||||
{
|
||||
LiveCastHandler caster;
|
||||
if (Casters.TryRemove(userName, out caster))
|
||||
if (Casters.TryRemove(userName, out caster))
|
||||
_logger.LogInformation("removed live info");
|
||||
else
|
||||
else
|
||||
_logger.LogError("could not remove live info");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,18 +12,14 @@ namespace Yavsc.Services
|
|||
{
|
||||
public class MailSender : IEmailSender
|
||||
{
|
||||
private ILogger _logger;
|
||||
SiteSettings siteSettings;
|
||||
SmtpSettings smtpSettings;
|
||||
readonly SiteSettings siteSettings;
|
||||
readonly SmtpSettings smtpSettings;
|
||||
|
||||
public MailSender(
|
||||
ILoggerFactory loggerFactory,
|
||||
IOptions<SiteSettings> sitesOptions,
|
||||
IOptions<SmtpSettings> smtpOptions,
|
||||
IOptions<GoogleAuthSettings> googleOptions
|
||||
IOptions<SmtpSettings> smtpOptions
|
||||
)
|
||||
{
|
||||
_logger = loggerFactory.CreateLogger<MailSender>();
|
||||
siteSettings = sitesOptions?.Value;
|
||||
smtpSettings = smtpOptions?.Value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace Yavsc.Services
|
|||
using Models.societe.com;
|
||||
public class SIRENChecker
|
||||
{
|
||||
private CompanyInfoSettings _settings;
|
||||
private readonly CompanyInfoSettings _settings;
|
||||
public SIRENChecker(CompanyInfoSettings settings)
|
||||
{
|
||||
_settings = settings;
|
||||
|
|
|
|||
|
|
@ -16,18 +16,16 @@ namespace Yavsc.Services
|
|||
{
|
||||
public class YavscMessageSender : IYavscMessageSender
|
||||
{
|
||||
private ILogger _logger;
|
||||
IEmailSender _emailSender;
|
||||
SiteSettings siteSettings;
|
||||
private IHubContext hubContext;
|
||||
ApplicationDbContext _dbContext;
|
||||
|
||||
IConnexionManager _cxManager;
|
||||
private readonly ILogger _logger;
|
||||
readonly IEmailSender _emailSender;
|
||||
readonly SiteSettings siteSettings;
|
||||
private readonly IHubContext hubContext;
|
||||
readonly ApplicationDbContext _dbContext;
|
||||
readonly IConnexionManager _cxManager;
|
||||
|
||||
public YavscMessageSender(
|
||||
ILoggerFactory loggerFactory,
|
||||
IOptions<SiteSettings> sitesOptions,
|
||||
IOptions<SmtpSettings> smtpOptions,
|
||||
IEmailSender emailSender,
|
||||
ApplicationDbContext dbContext,
|
||||
IConnexionManager cxManager
|
||||
|
|
@ -67,8 +65,10 @@ namespace Yavsc.Services
|
|||
foreach (var userId in raa)
|
||||
{
|
||||
_logger.LogDebug($"For performer id : {userId}");
|
||||
MessageWithPayloadResponse.Result result = new MessageWithPayloadResponse.Result();
|
||||
result.registration_id = userId;
|
||||
MessageWithPayloadResponse.Result result = new MessageWithPayloadResponse.Result
|
||||
{
|
||||
registration_id = userId
|
||||
};
|
||||
|
||||
var user = _dbContext.Users.FirstOrDefault(u => u.Id == userId);
|
||||
if (user == null)
|
||||
|
|
@ -125,8 +125,10 @@ namespace Yavsc.Services
|
|||
{
|
||||
// from usr asp.net Id : var hubClient = hubContext.Clients.User(userId);
|
||||
var hubClient = hubContext.Clients.Client(cxid);
|
||||
var data = new Dictionary<string, object>();
|
||||
data["event"] = JsonConvert.SerializeObject(ev);
|
||||
var data = new Dictionary<string, object>
|
||||
{
|
||||
["event"] = JsonConvert.SerializeObject(ev)
|
||||
};
|
||||
hubClient.push(ev.Topic, JsonConvert.SerializeObject(data));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -91,8 +91,7 @@ namespace Yavsc
|
|||
//
|
||||
;
|
||||
}
|
||||
private void ConfigureOAuthApp(IApplicationBuilder app,
|
||||
SiteSettings settingsOptions, ILogger logger)
|
||||
private void ConfigureOAuthApp(IApplicationBuilder app)
|
||||
{
|
||||
|
||||
app.UseIdentity();
|
||||
|
|
|
|||
|
|
@ -13,15 +13,9 @@ namespace Yavsc
|
|||
// * an AppData folder
|
||||
public partial class Startup
|
||||
{
|
||||
public void CheckServices(IServiceCollection services)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void CheckApp(IApplicationBuilder app,
|
||||
SiteSettings siteSettings, IHostingEnvironment env,
|
||||
ILoggerFactory loggerFactory
|
||||
)
|
||||
public void CheckApp(IHostingEnvironment env,
|
||||
ILoggerFactory loggerFactory)
|
||||
{
|
||||
|
||||
var logger = loggerFactory.CreateLogger<Startup>();
|
||||
|
|
|
|||
|
|
@ -11,8 +11,7 @@ namespace Yavsc
|
|||
{
|
||||
public partial class Startup
|
||||
{
|
||||
public void ConfigureWebSocketsApp(IApplicationBuilder app,
|
||||
SiteSettings siteSettings, IHostingEnvironment env)
|
||||
public void ConfigureWebSocketsApp(IApplicationBuilder app)
|
||||
{
|
||||
var webSocketOptions = new WebSocketOptions()
|
||||
{
|
||||
|
|
@ -25,7 +24,7 @@ namespace Yavsc
|
|||
app.UseSignalR(PathString.FromUriComponent(Constants.SignalRPath));
|
||||
}
|
||||
|
||||
private async Task Echo(HttpContext context, WebSocket webSocket)
|
||||
private async Task Echo(WebSocket webSocket)
|
||||
{
|
||||
var buffer = new byte[1024 * 4];
|
||||
WebSocketReceiveResult result = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace Yavsc
|
|||
/// </summary>
|
||||
public static readonly string[] Forms = new string[] { "Profiles", "HairCut" };
|
||||
|
||||
private void ConfigureWorkflow(IApplicationBuilder app, SiteSettings settings, ILogger logger)
|
||||
private void ConfigureWorkflow()
|
||||
{
|
||||
// System.AppDomain.CurrentDomain.ResourceResolve += OnYavscResourceResolve;
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ namespace Yavsc
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex.TargetSite.Name);
|
||||
_logger.LogError(ex.TargetSite.Name);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ namespace Yavsc
|
|||
// TODO swith () case {}
|
||||
if (typeof(IQueryable<ISpecializationSettings>).IsAssignableFrom(propinfo.PropertyType))
|
||||
{// double-bingo
|
||||
logger.LogVerbose($"Pro: {propinfo.Name}");
|
||||
_logger.LogVerbose($"Pro: {propinfo.Name}");
|
||||
BillingService.UserSettings.Add(propinfo);
|
||||
}
|
||||
else
|
||||
|
|
@ -75,7 +75,7 @@ namespace Yavsc
|
|||
base de donnée porte l'attribut [ActivitySetting],
|
||||
mais n'implemente pas l'interface IQueryable<ISpecializationSettings>
|
||||
({propinfo.MemberType.GetType()})";
|
||||
logger.LogCritical(msg);
|
||||
_logger.LogCritical(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -278,7 +278,6 @@ namespace Yavsc
|
|||
{
|
||||
options.ResourcesPath = "Resources";
|
||||
});
|
||||
CheckServices(services);
|
||||
}
|
||||
static ApplicationDbContext _dbContext;
|
||||
public static IServiceProvider Services { get; private set; }
|
||||
|
|
@ -288,7 +287,6 @@ namespace Yavsc
|
|||
IApplicationBuilder app, IHostingEnvironment env,
|
||||
ApplicationDbContext dbContext, IOptions<SiteSettings> siteSettings,
|
||||
IOptions<RequestLocalizationOptions> localizationOptions,
|
||||
IOptions<OAuth2AppSettings> oauth2SettingsContainer,
|
||||
IAuthorizationService authorizationService,
|
||||
IOptions<PayPalSettings> payPalSettings,
|
||||
IOptions<GoogleAuthSettings> googleSettings,
|
||||
|
|
@ -355,8 +353,10 @@ namespace Yavsc
|
|||
|
||||
app.UseDeveloperExceptionPage();
|
||||
app.UseRuntimeInfoPage();
|
||||
var epo = new ErrorPageOptions();
|
||||
epo.SourceCodeLineCount = 20;
|
||||
var epo = new ErrorPageOptions
|
||||
{
|
||||
SourceCodeLineCount = 20
|
||||
};
|
||||
app.UseDeveloperExceptionPage(epo);
|
||||
app.UseDatabaseErrorPage(
|
||||
x =>
|
||||
|
|
@ -404,19 +404,22 @@ namespace Yavsc
|
|||
});
|
||||
app.UseSession();
|
||||
|
||||
ConfigureOAuthApp(app, SiteSetup, _logger);
|
||||
ConfigureOAuthApp(app);
|
||||
ConfigureFileServerApp(app, SiteSetup, env, authorizationService);
|
||||
app.UseRequestLocalization(localizationOptions.Value, (RequestCulture)new RequestCulture((string)"en-US"));
|
||||
|
||||
ConfigureWorkflow(app, SiteSetup, _logger);
|
||||
ConfigureWorkflow();
|
||||
|
||||
// Empty this odd chat user list from db
|
||||
/*
|
||||
foreach (var p in dbContext.ChatConnection)
|
||||
{
|
||||
dbContext.Entry(p).State = EntityState.Deleted;
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
FIXME */
|
||||
|
||||
ConfigureWebSocketsApp(app, SiteSetup, env);
|
||||
ConfigureWebSocketsApp(app);
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
|
|
@ -451,7 +454,7 @@ namespace Yavsc
|
|||
}
|
||||
|
||||
});
|
||||
CheckApp(app, SiteSetup, env, loggerFactory);
|
||||
CheckApp( env, loggerFactory);
|
||||
}
|
||||
|
||||
// Entry point for the application.
|
||||
|
|
|
|||
|
|
@ -16,20 +16,17 @@ namespace Yavsc.ViewComponents
|
|||
{
|
||||
public class BillViewComponent : ViewComponent
|
||||
{
|
||||
ApplicationDbContext dbContext;
|
||||
IBillingService billing;
|
||||
IStringLocalizer<Yavsc.YavscLocalisation> localizer;
|
||||
ILogger logger ;
|
||||
readonly ApplicationDbContext dbContext;
|
||||
readonly IBillingService billing;
|
||||
readonly IStringLocalizer<Yavsc.YavscLocalisation> localizer;
|
||||
|
||||
public BillViewComponent(ApplicationDbContext dbContext,
|
||||
IStringLocalizer<Yavsc.YavscLocalisation> localizer,
|
||||
IBillingService billing,
|
||||
ILoggerFactory loggerFactory)
|
||||
IBillingService billing)
|
||||
{
|
||||
this.billing = billing;
|
||||
this.dbContext = dbContext;
|
||||
this.localizer = localizer;
|
||||
logger = loggerFactory.CreateLogger<BillViewComponent>();
|
||||
}
|
||||
|
||||
public async Task<IViewComponentResult> InvokeAsync(string code, IBillable billable, OutputFormat format, bool asBill)
|
||||
|
|
|
|||
|
|
@ -13,19 +13,11 @@ namespace Yavsc.ViewComponents
|
|||
{
|
||||
public class BlogIndexViewComponent: ViewComponent
|
||||
{
|
||||
ILogger _logger;
|
||||
private ApplicationDbContext _context;
|
||||
private IAuthorizationService _authorizationService;
|
||||
private readonly ApplicationDbContext _context;
|
||||
public BlogIndexViewComponent(
|
||||
ApplicationDbContext context,
|
||||
UserManager<ApplicationUser> userManager,
|
||||
ILoggerFactory loggerFactory,
|
||||
IAuthorizationService authorizationService,
|
||||
IOptions<SiteSettings> siteSettings)
|
||||
ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
_logger = loggerFactory.CreateLogger<BlogIndexViewComponent>();
|
||||
_authorizationService = authorizationService;
|
||||
}
|
||||
|
||||
// Renders blog index ofr the specified user by name
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ namespace Yavsc.ViewComponents
|
|||
{
|
||||
public class CalendarViewComponent : ViewComponent
|
||||
{
|
||||
ApplicationDbContext _dbContext;
|
||||
ICalendarManager _manager;
|
||||
readonly ApplicationDbContext _dbContext;
|
||||
readonly ICalendarManager _manager;
|
||||
|
||||
public CalendarViewComponent (
|
||||
ApplicationDbContext dbContext,
|
||||
|
|
@ -47,4 +47,4 @@ namespace Yavsc.ViewComponents
|
|||
return View(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,17 +9,14 @@ namespace Yavsc.ViewComponents
|
|||
public class TaggerViewComponent : ViewComponent
|
||||
|
||||
{
|
||||
ApplicationDbContext dbContext;
|
||||
IStringLocalizer<TaggerViewComponent> localizer;
|
||||
ILogger logger ;
|
||||
readonly ApplicationDbContext dbContext;
|
||||
readonly IStringLocalizer<TaggerViewComponent> localizer;
|
||||
public TaggerViewComponent(
|
||||
ApplicationDbContext pdbContext,
|
||||
IStringLocalizer<TaggerViewComponent> pLocalizer,
|
||||
ILoggerFactory loggerFactory)
|
||||
IStringLocalizer<TaggerViewComponent> pLocalizer)
|
||||
{
|
||||
dbContext = pdbContext;
|
||||
this.localizer = pLocalizer;
|
||||
this.logger = loggerFactory.CreateLogger<TaggerViewComponent>();
|
||||
}
|
||||
public IViewComponentResult Invoke(ITaggable<long> longTaggable)
|
||||
{
|
||||
|
|
@ -29,4 +26,4 @@ namespace Yavsc.ViewComponents
|
|||
return View(longTaggable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,10 +41,12 @@ namespace Yavsc.ViewModels.Streaming
|
|||
// this process is not safe at concurrent access.
|
||||
long usage = user.DiskUsage;
|
||||
|
||||
var item = new FileRecievedInfo();
|
||||
item.FileName = AbstractFileSystemHelpers.FilterFileName (destFileName);
|
||||
item.MimeType = contentType;
|
||||
item.DestDir = root;
|
||||
var item = new FileRecievedInfo
|
||||
{
|
||||
FileName = AbstractFileSystemHelpers.FilterFileName(destFileName),
|
||||
MimeType = contentType,
|
||||
DestDir = root
|
||||
};
|
||||
var fi = new FileInfo(Path.Combine(root, item.FileName));
|
||||
if (fi.Exists)
|
||||
{
|
||||
|
|
@ -59,26 +61,17 @@ namespace Yavsc.ViewModels.Streaming
|
|||
{
|
||||
if (queue.Count>0) {
|
||||
var buffer = queue.Dequeue();
|
||||
int count = buffer.Array[0]*256*1024 +buffer.Array[1]*1024+buffer.Array[2]*256 + buffer.Array[3];
|
||||
|
||||
if (count >0 && count <= Constants.WebSocketsMaxBufLen
|
||||
&& buffer.Array.Length >= count+4) {
|
||||
logger.LogInformation($"writing {count} bytes from {buffer.Array.Length}.");
|
||||
logger.LogInformation($"writing {buffer.Array.Length} bytes...");
|
||||
|
||||
await dest.WriteAsync(buffer.Array, 4, count);
|
||||
logger.LogInformation($"wrote {count} bytes.");
|
||||
usage += count;
|
||||
}
|
||||
else {
|
||||
var packetInfo = JsonConvert.SerializeObject(buffer);
|
||||
logger.LogError($"didn´t wrote {count} bytes from {buffer.Array.Length}!\n{packetInfo}");
|
||||
}
|
||||
await dest.WriteAsync(buffer.Array, 0, buffer.Array.Length);
|
||||
logger.LogInformation($"done.");
|
||||
usage += buffer.Array.Length;
|
||||
|
||||
}
|
||||
if (usage >= user.DiskQuota) break;
|
||||
if (queue.Count==0 && !isEndOfInput()) {
|
||||
logger.LogInformation($"Waitting 200ms.");
|
||||
await Task.Delay(100);
|
||||
logger.LogInformation($"Done waiting");
|
||||
}
|
||||
}
|
||||
user.DiskUsage = usage;
|
||||
|
|
@ -93,4 +86,4 @@ namespace Yavsc.ViewModels.Streaming
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue