public bool TryLoad(out DriverPresentationsDto driverPresentationsDto) { string fullPathName = Path.Combine(_storedDirectoryPath, FileName); try { using (TextReader file = File.OpenText(fullPathName)) { XmlReader reader = XmlReader.Create(file, new XmlReaderSettings() { CheckCharacters = false }); driverPresentationsDto = (DriverPresentationsDto)_xmlSerializer.Deserialize(reader); } return(driverPresentationsDto != null); } catch (Exception) { if (File.Exists(fullPathName)) { File.Delete(fullPathName); } driverPresentationsDto = null; return(false); } }
private DriverPresentationsDto LoadDriverPresentations() { if (!_driverPresentationsLoader.TryLoad(out _driverPresentationsDto)) { _driverPresentationsDto = new DriverPresentationsDto(); } return(_driverPresentationsDto); }
public void Save(DriverPresentationsDto driverPresentationsDto) { try { string fullPathName = Path.Combine(_storedDirectoryPath, FileName); Directory.CreateDirectory(_storedDirectoryPath); using (FileStream file = File.Exists(fullPathName) ? File.Open(fullPathName, FileMode.Truncate) : File.Create(fullPathName)) { _xmlSerializer.Serialize(file, driverPresentationsDto); } } catch (Exception ex) { _logger.Error(ex, "Error while saving driver presentation"); } }