?? servicesubject.cs
字號:
using System;
using System.Collections;
using System.Diagnostics;
using System.ServiceProcess;
namespace kae.ServiceStatePublisher
{
/// <summary>
/// ServiceSubject is the publisher establishing the client contract or interface. ServiceSubject sends a notification to its observers, or subscribers, when its state changes.
/// </summary>
/// <remarks>
/// ServiceSubject is part of the Observer Pattern implementation for the ServiceStatePublisher library. The .NET Framework supports this pattern through its built-in delegate and event mechanism.
/// For more information on the state pattern see <i>Design Patterns: Elements of Reusable Code</i> by Gamma, et al.
/// </remarks>
public class ServiceSubject : ServiceContext
{
public event EventHandler ServerChanged;
public event EventHandler ServiceChanged;
public event EventHandler StateChanged;
private string _serverName;
public ServiceSubject() : base() { }
public ServiceSubject( ServiceController service)
{
Controller = service;
}
public virtual string ServerName
{
get { return _serverName; }
set
{
_serverName = value;
OnServerChanged( EventArgs.Empty);
if (Controller != null && _serverName != Controller.MachineName)
Controller = null;
}
}
public override ServiceController Controller
{
get { return _controller; }
set
{
_controller = value;
_state = QueryServiceState();
OnServiceChanged( EventArgs.Empty);
}
}
public override ServiceState State
{
get { return _state; }
set
{
_state = value;
OnStateChanged( EventArgs.Empty);
}
}
public virtual void RefreshServices()
{
OnServerChanged( EventArgs.Empty);
}
protected virtual void OnServerChanged( System.EventArgs e)
{
if (ServerChanged != null)
ServerChanged( this, e);
}
protected virtual void OnServiceChanged( System.EventArgs e)
{
if (ServiceChanged != null)
ServiceChanged( this, e);
}
protected virtual void OnStateChanged( System.EventArgs e)
{
if (StateChanged != null)
StateChanged( this, e);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -