Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@ -0,0 +1,60 @@
//
// AssemblyInfo.cs
//
// Author:
// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
//
// (C) 2003 Ximian, Inc. http://www.ximian.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Security;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about the System.ServiceProcess assembly
[assembly: AssemblyTitle ("System.ServiceProcess.dll")]
[assembly: AssemblyDescription ("System.ServiceProcess.dll")]
[assembly: AssemblyDefaultAlias ("System.ServiceProcess.dll")]
[assembly: AssemblyCompany (Consts.MonoCompany)]
[assembly: AssemblyProduct (Consts.MonoProduct)]
[assembly: AssemblyCopyright (Consts.MonoCopyright)]
[assembly: AssemblyVersion (Consts.FxVersion)]
[assembly: SatelliteContractVersion (Consts.FxVersion)]
[assembly: AssemblyInformationalVersion (Consts.FxFileVersion)]
[assembly: NeutralResourcesLanguage ("en-US")]
[assembly: ComVisible (false)]
[assembly: CLSCompliant (true)]
[assembly: AssemblyDelaySign (true)]
[assembly: AssemblyKeyFile("../msfinal.pub")]
[assembly: AssemblyFileVersion (Consts.FxFileVersion)]
[assembly: CompilationRelaxations (CompilationRelaxations.NoStringInterning)]

View File

@ -0,0 +1,15 @@
2008-04-25 Andreas Nahr <ClassDevelopment@A-SoftTech.com>
* AssemblyInfo.cs: Rework consts scheme
2006-09-22 Gert Driesen <drieseng@users.sourceforge.net>
* AssemblyInfo.cs: AssemblyConfiguration and AssemblyTrademark
attributes are 1.1 only. Added AssemblyFileVersion, Debuggable and
CompilationRelaxtations attribute for 2.0 profile.
2004-04-06 Andreas Nahr <ClassDevelopment@A-SoftTech.com>
* AssemblyInfo.cs: Added
* ChangeLog: Added
* Locale.cs: Added

View File

@ -0,0 +1,55 @@
2007-10-05 Atsushi Enomoto <atsushi@ximian.com>
* Makefile : added /r:System.Windows.Forms. removed /warnaserror.
* System.ServiceProcess.dll.sources : added couple of missing types.
2007-04-07 Gert Driesen <drieseng@users.sourceforge.net>
* Makefile: Do not output deprecated warnings.
2006-09-22 Gert Driesen <drieseng@users.sourceforge.net>
* System.ServiceProcess.dll.sources: Added ServiceNameConverter.cs.
2006-09-14 Gert Driesen <drieseng@users.sourceforge.net>
* Makefile: Treat warnings as error. Ignore no warnings.
* System.ServiceProcess.dll.sources: Added ServiceControllerImpl.cs,
UnixServiceController.cs and Win32ServiceController.cs.
* System.ServiceProcess_test.dll.sources: Added
ServiceControllerTest.cs.
2005-01-23 Geoff Norton <gnorton@customerdna.com>
* System.ServiceProcess.dll.sources: Add ServiceInstaller and
ServiceProcessInstaller to the build.
2004-09-11 Sebastien Pouliot <sebastien@ximian.com>
* Makefile: Updated to include unit tests.
* System.ServiceProcess.dll.sources: Added ServiceControllerPermission
class to the build.
* System.ServiceProcess_test.dll.sources: New. Added sources file for
unit tests.
2003-07-30 Duncan Mak <duncan@ximian.com>
* TimeoutException.cs:
* ServiceProcessDescriptionAttribute.cs:
* ServiceControllerPermissionAttribute.cs:
* ServiceControllerPermissionEntryCollection.cs:
* ServiceControllerPermissionEntry.cs: Added.
* TODOAttribute.cs:
* Locale.cs: Added.
* ServiceBase.cs: Added missing APIs.
2003-02-23 Rafael Teixeira <rafaelteixeirabr@hotmail.com>
* added makefile and other tidbits to be able to make in Linux
2002-12-10 Jeroen Janssen <japj@darius.demon.nl>
* added System.ServiceProcess.build file
* added ChangeLog file

View File

@ -0,0 +1,12 @@
thisdir = class/System.ServiceProcess
SUBDIRS =
include ../../build/rules.make
LIBRARY = System.ServiceProcess.dll
LIB_MCS_FLAGS = /r:System.dll /r:System.Configuration.Install.dll \
/r:System.Windows.Forms.dll /nowarn:0618
TEST_MCS_FLAGS = $(LIB_MCS_FLAGS)
EXTRA_DISTFILES =
include ../../build/library.make

View File

@ -0,0 +1,8 @@
2007-10-05 Atsushi Enomoto <atsushi@ximian.com>
* ServiceInstallerDialogResult.cs, ServiceInstallerDialog.cs :
added missing files (winforms dependencies).
2006-09-22 Gert Driesen <drieseng@users.sourceforge.net>
* ServiceNameConverter.cs: Dummy implementation to fix class status.

View File

@ -0,0 +1,68 @@
//
// System.ServiceProcess.Design.ServiceInstallerDialog.cs
//
// Author:
// Atsushi Enomoto (atsushi@ximian.com)
//
// Copyright (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.ComponentModel.Design;
using System.Windows.Forms;
namespace System.ServiceProcess.Design
{
[MonoTODO]
public class ServiceInstallerDialog : Form
{
string username, password;
const ServiceInstallerDialogResult result = 0;
public ServiceInstallerDialog ()
{
}
[STAThread]
[MonoTODO]
public static void Main ()
{
Application.Run (new ServiceInstallerDialog ());
}
public string Username {
get { return username; }
set { username = value; }
}
public string Password {
get { return password; }
set { password = value; }
}
[MonoTODO]
public ServiceInstallerDialogResult Result {
get { return result; }
}
}
}

View File

@ -0,0 +1,41 @@
//
// System.ServiceProcess.Design.ServiceInstallerDialogResult.cs
//
// Author:
// Atsushi Enomoto (atsushi@ximian.com)
//
// Copyright (C) 2007 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.ComponentModel.Design;
namespace System.ServiceProcess.Design
{
public enum ServiceInstallerDialogResult
{
OK,
UseSystem,
Canceled,
}
}

