Ejemplo n.º 1
0
        private CommandResult Stop()
        {
            try
            {
                ServiceInstance instance = serviceProvider.AquaireInstance(serviceInstanceId);
                if (instance.IsServiceRunning())
                {
                    instance.Stop();
                }

                return(CommandResult.OKResult());
            }
            catch (Service.TimeoutException ex)
            {
                throw new TargetExecutionException(DaemonErrorCode.COMMAND_TIME_OUT, ex);
            }
            catch (TargetExecutionException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new TargetExecutionException(DaemonErrorCode.UNKNOWN_ERROR, ex);
            }
        }
Ejemplo n.º 2
0
        private CommandResult Start()
        {
            logger.Trace("ServiceCommand: Start()");
            try
            {
                if (CheckAndCleanupPreviousService())
                {
                    // Reload the configs and install service first
                    serviceProvider   = ComposeServiceProvider(minerConfig.InstanceType);
                    serviceInstanceId = minerConfig.InstanceId;

                    ServiceInstance instance = serviceProvider.InstallService(minerConfig.InstanceId);
                    instance.Start();
                }
                else
                {
                    ServiceInstance instance = serviceProvider.AquaireInstance(minerConfig.InstanceId);
                    if (!instance.IsServiceRunning())
                    {
                        instance.Start();
                    }
                }

                return(CommandResult.OKResult());
            }
            catch (Service.TimeoutException ex)
            {
                throw new TargetExecutionException(DaemonErrorCode.COMMAND_TIME_OUT, ex);
            }
            catch (TargetExecutionException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new TargetExecutionException(DaemonErrorCode.UNKNOWN_ERROR, ex);
            }
        }
Ejemplo n.º 3
0
        public override CommandResult Execute(string parameter)
        {
            try
            {
                ServiceProvider serviceProvider = ComposeServiceProvider(MinerConfig.GetInstance().InstanceType);
                int             instanceId      = MinerConfig.GetInstance().InstanceId;

                serviceInstance = serviceProvider.AquaireInstance(instanceId);

                ReportOutput outputResult = new ReportOutput();
                outputResult.Status = ReportOutput.StatusEnum.Unknown;

                if (!serviceInstance.IsServiceExist())
                {
                    outputResult.Status = ReportOutput.StatusEnum.NotInstalled;
                }
                else if (!serviceInstance.IsServiceRunning())
                {
                    outputResult.Status = ReportOutput.StatusEnum.Stopped;
                }
                else
                {
                    // Retrieve the miner status from NamedPipe
                    QueryServiceStatusByNamedPipe(outputResult);
                }

                return(CommandResult.CreateResult(outputResult));
            }
            catch (TargetExecutionException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new TargetExecutionException(DaemonErrorCode.UNKNOWN_ERROR, ex);
            }
        }