fixe l'execution (apparemment)
This commit is contained in:
parent
cb6309abdb
commit
21d5954bbf
6 changed files with 32 additions and 20 deletions
|
|
@ -2,10 +2,8 @@ namespace Yavsc.Server.Helpers
|
||||||
{
|
{
|
||||||
public static class DbHelpers
|
public static class DbHelpers
|
||||||
{
|
{
|
||||||
static string _connectionString = null;
|
// FIXME BUG [fr] DependencyInjection Pourquoi ce champ ne pourrait pas devenir une propriété ?
|
||||||
public static string ConnectionString {
|
// : casse à l'execution d'un controlleur, se plaignant d'une valeur nule
|
||||||
get { return _connectionString = null; }
|
public static string ConnectionString = null;
|
||||||
set { _connectionString = value; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -65,10 +65,8 @@ namespace Yavsc.Models
|
||||||
et.FindProperty("DateCreated").IsReadOnlyAfterSave = true;
|
et.FindProperty("DateCreated").IsReadOnlyAfterSave = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
{
|
||||||
|
|
||||||
optionsBuilder.UseNpgsql(DbHelpers.ConnectionString);
|
optionsBuilder.UseNpgsql(DbHelpers.ConnectionString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ public static FileRecievedInfo ReceiveProSignature(this ClaimsPrincipal user, st
|
||||||
|
|
||||||
public static void DeleteUserFile(this ApplicationUser user, string fileName)
|
public static void DeleteUserFile(this ApplicationUser user, string fileName)
|
||||||
{
|
{
|
||||||
var root = Path.Combine(Startup.UserFilesDirName, user.UserName);
|
var root = Path.Combine(AbstractFileSystemHelpers.UserFilesDirName, user.UserName);
|
||||||
var fi = new FileInfo(Path.Combine(root, fileName));
|
var fi = new FileInfo(Path.Combine(root, fileName));
|
||||||
if (!fi.Exists) return ;
|
if (!fi.Exists) return ;
|
||||||
fi.Delete();
|
fi.Delete();
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@ using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.AspNet.Hosting;
|
using Microsoft.AspNet.Hosting;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.StaticFiles;
|
using Microsoft.AspNet.StaticFiles;
|
||||||
|
using Yavsc.Abstract.FileSystem;
|
||||||
using Yavsc.ViewModels.Auth;
|
using Yavsc.ViewModels.Auth;
|
||||||
|
|
||||||
namespace Yavsc
|
namespace Yavsc
|
||||||
{
|
{
|
||||||
public partial class Startup
|
public partial class Startup
|
||||||
{
|
{
|
||||||
public static string UserFilesDirName { get; private set; }
|
|
||||||
public static FileServerOptions UserFilesOptions { get; private set; }
|
public static FileServerOptions UserFilesOptions { get; private set; }
|
||||||
|
|
||||||
public static FileServerOptions AvatarsOptions { get; set; }
|
public static FileServerOptions AvatarsOptions { get; set; }
|
||||||
|
|
@ -20,13 +20,13 @@ namespace Yavsc
|
||||||
SiteSettings siteSettings, IHostingEnvironment env, IAuthorizationService authorizationService)
|
SiteSettings siteSettings, IHostingEnvironment env, IAuthorizationService authorizationService)
|
||||||
{
|
{
|
||||||
var userFilesDirInfo = new DirectoryInfo( siteSettings.UserFiles.Blog );
|
var userFilesDirInfo = new DirectoryInfo( siteSettings.UserFiles.Blog );
|
||||||
UserFilesDirName = userFilesDirInfo.FullName;
|
AbstractFileSystemHelpers.UserFilesDirName = userFilesDirInfo.FullName;
|
||||||
|
|
||||||
if (!userFilesDirInfo.Exists) userFilesDirInfo.Create();
|
if (!userFilesDirInfo.Exists) userFilesDirInfo.Create();
|
||||||
|
|
||||||
UserFilesOptions = new FileServerOptions()
|
UserFilesOptions = new FileServerOptions()
|
||||||
{
|
{
|
||||||
FileProvider = new PhysicalFileProvider(UserFilesDirName),
|
FileProvider = new PhysicalFileProvider(AbstractFileSystemHelpers.UserFilesDirName),
|
||||||
RequestPath = new PathString(Constants.UserFilesPath),
|
RequestPath = new PathString(Constants.UserFilesPath),
|
||||||
EnableDirectoryBrowsing = env.IsDevelopment(),
|
EnableDirectoryBrowsing = env.IsDevelopment(),
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,11 +36,11 @@ namespace Yavsc
|
||||||
using ViewModels.Auth.Handlers;
|
using ViewModels.Auth.Handlers;
|
||||||
using Yavsc.Abstract.FileSystem;
|
using Yavsc.Abstract.FileSystem;
|
||||||
using Yavsc.Helpers;
|
using Yavsc.Helpers;
|
||||||
|
using Yavsc.Server.Helpers;
|
||||||
using static System.Environment;
|
using static System.Environment;
|
||||||
|
|
||||||
public partial class Startup
|
public partial class Startup
|
||||||
{
|
{
|
||||||
public static string ConnectionString { get; private set; }
|
|
||||||
public static string AvatarsDirName { private set; get; }
|
public static string AvatarsDirName { private set; get; }
|
||||||
public static string Authority { get; private set; }
|
public static string Authority { get; private set; }
|
||||||
public static string Temp { get; set; }
|
public static string Temp { get; set; }
|
||||||
|
|
@ -73,7 +73,12 @@ namespace Yavsc
|
||||||
|
|
||||||
builder.AddEnvironmentVariables();
|
builder.AddEnvironmentVariables();
|
||||||
Configuration = builder.Build();
|
Configuration = builder.Build();
|
||||||
ConnectionString = Configuration["Data:DefaultConnection:ConnectionString"];
|
|
||||||
|
var auth = Configuration["Site:Authority"];
|
||||||
|
var cxstr = Configuration["Data:DefaultConnection:ConnectionString"];
|
||||||
|
DbHelpers.ConnectionString = cxstr;
|
||||||
|
|
||||||
|
Console.WriteLine($"# {auth} ConnectionString: {cxstr}");
|
||||||
|
|
||||||
}
|
}
|
||||||
public static GoogleAuthSettings GoogleSettings { get; set; }
|
public static GoogleAuthSettings GoogleSettings { get; set; }
|
||||||
|
|
@ -82,6 +87,9 @@ namespace Yavsc
|
||||||
// This method gets called by the runtime. Use this method to add services to the container.
|
// This method gets called by the runtime. Use this method to add services to the container.
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Database connection
|
||||||
|
|
||||||
services.AddOptions();
|
services.AddOptions();
|
||||||
var siteSettings = Configuration.GetSection("Site");
|
var siteSettings = Configuration.GetSection("Site");
|
||||||
services.Configure<SiteSettings>(siteSettings);
|
services.Configure<SiteSettings>(siteSettings);
|
||||||
|
|
@ -146,10 +154,11 @@ namespace Yavsc
|
||||||
// DataProtection
|
// DataProtection
|
||||||
ConfigureProtectionServices(services);
|
ConfigureProtectionServices(services);
|
||||||
|
|
||||||
|
|
||||||
// Add framework services.
|
// Add framework services.
|
||||||
services.AddEntityFramework()
|
services.AddEntityFramework()
|
||||||
.AddNpgsql()
|
.AddNpgsql()
|
||||||
.AddDbContext<ApplicationDbContext>(options => options.UseNpgsql(ConnectionString))
|
.AddDbContext<ApplicationDbContext>()
|
||||||
;
|
;
|
||||||
|
|
||||||
ConfigureOAuthServices(services);
|
ConfigureOAuthServices(services);
|
||||||
|
|
@ -255,7 +264,6 @@ namespace Yavsc
|
||||||
IOptions<SiteSettings> siteSettings,
|
IOptions<SiteSettings> siteSettings,
|
||||||
IOptions<RequestLocalizationOptions> localizationOptions,
|
IOptions<RequestLocalizationOptions> localizationOptions,
|
||||||
IOptions<OAuth2AppSettings> oauth2SettingsContainer,
|
IOptions<OAuth2AppSettings> oauth2SettingsContainer,
|
||||||
RoleManager<IdentityRole> roleManager,
|
|
||||||
IAuthorizationService authorizationService,
|
IAuthorizationService authorizationService,
|
||||||
IOptions<PayPalSettings> payPalSettings,
|
IOptions<PayPalSettings> payPalSettings,
|
||||||
IOptions<GoogleAuthSettings> googleSettings,
|
IOptions<GoogleAuthSettings> googleSettings,
|
||||||
|
|
@ -266,15 +274,22 @@ namespace Yavsc
|
||||||
GlobalLocalizer = localizer;
|
GlobalLocalizer = localizer;
|
||||||
SiteSetup = siteSettings.Value;
|
SiteSetup = siteSettings.Value;
|
||||||
Authority = siteSettings.Value.Authority;
|
Authority = siteSettings.Value.Authority;
|
||||||
AbstractFileSystemHelpers.UserFilesDirName = new DirectoryInfo(siteSettings.Value.UserFiles.Blog).FullName;
|
var blogsDir = siteSettings.Value.UserFiles.Blog;
|
||||||
AbstractFileSystemHelpers.UserBillsDirName = new DirectoryInfo(siteSettings.Value.UserFiles.Bills).FullName;
|
if (blogsDir==null) throw new Exception ("blogsDir==null");
|
||||||
Startup.Temp = siteSettings.Value.TempDir;
|
var billsDir = siteSettings.Value.UserFiles.Bills;
|
||||||
|
if (billsDir==null) throw new Exception ("billsDir==null");
|
||||||
|
|
||||||
|
AbstractFileSystemHelpers.UserFilesDirName = new DirectoryInfo(blogsDir).FullName;
|
||||||
|
AbstractFileSystemHelpers.UserBillsDirName = new DirectoryInfo(billsDir).FullName;
|
||||||
|
Temp = siteSettings.Value.TempDir;
|
||||||
PayPalSettings = payPalSettings.Value;
|
PayPalSettings = payPalSettings.Value;
|
||||||
|
|
||||||
// TODO implement an installation & upgrade procedure
|
// TODO implement an installation & upgrade procedure
|
||||||
// Create required directories
|
// Create required directories
|
||||||
foreach (string dir in new string[] { UserFilesDirName, AbstractFileSystemHelpers.UserBillsDirName, SiteSetup.TempDir })
|
foreach (string dir in new string[] { AbstractFileSystemHelpers.UserFilesDirName, AbstractFileSystemHelpers.UserBillsDirName, SiteSetup.TempDir })
|
||||||
{
|
{
|
||||||
|
if (dir==null) throw new Exception (nameof(dir));
|
||||||
|
|
||||||
DirectoryInfo di = new DirectoryInfo(dir);
|
DirectoryInfo di = new DirectoryInfo(dir);
|
||||||
if (!di.Exists) di.Create();
|
if (!di.Exists) di.Create();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using Microsoft.AspNet.Mvc;
|
||||||
namespace Yavsc.ViewComponents
|
namespace Yavsc.ViewComponents
|
||||||
{
|
{
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Yavsc.Abstract.FileSystem;
|
||||||
using Yavsc.ViewModels.UserFiles;
|
using Yavsc.ViewModels.UserFiles;
|
||||||
|
|
||||||
public class DirectoryViewComponent : ViewComponent
|
public class DirectoryViewComponent : ViewComponent
|
||||||
|
|
@ -12,7 +13,7 @@ namespace Yavsc.ViewComponents
|
||||||
IViewComponentResult result = null;
|
IViewComponentResult result = null;
|
||||||
await Task.Run(() =>
|
await Task.Run(() =>
|
||||||
{
|
{
|
||||||
result = View(new UserDirectoryInfo(Startup.UserFilesDirName, User.Identity.Name, dirname));
|
result = View(new UserDirectoryInfo(AbstractFileSystemHelpers.UserFilesDirName, User.Identity.Name, dirname));
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue