aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Services
diff options
context:
space:
mode:
Diffstat (limited to 'Timeline/Services')
-rw-r--r--Timeline/Services/DatabaseBackupService.cs35
-rw-r--r--Timeline/Services/PathProvider.cs6
2 files changed, 41 insertions, 0 deletions
diff --git a/Timeline/Services/DatabaseBackupService.cs b/Timeline/Services/DatabaseBackupService.cs
new file mode 100644
index 00000000..a76b2a0d
--- /dev/null
+++ b/Timeline/Services/DatabaseBackupService.cs
@@ -0,0 +1,35 @@
+using System.Globalization;
+using System.IO;
+
+namespace Timeline.Services
+{
+ public interface IDatabaseBackupService
+ {
+ void BackupNow();
+ }
+
+ public class DatabaseBackupService : IDatabaseBackupService
+ {
+ private readonly IPathProvider _pathProvider;
+ private readonly IClock _clock;
+
+ public DatabaseBackupService(IPathProvider pathProvider, IClock clock)
+ {
+ _pathProvider = pathProvider;
+ _clock = clock;
+ }
+
+ public void BackupNow()
+ {
+ var databasePath = _pathProvider.GetDatabaseFilePath();
+ if (File.Exists(databasePath))
+ {
+ var backupDirPath = _pathProvider.GetDatabaseBackupDirectory();
+ Directory.CreateDirectory(backupDirPath);
+ var fileName = _clock.GetCurrentTime().ToString("yyyy-MM-ddTHH-mm-ss", CultureInfo.InvariantCulture);
+ var path = Path.Combine(backupDirPath, fileName);
+ File.Copy(databasePath, path);
+ }
+ }
+ }
+}
diff --git a/Timeline/Services/PathProvider.cs b/Timeline/Services/PathProvider.cs
index ac7cd800..1baba5c0 100644
--- a/Timeline/Services/PathProvider.cs
+++ b/Timeline/Services/PathProvider.cs
@@ -8,6 +8,7 @@ namespace Timeline.Services
{
public string GetWorkingDirectory();
public string GetDatabaseFilePath();
+ public string GetDatabaseBackupDirectory();
}
public class PathProvider : IPathProvider
@@ -32,5 +33,10 @@ namespace Timeline.Services
{
return Path.Combine(_workingDirectory, ApplicationConfiguration.DatabaseFileName);
}
+
+ public string GetDatabaseBackupDirectory()
+ {
+ return Path.Combine(_workingDirectory, ApplicationConfiguration.DatabaseBackupDirectoryName);
+ }
}
}