View File

@ -0,0 +1,51 @@
//
// System.ServiceProcess.Design.ServiceNameConverter
//
// Authors:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// (C) 2006 Novell Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.ComponentModel;
using System.Globalization;
namespace System.ServiceProcess.Design
{
internal class ServiceNameConverter : TypeConverter
{
public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof (string))
return true;
return base.CanConvertFrom (sourceType);
}
public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
return ((string) value);
return base.ConvertFrom (context, culture, value);
}
}
}

View File

@ -0,0 +1,28 @@
Assembly/AssemblyInfo.cs
../../build/common/Consts.cs
../../build/common/Locale.cs
../../build/common/MonoTODOAttribute.cs
System.ServiceProcess/PowerBroadcastStatus.cs
System.ServiceProcess/ServiceAccount.cs
System.ServiceProcess/ServiceController.cs
System.ServiceProcess/ServiceControllerImpl.cs
System.ServiceProcess/ServiceControllerPermissionAccess.cs
System.ServiceProcess/ServiceControllerStatus.cs
System.ServiceProcess/ServiceInstaller.cs
System.ServiceProcess/ServiceProcessInstaller.cs
System.ServiceProcess/ServiceStartMode.cs
System.ServiceProcess/ServiceType.cs
System.ServiceProcess/ServiceBase.cs
System.ServiceProcess/TimeoutException.cs
System.ServiceProcess/ServiceProcessDescriptionAttribute.cs
System.ServiceProcess/ServiceControllerPermission.cs
System.ServiceProcess/ServiceControllerPermissionAttribute.cs
System.ServiceProcess/ServiceControllerPermissionEntry.cs
System.ServiceProcess/ServiceControllerPermissionEntryCollection.cs
System.ServiceProcess/SessionChangeDescription.cs
System.ServiceProcess/SessionChangeReason.cs
System.ServiceProcess/UnixServiceController.cs
System.ServiceProcess/Win32ServiceController.cs
System.ServiceProcess.Design/ServiceInstallerDialog.cs
System.ServiceProcess.Design/ServiceInstallerDialogResult.cs
System.ServiceProcess.Design/ServiceNameConverter.cs

View File

@ -0,0 +1,126 @@
2008-08-09 Gert Driesen <drieseng@users.sourceforge.net>
* ServiceProcessInstaller.cs: Fixed argument name to match MS. Code
formatting.
* ServiceBase.cs: Fixed argument name to match MS. Code formatting.
* SessionChangeDescription.cs: Fixed argument name to match MS.
2007-10-05 Atsushi Enomoto <atsushi@ximian.com>
* SessionChangeDescription.cs, SessionChangeReason.cs :
new 2.0 types.
* ServiceBase.cs : added missing members.
2006-10-07 Gert Driesen <drieseng@users.sourceforge.net>
* ServiceController.cs: Modifying ServiceService, DisplayName
or MachineName does not cause cache to be cleared. Categorized as
"By Design" by MS.
2006-09-22 Gert Driesen <drieseng@users.sourceforge.net>
* ServiceProcessInstaller.cs: Added missing ServiceProcessDescription
attribute.
* ServiceAccount.cs: Removed extra Serializable attribute.
* ServiceInstaller.cs: Added ServiceProcessDescriptions.
* ServiceBase.cs: Added descriptions for ServiceProcessDescription
as reported by class status. Modified return type of OnPowerEvent
from void to bool.
* ServiceController.cs: Added description for class-level
ServiceProcessDescription. Added TypeConverter for ServiceName.
* TimeoutException.cs: Added ctor introduced in 2.0 profile.
2006-09-16 Gert Driesen <drieseng@users.sourceforge.net>
* ServiceProcessInstaller.cs: Added some missing attributes. Fixes
class status errors.
* ServiceBase.cs: Added missing attributes. Fixed signature of
OnCustomCommand and OnPowerEvent methods. Fixed code to match coding
guidelines and converted spaces to tabs.
* ServiceController.cs: Added missing attributes. Moved MonoTODO to
class level. Added descriptions for ServiceProcessDescription
attributes.
* TimeoutException.cs: Reduce accesibility of deserialization ctor to
protected to match MS. Fixed code to match coding guidelines and
converted spaces to tabs.
2006-09-14 Gert Driesen <drieseng@users.sourceforge.net>
* ServiceControllerPermissionEntryCollection.cs: Set eol-style to
native.
* ServiceAccount.cs: Set eol-style to native.
* ServiceControllerPermission.cs: Set eol-style to native.
* ServiceProcessInstaller.cs: Set eol-style to native.
* ServiceInstaller.cs: API compatibility fixes. Coding guidelines
fixes. Set eol-style to native.
* PowerBroadcastStatus.cs: Removed Serializable attribute. Coding
guidelines fixes. Set eol-style to native.
* ServiceStartMode.cs: Removed Serializable attribute. Coding
guidelines fixes. Set eol-style to native.
* ServiceProcessDescriptionAttribute.cs: Removed Serializable
attribute. Set eol-style to native.
* ServiceBase.cs: Set eol-style to native.
* ServiceControllerPermissionAccess.cs: Removed Serializable
attribute. Coding guidelines fixes. Set eol-style to native.
* ServiceControllerPermissionAccess.cs: Set eol-style to native.
* ServiceControllerPermissionEntry.cs: Set eol-style to native.
* ServiceControllerPermissionAttribute.cs: Set eol-style to native.
* ServiceType.cs: Removed Serializable attribute. Coding guidelines
fixes. Set eol-style to native.
* ServiceController.cs: API compatibility fixes. Added missing
MonoTODO's. Coding guidelines fixes. Set eol-style to native.
Provides an implementation for Win32.
* TimeoutException.cs: Set eol-style to native.
* ServiceControllerStatus.cs: Removed Serializable attribute.
Coding guidelines fixes. Set eol-style to native.
* UnixServiceController.cs: Dummy implementation for unix. Always
throws NotImplementedException.
* Win32ServiceController.cs: Win32 implementation. Built as a wrapper
for the Win32 Service API.
2006-01-13 Ben Maurer <bmaurer@andrew.cmu.edu>
* ServiceInstaller.cs: Stubs for 2.0 stuff
2005-11-14 Marek Safar <marek.safar@seznam.cz>
* ServiceController.cs: Simple stub only.
2005-05-31 Sebastien Pouliot <sebastien@ximian.com>
* ServiceControllerPermission.cs: Accept empty service name before 2.0
2005-04-09 Joerg Rosenkranz <joergr@voelcker.com>
* ServiceBase.cs: Cleaned up callback code.
2005-04-08 Joerg Rosenkranz <joergr@voelcker.com>
* ServiceBase.cs: Introduced static callback for interoperability
with mono-service.
2005-04-06 Joerg Rosenkranz <joergr@voelcker.com>
* ServiceBase.cs: Fixed default values of members.
2005-04-04 Joerg Rosenkranz <joergr@voelcker.com>
* ServiceBase.cs: Introduced static field for interoperation with monod.
Implemented Run methods.
2004-01-23 Geoff Norton <gnorton@customerdna.com>
* ServiceBase.cs: Implement missing virtuals.
* ServiceInstaller.cs: Initial Implementation.
* ServiceProcessInstaller.cs: Initial Implementation.
2004-09-11 Sebastien Pouliot <sebastien@ximian.com>
* ChangeLog: New.
* ServiceControllerPermission.cs: New. Added permission class.
* ServiceControllerPermissionAttribute.cs: Completed TODO, added
missing validations (machine and service names). Fixed AttributeUsage.
* ServiceControllerPermissionEntry.cs: Added internal GetBaseEntry for
synchronization. Converted spaces to tabs.
* ServiceControllerPermissionEntryCollection.cs: Added synchronization
with entries in the base class. Converted spaces to tabs.

