diff --git a/TIAM.Services/SignalRTags.cs b/TIAM.Services/SignalRTags.cs index d55f0f33..3ff10de9 100644 --- a/TIAM.Services/SignalRTags.cs +++ b/TIAM.Services/SignalRTags.cs @@ -5,17 +5,14 @@ namespace TIAM.Services; public class SignalRTags : AcSignalRTags { - //[SignalMessageTag(null, typeof(SignalResponseMessage), null, null)] - public const int GetTransfersAsync = 5; - - public const int GetPropertiesByOwnerIdAsync = 6; - - [SignalMessageTag(typeof(SignalPostJsonDataMessage), typeof(SignalResponseMessage), null, null)] - public const int UpdateTransferAsync = 7; - public const int AddTransferAsync = 8; - public const int RemoveTransferAsync = 9; - public const int GetCompaniesAsync = 10; - public const int UpdateCompanyAsync = 11; - public const int AddCompanyAsync = 12; - public const int RemoveCompanyAsync = 13; + public const int GetTransfers = 5; + public const int GetPropertiesByOwnerId = 6; + public const int UpdateTransfer = 7; + public const int AddTransfer = 8; + public const int RemoveTransfer = 9; + + public const int GetCompanies = 10; + public const int UpdateCompany = 11; + public const int AddCompany = 12; + public const int RemoveCompany = 13; } \ No newline at end of file diff --git a/TIAMSharedUI/Pages/User/SysAdmins/ManageTransfers.razor b/TIAMSharedUI/Pages/User/SysAdmins/ManageTransfers.razor index 3dd18d81..6bcf0b21 100644 --- a/TIAMSharedUI/Pages/User/SysAdmins/ManageTransfers.razor +++ b/TIAMSharedUI/Pages/User/SysAdmins/ManageTransfers.razor @@ -88,8 +88,8 @@ Logger="_logger" SignalRClient="AdminSignalRClient" OnDataSourceChanged="DataSourceChanged" - OnDataSourceItemChanging="DataSourceItemChanging" - OnDataSourceItemChanged="DataSourceItemChanged" + OnDataItemChanging="DataSourceItemChanging" + OnDataItemChanged="DataSourceItemChanged" OnDataItemDeleting="DataItemDeleting" OnDataItemSaving="DataItemSaving" diff --git a/TIAMSharedUI/Shared/Components/Grids/CompanyGrid.cs b/TIAMSharedUI/Shared/Components/Grids/CompanyGrid.cs index b8cf1f58..5c5c411c 100644 --- a/TIAMSharedUI/Shared/Components/Grids/CompanyGrid.cs +++ b/TIAMSharedUI/Shared/Components/Grids/CompanyGrid.cs @@ -10,10 +10,10 @@ public class CompanyGrid : TiamGrid { GridName = nameof(CompanyGrid); - GetAllMessageTag = SignalRTags.GetCompaniesAsync; - AddMessageTag = SignalRTags.AddCompanyAsync; - UpdateMessageTag = SignalRTags.UpdateCompanyAsync; - RemoveMessageTag = SignalRTags.RemoveCompanyAsync; + GetAllMessageTag = SignalRTags.GetCompanies; + AddMessageTag = SignalRTags.AddCompany; + UpdateMessageTag = SignalRTags.UpdateCompany; + RemoveMessageTag = SignalRTags.RemoveCompany; } protected override Task SetParametersAsyncCore(ParameterView parameters) diff --git a/TIAMSharedUI/Shared/Components/Grids/TiamGrid.cs b/TIAMSharedUI/Shared/Components/Grids/TiamGrid.cs index 64c89157..3f560224 100644 --- a/TIAMSharedUI/Shared/Components/Grids/TiamGrid.cs +++ b/TIAMSharedUI/Shared/Components/Grids/TiamGrid.cs @@ -5,7 +5,9 @@ using AyCode.Services.SignalRs; using AyCode.Utils.Extensions; using DevExpress.Blazor; using DevExpress.Blazor.Internal; +using DevExpress.Blazor.Navigation.Internal; using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Forms; using TIAMWebApp.Shared.Application.Services; using TIAMWebApp.Shared.Application.Utility; @@ -17,7 +19,6 @@ namespace TIAMSharedUI.Shared.Components.Grids private IList? _dataSource; private string _gridLogName; - public TiamGrid() : base() { } @@ -31,6 +32,16 @@ namespace TIAMSharedUI.Shared.Components.Grids [Parameter] public int UpdateMessageTag { get; set; } [Parameter] public int RemoveMessageTag { get; set; } + protected new EventCallback DataItemDeleting { get; set; } + [Parameter] public EventCallback OnDataItemDeleting{ get; set; } + + protected new EventCallback EditModelSaving { get; set; } + [Parameter] public EventCallback OnDataItemSaving { get; set; } + + [Parameter] public EventCallback> OnDataSourceChanged { get; set; } + [Parameter] public EventCallback OnDataItemChanging { get; set; } + [Parameter] public EventCallback OnDataItemChanged { get; set; } + [Parameter] [DefaultValue(null)] [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "BL0007:Component parameters should be auto properties", Justification = "")] @@ -73,20 +84,21 @@ namespace TIAMSharedUI.Shared.Components.Grids if (firstRender) RefreshDataSourceAsync().Forget(); } - protected new EventCallback DataItemDeleting { get; set; } - [Parameter] public EventCallback OnDataItemDeleting{ get; set; } + public Task AddDataItem(TDataItem dataItem) => PostDataToServerAsync(dataItem, AddMessageTag); + public Task UpdateDataItem(TDataItem dataItem) => PostDataToServerAsync(dataItem, UpdateMessageTag); + public Task RemoveDataItem(TDataItem dataItem) => PostDataToServerAsync(dataItem, RemoveMessageTag); - protected new EventCallback EditModelSaving { get; set; } - [Parameter] public EventCallback OnDataItemSaving { get; set; } - + public Task RemoveDataItem(Guid id) + { + var dataItem = _dataSource.FirstOrDefault(x => x.Id == id); - [Parameter] public EventCallback> OnDataSourceChanged { get; set; } - [Parameter] public EventCallback OnDataSourceItemChanging { get; set; } - [Parameter] public EventCallback OnDataSourceItemChanged { get; set; } + return dataItem == null ? Task.CompletedTask : RemoveDataItem(dataItem); + } private async Task OnItemSaving(GridEditModelSavingEventArgs e) { var dataItem = (e.EditModel as TDataItem)!; + var logText = e.IsNew ? "add" : "update"; Logger.Info($"{_gridLogName} OnItemSaving {logText}; Id: {dataItem.Id}"); @@ -99,10 +111,8 @@ namespace TIAMSharedUI.Shared.Components.Grids return; } - PostDataToServerAsync(dataItem, e.IsNew ? AddMessageTag : UpdateMessageTag).Forget(); - - //await transferDataService.CreateTransfer((TransferWizardModel)e.EditModel); - //transfer = await transferDataService.UpdateTransferAsync(transfer); + if (e.IsNew) await AddDataItem(dataItem); + else await UpdateDataItem(dataItem); } private async Task OnItemDeleting(GridDataItemDeletingEventArgs e) @@ -118,7 +128,7 @@ namespace TIAMSharedUI.Shared.Components.Grids } var dataItem = (e.DataItem as TDataItem)!; - PostDataToServerAsync(dataItem, RemoveMessageTag, true).Forget(); + await RemoveDataItem(dataItem); } public virtual Task RefreshDataSourceAsync() @@ -140,33 +150,33 @@ namespace TIAMSharedUI.Shared.Components.Grids }); } - public virtual async Task PostDataToServerAsync(TDataItem dataItem, int messageTag, bool isDelete = false) + protected virtual async Task PostDataToServerAsync(TDataItem dataItem, int messageTag, bool isDelete = false) { Logger.Info($"{_gridLogName} PostDataToServerAsync called; transferId " + dataItem.Id); //if (messageTag == 0) return; - await OnDataSourceItemChanging.InvokeAsync(dataItem); + await OnDataItemChanging.InvokeAsync(dataItem); if (dataItem.Id.IsNullOrEmpty()) dataItem.Id = Guid.NewGuid(); - RefreshDataSourceItem(dataItem, isDelete, false); //egyből látszódik a változás a grid-ben, nem csak a callback lefutásakor! felhasználóbarátabb... - J. + RefreshDataItem(dataItem, isDelete); //egyből látszódik a változás a grid-ben, nem csak a callback lefutásakor! felhasználóbarátabb... - J. SignalRClient.PostDataAsync(messageTag, dataItem, async repsonse => { - if (repsonse.Status != SignalResponseStatus.Success || repsonse.ResponseData == null || !RefreshDataSourceItem(repsonse.ResponseData, isDelete)) + if (repsonse.Status != SignalResponseStatus.Success || repsonse.ResponseData == null || !RefreshDataItem(repsonse.ResponseData, isDelete)) { RefreshDataSourceAsync().Forget(); return; } - await OnDataSourceItemChanged.InvokeAsync(dataItem); - await InvokeAsync(StateHasChanged); + await OnDataItemChanged.InvokeAsync(dataItem); + InvokeAsync(StateHasChanged).Forget(); }).Forget(); //transfer = await devAdminSignalClient.PostDataAsync(SignalRTags.UpdateTransferAsync, transfer); } - public bool RefreshDataSourceItem(TDataItem dataItem, bool isDelete, bool invokeItemChanged = true) + public bool RefreshDataItem(TDataItem dataItem, bool isDelete) { if (dataItem.Id.IsNullOrEmpty()) { diff --git a/TIAMSharedUI/Shared/Components/Grids/TransferGrid.cs b/TIAMSharedUI/Shared/Components/Grids/TransferGrid.cs index 8dfabc7d..6650ce64 100644 --- a/TIAMSharedUI/Shared/Components/Grids/TransferGrid.cs +++ b/TIAMSharedUI/Shared/Components/Grids/TransferGrid.cs @@ -10,10 +10,10 @@ public class TransferGrid : TiamGrid { GridName = nameof(TransferGrid); - GetAllMessageTag = SignalRTags.GetTransfersAsync; - AddMessageTag = SignalRTags.AddTransferAsync; - UpdateMessageTag = SignalRTags.UpdateTransferAsync; - RemoveMessageTag = SignalRTags.RemoveTransferAsync; + GetAllMessageTag = SignalRTags.GetTransfers; + AddMessageTag = SignalRTags.AddTransfer; + UpdateMessageTag = SignalRTags.UpdateTransfer; + RemoveMessageTag = SignalRTags.RemoveTransfer; } protected override Task SetParametersAsyncCore(ParameterView parameters) diff --git a/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs b/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs index d5c5743c..71a998dd 100644 --- a/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs +++ b/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs @@ -82,7 +82,7 @@ namespace TIAMWebApp.Server.Controllers } } - [SignalR(SignalRTags.AddCompanyAsync, MethodParamType.Object, typeof(Company))] + [SignalR(SignalRTags.AddCompany)] public async Task AddCompanyAsync(Company company) { if (company.Id.IsNullOrEmpty()) company.Id = Guid.NewGuid(); @@ -107,7 +107,7 @@ namespace TIAMWebApp.Server.Controllers [AllowAnonymous] [HttpGet] [Route(APIUrls.GetServiceProvidersRouteName)] - [SignalR(SignalRTags.GetCompaniesAsync, MethodParamType.None)] + [SignalR(SignalRTags.GetCompanies)] public async Task GetServiceProviders() { return await adminDal.GetServiceProvidersJsonAsync(); @@ -138,7 +138,7 @@ namespace TIAMWebApp.Server.Controllers [AllowAnonymous] [HttpPost] [Route(APIUrls.UpdateServiceProviderRouteName)] - [SignalR(SignalRTags.UpdateCompanyAsync, MethodParamType.Object, typeof(Company))] + [SignalR(SignalRTags.UpdateCompany)] public async Task UpdateServiceProvider(Company companyToModify) { _logger.Info($"UpdateServiceProvider called! + {companyToModify.Id}"); @@ -153,7 +153,7 @@ namespace TIAMWebApp.Server.Controllers [HttpPost] [Route(APIUrls.GetServiceProvidersByOwnerIdRouteName)] [Tags("Finished", "ServiceProvider")] - [SignalR(SignalRTags.GetPropertiesByOwnerIdAsync, MethodParamType.Id)] + [SignalR(SignalRTags.GetPropertiesByOwnerId)] public async Task> GetServiceProvidersByOwnerId([FromBody] Guid ownerId) { _logger.Info($@"GetServiceProvidersByOwnerId called with ownerId: {ownerId}"); diff --git a/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs b/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs index 1c452d02..3e228f28 100644 --- a/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs +++ b/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs @@ -1,5 +1,6 @@ using System.Text.Json; using AyCode.Core.Loggers; +using AyCode.Services.SignalRs; using AyCode.Utils.Extensions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -380,7 +381,7 @@ namespace TIAMWebApp.Server.Controllers [Authorize] [HttpGet] [Route(APIUrls.GetTransfersRouteName)] - [SignalR(SignalRTags.GetTransfersAsync, MethodParamType.None)] + [SignalR(SignalRTags.GetTransfers)] public async Task GetTransfers() { //var token = _authService.GetAuthTokenFromRequest(Request); @@ -406,7 +407,7 @@ namespace TIAMWebApp.Server.Controllers [AllowAnonymous] [HttpPost] [Route(APIUrls.UpdateTransferRouteName)] - [SignalR(SignalRTags.UpdateTransferAsync, MethodParamType.Object, typeof(Transfer))] + [SignalR(SignalRTags.UpdateTransfer)] public async Task UpdateTransfer(Transfer transferToModify) { _logger.Info($"UpdateTransfer called! + {Request?.ReadFormAsync()}"); diff --git a/TIAMWebApp/Server/Services/DevAdminSignalRhub.cs b/TIAMWebApp/Server/Services/DevAdminSignalRhub.cs index 65d7d160..0fe29ee0 100644 --- a/TIAMWebApp/Server/Services/DevAdminSignalRhub.cs +++ b/TIAMWebApp/Server/Services/DevAdminSignalRhub.cs @@ -17,6 +17,7 @@ using System.Runtime.CompilerServices; using MessagePack; using System.Security.Cryptography.Xml; using DevExpress.XtraPrinting.Native.WebClientUIControl; +using DevExpress.XtraReports.Parameters; namespace TIAMWebApp.Server.Services; @@ -34,30 +35,25 @@ public static class ExtensionMethods } } -public enum MethodParamType : byte +public class MethodInfoModel where TAttribute : TagAttribute { - None = 0, - Id = 5, - Object = 10 -} + public Type? ParameterType { get; init; } = null; + public TAttribute Attribute { get; init; } + public MethodInfo MethodInfo { get; init; } -[AttributeUsage(AttributeTargets.Method)] -public class TagAttribute(int messageTag) : Attribute -{ - public int MessageTag { get; init; } = messageTag; -} + public MethodInfoModel(TAttribute attribute, MethodInfo methodInfo) + { + Attribute = attribute; + MethodInfo = methodInfo; -[AttributeUsage(AttributeTargets.Method)] -public class SignalRAttribute(int messageTag, MethodParamType methodParamType, Type paramType = null) : TagAttribute(messageTag) -{ - public MethodParamType MethodParamType { get; init; } = methodParamType; - public Type ParamType { get; init; } = paramType; -} + var parameters = methodInfo.GetParameters(); -public class MethodInfoModel(TAttribute attribute, MethodInfo methodInfo) where TAttribute : TagAttribute -{ - public TAttribute Attribute { get; set; } = attribute; - public MethodInfo MethodInfo { get; set; } = methodInfo; + if (parameters.Length > 1) + throw new Exception("MethodInfoModel; parameters.Length > 1"); + + if (parameters.Length == 1) + ParameterType = parameters[0].ParameterType; + } } public class DynamicMethodCallModel where TAttribute : TagAttribute @@ -142,23 +138,22 @@ public class DevAdminSignalRHub : Hub, IAcSignalRHubServe if (!methodsByDeclaringObject.MethodsByMessageTag.TryGetValue(messageTag, out var methodInfoModel)) continue; object[]? paramValues = null; - var parameters = methodInfoModel.MethodInfo.GetParameters(); - logText = $"Found the dynamic method for the tag! tag: {messageTag}; method: {methodsByDeclaringObject.InstanceObject.GetType().Name}.{methodInfoModel.MethodInfo.Name}"; + logText = $"Found dynamic method for the tag! tag: {messageTag}; method: {methodsByDeclaringObject.InstanceObject.GetType().Name}.{methodInfoModel.MethodInfo.Name}"; - if (parameters.Length > 0) + if (methodInfoModel.ParameterType != null) { - _logger.Debug($"{logText}({parameters[0].ParameterType.Name})"); + _logger.Debug($"{logText}({methodInfoModel.ParameterType.Name})"); paramValues = new object[1]; - if (parameters[0].ParameterType == typeof(Guid) || parameters[0].ParameterType == typeof(Guid?)) + if (methodInfoModel.ParameterType == typeof(Guid) || methodInfoModel.ParameterType == typeof(Guid?)) { paramValues[0] = message!.MessagePackTo().Id; } else { var msg = message!.MessagePackTo>(MessagePackSerializerOptions.Standard); - paramValues[0] = msg.PostDataJson.JsonTo(parameters[0].ParameterType)!; + paramValues[0] = msg.PostDataJson.JsonTo(methodInfoModel.ParameterType)!; } } else _logger.Debug($"{logText}()"); @@ -168,11 +163,11 @@ public class DevAdminSignalRHub : Hub, IAcSignalRHubServe return; } - _logger.Debug($"Not found the dynamic method for the tag! tag: {messageTag};"); + _logger.Debug($"Not found dynamic method for the tag! tag: {messageTag};"); switch (messageTag) { - case SignalRTags.RemoveCompanyAsync: + case SignalRTags.RemoveCompany: var deleteCompany = message!.MessagePackTo>().PostData; await _adminDal.RemoveCompanyAsync(deleteCompany.Id); diff --git a/TIAMWebApp/Shared/Services/ServiceProviderDataService.cs b/TIAMWebApp/Shared/Services/ServiceProviderDataService.cs index 28fd9f22..d53b1d9d 100644 --- a/TIAMWebApp/Shared/Services/ServiceProviderDataService.cs +++ b/TIAMWebApp/Shared/Services/ServiceProviderDataService.cs @@ -98,7 +98,7 @@ namespace TIAMWebApp.Shared.Application.Services //17. public Task GetPropertiesByOwnerIdAsync(Guid id, Action?> callback) { - return _adminSignalRClient.GetByIdAsync>(SignalRTags.GetPropertiesByOwnerIdAsync, id, response => + return _adminSignalRClient.GetByIdAsync>(SignalRTags.GetPropertiesByOwnerId, id, response => { if (response.Status == SignalResponseStatus.Error) callback.Invoke(null); @@ -112,7 +112,7 @@ namespace TIAMWebApp.Shared.Application.Services //17. public async Task?> GetPropertiesByOwnerIdAsync(Guid id) { - var companyPropertiesByOwner = await _adminSignalRClient.GetByIdAsync>(SignalRTags.GetPropertiesByOwnerIdAsync, id); + var companyPropertiesByOwner = await _adminSignalRClient.GetByIdAsync>(SignalRTags.GetPropertiesByOwnerId, id); if (companyPropertiesByOwner != null) _logger.DetailConditional($"companyPropertiesByOwner: {string.Join("; ", companyPropertiesByOwner.Values)}"); return companyPropertiesByOwner; @@ -146,7 +146,7 @@ namespace TIAMWebApp.Shared.Application.Services //16. public async Task> GetServiceProvidersAsync() { - var companies = await _adminSignalRClient.GetAllAsync>(SignalRTags.GetCompaniesAsync); + var companies = await _adminSignalRClient.GetAllAsync>(SignalRTags.GetCompanies); if (companies != null) _logger.DetailConditional($"companies: {string.Join("; ", companies.Count)}"); return companies; @@ -167,7 +167,7 @@ namespace TIAMWebApp.Shared.Application.Services //14. public async Task UpdateServiceProviderAsync(Company company) { - var result = await _adminSignalRClient.PostDataAsync(SignalRTags.UpdateCompanyAsync, company); + var result = await _adminSignalRClient.PostDataAsync(SignalRTags.UpdateCompany, company); return result; }