///////////////////////////////////////////// // Interface methods for external parties. // ///////////////////////////////////////////// /// <summary> /// This method must be called by each application when it has started. /// </summary> public void OnAppStarted() { // The applications are no longer starting. if (m_cd.AppStatus != KwsAppStatus.Starting) { return; } // Not all applications have started. foreach (KwsApp app in m_kws.AppTree.Values) { if (app.AppStatus != KwsAppStatus.Started) { return; } } WmSm.LockNotif(); // All applications are started. m_cd.AppStatus = KwsAppStatus.Started; // Notify the listeners. WmSm.QueueNotif(new KwsSmNotifApp(m_kws, m_cd.AppStatus)); // Let the state machine sort it out. RequestRun("Applications started"); WmSm.UnlockNotif(); }
/// <summary> /// Called when the KCD connection status has changed. This method is /// only called by the WM state machine. /// </summary> public void HandleKcdConnStatusChange(KcdConnStatus status, Exception ex) { // Update our login state. if (status == KcdConnStatus.Disconnecting || status == KcdConnStatus.Disconnected) { UpdateStateOnLogout(ex); } // Notify the listeners. WmSm.QueueNotif(new KwsSmNotifKcdConn(m_kws, status, ex)); // Let the state machine sort it out. RequestRun("KCD connection status change"); }
/// <summary> /// Update KcdEventUpToDateFlag, EAnpFreshnessID and handle notifications. /// </summary> private void UpdateKcdEventUpToDateState() { bool newValue = AreKcdEventUpToDate(); if (m_ks.KcdEventUpToDateFlag == newValue) { return; } m_ks.KcdEventUpToDateFlag = newValue; if (newValue) { WmSm.QueueNotif(new KwsSmNotifKcdEventUpToDate(m_kws)); } }
/// <summary> /// Switch the current task to the task specified. Don't call this /// outside RequestSwitchTask() unless you know what you are doing. /// The state machine will run ASAP to handle the new state. /// </summary> private void SwitchTask(KwsTask task, Exception ex) { // The order of the calls is important here. WmSm.LockNotif(); Debug.Assert(m_taskSwitchFlag == false); m_taskSwitchFlag = true; m_cd.CurrentTask = task; StopAppIfNeeded(ex); DisconnectFromKcdIfNeeded(); LogoutIfNeeded(); StopRebuildIfNeeded(); UpdateKcdEventUpToDateState(); m_kws.OnStateChange(WmStateChange.Transient); RequestRun("task switch to " + task); m_taskSwitchFlag = false; WmSm.QueueNotif(new KwsSmNotifTaskSwitch(m_kws, task, ex)); WmSm.UnlockNotif(); }
/// <summary> /// Called when the workspace becomes logged in. /// </summary> public void HandleLoginSuccess() { WmSm.LockNotif(); Debug.Assert(m_ks.LoginStatus == KwsLoginStatus.LoggingIn); // We're now logged in. m_ks.LoginStatus = KwsLoginStatus.LoggedIn; // Update the event up to date state. UpdateKcdEventUpToDateState(); // Notify the listeners. WmSm.QueueNotif(new KwsSmNotifKcdLogin(m_kws, m_ks.LoginStatus, null)); // Let the state machine sort it out. RequestRun("Workspace login success"); WmSm.UnlockNotif(); }
/// <summary> /// Called when the workspace logs out normally, the login fails or /// the connection to the KCD is lost. /// </summary> private void UpdateStateOnLogout(Exception ex) { if (m_ks.LoginStatus == KwsLoginStatus.LoggedOut) { return; } // Set the last exception. m_kws.Cd.LastException = ex; m_kws.OnStateChange(WmStateChange.Transient); // Update the login status. m_kws.KcdLoginHandler.ResetOnLogout(); // Cancel all the pending KCD queries that depend on the login // state. m_kws.Kcd.CancelKwsKcdQuery(m_kws); // Update the event up to date state. UpdateKcdEventUpToDateState(); // Notify the listeners. WmSm.QueueNotif(new KwsSmNotifKcdLogin(m_kws, m_ks.LoginStatus, ex)); }