コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OsType"/> class.
        /// </summary>
        /// <param name="operatingSystemService">The application layer OsService.</param>
        /// <param name="logger">The NLog logger instance.</param>
        public OsType(IOsService operatingSystemService, ILogger logger)
        {
            this.Field(x => x.Name);
            this.Field(x => x.Kernel);
            this.Field(x => x.Hostname);
            this.Field(x => x.SshStarted);
            this.Field(x => x.SshPort);
            this.Field(x => x.UpgradeablePackages);

            this.Field <OsStatusType>()
            .Name("Status")
            .ResolveAsync(async context =>
            {
                logger.Debug("Os status field");

                return(await operatingSystemService.GetLastStatusAsync());
            });

            this.Connection <OsStatusType>()
            .Name("Statuses")
            .Bidirectional()
            .ResolveAsync(async context =>
            {
                logger.Debug("Os statuses connection");

                var pagingInput = context.GetPagingInput();
                var statuses    = await operatingSystemService.GetStatusesAsync(pagingInput);

                return(statuses.ToConnection());
            });
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OsWorker"/> class.
 /// </summary>
 /// <param name="operatingSystemService">The application layer OsService.</param>
 /// <param name="configuration">The IConfiguration instance.</param>
 /// <param name="logger">The NLog logger instance.</param>
 public OsWorker(
     IOsService operatingSystemService,
     IConfiguration configuration,
     ILogger logger)
     : base(operatingSystemService, configuration, logger)
 {
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ControlPanelService"/> class.
 /// </summary>
 /// <param name="onDemandService">The infrastructure layer on demand service.</param>
 /// <param name="operatingSystemService">The application layer OsService.</param>
 /// <param name="logger">The NLog logger instance.</param>
 public ControlPanelService(
     Infra.IControlPanelService onDemandService,
     IOsService operatingSystemService,
     ILogger logger)
 {
     this.onDemandService        = onDemandService;
     this.operatingSystemService = operatingSystemService;
     this.logger = logger;
 }
コード例 #4
0
        /// <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);
            }
        }
コード例 #5
0
 public SuTool(ISudoService sudoService, IOsService osService)
 {
     _sudoService = sudoService;
     _osService   = osService;
 }
コード例 #6
0
        /// <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());
            });
        }
コード例 #7
0
 public OsController(IOsService context, IMapper mapper)
 {
     _osService = context;
     _mapper    = mapper;
 }
コード例 #8
0
 public SudoService(IConsoleService console, IParentProcessService parentProcessService, IOsService osService)
 {
     _console = console;
     _parentProcessService = parentProcessService;
     _osService            = osService;
 }
