Vereinsmeisterschaften  22aa7800eae54b428d40e835886cefe1fdefdfdf
This is a software that can be used to manage the internal competition of the swimming club Illertissen called "Vereinsmeisterschaften".
Loading...
Searching...
No Matches
PersistAndRestoreService.cs
1using System.Collections;
2using System.IO;
3
4using Microsoft.Extensions.Options;
5
9
11
16{
17 private readonly IFileService _fileService;
18 private readonly AppConfig _appConfig;
19 private readonly string _localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
20
26 public PersistAndRestoreService(IFileService fileService, IOptions<AppConfig> appConfig)
27 {
28 _fileService = fileService;
29 _appConfig = appConfig.Value;
30 }
31
33 public void PersistData()
34 {
35 if (App.Current.Properties != null)
36 {
37 var folderPath = Path.Combine(_localAppData, _appConfig.ConfigurationsFolder);
38 var fileName = _appConfig.AppPropertiesFileName;
39 _fileService.Save(folderPath, fileName, App.Current.Properties);
40 }
41 }
42
44 public void RestoreData()
45 {
46 var folderPath = Path.Combine(_localAppData, _appConfig.ConfigurationsFolder);
47 var fileName = _appConfig.AppPropertiesFileName;
48 var properties = _fileService.Read<IDictionary>(folderPath, fileName);
49 if (properties != null)
50 {
51 foreach (DictionaryEntry property in properties)
52 {
53 App.Current.Properties.Add(property.Key, property.Value);
54 }
55 }
56 }
57}
Class representing the application configuration settings.
Definition AppConfig.cs:7
void RestoreData()
Restores the application data from a file in the local application data folder.
PersistAndRestoreService(IFileService fileService, IOptions< AppConfig > appConfig)
Constructor for the PersistAndRestoreService.
void PersistData()
Persists the application data to a file in the local application data folder.
Interface for a service to persist and restore application data.
Interface for a service that handles file operations.