public override void Run()
{
try
{
IOConnectionInfo ioc = _app.GetDb().Ioc;
IFileStorage fileStorage = _app.GetFileStorage(ioc);
if (fileStorage is CachingFileStorage)
{
throw new Exception("Cannot sync a cached database!");
}
StatusLogger.UpdateMessage(UiStringKey.CheckingDatabaseForChanges);
//download file from remote location and calculate hash:
StatusLogger.UpdateSubMessage(_app.GetResourceString(UiStringKey.DownloadingRemoteFile));
MemoryStream remoteData = new MemoryStream();
using (
HashingStreamEx hashingRemoteStream = new HashingStreamEx(fileStorage.OpenFileForRead(ioc), false,
new SHA256Managed()))
{
hashingRemoteStream.CopyTo(remoteData);
hashingRemoteStream.Close();
if (!MemUtil.ArraysEqual(_app.GetDb().KpDatabase.HashOfFileOnDisk, hashingRemoteStream.Hash))
{
_app.TriggerReload(_context);
Finish(true);
}
else
{
Finish(true, _app.GetResourceString(UiStringKey.RemoteDatabaseUnchanged));
}
}
}
catch (Exception e)
{
Finish(false, e.Message);
}
}