|
|
@@ -10,7 +10,7 @@ namespace InABox.Core
|
|
|
|
|
|
public interface IDigitalFormDocumentHandler
|
|
|
{
|
|
|
- void LoadDocument(Guid id, Action<byte[]> callback);
|
|
|
+ Task<byte[]> LoadDocumentAsync(Guid id);
|
|
|
byte[] LoadDocument(Guid id);
|
|
|
Guid SaveDocument(byte[] data);
|
|
|
void Run();
|
|
|
@@ -34,33 +34,27 @@ namespace InABox.Core
|
|
|
if (File.Exists(fullpath))
|
|
|
return File.ReadAllBytes(fullpath);
|
|
|
|
|
|
- var result = new Client<Document>().Query(
|
|
|
- new Filter<Document>(x => x.FileName).IsEqualTo(FileName(id)),
|
|
|
- null,
|
|
|
- null
|
|
|
- ).Rows.FirstOrDefault()?.Get<Document,byte[]>(c=>c.Data);
|
|
|
- return result;
|
|
|
+ var result = new Client<Document>().Query(
|
|
|
+ new Filter<Document>(x => x.FileName).IsEqualTo(FileName(id)),
|
|
|
+ null,
|
|
|
+ null
|
|
|
+ ).Rows.FirstOrDefault()?.Get<Document,byte[]>(c=>c.Data);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
- public void LoadDocument(Guid id, Action<byte[]> callback)
|
|
|
+ public async Task<byte[]> LoadDocumentAsync(Guid id)
|
|
|
{
|
|
|
var fullpath = Path.Combine(CachePath, FileName(id));
|
|
|
if (File.Exists(fullpath))
|
|
|
- callback(File.ReadAllBytes(fullpath));
|
|
|
+ return File.ReadAllBytes(fullpath);
|
|
|
else
|
|
|
{
|
|
|
- new Client<Document>().Query(
|
|
|
+ var data = await Client.QueryAsync(
|
|
|
new Filter<Document>(x => x.FileName).IsEqualTo(FileName(id)),
|
|
|
+ Columns.None<Document>().Add(x => x.Data),
|
|
|
null,
|
|
|
- null,
|
|
|
- CoreRange.All,
|
|
|
- (o, e) =>
|
|
|
- {
|
|
|
- var row = o?.Rows.FirstOrDefault();
|
|
|
- if (row != null)
|
|
|
- callback(row.Get<Document, byte[]>(c => c.Data));
|
|
|
- }
|
|
|
- );
|
|
|
+ CoreRange.All);
|
|
|
+ return data.Rows.FirstOrDefault().Get<Document, byte[]>(x => x.Data);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -143,12 +137,16 @@ namespace InABox.Core
|
|
|
_handler = handler;
|
|
|
}
|
|
|
|
|
|
+ public static IDigitalFormDocumentHandler Handler => _handler ?? throw new Exception("Digital form document handler uninitialised.");
|
|
|
+
|
|
|
public static void Run() => _handler?.Run();
|
|
|
public static void Stop() => _handler?.Stop();
|
|
|
-
|
|
|
- public static void LoadDocument(Guid id, Action<byte[]> callback) => _handler?.LoadDocument(id, callback);
|
|
|
- public static byte[]? LoadDocument(Guid id) => _handler?.LoadDocument(id);
|
|
|
- public static Guid SaveDocument(byte[] data) => _handler?.SaveDocument(data) ?? Guid.Empty;
|
|
|
+
|
|
|
+ public static void LoadDocument(Guid id, Action<byte[]> callback) =>
|
|
|
+ LoadDocumentAsync(id).ContinueWith(task => callback(task.Result));
|
|
|
+ public static Task<byte[]> LoadDocumentAsync(Guid id) => Handler.LoadDocumentAsync(id);
|
|
|
+ public static byte[]? LoadDocument(Guid id) => Handler.LoadDocument(id);
|
|
|
+ public static Guid SaveDocument(byte[] data) => Handler.SaveDocument(data);
|
|
|
|
|
|
}
|
|
|
}
|