Skip to content

Commit

Permalink
Merge pull request #687 from mixcore/feature/update-queue-event-log
Browse files Browse the repository at this point in the history
Update mix log
  • Loading branch information
nhathoang989 authored Aug 19, 2023
2 parents 18b9447 + 18d8339 commit 62ff543
Show file tree
Hide file tree
Showing 42 changed files with 525 additions and 283 deletions.
7 changes: 7 additions & 0 deletions src/Mixcore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "level_0", "level_0", "{6F92
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "level_1", "level_1", "{B4C40E02-E06A-4359-BDC5-349E103366AD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mix.log", "platform\mix.log\mix.log.csproj", "{BC6B8583-4F0F-45AD-BF71-1D998AA65869}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -247,6 +249,10 @@ Global
{B57EEC99-85CF-4C4E-BB10-929CCD1D3723}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B57EEC99-85CF-4C4E-BB10-929CCD1D3723}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B57EEC99-85CF-4C4E-BB10-929CCD1D3723}.Release|Any CPU.Build.0 = Release|Any CPU
{BC6B8583-4F0F-45AD-BF71-1D998AA65869}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC6B8583-4F0F-45AD-BF71-1D998AA65869}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC6B8583-4F0F-45AD-BF71-1D998AA65869}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC6B8583-4F0F-45AD-BF71-1D998AA65869}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -304,6 +310,7 @@ Global
{7C9FFA1B-D992-4E3F-B2B1-74D86E81512D} = {C0A05428-767E-46C5-A31F-0D220E41F7C5}
{6F925183-31E6-4DEB-BAB1-80F330B9E199} = {5B29B975-B0AC-46B3-8398-4C8A22EAE355}
{B4C40E02-E06A-4359-BDC5-349E103366AD} = {5B29B975-B0AC-46B3-8398-4C8A22EAE355}
{BC6B8583-4F0F-45AD-BF71-1D998AA65869} = {84C68A6F-ECE0-467E-91C0-AE63AC4FC4C7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0143C230-7F40-44B2-8BA3-EF5B92D55848}
Expand Down
14 changes: 8 additions & 6 deletions src/applications/Mixcore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Microsoft.Extensions.FileProviders;
using Mix.Database.Entities.Account;
using Mix.Lib.Middlewares;
using Mix.Log;
using Mix.Shared.Models.Configurations;
using Mix.Shared.Services;
using System.Reflection;
using System.Text.Encodings.Web;
Expand All @@ -26,11 +28,10 @@ public void ConfigureServices(IServiceCollection services)
options.TextEncoderSettings = new TextEncoderSettings(UnicodeRanges.All);
});


services.AddMixServices(Assembly.GetExecutingAssembly(), Configuration);
services.AddMixCors();
services.AddScoped<MixNavigationService>();

services.AddMixLog(Configuration);
services.AddMixAuthorize<MixCmsAccountContext>(Configuration);
services.AddMixRoutes();

Expand All @@ -40,6 +41,7 @@ public void ConfigureServices(IServiceCollection services)
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
var globalConfigs = Configuration.Get<GlobalConfigurations>();
if (!env.IsDevelopment())
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
Expand All @@ -50,12 +52,12 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseMixTenant();

app.UseMiddleware<AuditlogMiddleware>();

app.UseRouting();

// must go between app.UseRouting() and app.UseEndpoints.
app.UseMixAuth();

app.UseMixApps(Assembly.GetExecutingAssembly(), Configuration, env.ContentRootPath, env.IsDevelopment());
app.UseMixEndpoints();

Expand All @@ -68,13 +70,13 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
FileProvider = new PhysicalFileProvider(
Path.Combine(env.ContentRootPath, MixFolders.TemplatesFolder))
});