View File

@ -0,0 +1,43 @@
//
// System.ServiceProcess.PowerBroadcastStatus
//
// Author: Cesar Octavio Lopez Nataren (cesar@ciencias.unam.mx)
//
// (C) 2002, Cesar Octavio Lopez Nataren
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.ServiceProcess
{
public enum PowerBroadcastStatus
{
QuerySuspend = 0,
QuerySuspendFailed = 2,
Suspend = 4,
ResumeCritical = 6,
ResumeSuspend = 7,
BatteryLow = 9,
PowerStatusChange = 10,
OemEvent = 11,
ResumeAutomatic = 18
}
}

View File

@ -0,0 +1,37 @@
//
// System.ServiceProcess.ServiceAccount
//
// Author: Cesar Octavio Lopez Nataren (cesar@ciencias.unam.mx)
//
// (C) 2002, Cesar Octavio Lopez Nataren
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.ServiceProcess
{
public enum ServiceAccount {
LocalService = 0,
NetworkService = 1,
LocalSystem = 2,
User = 3
}
}

View File

@ -0,0 +1,491 @@
//
// System.ServiceProcess.ServiceBase.cs
//
// Authors:
// Cesar Octavio Lopez Nataren (cesar@ciencias.unam.mx)
// Duncan Mak (duncan@ximian.com)
// Joerg Rosenkranz (joergr@voelcker.com)
// Vincent Povirk (madewokherd@gmail.com)
//
// (C) 2003, Ximian Inc and Cesar Octavio Lopez Nataren.
// (C) 2005, Voelcker Informatik AG
// (C) 2014, CodeWeavers Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.ComponentModel;
using System.Globalization;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
namespace System.ServiceProcess
{
#if ONLY_1_1
[Designer ("Microsoft.VisualStudio.Install.UserNTServiceDesigner, " + Consts.AssemblyMicrosoft_VisualStudio, "System.ComponentModel.Design.IRootDesigner")]
#endif
[InstallerType (typeof (ServiceProcessInstaller))]
public class ServiceBase : Component
{
internal delegate void RunServiceCallback (ServiceBase [] services);
// This member is used for interoperation with mono-service
internal static RunServiceCallback RunService;
internal delegate void NotifyStatusCallback (ServiceBase service, ServiceControllerStatus status);
internal static NotifyStatusCallback NotifyStatus;
public const int MaxNameLength = 80;
bool hasStarted;
bool auto_log = true;
bool can_handle_power_event;
bool can_pause_and_continue;
bool can_shutdown;
bool can_stop = true;
EventLog event_log;
string service_name;
bool can_handle_session_change_event;
IntPtr service_handle;
ManualResetEvent stop_event;
static bool share_process;
public ServiceBase ()
{
}
[DefaultValue (true)]
[ServiceProcessDescription ("Whether the service should automatically write to the event log on common events such as Install and Start.")]
public bool AutoLog {
get { return auto_log; }
set { auto_log = value; }
}
[DefaultValue (false)]
[MonoTODO]
public bool CanHandlePowerEvent {
get { return can_handle_power_event; }
set {
if (hasStarted)
throw new InvalidOperationException (
Locale.GetText ("Cannot modify this property " +
"after the service has started."));
can_handle_power_event = value;
}
}
[DefaultValue (false)]
[MonoTODO]
[ComVisible (false)]
public bool CanHandleSessionChangeEvent {
get { return can_handle_session_change_event; }
set {
if (hasStarted)
throw new InvalidOperationException (
Locale.GetText ("Cannot modify this property " +
"after the service has started."));
can_handle_session_change_event = value;
}
}
[DefaultValue (false)]
public bool CanPauseAndContinue {
get { return can_pause_and_continue; }
set {
if (hasStarted)
throw new InvalidOperationException (
Locale.GetText ("Cannot modify this property " +
"after the service has started."));
can_pause_and_continue = value;
}
}
[DefaultValue (false)]
public bool CanShutdown {
get { return can_shutdown; }
set {
if (hasStarted)
throw new InvalidOperationException (
Locale.GetText ("Cannot modify this property " +
"after the service has started."));
can_shutdown = value;
}
}
[DefaultValue (true)]
public bool CanStop {
get { return can_stop; }
set {
if (hasStarted)
throw new InvalidOperationException (
Locale.GetText ("Cannot modify this property " +
"after the service has started."));
can_stop = value;
}
}
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public virtual EventLog EventLog {
get {
if (event_log == null)
event_log = new EventLog ("Application", ".", service_name);
return event_log;
}
}
[ComVisible (false)]
public int ExitCode { get; set; }
[MonoTODO]
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected IntPtr ServiceHandle {
get { return service_handle; }
}
[ServiceProcessDescription ("The name by which the service is identified to the system.")]
[TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
public string ServiceName {
get { return service_name; }
set {
if (hasStarted)
throw new InvalidOperationException (
Locale.GetText ("Cannot modify this property " +
"after the service has started."));
service_name = value;
}
}
protected override void Dispose (bool disposing)
{
}
protected virtual void OnStart (string [] args)
{
}
protected virtual void OnStop ()
{
}
protected virtual void OnContinue ()
{
}
protected virtual void OnCustomCommand (int command)
{
}
protected virtual void OnPause ()
{
}
protected virtual bool OnPowerEvent (PowerBroadcastStatus powerStatus)
{
return true;
}
protected virtual void OnShutdown ()
{
}
protected virtual void OnSessionChange (SessionChangeDescription changeDescription)
{
}
[ComVisible (false)]
[MonoTODO]
public void RequestAdditionalTime (int milliseconds)
{
throw new NotImplementedException ();
}
public void Stop ()
{
if (stop_event != null)
stop_event.Set ();
else
OnStop ();
}
private void SetStatus (ServiceControllerStatus status)
{
if (!hasStarted && status != ServiceControllerStatus.Stopped)
hasStarted = true;
if (NotifyStatus != null)
NotifyStatus (this, status);
}
#region Win32 implementation
private const int NO_ERROR = 0;
private const int ERROR_CALL_NOT_IMPLEMENTED = 120;
private const int SERVICE_NO_CHANGE = -1;
[Flags]
private enum SERVICE_CONTROL_ACCEPTED
{
SERVICE_ACCEPT_NONE = 0x0,
SERVICE_ACCEPT_STOP = 0x1,
SERVICE_ACCEPT_PAUSE_CONTINUE = 0x2,
SERVICE_ACCEPT_SHUTDOWN = 0x4,
SERVICE_ACCEPT_PARAMCHANGE = 0x8,
SERVICE_ACCEPT_NETBINDCHANGE = 0x10,
SERVICE_ACCEPT_HARDWAREPROFILECHANGE = 0x20,
SERVICE_ACCEPT_POWEREVENT = 0x40,
SERVICE_ACCEPT_SESSIONCHANGE = 0x80
}
private enum SERVICE_CONTROL_TYPE
{
SERVICE_CONTROL_STOP = 0x1,
SERVICE_CONTROL_PAUSE = 0x2,
SERVICE_CONTROL_CONTINUE = 0x3,
SERVICE_CONTROL_INTERROGATE = 0x4,
SERVICE_CONTROL_SHUTDOWN = 0x5,
SERVICE_CONTROL_PARAMCHANGE = 0x6,
SERVICE_CONTROL_NETBINDADD = 0x7,
SERVICE_CONTROL_NETBINDREMOVE = 0x8,
SERVICE_CONTROL_NETBINDENABLE = 0x9,
SERVICE_CONTROL_NETBINDDISABLE = 0xA,
SERVICE_CONTROL_DEVICEEVENT = 0xB,
SERVICE_CONTROL_HARDWAREPROFILECHANGE = 0xC,
SERVICE_CONTROL_POWEREVENT = 0xD,
SERVICE_CONTROL_SESSIONCHANGE = 0xE
}
private enum SERVICE_TYPE
{
SERVICE_KERNEL_DRIVER = 0x1,
SERVICE_FILE_SYSTEM_DRIVER = 0x2,
SERVICE_ADAPTER = 0x4,
SERVICE_RECOGNIZER_DRIVER = 0x8,
SERVICE_DRIVER = (SERVICE_KERNEL_DRIVER | SERVICE_FILE_SYSTEM_DRIVER | SERVICE_RECOGNIZER_DRIVER),
SERVICE_WIN32_OWN_PROCESS = 0x10,
SERVICE_WIN32_SHARE_PROCESS = 0x20,
SERVICE_INTERACTIVE_PROCESS = 0x100,
SERVICETYPE_NO_CHANGE = SERVICE_NO_CHANGE,
SERVICE_WIN32 = (SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS),
SERVICE_TYPE_ALL = (SERVICE_WIN32 | SERVICE_ADAPTER | SERVICE_DRIVER | SERVICE_INTERACTIVE_PROCESS)
}
[UnmanagedFunctionPointerAttribute (CallingConvention.StdCall)]
private delegate int LPHANDLER_FUNCTION_EX(int dwControl, int dwEventType, IntPtr lpEventData, IntPtr lpContext);
[UnmanagedFunctionPointerAttribute (CallingConvention.StdCall)]
private delegate void LPSERVICE_MAIN_FUNCTION(int dwArgc, IntPtr lpszArgv);
[StructLayout (LayoutKind.Sequential, Pack = 1)]
private struct SERVICE_STATUS
{
public int dwServiceType;
public int dwCurrentState;
public int dwControlsAccepted;
public int dwWin32ExitCode;
public int dwServiceSpecificErrorCode;
public int dwCheckPoint;
public int dwWaitHint;
}
[StructLayout (LayoutKind.Sequential, Pack = 1)]
private struct SERVICE_TABLE_ENTRY
{
[MarshalAs (UnmanagedType.LPWStr)]
public string lpServiceName;
public LPSERVICE_MAIN_FUNCTION lpServiceProc;
}
[DllImport ("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern IntPtr RegisterServiceCtrlHandlerEx (
string lpServiceName,
LPHANDLER_FUNCTION_EX lpHandlerProc,
IntPtr lpContext);
[DllImport ("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern bool SetServiceStatus (
IntPtr hServiceStatus,
[MarshalAs (UnmanagedType.LPStruct)] SERVICE_STATUS status);
[DllImport ("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern bool StartServiceCtrlDispatcher (
[MarshalAs (UnmanagedType.LPArray)] SERVICE_TABLE_ENTRY[] lpServiceTable);
private static void Win32NotifyStatus (ServiceBase service, ServiceControllerStatus status)
{
SERVICE_STATUS service_status = new SERVICE_STATUS ();
service_status.dwServiceType = share_process ? (int)SERVICE_TYPE.SERVICE_WIN32_SHARE_PROCESS : (int)SERVICE_TYPE.SERVICE_WIN32_OWN_PROCESS;
service_status.dwCurrentState = (int)status;
if (status != ServiceControllerStatus.StartPending)
{
if (service.can_stop)
service_status.dwControlsAccepted |= (int)SERVICE_CONTROL_ACCEPTED.SERVICE_ACCEPT_STOP;
if (service.can_pause_and_continue)
service_status.dwControlsAccepted |= (int)SERVICE_CONTROL_ACCEPTED.SERVICE_ACCEPT_PAUSE_CONTINUE;
if (service.can_handle_power_event)
service_status.dwControlsAccepted |= (int)SERVICE_CONTROL_ACCEPTED.SERVICE_ACCEPT_POWEREVENT;
if (service.can_handle_session_change_event)
service_status.dwControlsAccepted |= (int)SERVICE_CONTROL_ACCEPTED.SERVICE_ACCEPT_SESSIONCHANGE;
if (service.can_shutdown)
service_status.dwControlsAccepted |= (int)SERVICE_CONTROL_ACCEPTED.SERVICE_ACCEPT_SHUTDOWN;
}
service_status.dwWin32ExitCode = service.ExitCode;
service_status.dwWaitHint = 5000;
SetServiceStatus (service.service_handle, service_status);
}
private int Win32HandlerFn (int dwControl, int dwEventType, IntPtr lpEventData, IntPtr lpContext)
{
switch ((SERVICE_CONTROL_TYPE)dwControl)
{
case SERVICE_CONTROL_TYPE.SERVICE_CONTROL_STOP:
if (can_stop)
{
Stop ();
return NO_ERROR;
}
break;
case SERVICE_CONTROL_TYPE.SERVICE_CONTROL_PAUSE:
if (can_pause_and_continue)
{
SetStatus (ServiceControllerStatus.PausePending);
OnPause ();
SetStatus (ServiceControllerStatus.Paused);
return NO_ERROR;
}
break;
case SERVICE_CONTROL_TYPE.SERVICE_CONTROL_CONTINUE:
if (can_pause_and_continue)
{
SetStatus (ServiceControllerStatus.ContinuePending);
OnContinue ();
SetStatus (ServiceControllerStatus.Running);
return NO_ERROR;
}
break;
case SERVICE_CONTROL_TYPE.SERVICE_CONTROL_INTERROGATE:
return NO_ERROR;
case SERVICE_CONTROL_TYPE.SERVICE_CONTROL_SHUTDOWN:
if (can_shutdown)
{
OnShutdown ();
return NO_ERROR;
}
break;
default:
break;
}
return ERROR_CALL_NOT_IMPLEMENTED;
}
[ComVisible (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[MonoTODO ("This only makes sense on Windows")]
public void ServiceMainCallback (int argCount, IntPtr argPointer)
{
LPHANDLER_FUNCTION_EX handler = new LPHANDLER_FUNCTION_EX (Win32HandlerFn);
// handler needs to last until the service stops
service_handle = RegisterServiceCtrlHandlerEx (ServiceName ?? "", handler, IntPtr.Zero);
if (service_handle != IntPtr.Zero)
{
SetStatus (ServiceControllerStatus.StartPending);
stop_event = new ManualResetEvent (false);
string[] args = new string[argCount];
for (int i=0; i<argCount; i++)
{
IntPtr arg = Marshal.ReadIntPtr (argPointer, IntPtr.Size * i);
args[i] = Marshal.PtrToStringUni (arg);
}
OnStart (args);
SetStatus (ServiceControllerStatus.Running);
stop_event.WaitOne ();
SetStatus (ServiceControllerStatus.StopPending);
OnStop ();
SetStatus (ServiceControllerStatus.Stopped);
}
}
private static void Win32RunService (ServiceBase [] services)
{
SERVICE_TABLE_ENTRY[] table = new SERVICE_TABLE_ENTRY[services.Length + 1];
NotifyStatus = new NotifyStatusCallback (Win32NotifyStatus);
for (int i = 0; i<services.Length; i++)
{
table[i].lpServiceName = services[i].ServiceName ?? "";
table[i].lpServiceProc = new LPSERVICE_MAIN_FUNCTION (services[i].ServiceMainCallback);
}
// table[services.Length] is a NULL terminator
share_process = (services.Length > 1);
if (!StartServiceCtrlDispatcher (table))
throw new Win32Exception ();
}
#endregion Win32 implementation
public static void Run (ServiceBase service)
{
Run (new ServiceBase [] { service });
}
public static void Run (ServiceBase [] services)
{
int p = (int) Environment.OSVersion.Platform;
if (RunService != null)
RunService (services);
else if (!(p == 4 || p == 128 || p == 6))
Win32RunService (services);
else
Console.Error.WriteLine("Use mono-service to start service processes");
}
}
}

View File

@ -0,0 +1,420 @@
//
// System.ServiceProcess.ServiceController
//
// Authors:
// Marek Safar (marek.safar@seznam.cz)
// Gert Driesen (drieseng@users.sourceforge.net)
//
// (C) 2005, Marek Safar
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// TODO: check if there's more information to cache (eg. status)
// Start / Stop / ...
using System;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.InteropServices;
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 string _serviceName = string.Empty;
private string _machineName;
private string _displayName = string.Empty;
private readonly ServiceControllerImpl _impl;
private ServiceController [] _dependentServices;
private ServiceController [] _servicesDependedOn;
public ServiceController ()
{
_machineName = ".";
_name = string.Empty;
_impl = CreateServiceControllerImpl (this);
}
public ServiceController (string name) : this (name, ".")
{
}
public ServiceController (string name, string machineName)
{
if (name == null || name.Length == 0)
throw new ArgumentException (string.Format (CultureInfo.CurrentCulture,
"Invalid value {0} for parameter name.", name));
ValidateMachineName (machineName);
_machineName = machineName;
_name = name;
_impl = CreateServiceControllerImpl (this);
}
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[ServiceProcessDescription ("Whether this service recognizes the Pause and Continue commands.")]
public bool CanPauseAndContinue {
get {
ValidateServiceName (ServiceName);
return _impl.CanPauseAndContinue;
}
}
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[ServiceProcessDescription ("Whether this service can respond to a system shutdown.")]
public bool CanShutdown {
get
{
ValidateServiceName (ServiceName);
return _impl.CanShutdown;
}
}
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[ServiceProcessDescription ("Whether this service can be stopped.")]
public bool CanStop {
get
{
ValidateServiceName (ServiceName);
return _impl.CanStop;
}
}
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[ServiceProcessDescription ("The services that depend on this service in order to run.")]
public ServiceController [] DependentServices {
get
{
ValidateServiceName (ServiceName);
if (_dependentServices == null)
_dependentServices = _impl.DependentServices;
return _dependentServices;
}
}
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[ReadOnly (true)]
[ServiceProcessDescription ("The descriptive name of the service.")]
public string DisplayName {
get {
if (_displayName.Length == 0 && (_serviceName.Length > 0 || _name.Length > 0))
_displayName = _impl.DisplayName;
return _displayName;
}
set {
if (value == null)
throw new ArgumentNullException ("value");
if (_displayName == value)
return;
_displayName = value;
// if display name is modified, then we also need to force a
// new lookup of the corresponding service name
_serviceName = string.Empty;
// you'd expect the DependentServices and ServiceDependedOn cache
// to be cleared too, but the MS implementation doesn't do this
//
// categorized as by design:
// https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=201762
// release any handles and clear cache
Close ();
}
}
[Browsable (false)]
[DefaultValue (".")]
[RecommendedAsConfigurable (true)]
[ServiceProcessDescription ("The name of the machine on which this service resides.")]
public string MachineName {
get {
return _machineName;
}
set {
ValidateMachineName (value);
if (_machineName == value)
return;
_machineName = value;
// you'd expect the DependentServices and ServiceDependedOn cache
// to be cleared too, but the MS implementation doesn't do this
//
// categorized as by design:
// https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=201762
// release any handles and clear cache
Close ();
}
}
[DefaultValue ("")]
[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))
_serviceName = _impl.ServiceName;
return _serviceName;
}
set {
if (value == null)
throw new ArgumentNullException ("value");
if (_serviceName == value)
return;
ValidateServiceName (value);
_serviceName = value;
// if service name is modified, then we also need to force a
// new lookup of the corresponding display name
_displayName = string.Empty;
// you'd expect the DependentServices and ServiceDependedOn cache
// to be cleared too, but the MS implementation doesn't do this
//
// categorized as by design:
// https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=201762
// release any handles and clear cache
Close ();
}
}
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[ServiceProcessDescription ("Services that must be started in order for this one to start.")]
public ServiceController [] ServicesDependedOn {
get
{
ValidateServiceName (ServiceName);
if (_servicesDependedOn == null)
_servicesDependedOn = _impl.ServicesDependedOn;
return _servicesDependedOn;
}
}
[MonoTODO]
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public SafeHandle ServiceHandle
{
get {
throw new NotImplementedException ();
}
}
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[ServiceProcessDescription ("The type of this service.")]
public ServiceType ServiceType {
get
{
ValidateServiceName (ServiceName);
return _impl.ServiceType;
}
}
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[ServiceProcessDescription ("The status of the service, e.g., Running or Stopped.")]
public ServiceControllerStatus Status {
get
{
ValidateServiceName (ServiceName);
return _impl.Status;
}
}
public void Close ()
{
_impl.Close ();
}
public void Continue ()
{
ValidateServiceName (ServiceName);
_impl.Continue ();
}
protected override void Dispose (bool disposing)
{
_impl.Dispose (disposing);
base.Dispose (disposing);
}
public void ExecuteCommand (int command)
{
ValidateServiceName (ServiceName);
_impl.ExecuteCommand (command);
}
public static ServiceController[] GetDevices ()
{
return GetDevices (".");
}
public static ServiceController[] GetDevices (string machineName)
{
ValidateMachineName (machineName);
using (ServiceController sc = new ServiceController ("dummy", machineName)) {
ServiceControllerImpl impl = CreateServiceControllerImpl (sc);
return impl.GetDevices ();
}
}
public static ServiceController[] GetServices ()
{
return GetServices (".");
}
public static ServiceController[] GetServices (string machineName)
{
ValidateMachineName (machineName);
using (ServiceController sc = new ServiceController ("dummy", machineName)) {
ServiceControllerImpl impl = CreateServiceControllerImpl (sc);
return impl.GetServices ();
}
}
public void Pause ()
{
ValidateServiceName (ServiceName);
_impl.Pause ();
}
public void Refresh ()
{
// MSDN: this method also sets the ServicesDependedOn and
// DependentServices properties to a null reference
//
// I assume they wanted to say that the cache for these properties
// is cleared. Verified by unit tests.
_dependentServices = null;
_servicesDependedOn = null;
_impl.Refresh ();
}
public void Start ()
{
Start (new string [0]);
}
public void Start (string [] args)
{
ValidateServiceName (ServiceName);
_impl.Start (args);
}
public void Stop ()
{
ValidateServiceName (ServiceName);
_impl.Stop ();
}
public void WaitForStatus (ServiceControllerStatus desiredStatus)
{
WaitForStatus (desiredStatus, TimeSpan.MaxValue);
}
public void WaitForStatus (ServiceControllerStatus desiredStatus, TimeSpan timeout)
{
ValidateServiceName (ServiceName);
DateTime start = DateTime.Now;
while (Status != desiredStatus) {
if (timeout < (DateTime.Now - start))
throw new TimeoutException ("Time out has expired and the"
+ " operation has not been completed.");
Thread.Sleep (100);
// force refresh of status
Refresh ();
}
}
internal string Name {
get {
return _name;
}
set {
_name = value;
}
}
internal string InternalDisplayName {
get {
return _displayName;
}
set {
_displayName = value;
}
}
internal string InternalServiceName {
get {
return _serviceName;
}
set {
_serviceName = value;
}
}
private static void ValidateServiceName (string serviceName)
{
if (serviceName.Length == 0 || serviceName.Length > 80)
throw new ArgumentException (string.Format (CultureInfo.CurrentCulture,
"Service name {0} contains invalid characters, is empty"
+ " or is too long (max length = 80).", serviceName));
}
private static void ValidateMachineName (string machineName)
{
if (machineName == null || machineName.Length == 0)
throw new ArgumentException (string.Format (CultureInfo.CurrentCulture,
"MachineName value {0} is invalid.", machineName));
}
private static ServiceControllerImpl CreateServiceControllerImpl (ServiceController serviceController)
{
int p = (int) Environment.OSVersion.Platform;
if (p == 4 || p == 128 || p == 6){
return new UnixServiceController (serviceController);
} else {
return new Win32ServiceController (serviceController);
}
}
}
}

View File

@ -0,0 +1,104 @@
//
// System.ServiceProcess.ServiceControllerImpl
//
// Author:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.ServiceProcess
{
internal abstract class ServiceControllerImpl
{
protected ServiceControllerImpl (ServiceController serviceController)
{
_serviceController = serviceController;
}
protected ServiceController ServiceController {
get {
return _serviceController;
}
}
public abstract bool CanPauseAndContinue {
get;
}
public abstract bool CanShutdown {
get;
}
public abstract bool CanStop {
get;
}
public abstract ServiceController [] DependentServices {
get;
}
public abstract string DisplayName {
get;
}
public abstract string ServiceName {
get;
}
public abstract ServiceController [] ServicesDependedOn {
get;
}
public abstract ServiceType ServiceType {
get;
}
public abstract ServiceControllerStatus Status
{
get;
}
public abstract void Close ();
public abstract void Continue ();
public abstract void Dispose (bool disposing);
public abstract void ExecuteCommand (int command);
public abstract ServiceController [] GetDevices ();
public abstract ServiceController [] GetServices ();
public abstract void Pause ();
public abstract void Refresh ();
public abstract void Start (string [] args);
public abstract void Stop ();
private readonly ServiceController _serviceController;
}
}

View File

@ -0,0 +1,150 @@
//
// System.ServiceProcess.ServiceControllerPermission.cs
// (based on System.Diagnostics.EventLogPermission.cs)
//
// Authors:
// Jonathan Pryor (jonpryor@vt.edu)
// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2002 Jonathan Pryor
// (C) 2003 Andreas Nahr
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Security.Permissions;
namespace System.ServiceProcess {
[Serializable]
public sealed class ServiceControllerPermission : ResourcePermissionBase {
ServiceControllerPermissionEntryCollection innerCollection;
public ServiceControllerPermission ()
{
SetUp ();
}
public ServiceControllerPermission (ServiceControllerPermissionEntry[] permissionAccessEntries)
{
if (permissionAccessEntries == null)
throw new ArgumentNullException ("permissionAccessEntries");
SetUp ();
innerCollection = new ServiceControllerPermissionEntryCollection (this);
innerCollection.AddRange (permissionAccessEntries);
}
public ServiceControllerPermission (PermissionState state)
: base (state)
{
SetUp ();
}
public ServiceControllerPermission (ServiceControllerPermissionAccess permissionAccess, string machineName, string serviceName)
{
SetUp ();
ServiceControllerPermissionEntry scpe = new ServiceControllerPermissionEntry (permissionAccess, machineName, serviceName);
innerCollection = new ServiceControllerPermissionEntryCollection (this);
innerCollection.Add (scpe);
}
public ServiceControllerPermissionEntryCollection PermissionEntries {
get {
if (innerCollection == null) {
// must be here to work with XML deserialization
innerCollection = new ServiceControllerPermissionEntryCollection (this);
}
return innerCollection;
}
}
// private stuff
private void SetUp ()
{
TagNames = new string [2] { "Machine", "Service" };
PermissionAccessType = typeof (ServiceControllerPermissionAccess);
}
internal ResourcePermissionBaseEntry[] GetEntries ()
{
return base.GetPermissionEntries ();
}
internal void ClearEntries ()
{
base.Clear ();
}
internal void Add (object obj)
{
ServiceControllerPermissionEntry cspe = (obj as ServiceControllerPermissionEntry);
base.AddPermissionAccess (cspe.GetBaseEntry ());
}
internal void Remove (object obj)
{
ServiceControllerPermissionEntry cspe = (obj as ServiceControllerPermissionEntry);
base.RemovePermissionAccess (cspe.GetBaseEntry ());
}
// static helpers
private static char[] invalidChars = new char[] { '\t', '\n', '\v', '\f', '\r', ' ', '\\', '\x160' };
internal static void ValidateMachineName (string name)
{
// FIXME: maybe other checks are required (but not documented)
if ((name == null) || (name.Length == 0) || (name.IndexOfAny (invalidChars) != -1)) {
string msg = Locale.GetText ("Invalid machine name '{0}'.");
if (name == null)
name = "(null)";
msg = String.Format (msg, name);
throw new ArgumentException (msg, "MachineName");
}
}
#if NET_2_0
private static char[] invalidServiceNameChars = new char[] { '/', '\\' };
internal static void ValidateServiceName (string name)
{
if (name == null)
throw new ArgumentNullException ("ServiceName");
// FIXME: maybe other checks are required (but not documented)
if ((name.Length == 0) || (name.IndexOfAny (invalidServiceNameChars) != -1)) {
string msg = String.Format (Locale.GetText ("Invalid service name '{0}'."), name);
throw new ArgumentException (msg, "ServiceName");
}
}
#else
internal static void ValidateServiceName (string name)
{
if (name == null)
throw new ArgumentNullException ("ServiceName");
// FIXME: maybe other checks are required (but not documented)
}
#endif
}
}

View File

@ -0,0 +1,39 @@
//
// System.ServiceProcess.ServiceControllerPermissionAccess
//
// Author: Cesar Octavio Lopez Nataren (cesar@ciencias.unam.mx)
//
// (C) 2002, Cesar Octavio Lopez Nataren
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.ServiceProcess
{
[Flags]
public enum ServiceControllerPermissionAccess
{
None = 0,
Browse = 2,
Control = 6,
}
}

View File

@ -0,0 +1,88 @@
//
// System.ServiceProcess.ServiceControllerPermissionAttribute.cs
//
// Authors:
// Duncan Mak (duncan@ximian.com)
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003, Ximian Inc.
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Security;
using System.Security.Permissions;
namespace System.ServiceProcess {
[Serializable]
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class |
AttributeTargets.Struct | AttributeTargets.Constructor |
AttributeTargets.Method | AttributeTargets.Event,
AllowMultiple=true, Inherited=false)]
public class ServiceControllerPermissionAttribute : CodeAccessSecurityAttribute {
string machine_name;
string service_name;
ServiceControllerPermissionAccess permission_access;
public ServiceControllerPermissionAttribute (SecurityAction action)
: base (action)
{
machine_name = ResourcePermissionBase.Local;
service_name = ResourcePermissionBase.Any;
permission_access = ServiceControllerPermissionAccess.Browse;
}
public string MachineName {
get { return machine_name; }
set {
ServiceControllerPermission.ValidateMachineName (value);
machine_name = value;
}
}
public ServiceControllerPermissionAccess PermissionAccess {
get { return permission_access; }
set {
permission_access = value;
}
}
public string ServiceName {
get { return service_name; }
set {
if (value == null)
throw new ArgumentNullException ("ServiceName");
ServiceControllerPermission.ValidateServiceName (value);
service_name = value;
}
}
public override IPermission CreatePermission ()
{
if (base.Unrestricted)
return new ServiceControllerPermission (PermissionState.Unrestricted);
else
return new ServiceControllerPermission (PermissionState.None);
}
}
}

