ExecutorInternal.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using Quadarax.Application.QLiberace.Processor.Entities;
  2. using Quadarax.Application.QLiberace.Common.Executor;
  3. using Quadarax.Foundation.Core.Data.Interface.Entity.Dto;
  4. using Quadarax.Foundation.Core.Logging;
  5. using Quadarax.Foundation.Core.Reflection.Extensions;
  6. namespace Quadarax.Application.QLiberace.Processor.Executor
  7. {
  8. internal class ExecutorInternal
  9. {
  10. private ProcessingQueue _item;
  11. private IList<ParameterExecutorValue> _data;
  12. public ExecutorInternal(ProcessingQueue item, IEnumerable<ParameterExecutorValue> data)
  13. {
  14. _item = item ?? throw new ArgumentNullException(nameof(item));
  15. _data = new List<ParameterExecutorValue>();
  16. }
  17. public ResultBoolDto Execute(TimeSpan timeout, IQLogger? logger = null)
  18. {
  19. try
  20. {
  21. var provider = (IParametricExecutorProvider) ActivatorExt.CreateInstance(_item.Provider,true, timeout, logger);
  22. if (provider == null)
  23. throw new InvalidOperationException($"Cannot create executor provider from '{_item.Provider}'.");
  24. var result = provider.Execute(_data);
  25. return new ResultBoolDto(result);
  26. }
  27. catch (Exception e)
  28. {
  29. return new ResultBoolDto(e);
  30. }
  31. }
  32. }
  33. }