Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
im-mi committed Aug 10, 2018
0 parents commit e000291
Show file tree
Hide file tree
Showing 236 changed files with 13,262 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.vs/
/packages/
bin/
obj/
*.user
56 changes: 56 additions & 0 deletions KoiCatalog.App/ActionLockTarget.cs
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--;
}
}
19 changes: 19 additions & 0 deletions KoiCatalog.App/CancellableTask.cs
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;
}
}
}
42 changes: 42 additions & 0 deletions KoiCatalog.App/CancellableTaskGroup.cs
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();
}
}
}
}
16 changes: 16 additions & 0 deletions KoiCatalog.App/Data/DataColumn.cs
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;
}
}
}
23 changes: 23 additions & 0 deletions KoiCatalog.App/Data/DataRow.cs
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];
}
}
}
23 changes: 23 additions & 0 deletions KoiCatalog.App/Data/DataTable.cs
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);
}
}
}
10 changes: 10 additions & 0 deletions KoiCatalog.App/DatabaseLoadMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace KoiCatalog.App
{
public enum DatabaseLoadMode
{
Auto,
LoadCache,
Rebuild,
Refresh,
}
}
9 changes: 9 additions & 0 deletions KoiCatalog.App/DatabaseLoadingState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace KoiCatalog.App
{
public enum DatabaseLoadingState
{
None,
Normal,
Indeterminate,
}
}
87 changes: 87 additions & 0 deletions KoiCatalog.App/DatabaseStatus.cs
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;
}
}
}
}
10 changes: 10 additions & 0 deletions KoiCatalog.App/DatabaseStatusState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace KoiCatalog.App
{
public enum DatabaseStatusState
{
Ready,
Scanning,
Loading,
Saving,
}
}
Loading

0 comments on commit e000291

Please sign in to comment.