Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings #693

Merged
merged 7 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ public MixRoleViewModel()
{
}

public MixRoleViewModel(MixRole entity,

UnitOfWorkInfo uowInfo = null) : base(entity, uowInfo)
public MixRoleViewModel(MixRole entity, UnitOfWorkInfo uowInfo = null) : base(entity, uowInfo)
{
}

Expand Down
8 changes: 5 additions & 3 deletions src/modules/mix.common/Controllers/SharedApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ public SharedApiController(
MixCacheService cacheService,
IHttpContextAccessor httpContextAccessor,
MixQueueMessages<MessageQueueModel> mixMemoryMessageQueue,
IMixTenantService mixTenantService)
: base(httpContextAccessor, configuration,
IMixTenantService mixTenantService,
IMixCmsService mixCmsService)
: base(httpContextAccessor, configuration,
cacheService, translator, mixIdentityService, queueService, mixTenantService)
{
_uow = uow;
Expand All @@ -56,6 +57,7 @@ public SharedApiController(
_routeProvider = routeProvider;
_applicationLifetime = applicationLifetime;
_mixMemoryMessageQueue = mixMemoryMessageQueue;
_mixCmsService = mixCmsService;
}

#region Routes
Expand Down Expand Up @@ -136,7 +138,7 @@ public async Task<ActionResult> ClearCacheAsync(CancellationToken cancellationTo
[HttpGet("sitemap")]
public async Task<ActionResult> Sitemap(CancellationToken cancellationToken = default)
{
var file = await _mixCmsService.ParseSitemapAsync();
var file = await _mixCmsService.ParseSitemapAsync(cancellationToken);
return Ok(file);
}

Expand Down
6 changes: 3 additions & 3 deletions src/modules/mix.portal/Controllers/CommonController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public ActionResult<DashboardModel> Dashboard(string culture)

[MixAuthorize]
[HttpGet("portal-menus")]
public async Task<ActionResult<JArray?>> PortalMenus()
public async Task<ActionResult<JArray>> PortalMenus()
{
var user = await UserManager.GetUserAsync(User);
var roles = await UserManager.GetRolesAsync(user);
Expand All @@ -53,7 +53,7 @@ public ActionResult<DashboardModel> Dashboard(string culture)



private async Task<JArray?> LoadUserPortalMenus(string[] roles)
private async Task<JArray> LoadUserPortalMenus(string[] roles)
{
try
{
Expand Down Expand Up @@ -81,7 +81,7 @@ public ActionResult<DashboardModel> Dashboard(string culture)
}
return arrMenus;
}
catch (Exception ex)
catch (Exception)
{
return new();
}
Expand Down
5 changes: 3 additions & 2 deletions src/modules/mix.tenancy/Domain/Services/InitCmsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ public InitCmsService(
}


public async Task InitDbContext(InitCmsDto model)
public Task InitDbContext(InitCmsDto model)
{
_databaseService.InitConnectionStrings(model.ConnectionString, model.DatabaseProvider);

_databaseService.UpdateMixCmsContext();

return Task.CompletedTask;
}

public async Task InitTenantAsync(InitCmsDto model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private JObject ParseBody(JObject body, JObject data)
{
if (strBody.Contains($"[[{prop.Name}]]", StringComparison.OrdinalIgnoreCase))
{
strBody = strBody.Replace($"[[{prop.Name.ToTitleCase()}]]", data.GetValue(prop.Name).ToString());
strBody = strBody.Replace($"[[{prop.Name.ToTitleCase()}]]", data.GetValue(prop.Name)!.ToString());
}
}
return JObject.Parse(strBody);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

namespace Mix.Database.Entities.Account.EntityConfigurations
{
internal class ClientsConfiguration : AccountEntityBaseConfiguration<Clients>

public class ClientsConfiguration : AccountEntityBaseConfiguration<Clients>
{
public ClientsConfiguration(DatabaseService databaseService) : base(databaseService)
{
}

public virtual void Configure(EntityTypeBuilder<Clients> builder)
public override void Configure(EntityTypeBuilder<Clients> builder)
{
builder.Property(e => e.Id)
.HasCharSet(Config.CharSet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public class ExternalLoginViewModel

public class RegisterExternalBindingModel
{
public string? UserName { get; set; }
public string? Email { get; set; }
public string? PhoneNumber { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
public MixExternalLoginProviders Provider { get; set; }

public string ExternalAccessToken { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/platform/mix.library/Interfaces/IMixCmsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public interface IMixCmsService
{
public string GetAssetFolder(string culture, string domain);
public MixTenantSystemModel GetCurrentTenant();
Task<FileModel> ParseSitemapAsync();
Task<FileModel> ParseSitemapAsync(CancellationToken cancellationToken = default);
}
}
5 changes: 2 additions & 3 deletions src/platform/mix.library/Interfaces/IMixEdmService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ public interface IMixEdmService
{
public void SetTenantId(int tenantId);
public void SetTenant(MixTenantSystemModel tenant);
public Task<string?> GetEdmTemplate(string filename);

public Task SendMailWithEdmTemplate(string subject, string templateName, JObject data, string to, string? cc = null, string? from = null);
public Task<string> GetEdmTemplate(string filename);
public Task SendMailWithEdmTemplate(string subject, string templateName, JObject data, string to, string cc = null, string from = null);
}
}
12 changes: 5 additions & 7 deletions src/platform/mix.library/Services/MixCmsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public MixTenantSystemModel GetCurrentTenant()
return CurrentTenant;
}

public async Task<FileModel> ParseSitemapAsync()
public async Task<FileModel> ParseSitemapAsync(CancellationToken cancellationToken = default)
{
try
{
XNamespace aw = "http://www.sitemaps.org/schemas/sitemap/0.9";
var root = new XElement(aw + "urlset");

await ParseNavigationsAsync(root);
await ParseNavigationsAsync(root, cancellationToken);
await ParsePostsDocAsync(root);

string folder = $"wwwroot";
Expand All @@ -70,7 +70,7 @@ public async Task<FileModel> ParseSitemapAsync()

#region Navigation

protected virtual async Task ParseNavigationsAsync(XElement root)
protected virtual async Task ParseNavigationsAsync(XElement root, CancellationToken cancellation = default)
{
var navs = await MixNavigationViewModel.GetRepository(_mixdbUow, CacheService).GetListAsync(
m => m.MixTenantId == CurrentTenant.Id);
Expand All @@ -81,11 +81,9 @@ protected virtual async Task ParseNavigationsAsync(XElement root)
}
}

protected virtual async Task ParsePostsDocAsync(XElement root)
protected virtual async Task ParsePostsDocAsync(XElement root, CancellationToken cancellation = default)
{
var posts = await MixPostViewModel.GetRepository(_cmsUow, CacheService).GetListAsync(
m => m.MixTenantId == CurrentTenant.Id);

var posts = await MixPostViewModel.GetRepository(_cmsUow, CacheService).GetListAsync(m => m.MixTenantId == CurrentTenant.Id, cancellation);
foreach (var post in posts)
{
ParsePostDoc(root, post);
Expand Down
6 changes: 3 additions & 3 deletions src/platform/mix.library/Services/MixEdmService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public MixEdmService(
_queueService = queueService;
}

public async Task<string?> GetEdmTemplate(string filename)
public async Task<string> GetEdmTemplate(string filename)
{
var edmTemplate = await MixTemplateViewModel.GetRepository(_uow, CacheService).GetSingleAsync(
m => m.FolderType == MixTemplateFolderType.Edms
Expand All @@ -31,8 +31,8 @@ public MixEdmService(
public virtual async Task SendMailWithEdmTemplate(
string subject, string templateName, JObject data,
string to,
string? cc = null,
string? from = null)
string cc = null,
string from = null)
{
var template = await GetEdmTemplate(templateName);
if (template == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private async Task SendMail(MessageQueueModel model)

}

private async Task SendMessage(string message, bool result, Exception? ex = null)
private async Task SendMessage(string message, bool result, Exception ex = null)
{
SignalRMessageModel msg = new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed class MixTemplateViewModel
public int MixTenantId { get; set; }
public string Content { get; set; }
public string Extension { get; set; }
public string? FileFolder { get; set; }
public string FileFolder { get; set; }
public string FileName { get; set; }
public MixTemplateFolderType FolderType { get; set; }
public string Scripts { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/platform/mix.log/ViewModels/AuditLogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public AuditLogViewModel()
{
}

public AuditLogViewModel(AuditLog entity, UnitOfWorkInfo<AuditLogDbContext>? uowInfo)
public AuditLogViewModel(AuditLog entity, UnitOfWorkInfo uowInfo)
: base(entity, uowInfo)
{
}
Expand Down
16 changes: 7 additions & 9 deletions src/platform/mix.mixdb/Services/RuntimeDbContextService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void LoadDbContextAssembly()
}
}

public DbContext GetMixDatabaseDbContext()
public DbContext? GetMixDatabaseDbContext()
{
if (!string.IsNullOrEmpty(_databaseService.GetConnectionString(MixConstants.CONST_MIXDB_CONNECTION)))
{
Expand All @@ -90,17 +90,15 @@ public DbContext GetMixDatabaseDbContext()
}
if (_assembly != null)
{

_dbContextType = _assembly.GetType("TypedDataContext.Context.DataContext");
_ = _dbContextType ?? throw new Exception("DataContext type not found");

_dbContextType = _assembly.GetType("TypedDataContext.Context.DataContext") ?? throw new Exception("DataContext type not found");
var constr = _dbContextType.GetConstructor(Type.EmptyTypes);
_ = constr ?? throw new Exception("DataContext ctor not found");
var ctx = (DbContext)constr.Invoke(null);
ctx.Database.EnsureCreated();
return ctx;
}
}

return default;
}

Expand Down Expand Up @@ -139,10 +137,10 @@ public List<string> CreateDynamicDbContext()
string contextFileCode = scaffoldedModelSources.ContextFile.Code;
foreach (var item in scaffoldedModelSources.AdditionalFiles)
{
string name = item.Path.Substring(0, item.Path.LastIndexOf('.'));
string name = item.Path[..item.Path.LastIndexOf('.')];
if (databaseNames.Any(m => string.Equals(m, name, StringComparison.OrdinalIgnoreCase)))
{
ReplaceEntityNaming(databaseNames, item, ref contextFileCode);
ReplaceEntityNaming(item, ref contextFileCode);
}
sourceFiles.Add(item.Code);
}
Expand All @@ -154,9 +152,9 @@ public List<string> CreateDynamicDbContext()
return sourceFiles;
}

private void ReplaceEntityNaming(List<string> databaseNames, ScaffoldedFile item, ref string contextFileCode)
private void ReplaceEntityNaming(ScaffoldedFile item, ref string contextFileCode)
{
string name = item.Path.Substring(0, item.Path.LastIndexOf('.'));
string name = item.Path[..item.Path.LastIndexOf('.')];
string newName = name.ToLower();
contextFileCode = contextFileCode.Replace($"Entity<{name}>", $"Entity<{newName}>")
.Replace($"DbSet<{name}>", $"DbSet<{newName}>");
Expand Down
22 changes: 14 additions & 8 deletions src/platform/mix.queue/Engines/Google/GoogleQueuePublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,27 @@ private void InitializeQueue(string topicName)
CreateTopic(topicName);

var googleCredential = GoogleCredential.FromFile(_queueSetting.CredentialFile);
var createSettings = new PublisherClient.ClientCreationSettings(credentials: googleCredential.ToChannelCredentials());
var toppicName = new TopicName(_queueSetting.ProjectId, topicName);
var publisher = PublisherClient.CreateAsync(toppicName, createSettings);
_publisher = publisher.Result;
var publisherClientBuilder = new PublisherClientBuilder
{
Credential = googleCredential,
TopicName = new TopicName(_queueSetting.ProjectId, topicName)
};

_publisher = publisherClientBuilder.Build();
}
}

private Topic CreateTopic(string topicId)
{
try
{
PublisherServiceApiClientBuilder builder = new PublisherServiceApiClientBuilder();
builder.CredentialsPath = _queueSetting.CredentialFile;
PublisherServiceApiClient publisher = builder.Build();
TopicName topicName = new TopicName(_queueSetting.ProjectId, topicId);
var builder = new PublisherServiceApiClientBuilder
{
CredentialsPath = _queueSetting.CredentialFile
};

var publisher = builder.Build();
var topicName = new TopicName(_queueSetting.ProjectId, topicId);
return publisher.CreateTopic(topicName);
}
catch (RpcException e) when (e.Status.StatusCode == StatusCode.AlreadyExists)
Expand Down
12 changes: 8 additions & 4 deletions src/platform/mix.queue/Engines/Google/GoogleQueueSubscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ private void InitializeQueue(string topicId, string subscriptionId)
CreateSubscription(topicId, subscriptionId);
_subscriptionName = new SubscriptionName(_queueSetting.ProjectId, subscriptionId);
var googleCredential = GoogleCredential.FromFile(_queueSetting.CredentialFile);
var createSettings = new SubscriberClient.ClientCreationSettings(
credentials: googleCredential.ToChannelCredentials());
var subscriber = SubscriberClient.CreateAsync(_subscriptionName, createSettings);
_subscriber = subscriber.Result;

var builder = new SubscriberClientBuilder
{
Credential = googleCredential,
SubscriptionName = _subscriptionName
};

_subscriber = builder.Build();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/platform/mix.repodb/Interfaces/IMixDbDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

namespace Mix.RepoDb.Interfaces
{
public interface IMixDbDataService: IDisposable
public interface IMixDbDataService : IDisposable
{
public Task<JObject?> GetSingleByParent(string tableName, MixContentType parentType, object parentId, bool loadNestedData = false);

public Task<PagingResponseModel<JObject>> GetMyData(string tableName, SearchMixDbRequestDto req, string username);

public Task<JObject> GetMyDataById(string tableName, string username, int id, bool loadNestedData);
public Task<JObject?> GetMyDataById(string tableName, string username, int id, bool loadNestedData);

public Task<JObject?> GetById(string tableName, int id, bool loadNestedData);

Expand Down
2 changes: 1 addition & 1 deletion src/platform/mix.repodb/Interfaces/IMixDbService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IMixDbService
{
public Task<PagingResponseModel<JObject>> GetMyData(string tableName, SearchMixDbRequestDto req, string username);

public Task<JObject> GetMyDataById(string tableName, string username, int id, bool loadNestedData);
public Task<JObject?> GetMyDataById(string tableName, string username, int id, bool loadNestedData);

public Task<JObject?> GetById(string tableName, int id, bool loadNestedData);

Expand Down
Loading
Loading