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
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System.Globalization;
37 using System.Diagnostics;
39 namespace System.ServiceProcess
41 public class ServiceBase : System.ComponentModel.Component
43 internal delegate void RunServiceCallback (ServiceBase [] services);
45 // This member is used for interoperation with mono-service
46 internal static RunServiceCallback RunService = null;
48 public ServiceBase() { }
50 public const int MaxNameLength = 80;
52 bool hasStarted = false;
55 bool can_handle_power_event = false;
56 bool can_pause_and_continue = false;
57 bool can_shutdown = false;
59 EventLog event_log = null;
64 get { return auto_log; }
66 set { auto_log = value; }
69 public bool CanHandlePowerEvent {
71 get { return can_handle_power_event; }
75 throw new InvalidOperationException (
76 Locale.GetText ("Cannot modify this property " +
77 "after the service has started."));
79 can_handle_power_event = value;
83 public bool CanPauseAndContinue {
85 get { return can_pause_and_continue; }
89 throw new InvalidOperationException (
90 Locale.GetText ("Cannot modify this property " +
91 "after the service has started."));
93 can_pause_and_continue = value;
97 public bool CanShutdown {
99 get { return can_shutdown; }
103 throw new InvalidOperationException (
104 Locale.GetText ("Cannot modify this property " +
105 "after the service has started."));
107 can_shutdown = value;
111 public bool CanStop {
113 get { return can_stop; }
117 throw new InvalidOperationException (
118 Locale.GetText ("Cannot modify this property " +
119 "after the service has started."));
125 public virtual EventLog EventLog {
127 if (event_log == null)
128 event_log = new EventLog ("Application", ".", service_name);
133 public string ServiceName {
135 get { return service_name; }
139 throw new InvalidOperationException (
140 Locale.GetText ("Cannot modify this property " +
141 "after the service has started."));
143 service_name = value;
147 protected override void Dispose (bool disposing) { }
149 protected virtual void OnStart (string [] args) { }
151 protected virtual void OnStop () { }
153 protected virtual void OnContinue () { }
155 protected virtual void OnCustomCommand () { }
157 protected virtual void OnPause () { }
159 protected virtual void OnPowerEvent () { }
161 protected virtual void OnShutdown () { }
163 public static void Run (ServiceBase service)
165 Run (new ServiceBase [] {service});
168 public static void Run (ServiceBase [] servicesToRun)
170 if (RunService != null)
171 RunService (servicesToRun);