Skip to content

Commit c0aade4

Browse files
authored
introduce auto save option (#30)
* introduce auto save every minute * implement loading from AutoSave file * fix threading for loading auto.save on application start; cleanup * use Xunit.StaFact for testing using UI-dispatcher-like thread
1 parent 450c3d4 commit c0aade4

6 files changed

Lines changed: 616 additions & 137 deletions

File tree

src/SimpleAccounting/Abstractions/FileSystem.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
namespace lg2de.SimpleAccounting.Abstractions
66
{
7+
using System;
78
using System.Diagnostics.CodeAnalysis;
89
using System.IO;
10+
using System.Text;
911

1012
/// <summary>
1113
/// Redirects <see cref="IFileSystem"/> into real implementations from .NET framework.
@@ -21,5 +23,30 @@ public bool FileExists(string filePath)
2123
{
2224
return File.Exists(filePath);
2325
}
26+
27+
public void FileMove(string sourceFileName, string destFileName)
28+
{
29+
File.Move(sourceFileName, destFileName);
30+
}
31+
32+
public void FileDelete(string path)
33+
{
34+
File.Delete(path);
35+
}
36+
37+
public DateTime GetLastWriteTime(string path)
38+
{
39+
return File.GetLastWriteTime(path);
40+
}
41+
42+
public void WriteAllTextIntoFile(string path, string content)
43+
{
44+
File.WriteAllText(path, content, Encoding.UTF8);
45+
}
46+
47+
public string ReadAllTextFromFile(string path)
48+
{
49+
return File.ReadAllText(path);
50+
}
2451
}
2552
}

src/SimpleAccounting/Abstractions/IFileSystem.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace lg2de.SimpleAccounting.Abstractions
66
{
7+
using System;
8+
79
/// <summary>
810
/// Defines abstraction for file system access not available in .NET framework.
911
/// </summary>
@@ -15,5 +17,43 @@ internal interface IFileSystem
1517
/// <param name="filePath">The path to the file to be checked.</param>
1618
/// <returns>Returns <c>true</c> if the file exists.</returns>
1719
bool FileExists(string filePath);
20+
21+
/// <summary>
22+
/// Moves a specified file to a new location, providing the option to specify a new file name.
23+
/// </summary>
24+
/// <param name="sourceFileName">The name of the file to move. Can include a relative or absolute path.</param>
25+
/// <param name="destFileName">The new path and name for the file.</param>
26+
void FileMove(string sourceFileName, string destFileName);
27+
28+
/// <summary>
29+
/// Deletes the specified file.
30+
/// </summary>
31+
/// <param name="path">The name of the file to be deleted. Wildcard characters are not supported.</param>
32+
void FileDelete(string path);
33+
34+
/// <summary>
35+
/// Returns the date and time the specified file or directory was last written to.
36+
/// </summary>
37+
/// <param name="path">The file or directory for which to obtain write date and time information.</param>
38+
/// <returns>
39+
/// A DateTime structure set to the date and time that the specified file or directory was last written to.
40+
/// This value is expressed in local time.
41+
/// </returns>
42+
DateTime GetLastWriteTime(string path);
43+
44+
/// <summary>
45+
/// Creates a new file, writes the specified string to the file, and then closes the file.
46+
/// If the target file already exists, it is overwritten.
47+
/// </summary>
48+
/// <param name="path">The file to write to.</param>
49+
/// <param name="content">The string to write to the file.</param>
50+
void WriteAllTextIntoFile(string path, string content);
51+
52+
/// <summary>
53+
/// Opens a text file, reads all the text in the file into a string, and then closes the file.
54+
/// </summary>
55+
/// <param name="path">The file to open for reading.</param>
56+
/// <returns>A string containing all the text in the file.</returns>
57+
string ReadAllTextFromFile(string path);
1858
}
1959
}

src/SimpleAccounting/App.xaml.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,19 @@
44

55
namespace lg2de.SimpleAccounting
66
{
7-
using System.Collections.Specialized;
87
using System.Diagnostics.CodeAnalysis;
98
using System.Globalization;
109
using System.Windows;
1110
using System.Windows.Markup;
1211
using lg2de.SimpleAccounting.Properties;
1312

1413
[ExcludeFromCodeCoverage]
15-
public partial class App : Application
14+
public partial class App
1615
{
1716
public App()
1817
{
19-
Settings.Default.Upgrade();
20-
if (Settings.Default.RecentProjects == null)
21-
{
22-
Settings.Default.RecentProjects = new StringCollection();
23-
}
18+
var settings = Settings.Default;
19+
settings.Upgrade();
2420
}
2521

2622
private void ApplicationStartup(object sender, StartupEventArgs e)

0 commit comments

Comments
 (0)