Beispiel #1
0
        private void SyncUp()
        {
            var items = _playerItemDao.GetUnsynchronizedItems();

            if (items.Count > 0)
            {
                int numRemaining = items.Count;

                Logger.Info($"There are {numRemaining} items remaining to be synchronized to azure");
                while (numRemaining > 0)
                {
                    int numTaken = Math.Min(items.Count, 100);
                    var batch    = items
                                   .Skip(items.Count - numRemaining)
                                   .Take(numTaken)
                                   .Select(ItemConverter.ToUpload)
                                   .ToList();

                    Logger.Info($"Synchronizing {numTaken} items to azure");
                    try {
                        var mapping = _azureSyncService.Save(batch);
                        _playerItemDao.SetAzureIds(mapping.Items);

                        if (mapping.IsClosed)
                        {
                            _azurePartitionDao.Save(new AzurePartition {
                                Id       = mapping.Partition,
                                IsActive = false
                            });

                            Logger.Debug($"Storing partition {mapping.Partition} as closed.");
                        }

                        numRemaining -= numTaken;
                    }
                    catch (AggregateException ex) {
                        Logger.Warn(ex.Message, ex);
                        return;
                    }
                    catch (WebException ex) {
                        Logger.Warn(ex.Message, ex);
                        return;
                    }
                    catch (Exception ex) {
                        ExceptionReporter.ReportException(ex, "SyncUp");
                        return;
                    }
                }

                Logger.Info("Upload complete");
                OnUploadComplete?.Invoke(this, null);
            }
        }
Beispiel #2
0
    private async Task UpdateStatus(BitFileUploadStatus uploadStatus, int index)
    {
        if (Files is null)
        {
            return;
        }

        if (index < 0)
        {
            UploadStatus = uploadStatus;

            var files = Files.Where(c => c.Status != BitFileUploadStatus.NotAllowed).ToArray();
            foreach (var file in files)
            {
                file.Status = uploadStatus;
            }

            await OnChange.InvokeAsync(files);
        }
        else
        {
            if (Files[index].Status != uploadStatus)
            {
                Files[index].Status = uploadStatus;
                await OnChange.InvokeAsync(new[] { Files[index] });
            }

            if (uploadStatus == BitFileUploadStatus.InProgress)
            {
                await OnProgress.InvokeAsync(Files[index]);
            }

            if (uploadStatus == BitFileUploadStatus.Completed)
            {
                await OnUploadComplete.InvokeAsync(Files[index]);
            }

            if (uploadStatus == BitFileUploadStatus.Removed)
            {
                await OnRemoveComplete.InvokeAsync(Files[index]);
            }

            if (uploadStatus == BitFileUploadStatus.Failed)
            {
                await OnUploadFailed.InvokeAsync(Files[index]);
            }

            if (uploadStatus == BitFileUploadStatus.RemoveFailed)
            {
                await OnRemoveFailed.InvokeAsync(Files[index]);
            }
        }
    }
Beispiel #3
0
        private void SyncUp()
        {
            var items   = _playerItemDao.GetUnsynchronizedItems();
            var batches = ToBatches(items);

            foreach (var batch in batches)
            {
                Logger.Info($"Synchronizing batch with {batch.Count} items to cloud");
                try {
                    if (_cloudSyncService.Save(batch.Select(ItemConverter.ToUpload).ToList()))
                    {
                        // TODO: Hopefully all were stored?
                        Logger.Info($"Upload successful, marking {batch.Count} as synchronized");
                        _playerItemDao.SetAsSynchronized(batch);
                    }
                    else
                    {
                        Logger.Warn($"Upload of {batch.Count} items unsuccessful");
                    }
                }
                catch (AggregateException ex) {
                    Logger.Warn(ex.Message, ex);
                    return;
                }
                catch (WebException ex) {
                    Logger.Warn(ex.Message, ex);
                    return;
                }
                catch (Exception ex) {
                    ExceptionReporter.ReportException(ex, "SyncUp");
                    return;
                }
            }

            Logger.Info($"Upload complete ({items.Count} items)");
            OnUploadComplete?.Invoke(this, null);
        }