From fea84e2df70162d4c19125b35dca44626493ab22 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Mon, 25 Jun 2018 22:15:33 +0200 Subject: [PATCH] Projects may have got many repositories even local ones --- Yavsc.Abstract/Yavsc.Abstract.csproj | 8 +- Yavsc/Models/ApplicationDbContext.cs | 164 +++++++++++----------- Yavsc/Startup/Startup.cs | 1 + Yavsc/Views/MailingTemplate/Create.cshtml | 3 +- cli/Program.cs | 2 +- cli/Services/EMailer.cs | 4 +- cli/Startup.cs | 4 +- cli/project.json | 6 +- rc-num.txt | 2 +- 9 files changed, 102 insertions(+), 92 deletions(-) diff --git a/Yavsc.Abstract/Yavsc.Abstract.csproj b/Yavsc.Abstract/Yavsc.Abstract.csproj index 9f7c4714..86323d76 100644 --- a/Yavsc.Abstract/Yavsc.Abstract.csproj +++ b/Yavsc.Abstract/Yavsc.Abstract.csproj @@ -1,11 +1,15 @@ - + + + + Yavsc Client&Server Api Yavsc - l'abstrait 1.0.5 Paul Schneider <paul@pschneider.fr> - dnx451;net46;net451 + dnx451,net46,Profile111 + net46;net45;net451;net452;net461;net462 Yavsc.Abstract Yavsc.Abstract Blog;Blog;PoS;Chat diff --git a/Yavsc/Models/ApplicationDbContext.cs b/Yavsc/Models/ApplicationDbContext.cs index 4719b786..9d653f76 100644 --- a/Yavsc/Models/ApplicationDbContext.cs +++ b/Yavsc/Models/ApplicationDbContext.cs @@ -47,32 +47,32 @@ namespace Yavsc.Models // For example, you can rename the ASP.NET Identity table names and more. // Add your customizations after calling base.OnModelCreating(builder); builder.Entity().HasKey(x => new { x.OwnerId, x.UserId }); - builder.Entity().Property(x=>x.DeclarationDate).HasDefaultValueSql("LOCALTIMESTAMP"); - builder.Entity().HasKey(x=>new { x.PostId, x.TagId}); - builder.Entity().HasMany( c=>c.Connections ); - builder.Entity().Property(u=>u.Avatar).HasDefaultValue(Constants.DefaultAvatar); - builder.Entity().Property(u=>u.DiskQuota).HasDefaultValue(Constants.DefaultFSQ); - builder.Entity().HasKey(u=> new { u.DoesCode, u.UserId}); - builder.Entity().HasKey(u=> new { u.InstrumentId, u.UserId}); - builder.Entity().HasKey(a=> new { a.CircleId, a.BlogPostId}); - builder.Entity().HasKey(c=> new { MemberId = c.MemberId, CircleId = c.CircleId }); - builder.Entity().HasKey(c=>new { uid = c.UserId, notid = c.NotificationId}); - builder.Entity().HasKey(ti=>new { ti.TaintId, ti.PrestationId } ); - builder.Entity().HasKey(l=>new { l.HRef, l.Method }); - builder.Entity().HasKey(l=>new { l.Start, l.End }); - builder.Entity().HasKey( o => new { o.Code, o.CodeScrutin }); - builder.Entity().Property(n=> n.icon).HasDefaultValue("exclam"); - builder.Entity().HasKey(p=>new { room = p.ChannelName, user = p.ChatUserConnectionId }); - foreach (var et in builder.Model.GetEntityTypes()) { - if (et.ClrType.GetInterface("IBaseTrackedEntity")!=null) - et.FindProperty("DateCreated").IsReadOnlyAfterSave = true; + builder.Entity().Property(x => x.DeclarationDate).HasDefaultValueSql("LOCALTIMESTAMP"); + builder.Entity().HasKey(x => new { x.PostId, x.TagId }); + builder.Entity().HasMany(c => c.Connections); + builder.Entity().Property(u => u.Avatar).HasDefaultValue(Constants.DefaultAvatar); + builder.Entity().Property(u => u.DiskQuota).HasDefaultValue(Constants.DefaultFSQ); + builder.Entity().HasKey(u => new { u.DoesCode, u.UserId }); + builder.Entity().HasKey(u => new { u.InstrumentId, u.UserId }); + builder.Entity().HasKey(a => new { a.CircleId, a.BlogPostId }); + builder.Entity().HasKey(c => new { MemberId = c.MemberId, CircleId = c.CircleId }); + builder.Entity().HasKey(c => new { uid = c.UserId, notid = c.NotificationId }); + builder.Entity().HasKey(ti => new { ti.TaintId, ti.PrestationId }); + builder.Entity().HasKey(l => new { l.HRef, l.Method }); + builder.Entity().HasKey(l => new { l.Start, l.End }); + builder.Entity().HasKey(o => new { o.Code, o.CodeScrutin }); + builder.Entity().Property(n => n.icon).HasDefaultValue("exclam"); + builder.Entity().HasKey(p => new { room = p.ChannelName, user = p.ChatUserConnectionId }); + foreach (var et in builder.Model.GetEntityTypes()) + { + if (et.ClrType.GetInterface("IBaseTrackedEntity") != null) + et.FindProperty("DateCreated").IsReadOnlyAfterSave = true; } } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseNpgsql(Startup.ConnectionString); - } - + { + optionsBuilder.UseNpgsql((string) AppDomain.CurrentDomain.GetData("YAVSC_CONNECTION")); + } public DbSet Applications { get; set; } @@ -128,11 +128,11 @@ namespace Yavsc.Models /// References all declared external GCM devices /// /// - public DbSet GCMDevices { get; set; } + public DbSet GCMDevices { get; set; } + + public DbSet Services { get; set; } + public DbSet Products { get; set; } - public DbSet Services { get; set; } - public DbSet Products { get; set; } - public Task GetTokensAsync(string googleUserId) { @@ -145,7 +145,7 @@ namespace Yavsc.Models { var item = this.Tokens.FirstOrDefault(x => x.UserId == googleUserId); // TODO Refresh token - + return Task.FromResult(item); } } @@ -186,12 +186,12 @@ namespace Yavsc.Models Client FindApplication(string clientId) { return Applications.FirstOrDefault( - app=>app.Id == clientId); + app => app.Id == clientId); } public DbSet ExceptionsSIREN { get; set; } - public DbSet Locations { get; set; } + public DbSet Locations { get; set; } public DbSet Tags { get; set; } @@ -203,7 +203,7 @@ namespace Yavsc.Models public DbSet ClientProviderInfo { get; set; } - public DbSet Connections { get; set; } + public DbSet Connections { get; set; } public DbSet BlackListed { get; set; } @@ -214,99 +214,101 @@ namespace Yavsc.Models public DbSet Instrument { get; set; } [ActivitySettings] - public DbSet DjSettings { get; set; } + public DbSet DjSettings { get; set; } [ActivitySettings] - public DbSet Instrumentation { get; set; } + public DbSet Instrumentation { get; set; } [ActivitySettings] - public DbSet FormationSettings { get; set; } + public DbSet FormationSettings { get; set; } [ActivitySettings] - public DbSet GeneralSettings { get; set; } - public DbSet WorkflowProviders { get; set; } + public DbSet GeneralSettings { get; set; } + public DbSet WorkflowProviders { get; set; } private void AddTimestamps(string currentUsername) - { - var entities = - ChangeTracker.Entries() - .Where(x => x.Entity.GetType().GetInterface("IBaseTrackedEntity")!=null - && (x.State == EntityState.Added || x.State == EntityState.Modified)); - - - foreach (var entity in entities) { - if (entity.State == EntityState.Added) - { - ((IBaseTrackedEntity)entity.Entity).DateCreated = DateTime.Now; - ((IBaseTrackedEntity)entity.Entity).UserCreated = currentUsername; - } + var entities = + ChangeTracker.Entries() + .Where(x => x.Entity.GetType().GetInterface("IBaseTrackedEntity") != null + && (x.State == EntityState.Added || x.State == EntityState.Modified)); - ((IBaseTrackedEntity)entity.Entity).DateModified = DateTime.Now; - ((IBaseTrackedEntity)entity.Entity).UserModified = currentUsername; + + foreach (var entity in entities) + { + if (entity.State == EntityState.Added) + { + ((IBaseTrackedEntity)entity.Entity).DateCreated = DateTime.Now; + ((IBaseTrackedEntity)entity.Entity).UserCreated = currentUsername; + } + + ((IBaseTrackedEntity)entity.Entity).DateModified = DateTime.Now; + ((IBaseTrackedEntity)entity.Entity).UserModified = currentUsername; + } } - } - public int SaveChanges(string userId) { + public int SaveChanges(string userId) + { AddTimestamps(userId); return base.SaveChanges(); } - public async Task SaveChangesAsync(string userId, CancellationToken ctoken = default(CancellationToken)) { + public async Task SaveChangesAsync(string userId, CancellationToken ctoken = default(CancellationToken)) + { AddTimestamps(userId); return await base.SaveChangesAsync(); } - public DbSet Circle { get; set; } + public DbSet Circle { get; set; } - public DbSet BlogACL { get; set; } + public DbSet BlogACL { get; set; } - public DbSet CommandForm { get; set; } + public DbSet CommandForm { get; set; } - public DbSet
Form { get; set; } + public DbSet Form { get; set; } - public DbSet Banlist { get ; set; } + public DbSet Banlist { get; set; } - public DbSet HairTaint { get; set; } + public DbSet HairTaint { get; set; } - public DbSet Color { get; set; } + public DbSet Color { get; set; } - public DbSet Notification { get; set; } + public DbSet Notification { get; set; } - public DbSet DimissClicked { get; set; } + public DbSet DimissClicked { get; set; } - [ActivitySettings] - public DbSet BrusherProfile { get; set; } + [ActivitySettings] + public DbSet BrusherProfile { get; set; } - public DbSet BankIdentity { get; set; } + public DbSet BankIdentity { get; set; } - public DbSet PayPalPayments { get; set; } + public DbSet PayPalPayments { get; set; } - public DbSet Links { get; set; } + public DbSet Links { get; set; } - public DbSet Period { get; set; } + public DbSet Period { get; set; } - public DbSet BlogTags { get; set; } + public DbSet BlogTags { get; set; } - public DbSet ApplicationUser { get; set; } + public DbSet ApplicationUser { get; set; } - public DbSet Feature { get; set; } + public DbSet Feature { get; set; } - public DbSet Bug { get; set; } + public DbSet Bug { get; set; } - public DbSet Comment { get; set; } + public DbSet Comment { get; set; } - public DbSet Announce { get; set; } + public DbSet Announce { get; set; } - public DbSet ChatConnection { get; set; } + public DbSet ChatConnection { get; set; } - public DbSet ChatRoom { get; set; } + public DbSet ChatRoom { get; set; } - public DbSet MailingTemplate { get; set; } + public DbSet MailingTemplate { get; set; } - public DbSet GitRepositoryReference { get; set; } + public DbSet GitRepositoryReference { get; set; } + + public DbSet Projects { get; set; } - public DbSet Projects { get; set; } - } } diff --git a/Yavsc/Startup/Startup.cs b/Yavsc/Startup/Startup.cs index 3367c454..362b900f 100755 --- a/Yavsc/Startup/Startup.cs +++ b/Yavsc/Startup/Startup.cs @@ -78,6 +78,7 @@ namespace Yavsc var auth = Configuration["Site:Authority"]; var cxstr = Configuration["Data:DefaultConnection:ConnectionString"]; ConnectionString = cxstr; + AppDomain.CurrentDomain.SetData("YAVSC_CONNECTION", ConnectionString); } public static string ConnectionString { get; set; } public static GoogleAuthSettings GoogleSettings { get; set; } diff --git a/Yavsc/Views/MailingTemplate/Create.cshtml b/Yavsc/Views/MailingTemplate/Create.cshtml index 31269ece..575cd2fd 100644 --- a/Yavsc/Views/MailingTemplate/Create.cshtml +++ b/Yavsc/Views/MailingTemplate/Create.cshtml @@ -14,7 +14,8 @@
-
diff --git a/cli/Program.cs b/cli/Program.cs index 746a4c3e..acb7b52d 100644 --- a/cli/Program.cs +++ b/cli/Program.cs @@ -40,7 +40,7 @@ namespace cli var mailer = app.Services.GetService(); var loggerFactory = app.Services.GetService(); var logger = loggerFactory.CreateLogger(); - mailer.SendMonthlyEmail(2,"UserOrientedTemplate"); + mailer.SendMonthlyEmail(1,"UserOrientedTemplate"); logger.LogInformation("Finished"); } } diff --git a/cli/Services/EMailer.cs b/cli/Services/EMailer.cs index 6fb7fe0c..3ed31857 100644 --- a/cli/Services/EMailer.cs +++ b/cli/Services/EMailer.cs @@ -83,6 +83,7 @@ namespace cli.Services var templateInfo = dbContext.MailingTemplate.FirstOrDefault(t => t.Id == templateCode); + if (templateInfo==null) throw new Exception($"No template found under id {templateCode}."); logger.LogInformation($"Using code: {templateCode}, subject: {subtemp} "); logger.LogInformation("And body:\n"+templateInfo.Body); using (StringReader reader = new StringReader(templateInfo.Body)) @@ -104,7 +105,8 @@ namespace cli.Services typeof(IdentityUser), typeof(ApplicationUser), typeof(Template), - typeof(UserOrientedTemplate) + typeof(UserOrientedTemplate), + typeof(System.Threading.Tasks.TaskExtensions) } ) { var location = type.Assembly.Location; diff --git a/cli/Startup.cs b/cli/Startup.cs index 6ebbe393..63de2c6c 100644 --- a/cli/Startup.cs +++ b/cli/Startup.cs @@ -58,7 +58,8 @@ namespace cli .AddJsonFile("appsettings.json") .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); Configuration = builder.Build(); - + ConnectionString = Configuration["Data:DefaultConnection:ConnectionString"]; + AppDomain.CurrentDomain.SetData("YAVSC_CONNECTION", ConnectionString); } public void ConfigureServices (IServiceCollection services) @@ -79,7 +80,6 @@ namespace cli { options.ResourcesPath = "Resources"; }); - ConnectionString = Configuration["Data:DefaultConnection:ConnectionString"]; services.AddEntityFramework() .AddNpgsql() diff --git a/cli/project.json b/cli/project.json index 362c46cf..e5c6167c 100644 --- a/cli/project.json +++ b/cli/project.json @@ -44,9 +44,9 @@ "Microsoft.Framework.Configuration.Json": "1.0.0-beta8", "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4", "Newtonsoft.Json": "9.0.1", - "Yavsc": { "version": "1.0.5-rc21-beta2", "target": "package" }, - "Yavsc.Abstract": { "version": "1.0.5-rc21-beta2", "target": "package" }, - "Yavsc.Server": { "version": "1.0.5-rc21-beta2", "target": "package" } + "Yavsc": { "version": "1.0.5-rc21-beta4", "target": "package" }, + "Yavsc.Abstract": { "version": "1.0.5-rc21-beta4", "target": "package" }, + "Yavsc.Server": { "version": "1.0.5-rc21-beta4", "target": "package" } }, "frameworks": { "dnx451": { diff --git a/rc-num.txt b/rc-num.txt index cbbf2ac2..d818f966 100644 --- a/rc-num.txt +++ b/rc-num.txt @@ -1 +1 @@ -21-beta2 +21-beta4