Beispiel #1
0
        public MessageResult TryStart()
        {
            var serviceName  = ServiceInfo.ServiceName;
            var serviceState = GetServiceState(serviceName);

            if (serviceState == ServiceState.NotFound)
            {
                return(AppendLogsAndResult(false, string.Format("{0} not installed!", serviceName)));
            }

            if (serviceState == ServiceState.Running || serviceState == ServiceState.StartPending)
            {
                return(AppendLogsAndResult(true, string.Format("{0} is already running!", serviceName)));
            }

            ServiceInstaller.StartService(serviceName);
            return(AppendLogsAndResult(true, string.Format("{0} start completed!", serviceName)));
        }
Beispiel #2
0
        public MessageResult TryStop()
        {
            var serviceName  = ServiceInfo.ServiceName;
            var serviceState = GetServiceState(serviceName);

            if (serviceState == ServiceState.NotFound)
            {
                return(AppendLogsAndResult(true, string.Format("{0} not installed!", serviceName)));
            }

            if (serviceState == ServiceState.Stopped || serviceState == ServiceState.StopPending)
            {
                return(AppendLogsAndResult(true, string.Format("{0} is stopping!", serviceName)));
            }

            ServiceInstaller.StopService(serviceName);
            GetServiceState(serviceName);
            return(AppendLogsAndResult(true, string.Format("{0} stop completed!", serviceName)));
        }
Beispiel #3
0
        public MessageResult TryUninstall()
        {
            var failResult    = MessageResult.MethodResult(nameof(TryUninstall), false);
            var successResult = MessageResult.MethodResult(nameof(TryUninstall), true);

            try
            {
                var installed = ServiceInstaller.ServiceIsInstalled(ServiceName);
                if (!installed)
                {
                    var message = string.Format("{0} already uninstalled!", ServiceName);
                    successResult.Message = message;
                    return(successResult);
                }

                ServiceInstaller.Uninstall(ServiceName);
                return(successResult);
            }
            catch (Exception e)
            {
                failResult.Message = failResult.Message + " => " + e.Message;
                return(failResult);
            }
        }
Beispiel #4
0
        public string TryGetStatus()
        {
            var serviceStatus = ServiceInstaller.GetServiceState(ServiceName);

            return(serviceStatus.ToString());
        }
Beispiel #5
0
        public ServiceState GetServiceState()
        {
            var serviceStatus = ServiceInstaller.GetServiceState(ServiceName);

            return(serviceStatus);
        }