コード例 #1
0
        private static ServiceBE StopService(uint serviceId, ServiceBE service, ServiceStopType stopType)
        {
            if (IsLocalAuthService(serviceId))
            {
                return(service);
            }
            DekiContext context = DekiContext.Current;
            bool        saveBe  = false;

            if (service != null && service.ServiceLocal)
            {
                // local services should have their uri cleared out
                _log.DebugFormat("stopping service '{0}'", service.SID);
                service.Uri = null;
                saveBe      = true;
            }
            if (service != null && stopType == ServiceStopType.Disable)
            {
                // wipe out last error on disable
                service.ServiceLastStatus = null;
                saveBe = true;
            }
            var serviceInfo = context.Instance.RunningServices[serviceId];

            if (serviceInfo == null)
            {
                if (saveBe)
                {
                    service = UpdateService(service) ?? service;
                }

                // service is not registered as running, we're done here
                return(service);
            }

            try {
                context.Instance.DeregisterService(serviceId);
            } catch (Exception e) {
                // log the error, but ignore it otherwise
                if (service == null)
                {
                    context.Instance.Log.WarnExceptionMethodCall(e, "StopService", string.Format("Unable to stop {0} service id '{1}'", serviceInfo.IsLocal ? "local" : "remote", serviceId));
                }
                else
                {
                    context.Instance.Log.WarnExceptionMethodCall(e, "StopService", string.Format("Unable to stop {0} service id '{1}' with SID '{2}'", serviceInfo.IsLocal ? "local" : "remote", serviceId, service.SID));
                }
            }

            if (service != null && (stopType == ServiceStopType.Disable || saveBe))
            {
                service.ServiceEnabled = (stopType != ServiceStopType.Disable);
                service = UpdateService(service) ?? service;
            }
            return(service);
        }
コード例 #2
0
        private static ServiceBE StopService(uint serviceId, ServiceBE service, ServiceStopType stopType) {
            DekiContext context = DekiContext.Current;
            bool saveBe = false;
            if(service != null && service.ServiceLocal) {

                // local services should have their uri cleared out
                service.Uri = null;
                saveBe = true;
            }
            if(service != null && stopType == ServiceStopType.Disable) {

                // wipe out last error on disable
                service.ServiceLastStatus = null;
                saveBe = true;
            }
            var serviceInfo = context.Instance.RunningServices[serviceId];

            if(serviceInfo == null) {
                if(saveBe) {
                    service = UpdateService(service) ?? service;
                }

                // service is not registered as running, we're done here
                return service;
            }

            try {
                context.Instance.DeregisterService(serviceId);
            } catch(Exception e) {

                // log the error, but ignore it otherwise
                if(service == null) {
                    context.Instance.Log.WarnExceptionMethodCall(e, "StopService", string.Format("Unable to stop {0} service id '{1}'", serviceInfo.IsLocal ? "local" : "remote", serviceId));
                } else {
                    context.Instance.Log.WarnExceptionMethodCall(e, "StopService", string.Format("Unable to stop {0} service id '{1}' with SID '{2}'", serviceInfo.IsLocal ? "local" : "remote", serviceId, service.SID));
                }
            }

            if(service != null && (stopType == ServiceStopType.Disable || saveBe)) {
                service.ServiceEnabled = false;
                service = UpdateService(service) ?? service;
            }
            return service;
        }