Browse Source

Merge pull request #567 from colinin/5.2.0

fix: 使用Newtownsoft.Json来序列化作业参数
pull/580/head
yx lin 4 years ago
committed by GitHub
parent
commit
3bfaed0a90
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/SendEmailJob.cs
  2. 7
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/SendSmsJob.cs
  3. 8
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/ServiceInvocationJob.cs
  4. 8
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundJobAdapter.cs
  5. 7
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundJobManager.cs
  6. 25
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhookSendRecordAppService.cs

12
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/SendEmailJob.cs

@ -1,10 +1,9 @@
using System.Threading.Tasks;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Emailing;
using Volo.Abp.TextTemplating;
using Volo.Abp.Json;
using System.Collections.Generic;
using System;
using Newtonsoft.Json;
namespace LINGYUN.Abp.BackgroundTasks.Jobs;
@ -55,10 +54,9 @@ public class SendEmailJob : IJobRunnable
context.TryGetString(PropertyCulture, out var culture);
if (context.TryGetString(PropertyContext, out var globalCtx))
{
var jsonSerializer = context.GetRequiredService<IJsonSerializer>();
try
{
globalContext = jsonSerializer.Deserialize<Dictionary<string, object>>(globalCtx);
globalContext = JsonConvert.DeserializeObject<Dictionary<string, object>>(globalCtx);
}
catch { }
}

7
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/SendSmsJob.cs

@ -1,6 +1,6 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Json;
using Volo.Abp.Sms;
namespace LINGYUN.Abp.BackgroundTasks.Jobs;
@ -23,8 +23,7 @@ public class SendSmsJob : IJobRunnable
try
{
var jsonSerializer = context.GetRequiredService<IJsonSerializer>();
properties = jsonSerializer.Deserialize<Dictionary<string, object>>(data);
properties = JsonConvert.DeserializeObject<Dictionary<string, object>>(data);
}
catch { }

8
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/ServiceInvocationJob.cs

@ -1,5 +1,6 @@
using LINGYUN.Abp.Dapr.Client.DynamicProxying;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
@ -12,7 +13,6 @@ using Volo.Abp.Http.Client.ClientProxying;
using Volo.Abp.Http.Client.DynamicProxying;
using Volo.Abp.Http.Client.Proxying;
using Volo.Abp.Http.Modeling;
using Volo.Abp.Json;
using Volo.Abp.Localization;
using Volo.Abp.MultiTenancy;
@ -102,8 +102,7 @@ public class ServiceInvocationJob : IJobRunnable
var invokeParameters = new Dictionary<string, object>();
if (context.TryGetString(PropertyData, out var data))
{
var jsonSerializer = context.GetRequiredService<IJsonSerializer>();
invokeParameters = jsonSerializer.Deserialize<Dictionary<string, object>>(data);
invokeParameters = JsonConvert.DeserializeObject<Dictionary<string, object>>(data);
}
// 构造服务代理上下文
@ -196,8 +195,7 @@ public class ServiceInvocationJob : IJobRunnable
var invokeParameters = new Dictionary<string, object>();
if (context.TryGetString(PropertyData, out var data))
{
var jsonSerializer = context.GetRequiredService<IJsonSerializer>();
invokeParameters = jsonSerializer.Deserialize<Dictionary<string, object>>(data);
invokeParameters = JsonConvert.DeserializeObject<Dictionary<string, object>>(data);
}
// 构造服务代理上下文

8
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundJobAdapter.cs

@ -2,10 +2,9 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Threading.Tasks;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.Json;
namespace LINGYUN.Abp.BackgroundTasks;
@ -35,8 +34,9 @@ public class BackgroundJobAdapter<TArgs> : IJobRunnable
object args = null;
if (context.TryGetString(nameof(TArgs), out var argsJson))
{
var jsonSerializer = context.GetRequiredService<IJsonSerializer>();
args = jsonSerializer.Deserialize<TArgs>(argsJson);
//var jsonSerializer = context.GetRequiredService<IJsonSerializer>();
//args = jsonSerializer.Deserialize<TArgs>(argsJson);
args = JsonConvert.DeserializeObject<TArgs>(argsJson);
}
var jobType = Options.GetJob(typeof(TArgs)).JobType;

7
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundJobManager.cs

@ -1,11 +1,11 @@
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.Json;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Timing;
@ -19,7 +19,6 @@ public class BackgroundJobManager : IBackgroundJobManager, ITransientDependency
protected IJobPublisher JobPublisher { get; }
protected ICurrentTenant CurrentTenant { get; }
protected IGuidGenerator GuidGenerator { get; }
protected IJsonSerializer JsonSerializer { get; }
protected AbpBackgroundTasksOptions TasksOptions { get; }
protected AbpBackgroundJobOptions Options { get; }
public BackgroundJobManager(
@ -28,7 +27,6 @@ public class BackgroundJobManager : IBackgroundJobManager, ITransientDependency
IJobPublisher jobPublisher,
ICurrentTenant currentTenant,
IGuidGenerator guidGenerator,
IJsonSerializer jsonSerializer,
IOptions<AbpBackgroundJobOptions> options,
IOptions<AbpBackgroundTasksOptions> taskOptions)
{
@ -37,7 +35,6 @@ public class BackgroundJobManager : IBackgroundJobManager, ITransientDependency
JobPublisher = jobPublisher;
CurrentTenant = currentTenant;
GuidGenerator = guidGenerator;
JsonSerializer = jsonSerializer;
Options = options.Value;
TasksOptions = taskOptions.Value;
}
@ -56,7 +53,7 @@ public class BackgroundJobManager : IBackgroundJobManager, ITransientDependency
var jobId = GuidGenerator.Create();
var jobArgs = new Dictionary<string, object>
{
{ nameof(TArgs), JsonSerializer.Serialize(args) },
{ nameof(TArgs), JsonConvert.SerializeObject(args) },
{ "ArgsType", jobConfiguration.ArgsType.AssemblyQualifiedName },
{ "JobType", jobConfiguration.JobType.AssemblyQualifiedName },
{ "JobName", jobConfiguration.JobName },

25
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhookSendRecordAppService.cs

@ -68,17 +68,20 @@ public class WebhookSendRecordAppService : WebhooksManagementAppServiceBase, IWe
var sendEvent = await EventRepository.GetAsync(sendRecord.WebhookEventId);
var subscription = await SubscriptionRepository.GetAsync(sendRecord.WebhookSubscriptionId);
await BackgroundJobManager.EnqueueAsync(new WebhookSenderArgs
using (CurrentTenant.Change(sendRecord.TenantId))
{
TenantId = CurrentTenant.Id,
WebhookSubscriptionId = sendRecord.WebhookSubscriptionId,
WebhookEventId = sendRecord.WebhookEventId,
WebhookName = sendEvent.WebhookName,
WebhookUri = subscription.WebhookUri,
Data = sendEvent.Data,
Headers = subscription.GetWebhookHeaders(),
Secret = subscription.Secret,
TryOnce = true,
});
await BackgroundJobManager.EnqueueAsync(new WebhookSenderArgs
{
TenantId = CurrentTenant.Id,
WebhookSubscriptionId = sendRecord.WebhookSubscriptionId,
WebhookEventId = sendRecord.WebhookEventId,
WebhookName = sendEvent.WebhookName,
WebhookUri = subscription.WebhookUri,
Data = sendEvent.Data,
Headers = subscription.GetWebhookHeaders(),
Secret = subscription.Secret,
TryOnce = true,
});
}
}
}

Loading…
Cancel
Save