View File

@ -0,0 +1,80 @@
//
// System.ServiceProcess.ServiceControllerPermissionEntry.cs
//
// Authors:
// Duncan Mak (duncan@ximian.com)
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003, Ximian Inc.
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.ComponentModel;
using System.Security.Permissions;
namespace System.ServiceProcess {
[Serializable]
public class ServiceControllerPermissionEntry {
string machine_name;
string service_name;
ServiceControllerPermissionAccess permission_access;
public ServiceControllerPermissionEntry ()
{
machine_name = ResourcePermissionBase.Local;
service_name = ResourcePermissionBase.Any;
permission_access = ServiceControllerPermissionAccess.Browse;
}
public ServiceControllerPermissionEntry (ServiceControllerPermissionAccess permissionAccess,
string machineName, string serviceName)
{
ServiceControllerPermission.ValidateMachineName (machineName);
ServiceControllerPermission.ValidateServiceName (serviceName);
permission_access = permissionAccess;
machine_name = machineName;
service_name = serviceName;
}
public string MachineName {
get { return machine_name; }
}
public string ServiceName {
get { return service_name; }
}
public ServiceControllerPermissionAccess PermissionAccess {
get { return permission_access; }
}
// look at MSDN library ResourcePermissionBaseEntry sample for the "design"
internal ResourcePermissionBaseEntry GetBaseEntry ()
{
return new ResourcePermissionBaseEntry ((int) permission_access, new string[] { machine_name, service_name });
}
}
}

