/// <summary> /// Contains the middleware logic that handles HTTP requests. /// </summary> /// <param name="context">Encapsulates all HTTP-specific information about an individual HTTP request.</param> /// <param name="sshService">The injected instance of SshService.</param> /// <param name="operatingSystemService">The injected instance of OsService.</param> /// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns> public async Task InvokeAsync(HttpContext context, ISshService sshService, IOsService operatingSystemService) { if ("/shell".Equals(context.Request.Path)) { if (context.WebSockets.IsWebSocketRequest) { WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync(); var os = await operatingSystemService.GetAsync(); await sshService.BindAsync(webSocket, os.SshPort); } else { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; } } else { // Call the next delegate/middleware in the pipeline await this.next(context); } }
/// <summary> /// Initializes a new instance of the <see cref="RaspberryPiType"/> class. /// </summary> /// <param name="chipsetService">The application layer ChipsetService.</param> /// <param name="cpuService">The application layer CpuService.</param> /// <param name="randomAccessMemoryService">The application layer RandomAccessMemoryService.</param> /// <param name="swapMemoryService">The application layer SwapMemoryService.</param> /// <param name="gpuService">The application layer GpuService.</param> /// <param name="diskService">The application layer DiskService.</param> /// <param name="operatingSystemService">The application layer OsService.</param> /// <param name="networkService">The application layer NetworkService.</param> /// <param name="logger">The NLog logger instance.</param> public RaspberryPiType( IChipsetService chipsetService, ICpuService cpuService, IMemoryService <RandomAccessMemory, RandomAccessMemoryStatus> randomAccessMemoryService, IMemoryService <SwapMemory, SwapMemoryStatus> swapMemoryService, IGpuService gpuService, IDiskService diskService, IOsService operatingSystemService, INetworkService networkService, ILogger logger) { this.Field <ChipsetType>() .Name("Chipset") .ResolveAsync(async context => { logger.Debug("Chipset field"); return(await chipsetService.GetAsync()); }); this.Field <Cpu.CpuType>() .Name("Cpu") .ResolveAsync(async context => { logger.Debug("Cpu field"); return(await cpuService.GetAsync()); }); this.Field <MemoryType <RandomAccessMemory, RandomAccessMemoryStatus> >() .Name("Ram") .ResolveAsync(async context => { logger.Debug("Ram field"); return(await randomAccessMemoryService.GetAsync()); }); this.Field <MemoryType <SwapMemory, SwapMemoryStatus> >() .Name("swapMemory") .ResolveAsync(async context => { logger.Debug("Swap Memory field"); return(await swapMemoryService.GetAsync()); }); this.Field <GpuType>() .Name("Gpu") .ResolveAsync(async context => { logger.Debug("Gpu field"); return(await gpuService.GetAsync()); }); this.Field <Disk.DiskType>() .Name("Disk") .ResolveAsync(async context => { logger.Debug("Disk field"); return(await diskService.GetAsync()); }); this.Field <Os.OsType>() .Name("Os") .ResolveAsync(async context => { logger.Debug("Os field"); return(await operatingSystemService.GetAsync()); }); this.Field <Network.NetworkType>() .Name("Network") .ResolveAsync(async context => { logger.Debug("Network field"); return(await networkService.GetAsync()); }); }