Attività di "mariovh"

  • ABP Framework version: v6.0.0
  • UI Type: Blazor WASM
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes

Hello,

In the configuration of the DomainSharedModule with AbpLocalizationOptions, I want to know if it's possible to add key-value resources from an in-memory dictionary instead of a .json file. Our organization has an API for obtaining localization resources for each application in a key-value dictionary format. Once I've made the API call and have the dictionary in memory, I want to incorporate it into the localization resources options of the application.

Is this possible? Is there a way to implement this?

Best regards, thank you.

Hi,

In wich class is implemented that logic in Abp framework? I only see AddVirtualJson to AbpLocalizationOptions Resources

Thanks

  • ABP Framework version: v6.0.0
  • UI Type: Blazor WASM
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes/no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

Hello, i have the scenario where i want to send a message to azure service bus topic and after that set the entity as processed, wich is update a property as true. I want to do it transactional in app service method. So if database update throws exception, message should not be published in azure service bus preserving events integrity.

Wrapping in Transaction Scope throws this exception when updating in database:

I can't update because IRepository update is transactional, so message is not published in topic because is wrapped in the same transaction scope as database update, this is correct.

If I configure the module with:

making the update operation non transactional, both operations works fine, but is not the behavior i want because my database operations to be not transactional.

My question is, that if I remove transaction scope and AbpUnitOfWorkDefaultOptions transaction behavior is Enabled by default, asuming that in every appservice method begins a transactional UOW, when the update operation throws an exception, the azure client send message is publishing the message in the topic wich is wrong behavior. Both operations, send message and then update entity are in the same appservice method, same UOW, same Transaction Scope, so if an exception is thrown, a rollback of all operations should be made, and this is not the case.

I dont know what is the correct way to implement a pattern like this using Appservices UOW, and making transactional both operations, send message to service bus and update an entity via generic repository.

Thanks!

  • ABP Framework version: v6.0.0
  • UI Type:Blazor WASM
  • Database System: EF Core (SQL Server)

Hello, im using a AsyncBackgroundJob that need to query data from repositories and store after some operations that include generate a pdf document and send via email. The fact is that injected repositories are returning empty data, watching the context Tenant is null and User is null:

The job is enqueued in an appservice method. If i use the repository in the appservices that enqueues the job, gets and store data correctly. But if the same IRepository type is injected in the backgroundjob doesnt get the data probably because tenant and user are null.

What is the correct way to use an AsyncBackgroundJob, that do some queries and store data via IRepository in a multitenant app?

Thank you!

Hi,

I'm switching tenant, with ICurrentTenant, _currentTenant.Change(args.TenantId) and TenantId is correctly stored. But switching user with ICurrentPrincipalAccessor _currentPrincipalAccessor.Change(claims) where claims are generated like this:

public static (Guid? userId, ClaimsPrincipal claims) GetUserAsync(Guid? userId, string name, string surname, string userName, string[] roleNames)
        {
            var claimsList = new List<Claim>
            {
                new(AbpClaimTypes.UserId, userId.ToString()),
                new(AbpClaimTypes.Name, name ?? "BackgroundJobUser"),
                new(AbpClaimTypes.SurName, surname ?? "BackgroundJobUser"),
                new(AbpClaimTypes.UserName, userName)
            };
            claimsList.AddRange(roleNames
                .Select(_ => new Claim(AbpClaimTypes.Role, _)).ToList());


            return (userId, new ClaimsPrincipal(new ClaimsIdentity(claimsList)));
        }

But CreatorId still null, what am I doing wrong?

hi, yes sure, basically sends an email and then inserts a domain entity and marks as processed, or sending email error if there's an error.