View File

@ -0,0 +1,125 @@
//
// System.ServiceProcess.ServiceControllerPermissionEntry.cs
//
// Authors:
// Duncan Mak (duncan@ximian.com)
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003, Ximian Inc.
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections;
using System.Security.Permissions;
namespace System.ServiceProcess {
[Serializable]
public class ServiceControllerPermissionEntryCollection : CollectionBase {
private ServiceControllerPermission owner;
internal ServiceControllerPermissionEntryCollection (ServiceControllerPermission owner)
{
this.owner = owner;
ResourcePermissionBaseEntry[] entries = owner.GetEntries ();
if (entries.Length > 0) {
foreach (ResourcePermissionBaseEntry entry in entries) {
ServiceControllerPermissionAccess scpa = (ServiceControllerPermissionAccess) entry.PermissionAccess;
string machine = entry.PermissionAccessPath [0];
string service = entry.PermissionAccessPath [1];
ServiceControllerPermissionEntry scpe = new ServiceControllerPermissionEntry (scpa, machine, service);
// we don't want to add them (again) to the base class
InnerList.Add (scpe);
}
}
}
public ServiceControllerPermissionEntry this [int index] {
get { return base.List [index] as ServiceControllerPermissionEntry; }
set { base.List [index] = value; }
}
public int Add (ServiceControllerPermissionEntry value)
{
return base.List.Add (value);
}
public void AddRange (ServiceControllerPermissionEntry [] value)
{
foreach (ServiceControllerPermissionEntry entry in value)
base.List.Add (entry);
}
public void AddRange (ServiceControllerPermissionEntryCollection value)
{
foreach (ServiceControllerPermissionEntry entry in value)
base.List.Add (entry);
}
public bool Contains (ServiceControllerPermissionEntry value)
{
return base.List.Contains (value);
}
public void CopyTo (ServiceControllerPermissionEntry [] array, int index)
{
base.List.CopyTo (array, index);
}
public int IndexOf (ServiceControllerPermissionEntry value)
{
return base.List.IndexOf (value);
}
public void Insert (int index, ServiceControllerPermissionEntry value)
{
base.List.Insert (index, value);
}
public void Remove (ServiceControllerPermissionEntry value)
{
base.List.Remove (value);
}
protected override void OnClear ()
{
owner.ClearEntries ();
}
protected override void OnInsert (int index, object value)
{
owner.Add (value);
}
protected override void OnRemove (int index, object value)
{
owner.Remove (value);
}
protected override void OnSet (int index, object oldValue, object newValue)
{
owner.Remove (oldValue);
owner.Add (newValue);
}
}
}

Some files were not shown because too many files have changed in this diff Show More