Skip to content

Commit

Permalink
introduce auto save option (#30)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lg2de authored Mar 30, 2020
1 parent 450c3d4 commit c0aade4
Show file tree
Hide file tree
Showing 6 changed files with 616 additions and 137 deletions.
27 changes: 27 additions & 0 deletions src/SimpleAccounting/Abstractions/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace lg2de.SimpleAccounting.Abstractions
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;

/// <summary>
/// Redirects <see cref="IFileSystem"/> into real implementations from .NET framework.
Expand All @@ -21,5 +23,30 @@ public bool FileExists(string filePath)
{
return File.Exists(filePath);
}

public void FileMove(string sourceFileName, string destFileName)
{
File.Move(sourceFileName, destFileName);
}

public void FileDelete(string path)
{
File.Delete(path);
}

public DateTime GetLastWriteTime(string path)
{
return File.GetLastWriteTime(path);
}

public void WriteAllTextIntoFile(string path, string content)
{
File.WriteAllText(path, content, Encoding.UTF8);
}

public string ReadAllTextFromFile(string path)
{
return File.ReadAllText(path);
}
}
}
40 changes: 40 additions & 0 deletions src/SimpleAccounting/Abstractions/IFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace lg2de.SimpleAccounting.Abstractions
{
using System;

/// <summary>
/// Defines abstraction for file system access not available in .NET framework.
/// </summary>
Expand All @@ -15,5 +17,43 @@ internal interface IFileSystem
/// <param name="filePath">The path to the file to be checked.</param>
/// <returns>Returns <c>true</c> if the file exists.</returns>
bool FileExists(string filePath);

/// <summary>
/// Moves a specified file to a new location, providing the option to specify a new file name.
/// </summary>
/// <param name="sourceFileName">The name of the file to move. Can include a relative or absolute path.</param>
/// <param name="destFileName">The new path and name for the file.</param>
void FileMove(string sourceFileName, string destFileName);

/// <summary>
/// Deletes the specified file.
/// </summary>
/// <param name="path">The name of the file to be deleted. Wildcard characters are not supported.</param>
void FileDelete(string path);

/// <summary>
/// Returns the date and time the specified file or directory was last written to.
/// </summary>
/// <param name="path">The file or directory for which to obtain write date and time information.</param>
/// <returns>
/// A DateTime structure set to the date and time that the specified file or directory was last written to.
/// This value is expressed in local time.
/// </returns>
DateTime GetLastWriteTime(string path);

/// <summary>
/// Creates a new file, writes the specified string to the file, and then closes the file.
/// If the target file already exists, it is overwritten.
/// </summary>
/// <param name="path">The file to write to.</param>
/// <param name="content">The string to write to the file.</param>
void WriteAllTextIntoFile(string path, string content);

/// <summary>
/// Opens a text file, reads all the text in the file into a string, and then closes the file.
/// </summary>
/// <param name="path">The file to open for reading.</param>
/// <returns>A string containing all the text in the file.</returns>
string ReadAllTextFromFile(string path);
}
}
10 changes: 3 additions & 7 deletions src/SimpleAccounting/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@

namespace lg2de.SimpleAccounting
{
using System.Collections.Specialized;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Windows;
using System.Windows.Markup;
using lg2de.SimpleAccounting.Properties;

[ExcludeFromCodeCoverage]
public partial class App : Application
public partial class App
{
public App()
{
Settings.Default.Upgrade();
if (Settings.Default.RecentProjects == null)
{
Settings.Default.RecentProjects = new StringCollection();
}
var settings = Settings.Default;
settings.Upgrade();
}

private void ApplicationStartup(object sender, StartupEventArgs e)
Expand Down
Loading

0 comments on commit c0aade4

Please sign in to comment.