Ejemplo n.º 1
0
        public async Task <ClientDto> Handle(GetClientByIdQuery query, CancellationToken cancellationToken)
        {
            var client = await _context.Clients
                         .Select(x => new ClientDto
            {
                Id          = x.Id,
                Name        = x.Name,
                Description = x.Description,
                AllowedIps  = x.AllowedIps
                              .Select(n => TunnelFunctions.Text(n.NetworkAddress.Address))
                              .ToList(),
                AssignedIp = TunnelFunctions.Text(x.AssignedIp),
                IsRevoked  = x.IsRevoked,
                PublicKey  = x.PublicKey,
                CreatedAt  = x.CreatedAt,
                UpdatedAt  = x.UpdatedAt
            })
                         .SingleOrDefaultAsync(x => x.Id == query.Id, cancellationToken);

            if (client == null)
            {
                throw new NullReferenceException($"A client with id #{query.Id} could not be found");
            }

            return(client);
        }
 public async Task <IEnumerable <NetworkAddressDto> > Handle(GetAllNetworkAddressQuery query, CancellationToken cancellationToken)
 {
     return(await _context.NetworkAddresses
            .AsNoTracking()
            .Select(x => new NetworkAddressDto
     {
         Id = x.Id,
         Address = TunnelFunctions.Text(x.Address)
     })
            .ToListAsync(cancellationToken));
 }
Ejemplo n.º 3
0
 public async Task <IEnumerable <ClientDto> > Handle(GetServerClientsQuery query, CancellationToken cancellationToken)
 {
     return(await _context.Clients
            .AsNoTracking()
            .Where(x => !x.IsRevoked && x.ServerId == query.Id)
            .Select(x => new ClientDto
     {
         Id = x.Id,
         Name = x.Name,
         Description = x.Description,
         AssignedIp = TunnelFunctions.Text(x.AssignedIp),
         PublicKey = x.PublicKey
     })
            .ToListAsync(cancellationToken));
 }
Ejemplo n.º 4
0
        public async Task <ServerDto> Handle(GetServerByIdQuery query, CancellationToken cancellationToken)
        {
            var server = await _context.Servers
                         .AsNoTracking()
                         .Select(x => new ServerDto
            {
                Id            = x.Id,
                Name          = x.Name,
                Description   = x.Description,
                AssignedRange = TunnelFunctions.Text(x.AssignedRange),
                Clients       = x.Clients
                                .Where(c => !c.IsRevoked)
                                .Select(c => new ClientDto
                {
                    Id          = c.Id,
                    Name        = c.Name,
                    Description = c.Description
                })
                                .ToList(),
                DefaultAllowedRange = x.DefaultAllowedRange
                                      .Select(n => TunnelFunctions.Text(n.NetworkAddress.Address))
                                      .ToList(),
                Dns        = x.Dns.ToString(),
                Endpoint   = x.Endpoint,
                ListenPort = x.ListenPort,
                PublicKey  = x.PublicKey,
                CreatedAt  = x.CreatedAt,
                UpdatedAt  = x.UpdatedAt
            })
                         .AsSingleQuery()
                         .SingleOrDefaultAsync(x => x.Id == query.Id, cancellationToken);

            if (server == null)
            {
                throw new NullReferenceException($"A server with id #{query.Id} could not be found.");
            }

            return(server);
        }