Esempio n. 1
0
        private async Task UploadAsync()
        {
            // TODO: When the online file is corrupt then the upload does not run anymore.
            if (!isInSync || accountService.CurrentAccount == null)
            {
                return;
            }
            var token = await accountService.GetTokenAsync();

            if (token == null)
            {
                return;
            }

            try
            {
                using (var stream = await appDataService.GetFileStreamForReadAsync(dataFileName))
                    using (var cryptoStream = await cryptographicService.EncryptAsync(stream, accountService.CurrentAccount.Id, salt + accountService.CurrentAccount.Id, iterationCount))
                    {
                        await webStorageService.UploadFileAsync(cryptoStream, dataFileName, token);
                    }
            }
            catch (Exception ex)
            {
                messageService.ShowMessage(resourceService.GetString("SynchronizationUploadError"), ex.Message);
            }
        }
Esempio n. 2
0
        private async Task UploadAsync()
        {
            // TODO: When the online file is corrupt then the upload does not run anymore.
            if (!isInSync || accountService.CurrentAccount == null || !networkInfoService.InternetAccess)
            {
                return;
            }
            var token = await accountService.GetTokenAsync();

            if (token == null)
            {
                return;
            }

            try
            {
                using (var stream = await appDataService.GetFileStreamForReadAsync(dataFileName))
                {
                    var dataFileHash = await cryptographicService.HashAsync(stream);

                    if (dataFileHash.Equals(appDataService.LocalSettings[lastUploadedDataFileHashSettingsKey]))
                    {
                        return;
                    }
                    stream.Position = 0;
                    using (var cryptoStream = await cryptographicService.EncryptAsync(stream, accountService.CurrentAccount.Id, salt + accountService.CurrentAccount.Id, iterationCount))
                    {
                        var eTag = await webStorageService.UploadFileAsync(cryptoStream, dataFileName, token);

                        appDataService.LocalSettings[webStorageFileETagSettingsKey]       = eTag;
                        appDataService.LocalSettings[lastUploadedDataFileHashSettingsKey] = dataFileHash;
                    }
                }
            }
            catch (Exception ex)
            {
                messageService.ShowMessage(resourceService.GetString("SynchronizationUploadError"), ex.Message);
            }
        }