Add query in agent

master
Tudor Stanciu 2020-12-23 01:27:39 +02:00
parent 3264ef6a24
commit 6a634a7791
5 changed files with 84 additions and 8 deletions

View File

@ -1,8 +0,0 @@
using System;
namespace NetworkResurrector.Agent.Application
{
public class Class1
{
}
}

View File

@ -0,0 +1,11 @@
using Microsoft.Extensions.DependencyInjection;
namespace NetworkResurrector.Agent.Application
{
public static class DependencyInjectionExtensions
{
public static void AddApplicationServices(this IServiceCollection services)
{
}
}
}

View File

@ -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<Machine, GetMachines.Model>();
}
}
}

View File

@ -4,4 +4,16 @@
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="$(AutoMapperPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="NDB.Application.DataContracts" Version="$(NDBApplicationPackageVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NetworkResurrector.Agent.Domain\NetworkResurrector.Agent.Domain.csproj" />
</ItemGroup>
</Project>

View File

@ -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<Model[]>
{
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<Query, Model[]>
{
private readonly IAgentRepository _repository;
private readonly IMapper _mapper;
public QueryHandler(IAgentRepository repository, IMapper mapper)
{
_repository = repository;
_mapper = mapper;
}
public async Task<Model[]> Handle(Query request, CancellationToken cancellationToken)
{
var bots = await _repository.GetMachines();
var result = _mapper.Map<Model[]>(bots);
return result;
}
}
}
}