コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ControlPanelMutation"/> class.
        /// </summary>
        /// <param name="controlPanelService">The application layer ControlPanelService.</param>
        /// <param name="logger">The NLog logger instance.</param>
        public ControlPanelMutation(IControlPanelService controlPanelService, ILogger logger)
        {
            this.AuthorizeWith(AuthorizationPolicyName.AuthenticatedPolicy);

            this.FieldAsync <BooleanGraphType>(
                "Reboot",
                resolve: async context =>
            {
                logger.Info("Reboot mutation");

                return(await controlPanelService.RebootAsync());
            })
            .AuthorizeWith(AuthorizationPolicyName.SuperUserPolicy);

            this.FieldAsync <BooleanGraphType>(
                "Shutdown",
                resolve: async context =>
            {
                logger.Info("Shutdown mutation");

                return(await controlPanelService.ShutdownAsync());
            })
            .AuthorizeWith(AuthorizationPolicyName.SuperUserPolicy);

            this.FieldAsync <BooleanGraphType>(
                "Update",
                resolve: async context =>
            {
                logger.Info("Update mutation");

                return(await controlPanelService.UpdateAsync());
            })
            .AuthorizeWith(AuthorizationPolicyName.SuperUserPolicy);

            this.FieldAsync <BooleanGraphType>(
                "Kill",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "ProcessId"
            }),
                resolve: async context =>
            {
                logger.Info("Kill mutation");

                var graphQLUserContext = context.UserContext as GraphQLUserContext;
                var userContext        = graphQLUserContext.GetUserContext();

                var processId = context.GetArgument <int>("processId");

                return(await controlPanelService.KillAsync(userContext, processId));
            })
            .AuthorizeWith(AuthorizationPolicyName.AuthenticatedPolicy);

            this.FieldAsync <BooleanGraphType>(
                "Overclock",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <CpuMaxFrequencyLevelType> > {
                Name = "CpuMaxFrequencyLevel"
            }),
                resolve: async context =>
            {
                logger.Info("Overclock mutation");

                var cpuMaxFrequencyLevel = context.GetArgument <CpuMaxFrequencyLevel>("cpuMaxFrequencyLevel");

                return(await controlPanelService.OverclockAsync(cpuMaxFrequencyLevel));
            })
            .AuthorizeWith(AuthorizationPolicyName.SuperUserPolicy);

            this.FieldAsync <BooleanGraphType>(
                "StartSsh",
                resolve: async context =>
            {
                logger.Info("StartSsh mutation");

                return(await controlPanelService.StartSshAsync());
            })
            .AuthorizeWith(AuthorizationPolicyName.SuperUserPolicy);
        }
コード例 #2
0
 public ControlPanelController(IControlPanelService controlPanelService)
 {
     _controlPanelService = controlPanelService;
 }
コード例 #3
0
 public ControlPanelController(IErrorService errorService, IControlPanelService controlPanelService) : base(errorService)
 {
     this._controlPanelService = controlPanelService;
 }