ServiceEntry.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Edge.Core.Processor;
  2. using Edge.Core.Processor.Dispatcher.Attributes;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Microsoft.Extensions.DependencyInjection;
  9. namespace Edge.Core.UniversalApi
  10. {
  11. [MetaPartsDescriptor("ServiceEntry", "Used for host service discovery api.",
  12. IsSystemInternalComponent = true)]
  13. public class ServiceEntry : IAppProcessor
  14. {
  15. protected IServiceProvider services;
  16. public string MetaConfigName { get; set; } = "ServiceDiscovery";
  17. public ServiceEntry(IServiceProvider services)
  18. {
  19. this.services = services;
  20. }
  21. /// <summary>
  22. ///
  23. /// </summary>
  24. /// <param name="apiType">localmqtt, remotemqtt, webapi</param>
  25. /// <param name="tags"></param>
  26. /// <returns></returns>
  27. [UniversalApi(InputParametersExampleJson = "[\"localMqtt\",[\"Pump\",\"ATG\"]]")]
  28. public async Task<IEnumerable<UniversalApiInfoDoc>> ShowMeApi(string apiType, string[] tags)
  29. {
  30. var communicationProvider =
  31. this.services.GetService<UniversalApiHub>()?.CommunicationProviders?.Where(p => p.GetType().Name.Contains(apiType, StringComparison.OrdinalIgnoreCase))?.FirstOrDefault();
  32. if (communicationProvider == null)
  33. return Enumerable.Empty<UniversalApiInfoDoc>();
  34. return communicationProvider.GetApiDocuments().FilterByTags(tags);
  35. }
  36. public void Init(IEnumerable<IProcessor> processors)
  37. {
  38. }
  39. }
  40. }