/// <summary> /// Import workspaces from the legacy file format. /// </summary> private static WmImportData ImportKwsFromFileLegacy(String path) { WmImportData data = new WmImportData(); Stream stream = null; try { stream = File.Open(path, FileMode.Open); SoapFormatter formatter = new SoapFormatter(); ArrayList list = (ArrayList)formatter.Deserialize(stream); // Folder list in the legacy format is ignored. No customer asked for this feature. foreach (Workspace.Credentials cred in list) data.KwsList.Add(new ExportedKws(cred.newCreds, "")); } finally { if (stream != null) stream.Close(); } return data; }
/// <summary> /// Process the workspaces and folders that are waiting to be imported, /// if required. This method does not throw. /// </summary> public void ProcessPendingKwsToImport() { // Set a new import data in case somebody adds data to it while // we're working with it. WmImportData data = ImportData; ImportData = new WmImportData(); // Create the folders specified. foreach (String folderPath in data.FolderList) UiBroker.Browser.CreateFolderFromPath(folderPath); // Remember how many workspaces we have to import. In particular, // if there are multiple workspaces to import, we do not prompt for // passwords. bool singleFlag = (data.KwsList.Count <= 1); // Import the workspaces specified using the appropriate handler. foreach (ExportedKws eKws in data.KwsList) { Workspace kws = GetKwsByExternalID(eKws.Creds.KasID, eKws.Creds.ExternalID); if (kws != null) ImportExistingKws(kws, eKws.Creds, singleFlag); else ImportNewKws(eKws.Creds, eKws.FolderPath, singleFlag); } }
/// <summary> /// Import the content of an Xml file created in the new Export format. /// </summary> private static WmImportData ImportKwsFromFile(String path) { WmImportData data = new WmImportData(); XmlDocument XmlFile = new XmlDocument(); XmlFile.Load(path); UInt32 version = UInt32.Parse(XmlFile.DocumentElement.GetAttribute("version")); if (version == 1) { foreach (XmlNode el in XmlFile.DocumentElement.ChildNodes) { XmlElement elem = el as XmlElement; if (elem == null) throw new Exception("Corrupted document (Node is not an XmlElement)."); if (elem.Name == "Kws") data.KwsList.Add(ExportedKws.FromXml(elem)); else if (elem.Name == "KwsBrowser") data.FolderList.AddRange(KwsBrowser.FromXml(elem)); else throw new Exception("Corrupted document (unknown node '" + elem.Name + "'."); } } else { throw new Exception("Unsupported KwsExport version ('" + version + "')."); } return data; }
/// <summary> /// Add the content of the other object specified to this object. /// </summary> public void Add(WmImportData other) { KwsList.AddRange(other.KwsList); FolderList.AddRange(other.FolderList); }