|
@@ -14,6 +14,7 @@ namespace PRS.Mobile
|
|
|
void LoadDocument(Guid id, Action<byte[]> callback);
|
|
|
Guid SaveDocument(byte[] data);
|
|
|
void Run(Action<bool> status);
|
|
|
+ void Stop();
|
|
|
}
|
|
|
|
|
|
public abstract class DigitalFormDocumentHandler : IDigitalFormDocumentHandler
|
|
@@ -53,14 +54,27 @@ namespace PRS.Mobile
|
|
|
File.WriteAllBytes(filename,data);
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ private CancellationTokenSource? _cancel;
|
|
|
+
|
|
|
+ public void Stop()
|
|
|
+ {
|
|
|
+ if (_cancel != null)
|
|
|
+ {
|
|
|
+ _cancel.Cancel();
|
|
|
+ _cancel = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public void Run(Action<bool> status)
|
|
|
{
|
|
|
+ Stop();
|
|
|
+ _cancel = new CancellationTokenSource();
|
|
|
Task.Run(
|
|
|
() =>
|
|
|
{
|
|
|
bool? previouslyActive = null;
|
|
|
- while (true)
|
|
|
+ while (true && !_cancel.IsCancellationRequested)
|
|
|
{
|
|
|
var file = Directory.EnumerateFiles(CachePath, "*.formdocument")
|
|
|
.FirstOrDefault();
|
|
@@ -90,7 +104,8 @@ namespace PRS.Mobile
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+ _cancel.Token
|
|
|
);
|
|
|
}
|
|
|
}
|
|
@@ -98,17 +113,17 @@ namespace PRS.Mobile
|
|
|
public static class DigitalFormDocumentFactory
|
|
|
{
|
|
|
|
|
|
- private static IDigitalFormDocumentHandler _handler;
|
|
|
+ private static IDigitalFormDocumentHandler? _handler;
|
|
|
|
|
|
- public static void Run<THandler>(Action<bool> status) where THandler : IDigitalFormDocumentHandler, new()
|
|
|
+ public static void Run<THandler>(THandler handler, Action<bool> status) where THandler : IDigitalFormDocumentHandler
|
|
|
{
|
|
|
- _handler = new THandler();
|
|
|
+ _handler = handler;
|
|
|
_handler.Run(status);
|
|
|
}
|
|
|
|
|
|
- public static void LoadDocument(Guid id, Action<byte[]> callback) => _handler.LoadDocument(id, callback);
|
|
|
+ public static void LoadDocument(Guid id, Action<byte[]> callback) => _handler?.LoadDocument(id, callback);
|
|
|
|
|
|
- public static Guid SaveDocument(byte[] data) => _handler.SaveDocument(data);
|
|
|
+ public static Guid SaveDocument(byte[] data) => _handler?.SaveDocument(data) ?? Guid.Empty;
|
|
|
|
|
|
}
|
|
|
}
|