/// <summary> /// Loads a File object designated by its Guid from its definition file /// </summary> /// <param name="g">The guid of the file to load</param> /// <param name="di">The directory where to read the definition file</param> /// <returns>The File designated by g</returns> public static File SelectByGuid(Guid g, DirectoryInfo di) { if (g.Equals(Guid.Empty)) { throw new ArgumentException(Properties.Resources.BLExceptionEmptyFileGuid, "g"); } if (!di.Exists) { throw new ArgumentException(Properties.Resources.BLExceptionMissingDirectory, "di"); } FileInfo[] arrFileInfo = di.GetFiles(FileBroker.GetDefinitionFile(g)); if ((arrFileInfo == null) || (arrFileInfo.Length < 1)) { throw new ArgumentException(Properties.Resources.BLExceptionMissingDefinition, "g"); } File objFileRet; using (XmlReader objXmlReader = XmlReader.Create(Path.Combine(di.FullName, FileBroker.GetDefinitionFile(g)))) { XmlSerializer objXmlSerializer = new XmlSerializer(typeof(File)); objFileRet = objXmlSerializer.Deserialize(objXmlReader) as File; } return(objFileRet); }
/// <summary> /// Creates a definition file for a File object /// </summary> /// <param name="f">The File object to persist</param> /// <param name="di">The directory where to write the definition file</param> public static void Insert(File f, DirectoryInfo di) { if (f == null) { throw new ArgumentNullException("f", Properties.Resources.BLExceptionNullFile); } if (!di.Exists) { throw new ArgumentException(Properties.Resources.BLExceptionMissingDirectory, "di"); } if (f.IsSaveRequired) { FileInfo[] arrFileInfo = di.GetFiles(FileBroker.GetDefinitionFile(f.Guid)); if ((arrFileInfo != null) && (arrFileInfo.Length > 0)) { throw new ArgumentException(Properties.Resources.BLExceptionDefinitionExists, "f"); } using (XmlWriter objXmlWriter = XmlWriter.Create(Path.Combine(di.FullName, FileBroker.GetDefinitionFile(f.Guid)))) { XmlSerializer objXmlSerializer = new XmlSerializer(typeof(File)); objXmlSerializer.Serialize(objXmlWriter, f); } f.SaveCompleted(); } }