public class CertificateEmailSendingJob : AsyncBackgroundJob<CertificateEmailSendingArgs>, ITransientDependency
    {
        private readonly IEmailSender _emailSender;
        private readonly ISettingProvider _settingsProvider;
        private readonly ICurrentTenant _currentTenant;
        private readonly IDonationCertificateRepository _certificateRepository;
        private readonly IUnitOfWorkManager _unitOfWorkManager;
        private readonly ICurrentPrincipalAccessor _currentPrincipalAccessor;

        public CertificateEmailSendingJob(IEmailSender emailSender, 
            ISettingProvider settingsProvider, 
            ICurrentTenant currentTenant, 
            IDonationCertificateRepository certificateRepository,
            IUnitOfWorkManager unitOfWorkManager,
            ICurrentPrincipalAccessor currentPrincipalAccessor)
        {
            _emailSender = emailSender;
            _settingsProvider = settingsProvider;
            _currentTenant = currentTenant;
            _certificateRepository = certificateRepository;
            _unitOfWorkManager = unitOfWorkManager;
            _currentPrincipalAccessor = currentPrincipalAccessor;
        }

        public override async Task ExecuteAsync(CertificateEmailSendingArgs args)
        {
            var claims = JobsExtensions.GetUserAsync(args.User.Id, args.User.Name, args.User.Surname, args.User.UserName, args.User.Roles);

            using (_currentPrincipalAccessor.Change(claims.claims))
            {
                using (_currentTenant.Change(args.TenantId))
                {
                    var from = await _settingsProvider.GetOrNullAsync(FundraisingSettingsConst.SmtpUserName);

                    using var memoryStream = new MemoryStream(args.CertificateFile);
                    var attachment = new Attachment(memoryStream, new ContentType(MediaTypeNames.Application.Pdf))
                    {
                        ContentDisposition = { FileName = args.CertificateFileName }
                    };

                    var message = new MailMessage(
                        from,
                        args.DonorEmail,
                        args.EmailSubject,
                        args.EmailBody);

                    message.Attachments.Add(attachment);

                    using var uow = _unitOfWorkManager.Begin(
                        requiresNew: true, isTransactional: false);
                   
                    try
                    {
                        await _emailSender.SendAsync(message);
                        var certificateRecord =
                            new DonationCertificate(Guid.NewGuid(), args.DonorId, args.LabelId,
                                args.EmailTemplateLabelId,
                                DonationCertificateStatus.Processed,
                                args.Year,
                                args.DonationId);
                        await _certificateRepository.InsertAsync(certificateRecord);

                    }
                    catch (Exception)
                    {
                        var certificateRecord =
                            new DonationCertificate(Guid.NewGuid(), args.DonorId, args.LabelId,
                                args.EmailTemplateLabelId,
                                DonationCertificateStatus.EmailSendingError,
                                args.Year,
                                args.DonationId);
                        await _certificateRepository.InsertAsync(certificateRecord);
                    }
                    
                    await uow.CompleteAsync();
                }
            }
        }
    }
    public static class JobsExtensions
    {
        public static (Guid? userId, ClaimsPrincipal claims) GetUserAsync(Guid? userId, string name, string surname, string userName, string[] roleNames)
        {
            var claimsList = new List<Claim>
            {
                new(AbpClaimTypes.UserId, userId.ToString()),
                new(AbpClaimTypes.Name, name ?? "BackgroundJobUser"),
                new(AbpClaimTypes.SurName, surname ?? "BackgroundJobUser"),
                new(AbpClaimTypes.UserName, userName)
            };
            claimsList.AddRange(roleNames
                .Select(_ => new Claim(AbpClaimTypes.Role, _)).ToList());


            return (userId, new ClaimsPrincipal(new ClaimsIdentity(claimsList)));
        }
    }
    
    public class CertificateEmailSendingArgs
    {
        public Guid? TenantId { get; set; }
        public string DonorEmail { get; set; }
        public string EmailSubject { get; set; }
        public string EmailBody { get; set; }
        public string CertificateFileName { get; set; }
        public byte[] CertificateFile { get; set; }

        public Guid DonorId { get; set; }
        public Guid LabelId { get; set; }
        public Guid EmailTemplateLabelId { get; set; }
        public int? Year { get; set; }
        public Guid? DonationId { get; set; }

        public UserArgs User { get; set; }
    }
    
    internal class DonationCertificateRepository: EfCoreRepository<FundraisingDbContext, DonationCertificate, Guid>,IDonationCertificateRepository

I tried to switch order of change tenant and change user, same result, CreatorId is null. Something i should be doing wrong changing user, because values when i generate ClaimsPrincipal are correct.

hi,

Id es correct, tenant id is null, wich is incorrect. I attach ICurrentUser inspection where you can see TenantId null and query to AbpUsers, where you can see that the user has TenantId not null.

Thanks!

hello,

i tried this

ObjectHelper.TrySetProperty(certificateRecord, x => x.CreatorId, () => YourId);
await _certificateRepository.InsertAsync(certificateRecord);

And it works fine.

Thank you!

  • ABP Framework version: v7.0.0
  • UI Type:Blazor WASM
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

Hi, I need to restrict the acces in each tenant to a setting value in settings management. Im trying to make a SettingComponentGroup, only visible for a settings admin user, wich could be a role created for this purpose. Following your example:

`

  public class BookStoreSettingPageContributor : ISettingPageContributor{
public Task ConfigureAsync(SettingPageCreationContext context)
{
    context.Groups.Add(
        new SettingPageGroup(
            "Volo.Abp.MySettingGroup",
            "MySettingGroup",
            typeof(MySettingGroupViewComponent),
            order : 1
        )
    );  return Task.CompletedTask;
}

public Task<bool> CheckPermissionsAsync(SettingPageCreationContext context)
{
    // You can check the permissions here
    return Task.FromResult(true);
}

} `

How i can in CheckPermissionsAsync, make "MySettingGroup" only visible for an specific role? Wich is the correct way to do it?

Thank you

  • ABP Framework version: v7.0.0
  • UI Type:Blazor WASM
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes/no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

Hello,

I'm using AbpBackgroundJobs for tasks that mainly involve generating a PDF certificate, attaching it to an email, and sending it via email through Azure Communication Services in bulk. Around 2000 jobs are queued on average in this operation.

To avoid exceeding the limits of Exchange 365 in email sending (30 emails per minute), I'm queuing the jobs with a 15-second delay between each consecutive one.

During the execution, I've noticed that the 15-second delay isn't always respected, and I've also observed that the execution order of the jobs doesn't strictly follow the NextTryTime. What logic does the polling on the BackgroundJobs table use to select the job to execute?

Here's the scenario: there are 10 jobs with NextTryTime before the current date, and then there are others with NextTryTime after the current date. In what order will they be executed?

If it's not possible to enforce the delay when enqueuing, as job execution times are sometimes less than the planned delay, is it possible to introduce a delay when the job is selected for execution to avoid mailbox saturation?

Finally, with the aim of scaling the application, as it's multi-tenant, is there a possibility for each tenant to have its dedicated background jobs thread independent of other tenants?

Thank you and regards,

1 - 10 di 17
Made with ❤️ on ABP v8.2.0-preview Updated on marzo 25, 2024, 15:11