From 6a634a779132e4a37299b0fcc94d936012843a0f Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Wed, 23 Dec 2020 01:27:39 +0200 Subject: [PATCH] Add query in agent --- .../Class1.cs | 8 ---- .../DependencyInjectionExtensions.cs | 11 +++++ .../Mappings/MappingProfile.cs | 14 ++++++ ...etworkResurrector.Agent.Application.csproj | 12 +++++ .../Queries/GetMachines.cs | 47 +++++++++++++++++++ 5 files changed, 84 insertions(+), 8 deletions(-) delete mode 100644 NetworkResurrector.Agent.Application/Class1.cs create mode 100644 NetworkResurrector.Agent.Application/DependencyInjectionExtensions.cs create mode 100644 NetworkResurrector.Agent.Application/Mappings/MappingProfile.cs create mode 100644 NetworkResurrector.Agent.Application/Queries/GetMachines.cs diff --git a/NetworkResurrector.Agent.Application/Class1.cs b/NetworkResurrector.Agent.Application/Class1.cs deleted file mode 100644 index 863eda3..0000000 --- a/NetworkResurrector.Agent.Application/Class1.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; - -namespace NetworkResurrector.Agent.Application -{ - public class Class1 - { - } -} diff --git a/NetworkResurrector.Agent.Application/DependencyInjectionExtensions.cs b/NetworkResurrector.Agent.Application/DependencyInjectionExtensions.cs new file mode 100644 index 0000000..2d33f39 --- /dev/null +++ b/NetworkResurrector.Agent.Application/DependencyInjectionExtensions.cs @@ -0,0 +1,11 @@ +using Microsoft.Extensions.DependencyInjection; + +namespace NetworkResurrector.Agent.Application +{ + public static class DependencyInjectionExtensions + { + public static void AddApplicationServices(this IServiceCollection services) + { + } + } +} diff --git a/NetworkResurrector.Agent.Application/Mappings/MappingProfile.cs b/NetworkResurrector.Agent.Application/Mappings/MappingProfile.cs new file mode 100644 index 0000000..84b7586 --- /dev/null +++ b/NetworkResurrector.Agent.Application/Mappings/MappingProfile.cs @@ -0,0 +1,14 @@ +using AutoMapper; +using NetworkResurrector.Agent.Application.Queries; +using NetworkResurrector.Agent.Domain.Entities; + +namespace NetworkResurrector.Agent.Application.Mappings +{ + public class MappingProfile : Profile + { + public MappingProfile() + { + CreateMap(); + } + } +} diff --git a/NetworkResurrector.Agent.Application/NetworkResurrector.Agent.Application.csproj b/NetworkResurrector.Agent.Application/NetworkResurrector.Agent.Application.csproj index 9f5c4f4..38e9483 100644 --- a/NetworkResurrector.Agent.Application/NetworkResurrector.Agent.Application.csproj +++ b/NetworkResurrector.Agent.Application/NetworkResurrector.Agent.Application.csproj @@ -4,4 +4,16 @@ netstandard2.0 + + + + + + + + + + + + diff --git a/NetworkResurrector.Agent.Application/Queries/GetMachines.cs b/NetworkResurrector.Agent.Application/Queries/GetMachines.cs new file mode 100644 index 0000000..f102530 --- /dev/null +++ b/NetworkResurrector.Agent.Application/Queries/GetMachines.cs @@ -0,0 +1,47 @@ +using AutoMapper; +using MediatR; +using NDB.Application.DataContracts; +using NetworkResurrector.Agent.Domain.Repositories; +using System.Threading; +using System.Threading.Tasks; + +namespace NetworkResurrector.Agent.Application.Queries +{ + public class GetMachines + { + public class Query : Query + { + public Query() { } + } + + public class Model + { + public int MachineId { get; set; } + public string MachineName { get; set; } + public string FullMachineName { get; set; } + public string MACAddress { get; set; } + public string IPv4Address { get; set; } + public string Description { get; set; } + } + + public class QueryHandler : IRequestHandler + { + private readonly IAgentRepository _repository; + private readonly IMapper _mapper; + + public QueryHandler(IAgentRepository repository, IMapper mapper) + { + _repository = repository; + _mapper = mapper; + } + + public async Task Handle(Query request, CancellationToken cancellationToken) + { + var bots = await _repository.GetMachines(); + var result = _mapper.Map(bots); + + return result; + } + } + } +}