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.

99 lines
3.6 KiB

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