1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using Edge.Core.Processor;
- using Edge.Core.Processor.Dispatcher.Attributes;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.Extensions.DependencyInjection;
- namespace Edge.Core.UniversalApi
- {
- [MetaPartsDescriptor("ServiceEntry", "Used for host service discovery api.",
- IsSystemInternalComponent = true)]
- public class ServiceEntry : IAppProcessor
- {
- protected IServiceProvider services;
- public string MetaConfigName { get; set; } = "ServiceDiscovery";
- public ServiceEntry(IServiceProvider services)
- {
- this.services = services;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="apiType">localmqtt, remotemqtt, webapi</param>
- /// <param name="tags"></param>
- /// <returns></returns>
- [UniversalApi(InputParametersExampleJson = "[\"localMqtt\",[\"Pump\",\"ATG\"]]")]
- public async Task<IEnumerable<UniversalApiInfoDoc>> ShowMeApi(string apiType, string[] tags)
- {
- var communicationProvider =
- this.services.GetService<UniversalApiHub>()?.CommunicationProviders?.Where(p => p.GetType().Name.Contains(apiType, StringComparison.OrdinalIgnoreCase))?.FirstOrDefault();
- if (communicationProvider == null)
- return Enumerable.Empty<UniversalApiInfoDoc>();
- return communicationProvider.GetApiDocuments().FilterByTags(tags);
- }
- public void Init(IEnumerable<IProcessor> processors)
- {
- }
- }
- }
|