/*******************************************************************************/ public virtual void ReleaseListeners(object view) { if (Loaded != null) { foreach (Delegate d in Loaded.GetInvocationList()) { if (view == null || d.Target == view) { Loaded -= (LoadFinishedEventHandler)d; } } } if (Changed != null) { foreach (Delegate d in Changed.GetInvocationList()) { if (view == null || d.Target == view) { Changed -= (ChangedEventHandler)d; } } } if (Persisted != null) { foreach (Delegate d in Persisted.GetInvocationList()) { if (view == null || d.Target == view) { Persisted -= (PersistFinishedEventHandler)d; } } } }
public void SubscribeToLoadedEvent(EventHandler loaded) { if (Loaded != null) { Delegate[] clientList = Loaded.GetInvocationList(); foreach (var d in clientList) { Loaded -= (d as EventHandler); } } Loaded += loaded; }
/*******************************************************************************/ private void DbThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { HraState = States.Ready; LoadCompleted(sender, e); if (Loaded != null) { #if (CHATTY_DEBUG) string msg2 = "*** HRA OBJECT Load Finished Firing on : " + this.ToString() + System.Environment.NewLine; foreach (Delegate d in Loaded.GetInvocationList()) { msg2 += "FOR: " + d.Target + Environment.NewLine; } Logger.Instance.DebugToLog(msg2); #endif Loaded(this, e); } }
public void AddHandlersWithLoad(ChangedEventHandler changedEventHandler, LoadFinishedEventHandler loadFinishedEventHandler, PersistFinishedEventHandler persistFinishedEventHandler) { #if (CHATTY_DEBUG) string msg = "*** HRA OBJECT AddHandlersWithLoad on : " + this.ToString() + System.Environment.NewLine; if (changedEventHandler != null) { msg += "By: " + changedEventHandler.Target.ToString(); } else if (loadFinishedEventHandler != null) { msg += "By: " + loadFinishedEventHandler.Target.ToString(); } else if (persistFinishedEventHandler != null) { msg += "By: " + persistFinishedEventHandler.Target.ToString(); } Logger.Instance.DebugToLog(msg); #endif if (changedEventHandler != null) { if (Changed == null) { Changed += changedEventHandler; } else { bool ok = true; foreach (Delegate d in Changed.GetInvocationList()) { if (d.Target == changedEventHandler.Target) { ok = false; } } if (ok) { Changed += changedEventHandler; } } } if (loadFinishedEventHandler != null) { if (Loaded == null) { Loaded += loadFinishedEventHandler; } else { bool ok = true; foreach (Delegate d in Loaded.GetInvocationList()) { if (d.Target == loadFinishedEventHandler.Target) { ok = false; } } if (ok) { Loaded += loadFinishedEventHandler; } } } if (persistFinishedEventHandler != null) { if (Persisted == null) { Persisted += persistFinishedEventHandler; } else { bool ok = true; foreach (Delegate d in Persisted.GetInvocationList()) { if (d.Target == persistFinishedEventHandler.Target) { ok = false; } } if (ok) { Persisted += persistFinishedEventHandler; } } } switch (HraState) { case States.Null: LoadObject(); break; case States.Loading: break; case States.Ready: if (loadFinishedEventHandler != null) { RunWorkerCompletedEventArgs dummy = new RunWorkerCompletedEventArgs(this, null, false); #if (CHATTY_DEBUG) string msg2 = "*** HRA OBJECT loadFinishedEventHandler Firing on : " + this.ToString() + System.Environment.NewLine; msg2 += "FOR " + loadFinishedEventHandler.Target.ToString(); Logger.Instance.DebugToLog(msg2); #endif loadFinishedEventHandler.Invoke(null, dummy); } break; } }