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 ("Provides the ability to connect to, query, and manipulate running or stopped Windows services.")]
public class ServiceController : Component
{
private string _name;
private ServiceController [] _dependentServices;
private ServiceController [] _servicesDependedOn;
- [MonoTODO ("No unix implementation")]
public ServiceController ()
{
_machineName = ".";
_impl = CreateServiceControllerImpl (this);
}
- [MonoTODO ("No unix implementation")]
public ServiceController (string name) : this (name, ".")
{
}
- [MonoTODO ("No unix implementation")]
public ServiceController (string name, string machineName)
{
if (name == null || name.Length == 0)
_impl = CreateServiceControllerImpl (this);
}
- [MonoTODO ("No unix implementation")]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [ServiceProcessDescription ("")]
+ [ServiceProcessDescription ("Whether this service recognizes the Pause and Continue commands.")]
public bool CanPauseAndContinue {
get {
-#if NET_2_0
ValidateServiceName (ServiceName);
-#endif
return _impl.CanPauseAndContinue;
}
}
- [MonoTODO ("No unix implementation")]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [ServiceProcessDescription ("")]
+ [ServiceProcessDescription ("Whether this service can respond to a system shutdown.")]
public bool CanShutdown {
get
{
-#if NET_2_0
ValidateServiceName (ServiceName);
-#endif
return _impl.CanShutdown;
}
}
- [MonoTODO ("No unix implementation")]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [ServiceProcessDescription ("")]
+ [ServiceProcessDescription ("Whether this service can be stopped.")]
public bool CanStop {
get
{
-#if NET_2_0
ValidateServiceName (ServiceName);
-#endif
return _impl.CanStop;
}
}
- [MonoTODO ("No unix implementation")]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [ServiceProcessDescription ("")]
+ [ServiceProcessDescription ("The services that depend on this service in order to run.")]
public ServiceController [] DependentServices {
get
{
-#if NET_2_0
ValidateServiceName (ServiceName);
-#endif
if (_dependentServices == null)
_dependentServices = _impl.DependentServices;
return _dependentServices;
}
}
- [MonoTODO ("No unix implementation")]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[ReadOnly (true)]
- [ServiceProcessDescription ("")]
+ [ServiceProcessDescription ("The descriptive name of the service.")]
public string DisplayName {
get {
if (_displayName.Length == 0 && (_serviceName.Length > 0 || _name.Length > 0))
// 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
}
}
- [MonoTODO ("No unix implementation")]
[Browsable (false)]
[DefaultValue (".")]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [ServiceProcessDescription ("")]
+ [RecommendedAsConfigurable (true)]
+ [ServiceProcessDescription ("The name of the machine on which this service resides.")]
public string MachineName {
get {
return _machineName;
// 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
}
}
- [MonoTODO ("No unix implementation")]
[DefaultValue ("")]
[ReadOnly (true)]
[RecommendedAsConfigurable (true)]
- [ServiceProcessDescription ("")]
+ [ServiceProcessDescription ("The short name of the service.")]
+ [TypeConverter (typeof (ServiceNameConverter))]
public string ServiceName {
get {
if (_serviceName.Length == 0 && (_displayName.Length > 0 || _name.Length > 0))
if (_serviceName == value)
return;
-#if NET_2_0
ValidateServiceName (value);
-#endif
_serviceName = value;
// 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
}
}
- [MonoTODO ("No unix implementation")]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [ServiceProcessDescription ("")]
+ [ServiceProcessDescription ("Services that must be started in order for this one to start.")]
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)]
throw new NotImplementedException ();
}
}
-#endif
- [MonoTODO ("No unix implementation")]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [ServiceProcessDescription ("")]
+ [ServiceProcessDescription ("The type of this service.")]
public ServiceType ServiceType {
get
{
-#if NET_2_0
ValidateServiceName (ServiceName);
-#endif
return _impl.ServiceType;
}
}
- [MonoTODO ("No unix implementation")]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [ServiceProcessDescription ("")]
+ [ServiceProcessDescription ("The status of the service, e.g., Running or Stopped.")]
public ServiceControllerStatus Status {
get
{
-#if NET_2_0
ValidateServiceName (ServiceName);
-#endif
return _impl.Status;
}
}
- [MonoTODO ("No unix implementation")]
public void Close ()
{
_impl.Close ();
}
- [MonoTODO ("No unix implementation")]
public void Continue ()
{
-#if NET_2_0
ValidateServiceName (ServiceName);
-#endif
_impl.Continue ();
}
- [MonoTODO ("No unix implementation")]
protected override void Dispose (bool disposing)
{
_impl.Dispose (disposing);
base.Dispose (disposing);
}
- [MonoTODO ("No unix implementation")]
public void ExecuteCommand (int command)
{
-#if NET_2_0
ValidateServiceName (ServiceName);
-#endif
_impl.ExecuteCommand (command);
}
- [MonoTODO ("No unix implementation")]
public static ServiceController[] GetDevices ()
{
return GetDevices (".");
}
- [MonoTODO ("No unix implementation")]
public static ServiceController[] GetDevices (string machineName)
{
ValidateMachineName (machineName);
}
}
- [MonoTODO ("No unix implementation")]
public static ServiceController[] GetServices ()
{
return GetServices (".");
}
- [MonoTODO ("No unix implementation")]
public static ServiceController[] GetServices (string machineName)
{
ValidateMachineName (machineName);
}
}
- [MonoTODO ("No unix implementation")]
public void Pause ()
{
-#if NET_2_0
ValidateServiceName (ServiceName);
-#endif
_impl.Pause ();
}
- [MonoTODO ("No unix implementation")]
public void Refresh ()
{
// MSDN: this method also sets the ServicesDependedOn and
_impl.Refresh ();
}
- [MonoTODO ("No unix implementation")]
public void Start ()
{
Start (new string [0]);
}
- [MonoTODO ("No unix implementation")]
public void Start (string [] args)
{
-#if NET_2_0
ValidateServiceName (ServiceName);
-#endif
_impl.Start (args);
}
- [MonoTODO ("No unix implementation")]
public void Stop ()
{
-#if NET_2_0
ValidateServiceName (ServiceName);
-#endif
_impl.Stop ();
}
- [MonoTODO ("No unix implementation")]
public void WaitForStatus (ServiceControllerStatus desiredStatus)
{
WaitForStatus (desiredStatus, TimeSpan.MaxValue);
}
- [MonoTODO ("No unix implementation")]
public void WaitForStatus (ServiceControllerStatus desiredStatus, TimeSpan timeout)
{
-#if NET_2_0
ValidateServiceName (ServiceName);
-#endif
DateTime start = DateTime.Now;
while (Status != desiredStatus) {
}
}
-#if NET_2_0
private static void ValidateServiceName (string serviceName)
{
if (serviceName.Length == 0 || serviceName.Length > 80)
"Service name {0} contains invalid characters, is empty"
+ " or is too long (max length = 80).", serviceName));
}
-#endif
private static void ValidateMachineName (string machineName)
{
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);