You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.8 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. using Hangfire;
  2. using Microsoft.Extensions.Configuration;
  3. using Microsoft.Extensions.Logging;
  4. using Shentun.Peis.ThirdInterfaces;
  5. using Shentun.Utilities;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using Volo.Abp.BackgroundWorkers.Hangfire;
  13. namespace Shentun.Peis.Schedulers
  14. {
  15. public interface IImportLisResultInterfaceWorker
  16. {
  17. public void DoWork(Guid interfaceId);
  18. public void DoWork();
  19. }
  20. public class ImportLisResultInterfaceWorker : ThirdInterfaceWorkerBase, IImportLisResultInterfaceWorker
  21. {
  22. private static long i;
  23. private static bool _isRunning = false;
  24. private static readonly object lockObject = new object();
  25. private readonly IConfiguration _configuration;
  26. public ImportLisResultInterfaceWorker(IConfiguration configuration)
  27. {
  28. _configuration = configuration;
  29. }
  30. public virtual void DoWork(Guid interfaceId)
  31. {
  32. if (_isRunning) return;
  33. //lock (lockObject)
  34. //{
  35. _isRunning = true;
  36. try
  37. {
  38. var backJobTypeIds = _configuration.GetSection("BackJobTypeId").Value;
  39. //Logger.LogInformation("Executed" + GetType().Name + "..!");
  40. var appServiceHelper = new AppServiceHelper();
  41. //appServiceHelper.Login();
  42. var thirdInterfaceDtos = appServiceHelper.CallAppService<object, List<ThirdInterfaceDto>>("api/app/ThirdInterface/GetList", null);
  43. var thirdInterfaceDto = thirdInterfaceDtos.Where(o => o.Id == interfaceId).FirstOrDefault();
  44. if (thirdInterfaceDto == null)
  45. {
  46. _isRunning = false;
  47. return;
  48. }
  49. if (!backJobTypeIds.Contains(thirdInterfaceDto.ThirdInterfaceType))
  50. {
  51. _isRunning = false;
  52. return;
  53. }
  54. if (thirdInterfaceDto.IsActive != 'Y')
  55. {
  56. _isRunning = false;
  57. return;
  58. }
  59. var parmValue = thirdInterfaceDto.ParmValue;
  60. if (!string.IsNullOrWhiteSpace(parmValue))
  61. {
  62. var configurationBuilder = new ConfigurationBuilder()
  63. .AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
  64. var interfaceConfig = configurationBuilder.Build();
  65. var isActive = interfaceConfig.GetSection("Interface").GetSection("Scheduler")
  66. .GetSection("IsActive").Value;
  67. if (isActive != "Y")
  68. {
  69. _isRunning = false;
  70. return;
  71. }
  72. var assemblyName = interfaceConfig.GetSection("Interface").GetSection("AssemblyName").Value;
  73. var className = interfaceConfig.GetSection("Interface").GetSection("ClassName").Value;
  74. var funName = "DoWork";
  75. object[] classConstructorArg = new object[] { thirdInterfaceDto.Id };
  76. ReflectionHelper.Invoke(assemblyName, className, classConstructorArg, funName);
  77. }
  78. }
  79. catch (Exception ex)
  80. {
  81. _isRunning = false;
  82. Logger.LogError("Executed " + GetType().Name + " Error" + ex.Message);
  83. }
  84. _isRunning = false;
  85. return;
  86. //}
  87. }
  88. public void DoWork()
  89. {
  90. throw new System.NotImplementedException();
  91. }
  92. public override Task DoWorkAsync(CancellationToken cancellationToken = default)
  93. {
  94. throw new NotImplementedException();
  95. }
  96. }
  97. }