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