diff --git a/AudioCuesheetEditor/Model/Utility/DateTimeUtility.cs b/AudioCuesheetEditor/Model/Utility/DateTimeUtility.cs
deleted file mode 100644
index a6d0ec43..00000000
--- a/AudioCuesheetEditor/Model/Utility/DateTimeUtility.cs
+++ /dev/null
@@ -1,143 +0,0 @@
-//This file is part of AudioCuesheetEditor.
-
-//AudioCuesheetEditor is free software: you can redistribute it and/or modify
-//it under the terms of the GNU General Public License as published by
-//the Free Software Foundation, either version 3 of the License, or
-//(at your option) any later version.
-
-//AudioCuesheetEditor is distributed in the hope that it will be useful,
-//but WITHOUT ANY WARRANTY; without even the implied warranty of
-//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-//GNU General Public License for more details.
-
-//You should have received a copy of the GNU General Public License
-//along with Foobar. If not, see
-//.
-using AudioCuesheetEditor.Data.Options;
-using AudioCuesheetEditor.Model.Options;
-using System.Linq.Expressions;
-using System.Reflection;
-
-namespace AudioCuesheetEditor.Model.Utility
-{
- //TODO: delete me!
- [Obsolete("Use ApplicationOptionsTimeSpanParser!")]
- public class DateTimeUtility : IDisposable
- {
- private readonly LocalStorageOptionsProvider? _localStorageOptionsProvider;
- private readonly TimeSpanFormat? _timeFormat;
-
- private ApplicationOptions? applicationOptions;
- private bool disposedValue;
-
- public DateTimeUtility(LocalStorageOptionsProvider localStorageOptionsProvider)
- {
- _localStorageOptionsProvider = localStorageOptionsProvider;
- _localStorageOptionsProvider.OptionSaved += LocalStorageOptionsProvider_OptionSaved;
- Task.Run(InitAsync);
- }
-
- public DateTimeUtility(TimeSpanFormat timeSpanFormat)
- {
- _timeFormat = timeSpanFormat;
- }
-
- public void Dispose()
- {
- // Ändern Sie diesen Code nicht. Fügen Sie Bereinigungscode in der Methode "Dispose(bool disposing)" ein.
- Dispose(disposing: true);
- GC.SuppressFinalize(this);
- }
- //TODO: Make static
- public TimeSpan? ParseTimeSpan(String input)
- {
- TimeSpan? result = null;
- if (String.IsNullOrEmpty(input) == false)
- {
- if (TimeSpanFormat?.Scheme == null)
- {
- if (TimeSpan.TryParse(input, out var parsed))
- {
- result = parsed;
- }
- }
- else
- {
- result = TimeSpanFormat.ParseTimeSpan(input);
- }
- }
- return result;
- }
-
- public async Task TimespanTextChanged(T entity, Expression> expression, String value)
- {
- if (expression.Body is not MemberExpression memberExpression)
- {
- throw new ArgumentException("'expression' should be a member expression");
- }
- if (applicationOptions == null)
- {
- await InitAsync();
- }
- TimeSpan? result = ParseTimeSpan(value);
- switch (memberExpression.Member.MemberType)
- {
- case MemberTypes.Property:
- ((PropertyInfo)memberExpression.Member).SetValue(entity, result);
- break;
- default:
- throw new NotImplementedException();
- }
- }
-
- TimeSpanFormat? TimeSpanFormat
- {
- get
- {
- if (applicationOptions != null)
- {
- return applicationOptions.TimeSpanFormat;
- }
- if (_timeFormat != null)
- {
- return _timeFormat;
- }
- return null;
- }
- }
-
- private async Task InitAsync()
- {
- if (_localStorageOptionsProvider != null)
- {
- applicationOptions ??= await _localStorageOptionsProvider.GetOptions();
- }
- }
-
- private void LocalStorageOptionsProvider_OptionSaved(object? sender, IOptions options)
- {
- if (options is ApplicationOptions applicationOption)
- {
- applicationOptions = applicationOption;
- }
- }
-
- protected virtual void Dispose(bool disposing)
- {
- if (!disposedValue)
- {
- if (disposing)
- {
- // Verwalteten Zustand (verwaltete Objekte) bereinigen
- if (_localStorageOptionsProvider != null)
- {
- _localStorageOptionsProvider.OptionSaved -= LocalStorageOptionsProvider_OptionSaved;
- }
- }
-
- disposedValue = true;
- }
- }
-
- }
-}
diff --git a/AudioCuesheetEditor/Model/Utility/TimeSpanUtility.cs b/AudioCuesheetEditor/Model/Utility/TimeSpanUtility.cs
index 230a6c0a..7ca259e8 100644
--- a/AudioCuesheetEditor/Model/Utility/TimeSpanUtility.cs
+++ b/AudioCuesheetEditor/Model/Utility/TimeSpanUtility.cs
@@ -17,7 +17,6 @@ namespace AudioCuesheetEditor.Model.Utility
{
public class TimeSpanUtility
{
- //TODO: Unit Tests
public static TimeSpan? ParseTimeSpan(String input, TimeSpanFormat? timeSpanFormat = null)
{
TimeSpan? result = null;
diff --git a/AudioCuesheetEditor/Program.cs b/AudioCuesheetEditor/Program.cs
index 6c6a74aa..faff2bd2 100644
--- a/AudioCuesheetEditor/Program.cs
+++ b/AudioCuesheetEditor/Program.cs
@@ -54,7 +54,6 @@
builder.Services.AddScoped();
builder.Services.AddScoped();
-builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
diff --git a/AudioCuesheetEditorTests/Model/Utility/DateTimeUtilityTests.cs b/AudioCuesheetEditorTests/Model/Utility/TimeSpanUtilityTests.cs
similarity index 52%
rename from AudioCuesheetEditorTests/Model/Utility/DateTimeUtilityTests.cs
rename to AudioCuesheetEditorTests/Model/Utility/TimeSpanUtilityTests.cs
index 4da6ac1f..a86b6eb6 100644
--- a/AudioCuesheetEditorTests/Model/Utility/DateTimeUtilityTests.cs
+++ b/AudioCuesheetEditorTests/Model/Utility/TimeSpanUtilityTests.cs
@@ -1,63 +1,51 @@
-//This file is part of AudioCuesheetEditor.
-
-//AudioCuesheetEditor is free software: you can redistribute it and/or modify
-//it under the terms of the GNU General Public License as published by
-//the Free Software Foundation, either version 3 of the License, or
-//(at your option) any later version.
-
-//AudioCuesheetEditor is distributed in the hope that it will be useful,
-//but WITHOUT ANY WARRANTY; without even the implied warranty of
-//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-//GNU General Public License for more details.
-
-//You should have received a copy of the GNU General Public License
-//along with Foobar. If not, see
-//.
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using AudioCuesheetEditor.Model.Utility;
using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
namespace AudioCuesheetEditor.Model.Utility.Tests
{
[TestClass()]
- public class DateTimeUtilityTests
+ public class TimeSpanUtilityTests
{
[TestMethod()]
public void ParseTimeSpanTest()
{
- var utility = new DateTimeUtility(new TimeSpanFormat());
- var timespan = utility.ParseTimeSpan("01:23:45");
+ var timespan = TimeSpanUtility.ParseTimeSpan("01:23:45");
Assert.IsNotNull(timespan);
Assert.AreEqual(new TimeSpan(1, 23, 45), timespan);
var format = new TimeSpanFormat() { Scheme = "(?'Minutes'\\d{1,})[:](?'Seconds'\\d{1,})" };
- utility = new DateTimeUtility(format);
- timespan = utility.ParseTimeSpan("3:12");
+ timespan = TimeSpanUtility.ParseTimeSpan("3:12", format);
Assert.IsNotNull(timespan);
Assert.AreEqual(new TimeSpan(0, 3, 12), timespan);
- timespan = utility.ParseTimeSpan("63:12");
+ timespan = TimeSpanUtility.ParseTimeSpan("63:12", format);
Assert.IsNotNull(timespan);
Assert.AreEqual(new TimeSpan(1, 3, 12), timespan);
format.Scheme = "(?'Hours'\\d{1,})[:](?'Minutes'\\d{1,})";
- timespan = utility.ParseTimeSpan("23:12");
+ timespan = TimeSpanUtility.ParseTimeSpan("23:12", format);
Assert.IsNotNull(timespan);
Assert.AreEqual(new TimeSpan(23, 12, 0), timespan);
format.Scheme = "(?'Hours'\\d{1,})[:](?'Minutes'\\d{1,})[:](?'Seconds'\\d{1,})";
- timespan = utility.ParseTimeSpan("23:45:56");
+ timespan = TimeSpanUtility.ParseTimeSpan("23:45:56", format);
Assert.IsNotNull(timespan);
Assert.AreEqual(new TimeSpan(0, 23, 45, 56), timespan);
format.Scheme = "(?'Days'\\d{1,})[.](?'Hours'\\d{1,})[:](?'Minutes'\\d{1,})[:](?'Seconds'\\d{1,})";
- timespan = utility.ParseTimeSpan("2.23:45:56");
+ timespan = TimeSpanUtility.ParseTimeSpan("2.23:45:56", format);
Assert.IsNotNull(timespan);
Assert.AreEqual(new TimeSpan(2, 23, 45, 56), timespan);
format.Scheme = "(?'Hours'\\d{1,})[:](?'TimeSpanFormat.Minutes'\\d{1,})[:](?'TimeSpanFormat.Seconds'\\d{1,})[.](?'TimeSpanFormat.Milliseconds'\\d{1,})";
- timespan = utility.ParseTimeSpan("23:45:56.599");
+ timespan = TimeSpanUtility.ParseTimeSpan("23:45:56.599", format);
Assert.IsNotNull(timespan);
Assert.AreEqual(new TimeSpan(0, 23, 45, 56, 599), timespan);
- timespan = utility.ParseTimeSpan("1.2e:45:87.h3a");
+ timespan = TimeSpanUtility.ParseTimeSpan("1.2e:45:87.h3a", format);
Assert.IsNull(timespan);
- timespan = utility.ParseTimeSpan("Test");
+ timespan = TimeSpanUtility.ParseTimeSpan("Test", format);
Assert.IsNull(timespan);
format.Scheme = "this is a test";
- timespan = utility.ParseTimeSpan("Test");
+ timespan = TimeSpanUtility.ParseTimeSpan("Test", format);
Assert.IsNull(timespan);
}
}