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;
37 using System.Runtime.InteropServices;
39 namespace System.ServiceProcess
42 [Designer ("Microsoft.VisualStudio.Install.UserNTServiceDesigner, " + Consts.AssemblyMicrosoft_VisualStudio, "System.ComponentModel.Design.IRootDesigner")]
44 [InstallerType (typeof (ServiceProcessInstaller))]
45 public class ServiceBase : Component
47 internal delegate void RunServiceCallback (ServiceBase [] services);
49 // This member is used for interoperation with mono-service
50 internal static RunServiceCallback RunService;
52 public const int MaxNameLength = 80;
56 bool can_handle_power_event;
57 bool can_pause_and_continue;
63 bool can_handle_session_change_event;
71 [ServiceProcessDescription ("Whether the service should automatically write to the event log on common events such as Install and Start.")]
73 get { return auto_log; }
74 set { auto_log = value; }
77 [DefaultValue (false)]
78 public bool CanHandlePowerEvent {
79 get { return can_handle_power_event; }
82 throw new InvalidOperationException (
83 Locale.GetText ("Cannot modify this property " +
84 "after the service has started."));
86 can_handle_power_event = value;
91 [DefaultValue (false)]
94 public bool CanHandleSessionChangeEvent {
95 get { return can_handle_session_change_event; }
98 throw new InvalidOperationException (
99 Locale.GetText ("Cannot modify this property " +
100 "after the service has started."));
102 can_handle_session_change_event = value;
107 [DefaultValue (false)]
108 public bool CanPauseAndContinue {
109 get { return can_pause_and_continue; }
112 throw new InvalidOperationException (
113 Locale.GetText ("Cannot modify this property " +
114 "after the service has started."));
116 can_pause_and_continue = value;
120 [DefaultValue (false)]
121 public bool CanShutdown {
122 get { return can_shutdown; }
125 throw new InvalidOperationException (
126 Locale.GetText ("Cannot modify this property " +
127 "after the service has started."));
129 can_shutdown = value;
133 [DefaultValue (true)]
134 public bool CanStop {
135 get { return can_stop; }
138 throw new InvalidOperationException (
139 Locale.GetText ("Cannot modify this property " +
140 "after the service has started."));
147 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
148 public virtual EventLog EventLog {
150 if (event_log == null)
151 event_log = new EventLog ("Application", ".", service_name);
159 public int ExitCode {
160 get { throw new NotImplementedException (); }
161 set { throw new NotImplementedException (); }
165 [EditorBrowsable (EditorBrowsableState.Advanced)]
166 protected IntPtr ServiceHandle {
167 get { throw new NotImplementedException (); }
171 [ServiceProcessDescription ("The name by which the service is identified to the system.")]
172 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
173 public string ServiceName {
174 get { return service_name; }
177 throw new InvalidOperationException (
178 Locale.GetText ("Cannot modify this property " +
179 "after the service has started."));
181 service_name = value;
185 protected override void Dispose (bool disposing)
189 protected virtual void OnStart (string [] args)
193 protected virtual void OnStop ()
197 protected virtual void OnContinue ()
201 protected virtual void OnCustomCommand (int command)
205 protected virtual void OnPause ()
209 protected virtual bool OnPowerEvent (PowerBroadcastStatus powerStatus)
214 protected virtual void OnShutdown ()
219 protected virtual void OnSessionChange (SessionChangeDescription changeDescription)
225 public void RequestAdditionalTime (int milliseconds)
227 throw new NotImplementedException ();
231 [EditorBrowsable (EditorBrowsableState.Never)]
233 public void ServiceMainCallback (int argCount, IntPtr argPointer)
235 throw new NotImplementedException ();
244 public static void Run (ServiceBase service)
246 Run (new ServiceBase [] { service });
249 public static void Run (ServiceBase [] services)
251 if (RunService != null)
252 RunService (services);