public void LoadBufers() { if (this._fileStorage.FileExists(this._filePath)) { try { using (var fileReader = BufersFileStorage.GetMultiLanguageFileReader(this._filePath)) { var bufers = this._fileFormatter.Parse(fileReader.ReadToEnd()); if (bufers.Any()) { this.BufersLoaded?.Invoke(this, new BufersLoadedEventArgs(bufers)); } } } catch (IOException exc) { throw new ClipboardMessageException(Resource.LoadFileErrorPrefix + $" {this._filePath}:\n\n {exc.Message}", exc) { Title = Resource.LoadFileErrorTitle }; } catch (JsonReaderException exc) { throw new ClipboardMessageException(exc.Message, exc); } } }
public void SaveBufers(IEnumerable <BuferItem> buferItems) { try { if (!this._fileStorage.FileExists(this._filePath)) { this._fileStorage.CreateFile(this._filePath); } List <BuferItem> bufers; using (var fileReader = BufersFileStorage.GetMultiLanguageFileReader(this._filePath)) { bufers = this._fileFormatter.Parse(fileReader.ReadToEnd()).ToList(); } foreach (var buferItem in buferItems) { bufers.Add(buferItem); } using (var fileWriter = BufersFileStorage.GetMultiLanguageFileWriter(this._filePath)) { fileWriter.Write(this._fileFormatter.ToString(bufers)); } } catch (IOException exc) { throw new ClipboardMessageException(Resource.LoadFileErrorPrefix + $" {this._filePath}:\n\n {exc.Message}", exc) { Title = Resource.LoadFileErrorTitle }; } catch (JsonReaderException exc) { throw new ClipboardMessageException(exc.Message, exc); } }