115 lines
2.9 KiB
C#
115 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace De.Lambertz.Essentials
|
|
{
|
|
/// <summary>
|
|
/// Singelton zur Überwachung aller registrierten Singeltons
|
|
/// </summary>
|
|
public class SingeltonManager
|
|
{
|
|
private static SingeltonManager me = null;
|
|
private List<ISingelton> singeltons = null;
|
|
private bool allowMore = true;
|
|
|
|
private SingeltonManager()
|
|
{
|
|
singeltons = new List<ISingelton>();
|
|
}
|
|
|
|
public static SingeltonManager GetInstance()
|
|
{
|
|
if (me == null)
|
|
{
|
|
me = new SingeltonManager();
|
|
}
|
|
return me;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Schaltet den SingeltonManager ab.
|
|
/// </summary>
|
|
public void KillMe()
|
|
{
|
|
me = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Trägt einen Singelton zur Überwachung ein
|
|
/// </summary>
|
|
/// <param name="sigelton"></param>
|
|
public void RegisterSingelton(ISingelton singelton)
|
|
{
|
|
if(allowMore)
|
|
{
|
|
singeltons.Add(singelton);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Trägt einen Singelton aus der Überwachung aus
|
|
/// </summary>
|
|
/// <param name="sigelton"></param>
|
|
public void UnRegisterSigelton(ISingelton singelton)
|
|
{
|
|
if (allowMore)
|
|
{
|
|
if (singeltons.Contains(singelton))
|
|
{
|
|
singeltons.Remove(singelton);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resetet alle registrierten Singeltons
|
|
/// </summary>
|
|
/// <param name="userName"></param>
|
|
public void ResetAll(string userName)
|
|
{
|
|
allowMore = false;
|
|
try
|
|
{
|
|
foreach (ISingelton s in singeltons)
|
|
{
|
|
try
|
|
{
|
|
s.ManagedReset(userName);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
//
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
//
|
|
}
|
|
allowMore = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Beendet alle registrierten Singeltons
|
|
/// </summary>
|
|
public void KillAll()
|
|
{
|
|
allowMore = false;
|
|
foreach (ISingelton s in singeltons)
|
|
{
|
|
try
|
|
{
|
|
s.ManagedKill();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
}
|
|
singeltons = new List<ISingelton>();
|
|
allowMore = true;
|
|
}
|
|
}
|
|
}
|