2 // System.ServiceProcess.ServiceBase.cs
5 // Cesar Octavio Lopez Nataren (cesar@ciencias.unam.mx)
6 // Duncan Mak (duncan@ximian.com)
7 // Joerg Rosenkranz (joergr@voelcker.com)
9 // (C) 2003, Ximian Inc and Cesar Octavio Lopez Nataren.
10 // (C) 2005, Voelcker Informatik AG
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.ComponentModel;
35 using System.Globalization;
36 using System.Diagnostics;
38 namespace System.ServiceProcess
41 [Designer ("Microsoft.VisualStudio.Install.UserNTServiceDesigner, " + Consts.AssemblyMicrosoft_VisualStudio, "System.ComponentModel.Design.IRootDesigner")]
43 [InstallerType (typeof (ServiceProcessInstaller))]
44 public class ServiceBase : System.ComponentModel.Component
46 internal delegate void RunServiceCallback (ServiceBase [] services);
48 // This member is used for interoperation with mono-service
49 internal static RunServiceCallback RunService = null;
51 public const int MaxNameLength = 80;
55 bool can_handle_power_event;
56 bool can_pause_and_continue;
67 [ServiceProcessDescription ("Whether the service should automatically write to the event log on common events such as Install and Start.")]
69 get { return auto_log; }
70 set { auto_log = value; }
73 [DefaultValue (false)]
74 public bool CanHandlePowerEvent {
75 get { return can_handle_power_event; }
78 throw new InvalidOperationException (
79 Locale.GetText ("Cannot modify this property " +
80 "after the service has started."));
82 can_handle_power_event = value;
86 [DefaultValue (false)]
87 public bool CanPauseAndContinue {
88 get { return can_pause_and_continue; }
91 throw new InvalidOperationException (
92 Locale.GetText ("Cannot modify this property " +
93 "after the service has started."));
95 can_pause_and_continue = value;
99 [DefaultValue (false)]
100 public bool CanShutdown {
101 get { return can_shutdown; }
104 throw new InvalidOperationException (
105 Locale.GetText ("Cannot modify this property " +
106 "after the service has started."));
108 can_shutdown = value;
112 [DefaultValue (true)]
113 public bool CanStop {
114 get { return can_stop; }
117 throw new InvalidOperationException (
118 Locale.GetText ("Cannot modify this property " +
119 "after the service has started."));
126 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
127 public virtual EventLog EventLog {
129 if (event_log == null)
130 event_log = new EventLog ("Application", ".", service_name);
135 [ServiceProcessDescription ("The name by which the service is identified to the system.")]
136 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
137 public string ServiceName {
138 get { return service_name; }
141 throw new InvalidOperationException (
142 Locale.GetText ("Cannot modify this property " +
143 "after the service has started."));
145 service_name = value;
149 protected override void Dispose (bool disposing)
153 protected virtual void OnStart (string [] args)
157 protected virtual void OnStop ()
161 protected virtual void OnContinue ()
165 protected virtual void OnCustomCommand (int command)
169 protected virtual void OnPause ()
173 protected virtual bool OnPowerEvent (PowerBroadcastStatus powerStatus)
178 protected virtual void OnShutdown ()
182 public static void Run (ServiceBase service)
184 Run (new ServiceBase [] { service });
187 public static void Run (ServiceBase [] servicesToRun)
189 if (RunService != null)
190 RunService (servicesToRun);