private void LoadFISLibrary(FileInfo filePath, FISLibraryItemTypes eType) { // System FIS Library contains relative paths and the directory storing the manifest XML is needed DirectoryInfo rootDir = null; if (eType == FISLibraryItemTypes.System) { rootDir = filePath.Directory; } XmlDocument xmlDoc = new XmlDocument(); try { if (!filePath.Exists) { if (eType == FISLibraryItemTypes.System) { throw new Exception("FIS library XML file missing."); } else { return; } } xmlDoc.Load(filePath.FullName); foreach (XmlNode nodItem in xmlDoc.DocumentElement.SelectNodes("FISLibraryItem")) { try { FISLibraryItem item = new FISLibraryItem(nodItem, eType, rootDir); FISItems.Add(item); } catch (Exception ex) { Debug.WriteLine(ex.Message); Console.WriteLine(string.Format("Error reading {0} FIS library item from file {1}", eType.ToString(), filePath)); } } } catch (Exception ex) { ex.Data["FIS Library File Path"] = filePath.FullName; ex.Data["FIS Library Type"] = eType.ToString(); throw; } }
public FISLibraryItem Copy(string fileName, DirectoryInfo destination) { // Should already exist because it was used for the error surface destination.Create(); FileInfo fisPath = naru.os.File.GetNewSafeName(destination.FullName, fileName, FilePath.Extension); FileInfo xmlPath = naru.os.File.GetNewSafeName(destination.FullName, Path.GetFileNameWithoutExtension(fisPath.FullName), FilePath.Extension + ".xml"); // Copy the FIS rule file FilePath.CopyTo(fisPath.FullName); // Generate an XML file adjacent to the FIS rule file. XmlNode nodParent = FISLibrary.CreateFISLibraryXML(); Serialize(nodParent); nodParent.OwnerDocument.Save(xmlPath.FullName); // Reload the FIS library item (lazy way to clone) using the project file path XmlNode nodItem = nodParent.SelectSingleNode("FISLibraryItem"); FISLibraryItem projectFIS = new FISLibraryItem(nodItem, fisPath); return(projectFIS); }