if (GlobalConfigService.Instance.AppSettings.IsHttps)
{
app.UseHttpsRedirection();
}


}
}
}
1 change: 1 addition & 0 deletions src/platform/mix.constant/Constants/MixFolders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class MixFolders
public const string JsonDataFolder = "mixcontent/shared/json";
public const string MixCacheFolder = "mixcontent/cache";
public const string MixAuditLogFolder = "mixcontent/auditlog";
public const string MixQueueLogFolder = "mixcontent/queuelog";
public const string MixDbCacheFolder = "MixDb";
public const string MixLogsFolder = "mixcontent/logs";
public const string ExportFolder = "mixcontent/staticfiles/exports";
Expand Down
2 changes: 2 additions & 0 deletions src/platform/mix.constant/Constants/MixQueueActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
public class MixQueueActions
{
public const string AuditLog = "AuditLog";
public const string EnqueueLog = "QueueLog";
public const string AckLog = "AckLog";
public const string ExceptionLog = "ExceptionLog";
public const string DeadLetter = "DeadLetter";
public const string ScaleImage = "ScaleImage";
Expand Down
1 change: 1 addition & 0 deletions src/platform/mix.constant/Constants/MixQueueTopics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class MixQueueTopics
{
public const string MixDbCommand = "MixDbCommand";
public const string MixLog = "MixLog";
public const string MixBackgroundTasks = "MixBackgroundTasks";
public const string MixViewModelChanged = "MixViewModelChanged";
public const string MixRepoDb = "MixRepoDb";
Expand Down
15 changes: 15 additions & 0 deletions src/platform/mix.constant/Enums/MixQueueMessageLogState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mix.Constant.Enums
{
public enum MixQueueMessageLogState
{
ACK,
NACK,
DeadLetter
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ public class AuditLogDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
MixFileHelper.CreateFolderIfNotExist(MixFolders.MixAuditLogFolder);

string cnn = $"Data Source={MixFolders.MixAuditLogFolder}/auditlog_{DateTime.Now.ToString("dd_MM_yyyy")}.db";
MixFileHelper.CreateFolderIfNotExist($"{MixFolders.MixAuditLogFolder}/{DateTime.Now.ToString("dd_MM")}");
string cnn = $"Data Source={MixFolders.MixAuditLogFolder}/{DateTime.Now.ToString("dd_MM")}/auditlog_{DateTime.Now.ToString("dd_MM_yyyy")}.sqlite";
optionsBuilder.UseSqlite(cnn);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration<AuditLog>(new AuditLogConfiguration());
modelBuilder.ApplyConfiguration(new AuditLogConfiguration());
}
public virtual DbSet<AuditLog> AuditLog { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mix.Database.Entities.Queue.EntityConfigurations
{
internal class MixQueueMessageConfiguration : IEntityTypeConfiguration<MixQueueMessageLog>
{
public IDatabaseConstants Config;
public MixQueueMessageConfiguration()
{
Config = new SqliteDatabaseConstants();
}
public void Configure(EntityTypeBuilder<MixQueueMessageLog> builder)
{
builder.Property(e => e.TopicId)
.HasColumnType($"{Config.String}{Config.MediumLength}");

builder.Property(e => e.SubscriptionId)
.HasColumnType($"{Config.String}{Config.MediumLength}");

builder.Property(e => e.DataTypeFullName)
.HasColumnType($"{Config.String}{Config.MediumLength}");

builder.Property(e => e.Action)
.HasColumnType($"{Config.String}{Config.MediumLength}");

builder.Property(e => e.Note)
.HasColumnType($"{Config.String}{Config.MediumLength}");

builder.Property(e => e.State)
.IsRequired()
.HasConversion(new EnumToStringConverter<MixQueueMessageLogState>())
.HasColumnType($"{Config.String}{Config.SmallLength}")
.HasCharSet(Config.CharSet);

builder.Property(e => e.StringData)
.HasColumnType(Config.Text);

builder.Property(e => e.IsDeleted)
.HasColumnType(Config.Boolean);

builder.Property(e => e.CreatedDateTime)
.HasColumnType(Config.DateTime);

builder.Property(e => e.LastModified)
.HasColumnType(Config.DateTime);

builder.Property(e => e.CreatedBy)
.HasColumnType($"{Config.String}{Config.MediumLength}");

builder.Property(e => e.ModifiedBy)
.HasColumnType($"{Config.String}{Config.MediumLength}");

builder.Property(e => e.Priority)
.HasColumnType(Config.Integer);

builder.Property(e => e.Status)
.IsRequired()
.HasConversion(new EnumToStringConverter<MixContentStatus>())
.HasColumnType($"{Config.String}{Config.SmallLength}")
.HasCharSet(Config.CharSet);

builder.Property(e => e.ObjectData)
.HasConversion(
v => v.ToString(Newtonsoft.Json.Formatting.None),
v => !string.IsNullOrEmpty(v) ? JObject.Parse(v) : new())
.IsRequired(false)
.HasColumnType(Config.Text);
}
}
}
29 changes: 29 additions & 0 deletions src/platform/mix.database/Entities/Queue/MixQueueDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.Extensions.Options;
using Mix.Database.Entities.AuditLog.EntityConfigurations;
using Mix.Database.Entities.Queue.EntityConfigurations;
using Mix.Database.Services;
using Mix.Heart.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mix.Database.Entities.Queue
{
public sealed class MixQueueDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
MixFileHelper.CreateFolderIfNotExist($"{MixFolders.MixQueueLogFolder}/{DateTime.Now.ToString("dd_MM")}");
string cnn = $"Data Source={MixFolders.MixQueueLogFolder}/{DateTime.Now.ToString("dd_MM")}/queuelog_{DateTime.Now.ToString("dd_MM_yyyy")}.sqlite";
optionsBuilder.UseSqlite(cnn);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(new MixQueueMessageConfiguration());
}

public DbSet<MixQueueMessageLog> MixQueueMessage { get; set; }
}
}
23 changes: 23 additions & 0 deletions src/platform/mix.database/Entities/Queue/MixQueueMessageLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mix.Database.Entities.Queue
{
public sealed class MixQueueMessageLog: EntityBase<Guid>
{
public Guid QueueMessageId { get; set; }
public string TopicId { get; set; }
public string SubscriptionId { get; set; }
public string Action { get; set; }
public string StringData { get; set; }
public JObject ObjectData { get; set; }
public string DataTypeFullName { get; set; }
public string Note { get; set; }
public MixQueueMessageLogState State { get; set; }
public int TenantId { get; set; }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 62ff543

Please sign in to comment.