コード例 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ControlPanelSubscription"/> class.
        /// </summary>
        /// <param name="cpuService">The application layer CpuService.</param>
        /// <param name="diskService">The application layer DiskService.</param>
        /// <param name="randomAccessMemoryService">The application layer RandomAccessMemoryService.</param>
        /// <param name="swapMemoryService">The application layer SwapMemoryService.</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 ControlPanelSubscription(
            ICpuService cpuService,
            IDiskService diskService,
            IMemoryService <RandomAccessMemory, RandomAccessMemoryStatus> randomAccessMemoryService,
            IMemoryService <SwapMemory, SwapMemoryStatus> swapMemoryService,
            IOsService operatingSystemService,
            INetworkService networkService,
            ILogger logger)
        {
            this.FieldSubscribe <CpuLoadStatusType>(
                "CpuLoadStatus",
                resolve: context =>
            {
                return(context.Source);
            },
                subscribe: context =>
            {
                logger.Info("CpuAverageLoad subscription");

                var messageHandlingContext = context.UserContext.As <MessageHandlingContext>();
                var graphQLUserContext     = messageHandlingContext.Get <GraphQLUserContext>("GraphQLUserContext");
                var userContext            = graphQLUserContext.GetUserContext();

                return(cpuService.GetLoadStatusObservable());
            });

            this.FieldSubscribe <CpuSensorsStatusType>(
                "CpuSensorsStatus",
                resolve: context =>
            {
                return(context.Source);
            },
                subscribe: context =>
            {
                logger.Info("CpuSensorsStatus subscription");

                var messageHandlingContext = context.UserContext.As <MessageHandlingContext>();
                var graphQLUserContext     = messageHandlingContext.Get <GraphQLUserContext>("GraphQLUserContext");
                var userContext            = graphQLUserContext.GetUserContext();

                return(cpuService.GetSensorsStatusObservable());
            });

            this.FieldSubscribe <CpuFrequencyType>(
                "CpuFrequency",
                resolve: context =>
            {
                return(context.Source);
            },
                subscribe: context =>
            {
                logger.Info("CpuFrequency subscription");

                var messageHandlingContext = context.UserContext.As <MessageHandlingContext>();
                var graphQLUserContext     = messageHandlingContext.Get <GraphQLUserContext>("GraphQLUserContext");
                var userContext            = graphQLUserContext.GetUserContext();

                return(cpuService.GetFrequencyObservable());
            });

            this.FieldSubscribe <MemoryStatusType <RandomAccessMemoryStatus> >(
                "RamStatus",
                resolve: context =>
            {
                return(context.Source);
            },
                subscribe: context =>
            {
                logger.Info("RamStatus subscription");

                var messageHandlingContext = context.UserContext.As <MessageHandlingContext>();
                var graphQLUserContext     = messageHandlingContext.Get <GraphQLUserContext>("GraphQLUserContext");
                var userContext            = graphQLUserContext.GetUserContext();

                return(randomAccessMemoryService.GetStatusObservable());
            });

            this.FieldSubscribe <MemoryStatusType <SwapMemoryStatus> >(
                "SwapMemoryStatus",
                resolve: context =>
            {
                return(context.Source);
            },
                subscribe: context =>
            {
                logger.Info("SwapMemoryStatus subscription");

                var messageHandlingContext = context.UserContext.As <MessageHandlingContext>();
                var graphQLUserContext     = messageHandlingContext.Get <GraphQLUserContext>("GraphQLUserContext");
                var userContext            = graphQLUserContext.GetUserContext();

                return(swapMemoryService.GetStatusObservable());
            });

            this.FieldSubscribe <FileSystemStatusType>(
                "FileSystemStatus",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "FileSystemName"
            }),
                resolve: context =>
            {
                return(context.Source);
            },
                subscribe: context =>
            {
                logger.Info("FileSystemStatus subscription");

                var messageHandlingContext = context.UserContext.As <MessageHandlingContext>();
                var graphQLUserContext     = messageHandlingContext.Get <GraphQLUserContext>("GraphQLUserContext");
                var userContext            = graphQLUserContext.GetUserContext();

                var fileSystemName = context.GetArgument <string>("fileSystemName");

                return(diskService.GetFileSystemStatusObservable(fileSystemName));
            });

            this.FieldSubscribe <OsStatusType>(
                "OsStatus",
                resolve: context =>
            {
                return(context.Source);
            },
                subscribe: context =>
            {
                logger.Info("OsStatus subscription");

                var messageHandlingContext = context.UserContext.As <MessageHandlingContext>();
                var graphQLUserContext     = messageHandlingContext.Get <GraphQLUserContext>("GraphQLUserContext");
                var userContext            = graphQLUserContext.GetUserContext();

                return(operatingSystemService.GetStatusObservable());
            });

            this.FieldSubscribe <NetworkInterfaceStatusType>(
                "NetworkInterfaceStatus",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "NetworkInterfaceName"
            }),
                resolve: context =>
            {
                return(context.Source);
            },
                subscribe: context =>
            {
                logger.Info("NetworkInterfaceStatus subscription");

                var messageHandlingContext = context.UserContext.As <MessageHandlingContext>();
                var graphQLUserContext     = messageHandlingContext.Get <GraphQLUserContext>("GraphQLUserContext");
                var userContext            = graphQLUserContext.GetUserContext();

                var networkInterfaceName = context.GetArgument <string>("networkInterfaceName");

                return(networkService.GetNetworkInterfaceStatusObservable(networkInterfaceName));
            });
        }