-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e000291
Showing
236 changed files
with
13,262 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/.vs/ | ||
/packages/ | ||
bin/ | ||
obj/ | ||
*.user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using KoiCatalog.Util; | ||
|
||
namespace KoiCatalog.App | ||
{ | ||
public sealed class ActionLockTarget | ||
{ | ||
private int LockDepth | ||
{ | ||
get => _lockDepth; | ||
set | ||
{ | ||
if (value < 0) | ||
throw new InvalidOperationException(); | ||
_lockDepth = value; | ||
} | ||
} | ||
private int _lockDepth; | ||
|
||
public bool IsLocked => LockDepth != 0; | ||
|
||
public ActionLockHandle AcquireLock() | ||
{ | ||
return new ActionLockHandle(this); | ||
} | ||
|
||
public sealed class ActionLockHandle : Disposable | ||
{ | ||
private ActionLockTarget Owner { get; } | ||
|
||
internal ActionLockHandle(ActionLockTarget owner) | ||
{ | ||
if (owner == null) throw new ArgumentNullException(nameof(owner)); | ||
Owner = owner; | ||
Owner.PushLock(); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (disposing) | ||
{ | ||
Owner.PopLock(); | ||
} | ||
else | ||
{ | ||
throw new InvalidOperationException("Undisposed object detected."); | ||
} | ||
|
||
base.Dispose(disposing); | ||
} | ||
} | ||
|
||
private void PushLock() => LockDepth++; | ||
private void PopLock() => LockDepth--; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace KoiCatalog.App | ||
{ | ||
public sealed class CancellableTask | ||
{ | ||
public Task Task { get; } | ||
public CancellationTokenSource CancellationTokenSource { get; } | ||
|
||
public CancellableTask(Task task, CancellationTokenSource cancellationTokenSource) | ||
{ | ||
if (task == null) throw new ArgumentNullException(nameof(task)); | ||
Task = task; | ||
CancellationTokenSource = cancellationTokenSource; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace KoiCatalog.App | ||
{ | ||
public sealed class CancellableTaskGroup | ||
{ | ||
private List<CancellableTask> Tasks { get; } = new List<CancellableTask>(); | ||
|
||
private void FlushCompletedTasks() | ||
{ | ||
Tasks.RemoveAll(i => i.Task.IsCompleted); | ||
} | ||
|
||
public void Add(CancellableTask task) | ||
{ | ||
if (task == null) throw new ArgumentNullException(nameof(task)); | ||
Tasks.Add(task); | ||
FlushCompletedTasks(); | ||
} | ||
|
||
public bool IsAnyTaskRunning | ||
{ | ||
get { return Tasks.Any(i => !i.Task.IsCompleted); } | ||
} | ||
|
||
public void WaitAll() | ||
{ | ||
Task.WaitAll(Tasks.Select(i => i.Task).ToArray()); | ||
} | ||
|
||
public void CancelAll() | ||
{ | ||
foreach (var task in Tasks) | ||
{ | ||
task.CancellationTokenSource.Cancel(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Reflection; | ||
|
||
namespace KoiCatalog.App.Data | ||
{ | ||
public sealed class DataColumn | ||
{ | ||
public PropertyInfo Property { get; } | ||
|
||
public DataColumn(PropertyInfo property) | ||
{ | ||
if (property == null) throw new ArgumentNullException(nameof(property)); | ||
Property = property; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
|
||
namespace KoiCatalog.App.Data | ||
{ | ||
public sealed class DataRow | ||
{ | ||
private DataTable DataTable { get; } | ||
private object[] Values { get; } | ||
|
||
public object this[int index] | ||
{ | ||
get => Values[index]; | ||
set => Values[index] = value; | ||
} | ||
|
||
internal DataRow(DataTable dataTable) | ||
{ | ||
if (dataTable == null) throw new ArgumentNullException(nameof(dataTable)); | ||
DataTable = dataTable; | ||
Values = new object[dataTable.Columns.Count]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Collections.ObjectModel; | ||
|
||
namespace KoiCatalog.App.Data | ||
{ | ||
public sealed class DataTable | ||
{ | ||
public ObservableCollection<DataColumn> Columns { get; } = | ||
new ObservableCollection<DataColumn>(); | ||
|
||
public ObservableCollection<DataRow> Rows { get; } = | ||
new ObservableCollection<DataRow>(); | ||
|
||
public void Clear() | ||
{ | ||
Rows.Clear(); | ||
} | ||
|
||
public DataRow NewRow() | ||
{ | ||
return new DataRow(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace KoiCatalog.App | ||
{ | ||
public enum DatabaseLoadMode | ||
{ | ||
Auto, | ||
LoadCache, | ||
Rebuild, | ||
Refresh, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace KoiCatalog.App | ||
{ | ||
public enum DatabaseLoadingState | ||
{ | ||
None, | ||
Normal, | ||
Indeterminate, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using System.Collections.ObjectModel; | ||
using System.ComponentModel; | ||
using System.Runtime.CompilerServices; | ||
using KoiCatalog.Data; | ||
|
||
namespace KoiCatalog.App | ||
{ | ||
public sealed class DatabaseStatus : INotifyPropertyChanged | ||
{ | ||
public ObservableCollection<DatabaseEvent> Events { get; } = | ||
new ObservableCollection<DatabaseEvent>(); | ||
|
||
public Progress Progress | ||
{ | ||
get => _progress; | ||
set | ||
{ | ||
_progress = value; | ||
NotifyPropertyChanged(); | ||
NotifyPropertyChanged(nameof(LoadingState)); | ||
} | ||
} | ||
private Progress _progress; | ||
|
||
public DatabaseStatusState State | ||
{ | ||
get => _state; | ||
set | ||
{ | ||
_state = value; | ||
NotifyPropertyChanged(); | ||
NotifyPropertyChanged(nameof(LoadingState)); | ||
} | ||
} | ||
private DatabaseStatusState _state = DatabaseStatusState.Ready; | ||
|
||
public DatabaseLoadingState LoadingState | ||
{ | ||
get | ||
{ | ||
if (State == DatabaseStatusState.Ready) | ||
return DatabaseLoadingState.None; | ||
if (Progress == null) | ||
return DatabaseLoadingState.Indeterminate; | ||
return DatabaseLoadingState.Normal; | ||
} | ||
} | ||
|
||
public int TotalDatabaseItemCount | ||
{ | ||
get => _totalDatabaseItemCount; | ||
set | ||
{ | ||
if (value == _totalDatabaseItemCount) return; | ||
_totalDatabaseItemCount = value; | ||
NotifyPropertyChanged(); | ||
} | ||
} | ||
private int _totalDatabaseItemCount; | ||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "") | ||
{ | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
|
||
public static DatabaseStatusState? DatabaseEventTypeToStatusStatus(DatabaseEventType eventType) | ||
{ | ||
switch (eventType) | ||
{ | ||
case DatabaseEventType.SaveStart: | ||
return DatabaseStatusState.Saving; | ||
case DatabaseEventType.ScanStart: | ||
return DatabaseStatusState.Scanning; | ||
case DatabaseEventType.LoadStart: | ||
case DatabaseEventType.LoadProgress: | ||
return DatabaseStatusState.Loading; | ||
case DatabaseEventType.SaveEnd: | ||
case DatabaseEventType.ScanEnd: | ||
case DatabaseEventType.LoadEnd: | ||
return DatabaseStatusState.Ready; | ||
default: | ||
return null; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace KoiCatalog.App | ||
{ | ||
public enum DatabaseStatusState | ||
{ | ||
Ready, | ||
Scanning, | ||
Loading, | ||
Saving, | ||
} | ||
} |
Oops, something went wrong.