Add query in agent
parent
3264ef6a24
commit
6a634a7791
|
@ -1,8 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace NetworkResurrector.Agent.Application
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace NetworkResurrector.Agent.Application
|
||||
{
|
||||
public static class DependencyInjectionExtensions
|
||||
{
|
||||
public static void AddApplicationServices(this IServiceCollection services)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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>();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue