/// <summary> /// Import a workspace list from the XML document specified. /// </summary> public static void ImportKwsListFromXmlDoc(XmlDocument doc) { UInt32 version = UInt32.Parse(doc.DocumentElement.GetAttribute("version")); if (version > 1) { throw new Exception("unsupported KwsExport version ('" + version + "')"); } // Import all nodes. foreach (XmlNode node in doc.DocumentElement.ChildNodes) { XmlElement el = node as XmlElement; if (el == null) { throw new Exception("Corrupted document (Node is not an XmlElement)."); } else if (el.Name == "Kws") { ImportKws(XmlToKwsCredentials(el)); } else if (el.Name == "KwsBrowser") { ImportFolderList(XmlToFolderList(el)); } else { throw new Exception("Corrupted document (unknown node '" + el.Name + "'."); } } // Serialize the WM since we may have created workspaces. Wm.Serialize(); }
/// <summary> /// Complete the operation if we are ready to. /// </summary> private void CompleteIfNeeded() { if (DoneFlag || m_step != OpStep.LoggingIn || Kws.Cd.KcdState.LoginStatus != KwsLoginStatus.LoggedIn || Kws.Cd.MainStatus != KwsMainStatus.NotYetSpawned || Kws.Cd.CurrentTask != KwsTask.Spawn) { return; } // Update the main status of the workspace. Kws.Cd.MainStatus = KwsMainStatus.Good; Kws.OnStateChange(WmStateChange.Permanent); // Ask the state machine to work online. Kws.Sm.RequestTaskSwitch(KwsTask.WorkOnline); // Serialize the KWM so we don't lose the workspace if the KWM // crashes. Wm.Serialize(); // We're done. Complete(); }
/// <summary> /// This method is called when the workspace manager has stopped. /// The WM is serialized and the application is told to quit. /// </summary> private static void HandlePostStop() { KLogging.Log("WmSm: " + KwmStrings.Kwm + " has stopped."); Wm.MainStatus = WmMainStatus.Stopped; Wm.Serialize(); Program.RequestAppExit(); }
/// <summary> /// Serialize the WM if it is time to do so. /// </summary> private static void SerializeWmIfNeeded() { DateTime now = DateTime.Now; if (m_lastSerializationDate.AddSeconds(WmSerializationDelay) < now) { m_lastSerializationDate = now; Wm.Serialize(); } ScheduleRun("WM serialization", m_lastSerializationDate.AddSeconds(WmSerializationDelay)); }
/// <summary> /// Enter the main mode of the KWM. Return true if the application /// must continue. /// </summary> private static bool EnterMainMode() { // Perform early linking. Wm.LocalDbBroker.Relink(Wm.LocalDb); // FIXME. #if true // Open a temporary console. ConsoleWindow foo = new ConsoleWindow(); foo.Show(); foo.OnConsoleClosing += delegate(Object sender, EventArgs args) { WmSm.RequestStop(); }; // Create an empty database. Wm.LocalDb.DeleteDb(); Wm.LocalDb.OpenOrCreateDb(KwmPath.GetKwmDbPath()); Wm.LocalDbBroker.InitDb(); WmDeserializer ds = new WmDeserializer(); ds.Deserialize(); Debug.Assert(ds.Ex == null); #else // Open or create the database. Wm.LocalDb.OpenOrCreateDb(KwmPath.GetKwmDbPath()); Wm.LocalDbBroker.InitDb(); // Try to deserialize. WmDeserializer ds = new WmDeserializer(); ds.Deserialize(); // The deserialization failed. if (ds.Ex != null) { // If the user doesn't want to recover, bail out. if (!TellUserAboutDsrFailure()) { return(false); } // Backup, delete and recreate a database. BackupDb(); Wm.LocalDb.DeleteDb(); Wm.LocalDb.OpenOrCreateDb(KwmPath.GetKwmDbPath()); Wm.LocalDbBroker.InitDb(); // Retry to deserialize. ds = new WmDeserializer(); ds.Deserialize(); if (ds.Ex != null) { throw ds.Ex; } // Set the next internal workspace ID to a high value based on // the date to avoid conflicts with old KFS directories. ds.WmCd.NextKwsInternalID = (UInt64)(DateTime.Now - new DateTime(2010, 1, 1)).TotalSeconds; } #endif // Relink the workspace manager object graphs. Wm.Relink(ds); // Open the lingering database transaction. Wm.LocalDb.BeginTransaction(); // Serialize the WM state that has changed. Wm.Serialize(); // Export the workspaces, then exit. if (ExportKwsPath != "") { WmKwsImportExport.ExportKws(ExportKwsPath, 0); return(false); } // Set the handle to the message window. SetKwmHandle(MsgWindow.Handle); // Pass the hand to the WM state machine. WmSm.RequestStart(); return(true); }