Hash functions

This commit is contained in:
2022-02-16 21:03:34 +01:00
parent 27a974e3e2
commit d1ceb95884
18 changed files with 240 additions and 39 deletions

View File

@@ -2,15 +2,38 @@ namespace FileTime.Core.Interactions
{
public class InputElement
{
public string Text { get; }
public string Label { get; }
public InputType InputType { get; }
public string? DefaultValue { get; }
public List<object>? Options { get; }
public InputElement(string text, InputType inputType, string? defaultValue = null)
protected InputElement(string text, InputType inputType, string? defaultValue = null)
{
Text = text;
Label = text;
InputType = inputType;
DefaultValue = defaultValue;
}
protected InputElement(string text, InputType inputType, List<object> defaultValue)
{
Label = text;
InputType = inputType;
Options = defaultValue;
}
public static InputElement ForText(string label, string? defaultValue = null)
{
return new InputElement(label, InputType.Text, defaultValue);
}
public static InputElement ForPassword(string label, string? defaultValue = null)
{
return new InputElement(label, InputType.Password, defaultValue);
}
public static InputElement ForOptions(string label, List<object> defaultValue)
{
return new InputElement(label, InputType.Options, defaultValue);
}
}
}

View File

@@ -2,8 +2,8 @@ namespace FileTime.Core.Interactions
{
public enum InputType
{
Text,
Options,
Password,
Bool
Text,
}
}

View File

@@ -0,0 +1,61 @@
using System.Threading.Tasks;
namespace FileTime.Core.Providers
{
public class ContentProviderStream : Stream
{
private readonly IContentReader? _contentReader;
private readonly IContentWriter? _contentWriter;
public override bool CanRead => _contentReader == null;
public override bool CanSeek => false;
public override bool CanWrite => _contentWriter == null;
public override long Length => throw new NotImplementedException();
public override long Position { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public ContentProviderStream(IContentReader contentReader)
{
_contentReader = contentReader;
}
public ContentProviderStream(IContentWriter contentWriter)
{
_contentWriter = contentWriter;
}
public override void Flush()
{
throw new NotImplementedException();
}
public override int Read(byte[] buffer, int offset, int count)
{
if (_contentReader == null) throw new IOException("This stream is not readable");
var dataTask = Task.Run(async () => await _contentReader.ReadBytesAsync(count, offset));
dataTask.Wait();
var data = dataTask.Result;
if (data.Length > count) throw new Exception("More bytes has been read than requested");
Array.Copy(data, buffer, data.Length);
return data.Length;
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotImplementedException();
}
public override void SetLength(long value)
{
throw new NotImplementedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new NotImplementedException();
}
}
}

View File

@@ -4,6 +4,6 @@ namespace FileTime.Core.Providers
{
int PreferredBufferSize { get; }
Task<byte[]> ReadBytesAsync(int bufferSize);
Task<byte[]> ReadBytesAsync(int bufferSize, int? offset = null);
}
}

View File

@@ -1,3 +1,4 @@
using System.Threading.Tasks;
using FileTime.Core.Command;
namespace FileTime.Core.Timeline
@@ -12,7 +13,7 @@ namespace FileTime.Core.Timeline
public CommandTimeState(ICommand command, PointInTime? startTime)
{
Command = command;
UpdateState(startTime).Wait();
Task.Run(async () => await UpdateState(startTime)).Wait();
}
public async Task UpdateState(PointInTime? startPoint)

View File

@@ -1,3 +1,4 @@
using System.Threading.Tasks;
using AsyncEvent;
using FileTime.Core.Command;
using FileTime.Core.Models;
@@ -136,7 +137,7 @@ namespace FileTime.Core.Timeline
if (arg is CommandTimeState commandToRun2)
{
commandToRun = commandToRun2;
_commandExecutor.ExecuteCommandAsync(commandToRun.Command, this).Wait();
Task.Run(async () => await _commandExecutor.ExecuteCommandAsync(commandToRun.Command, this)).Wait();
}
}
catch (Exception e)
@@ -150,7 +151,7 @@ namespace FileTime.Core.Timeline
}
finally
{
DisposeCommandThread(Thread.CurrentThread, commandToRun).Wait();
Task.Run(async () => await DisposeCommandThread(Thread.CurrentThread, commandToRun)).Wait();
}
}
@@ -238,6 +239,6 @@ namespace FileTime.Core.Timeline
}
}
private void RunWithLock(Action action) => RunWithLockAsync(action).Wait();
private void RunWithLock(Action action) => Task.Run(async () => await RunWithLockAsync(action)).Wait();
}
}