예제 #1
0
        public static WindowServiceInfo Create(string serviceName, string servicePath, string serviceFriendlyName, bool validateFailThrows = false)
        {
            var info = new WindowServiceInfo()
            {
                ServiceName         = serviceName,
                ServicePath         = servicePath,
                ServiceFriendlyName = serviceFriendlyName
            };

            if (validateFailThrows)
            {
                var success = Validate(info, out var message);
                if (!success)
                {
                    throw new ArgumentException(message);
                }
            }

            return(info);
        }
예제 #2
0
        public static bool Validate(WindowServiceInfo info, out string message)
        {
            if (info == null)
            {
                message = "info should not be null";
                return(false);
            }

            if (string.IsNullOrWhiteSpace(info.ServiceName))
            {
                message = "ServiceName should not be null or empty";
                return(false);
            }

            if (string.IsNullOrWhiteSpace(info.ServicePath))
            {
                message = "ServicePath should not be null or empty";
                return(false);
            }

            message = "OK";
            return(true);
        }
예제 #3
0
 public ServiceController(WindowServiceInfo info)
 {
     ServiceInfo = info ?? throw new ArgumentNullException(nameof(info));
 }
예제 #4
0
 public static ServiceController Create(WindowServiceInfo info)
 {
     return(new ServiceController(info));
 }