Merge remote-tracking branch 'mfoliveira/ppc64el-v2'
[mono.git] / mcs / class / System.ServiceProcess / System.ServiceProcess / ServiceController.cs
index d4a974b2e188bdba2644445f120f3e4f8470bdff..9cecbce11fde51d42b54ec7fd1c249d665849d13 100644 (file)
 using System;
 using System.ComponentModel;
 using System.Globalization;
-#if NET_2_0
 using System.Runtime.InteropServices;
-#endif
+using System.ServiceProcess.Design;
 using System.Threading;
 
 namespace System.ServiceProcess
 {
        [Designer("System.ServiceProcess.Design.ServiceControllerDesigner, " + Consts.AssemblySystem_Design)]
        [MonoTODO ("No unix implementation")]
-       [ServiceProcessDescription ("")]
+       [ServiceProcessDescription ("Provides the ability to connect to, query, and manipulate running or stopped Windows services.")]
        public class ServiceController : Component
        {
                private string _name;
@@ -81,9 +80,7 @@ namespace System.ServiceProcess
                [ServiceProcessDescription ("Whether this service recognizes the Pause and Continue commands.")]
                public bool CanPauseAndContinue {
                        get {
-#if NET_2_0
                                ValidateServiceName (ServiceName);
-#endif
                                return _impl.CanPauseAndContinue;
                        }
                }
@@ -93,9 +90,7 @@ namespace System.ServiceProcess
                public bool CanShutdown {
                        get
                        {
-#if NET_2_0
                                ValidateServiceName (ServiceName);
-#endif
                                return _impl.CanShutdown;
                        }
                }
@@ -105,9 +100,7 @@ namespace System.ServiceProcess
                public bool CanStop {
                        get
                        {
-#if NET_2_0
                                ValidateServiceName (ServiceName);
-#endif
                                return _impl.CanStop;
                        }
                }
@@ -117,9 +110,7 @@ namespace System.ServiceProcess
                public ServiceController [] DependentServices {
                        get
                        {
-#if NET_2_0
                                ValidateServiceName (ServiceName);
-#endif
                                if (_dependentServices == null)
                                        _dependentServices = _impl.DependentServices;
                                return _dependentServices;
@@ -151,7 +142,7 @@ namespace System.ServiceProcess
                                // you'd expect the DependentServices and ServiceDependedOn cache
                                // to be cleared too, but the MS implementation doesn't do this
                                //
-                               // bug submitted:
+                               // categorized as by design:
                                // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=201762
 
                                // release any handles and clear cache
@@ -178,7 +169,7 @@ namespace System.ServiceProcess
                                // you'd expect the DependentServices and ServiceDependedOn cache
                                // to be cleared too, but the MS implementation doesn't do this
                                //
-                               // bug submitted:
+                               // categorized as by design:
                                // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=201762
 
                                // release any handles and clear cache
@@ -190,6 +181,7 @@ namespace System.ServiceProcess
                [ReadOnly (true)]
                [RecommendedAsConfigurable (true)]
                [ServiceProcessDescription ("The short name of the service.")]
+               [TypeConverter (typeof (ServiceNameConverter))]
                public string ServiceName {
                        get {
                                if (_serviceName.Length == 0 && (_displayName.Length > 0 || _name.Length > 0))
@@ -203,9 +195,7 @@ namespace System.ServiceProcess
                                if (_serviceName == value)
                                        return;
 
-#if NET_2_0
                                ValidateServiceName (value);
-#endif
 
                                _serviceName = value;
 
@@ -216,7 +206,7 @@ namespace System.ServiceProcess
                                // you'd expect the DependentServices and ServiceDependedOn cache
                                // to be cleared too, but the MS implementation doesn't do this
                                //
-                               // bug submitted:
+                               // categorized as by design:
                                // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=201762
 
                                // release any handles and clear cache
@@ -229,16 +219,13 @@ namespace System.ServiceProcess
                public ServiceController [] ServicesDependedOn {
                        get
                        {
-#if NET_2_0
                                ValidateServiceName (ServiceName);
-#endif
                                if (_servicesDependedOn == null)
                                        _servicesDependedOn = _impl.ServicesDependedOn;
                                return _servicesDependedOn;
                        }
                }
 
-#if NET_2_0
                [MonoTODO]
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
@@ -248,16 +235,13 @@ namespace System.ServiceProcess
                                throw new NotImplementedException ();
                        }
                }
-#endif
 
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                [ServiceProcessDescription ("The type of this service.")]
                public ServiceType ServiceType {
                        get
                        {
-#if NET_2_0
                                ValidateServiceName (ServiceName);
-#endif
                                return _impl.ServiceType;
                        }
                }
@@ -267,9 +251,7 @@ namespace System.ServiceProcess
                public ServiceControllerStatus Status {
                        get
                        {
-#if NET_2_0
                                ValidateServiceName (ServiceName);
-#endif
                                return _impl.Status;
                        }
                }
@@ -281,9 +263,7 @@ namespace System.ServiceProcess
 
                public void Continue ()
                {
-#if NET_2_0
                        ValidateServiceName (ServiceName);
-#endif
                        _impl.Continue ();
                }
 
@@ -295,9 +275,7 @@ namespace System.ServiceProcess
 
                public void ExecuteCommand (int command)
                {
-#if NET_2_0
                        ValidateServiceName (ServiceName);
-#endif
                        _impl.ExecuteCommand (command);
                }
 
@@ -333,9 +311,7 @@ namespace System.ServiceProcess
 
                public void Pause ()
                {
-#if NET_2_0
                        ValidateServiceName (ServiceName);
-#endif
                        _impl.Pause ();
                }
 
@@ -358,17 +334,13 @@ namespace System.ServiceProcess
 
                public void Start (string [] args)
                {
-#if NET_2_0
                        ValidateServiceName (ServiceName);
-#endif
                        _impl.Start (args);
                }
 
                public void Stop ()
                {
-#if NET_2_0
                        ValidateServiceName (ServiceName);
-#endif
                        _impl.Stop ();
                }
 
@@ -379,9 +351,7 @@ namespace System.ServiceProcess
 
                public void WaitForStatus (ServiceControllerStatus desiredStatus, TimeSpan timeout)
                {
-#if NET_2_0
                        ValidateServiceName (ServiceName);
-#endif
 
                        DateTime start = DateTime.Now;
                        while (Status != desiredStatus) {
@@ -421,7 +391,6 @@ namespace System.ServiceProcess
                        }
                }
 
-#if NET_2_0
                private static void ValidateServiceName (string serviceName)
                {
                        if (serviceName.Length == 0 || serviceName.Length > 80)
@@ -429,7 +398,6 @@ namespace System.ServiceProcess
                                        "Service name {0} contains invalid characters, is empty"
                                        + " or is too long (max length = 80).", serviceName));
                }
-#endif
 
                private static void ValidateMachineName (string machineName)
                {
@@ -440,11 +408,9 @@ namespace System.ServiceProcess
 
                private static ServiceControllerImpl CreateServiceControllerImpl (ServiceController serviceController)
                {
-#if NET_2_0
-                       if (Environment.OSVersion.Platform == PlatformID.Unix) {
-#else
-                       if ((int) Environment.OSVersion.Platform == 128) {
-#endif
+                       int p = (int) Environment.OSVersion.Platform;
+
+                       if (p == 4 || p == 128 || p == 6){
                                return new UnixServiceController (serviceController);
                        } else {
                                return new Win32ServiceController (serviceController);