|
@@ -1,11 +1,3 @@
|
|
|
-using System;
|
|
|
-using System.IO;
|
|
|
-using System.Linq;
|
|
|
-using System.Threading;
|
|
|
-using System.Threading.Tasks;
|
|
|
-using InABox.Clients;
|
|
|
-using InABox.Core;
|
|
|
-using InABox.Mobile;
|
|
|
using Xamarin.Forms;
|
|
|
|
|
|
namespace PRS.Mobile
|
|
@@ -60,84 +52,4 @@ namespace PRS.Mobile
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- public static class DigitalFormDocumentHandler
|
|
|
- {
|
|
|
-
|
|
|
- private static String FileName(Guid id) => $"{id}.formdocument";
|
|
|
-
|
|
|
- private static String CacheFileName(Guid id) => CoreRepository.CacheFileName(FileName(id));
|
|
|
-
|
|
|
- public static void LoadDocument(Guid id, Action<byte[]> callback)
|
|
|
- {
|
|
|
- var filename = CacheFileName(id);
|
|
|
- if (CoreRepository.IsCached(filename))
|
|
|
- callback(File.ReadAllBytes(filename));
|
|
|
- else
|
|
|
- {
|
|
|
- new Client<Document>().Query(
|
|
|
- new Filter<Document>(x => x.FileName).IsEqualTo(FileName(id)),
|
|
|
- null,
|
|
|
- null,
|
|
|
- (o, e) =>
|
|
|
- {
|
|
|
- var row = o?.Rows.FirstOrDefault();
|
|
|
- if (row != null)
|
|
|
- {
|
|
|
- Device.BeginInvokeOnMainThread(() =>
|
|
|
- callback(row.Get<Document, byte[]>(c => c.Data))
|
|
|
- );
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static Guid SaveDocument(byte[] data)
|
|
|
- {
|
|
|
- Guid result = Guid.NewGuid();
|
|
|
- File.WriteAllBytes(CacheFileName(result),data);
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- public static void Run(Action<bool> status)
|
|
|
- {
|
|
|
- Task.Run(
|
|
|
- () =>
|
|
|
- {
|
|
|
- bool? previouslyActive = null;
|
|
|
- while (true)
|
|
|
- {
|
|
|
- var file = Directory.EnumerateFiles(CoreRepository.CacheFolder(), "*.formdocument")
|
|
|
- .FirstOrDefault();
|
|
|
-
|
|
|
- var isActive = !String.IsNullOrWhiteSpace(file);
|
|
|
- if (isActive != previouslyActive)
|
|
|
- {
|
|
|
- previouslyActive = isActive;
|
|
|
- status(isActive);
|
|
|
- }
|
|
|
-
|
|
|
- if (!String.IsNullOrWhiteSpace(file) && File.Exists(file) && App.Data.IsConnected())
|
|
|
- {
|
|
|
- var data = File.ReadAllBytes(file);
|
|
|
- var document = new Document()
|
|
|
- {
|
|
|
- FileName = Path.GetFileName(file),
|
|
|
- Data = data,
|
|
|
- CRC = CoreUtils.CalculateCRC(data),
|
|
|
- TimeStamp = DateTime.Now,
|
|
|
- Created = DateTime.Now,
|
|
|
- CreatedBy = App.Data.Me.Code
|
|
|
- };
|
|
|
- new Client<Document>().Save(document, "Uploaded from Mobile Device");
|
|
|
- File.Delete(file);
|
|
|
- }
|
|
|
-
|
|
|
- Thread.Sleep(1000);
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- }
|
|
|
- }
|
|
|
}
|