Exemplo n.º 1
0
        private HttpResponseMessage GetServiceStatus(string service)
        {
            var healthCheckServiceManager = new HealthCheckServiceManager(HealthCheckRunner.ServiceRepository);
            var serviceName = healthCheckServiceManager.GetServiceName(service);

            if (!serviceName.HasValue)
            {
                log.ErrorFormat("Wrong service {0}", service);
                return(ResultHelper.WrongParameterError());
            }
            var    serviceStatus = healthCheckServiceManager.GetStatus(serviceName.Value);
            var    status        = serviceStatus.GetStringStatus();
            string message;
            int    code;

            switch (serviceStatus)
            {
            case ServiceStatus.StartPending:
                message = HealthCheckResource.ServiceStartWorking;
                code    = 1;
                break;

            case ServiceStatus.Running:
                message = HealthCheckResource.ServiceRun;
                code    = 2;
                break;

            case ServiceStatus.Stopped:
                message = HealthCheckResource.ServiceStop;
                code    = 3;
                break;

            default:
                message = HealthCheckResource.NotExpectedState;
                code    = 0;
                break;
            }

            HealthCheckRunner.ServiceRepository.SetStates(serviceName.Value, status,
                                                          message != HealthCheckResource.ServiceRun ? HealthCheckResource.ServiceRun : string.Empty);

            return(ResultHelper.GetContent(new { code, status, message }));
        }
Exemplo n.º 2
0
        private HttpResponseMessage Stop(string service)
        {
            var healthCheckServiceManager = new HealthCheckServiceManager(HealthCheckRunner.ServiceRepository);
            var serviceName = healthCheckServiceManager.GetServiceName(service);

            if (!serviceName.HasValue)
            {
                log.ErrorFormat("Wrong service {0}", service);
                return(ResultHelper.WrongServiceNameError());
            }
            var message = healthCheckServiceManager.StopService(serviceName.Value);

            if (message == string.Empty)
            {
                log.DebugFormat("Stop service: {0}", serviceName);
                return(ResultHelper.Success(ServiceStatus.Stopped.GetStringStatus(), ServiceStatus.Stopped.GetMessageStatus()));
            }
            log.ErrorFormat("Not stop service: {0}, status = {1}", serviceName, message);
            return(ResultHelper.StatusServerError(message));
        }