コード例 #1
0
ファイル: MediaSync.cs プロジェクト: daltekkie/Emby.ApiClient
        public async Task Sync(IApiClient apiClient,
            ServerInfo serverInfo,
            IProgress<double> progress,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            _logger.Debug("Beginning media sync process with server Id: {0}", serverInfo.Id);

            // First report actions to the server that occurred while offline
            await ReportOfflineActions(apiClient, serverInfo, cancellationToken).ConfigureAwait(false);
            progress.Report(1);

            await SyncData(apiClient, serverInfo, false, cancellationToken).ConfigureAwait(false);
            progress.Report(3);

            var innerProgress = new DoubleProgress();
            innerProgress.RegisterAction(pct =>
            {
                var totalProgress = pct * .97;
                totalProgress += 1;
                progress.Report(totalProgress);
            });

            await GetNewMedia(apiClient, serverInfo, innerProgress, cancellationToken);
            progress.Report(100);

            // Do the data sync twice so the server knows what was removed from the device
            await SyncData(apiClient, serverInfo, true, cancellationToken).ConfigureAwait(false);
        }
コード例 #2
0
ファイル: MediaSync.cs プロジェクト: daltekkie/Emby.ApiClient
        private async Task GetNewMedia(IApiClient apiClient,
            ServerInfo server,
            IProgress<double> progress,
            CancellationToken cancellationToken)
        {
            var jobItems = await apiClient.GetReadySyncItems(apiClient.DeviceId).ConfigureAwait(false);

            var numComplete = 0;
            double startingPercent = 0;
            double percentPerItem = 1;
            if (jobItems.Count > 0)
            {
                percentPerItem /= jobItems.Count;
            }

            foreach (var jobItem in jobItems)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var currentPercent = startingPercent;
                var innerProgress = new DoubleProgress();
                innerProgress.RegisterAction(pct =>
                {
                    var totalProgress = pct * percentPerItem;
                    totalProgress += currentPercent;
                    progress.Report(totalProgress);
                });

                try
                {
                    await GetItem(apiClient, server, jobItem, innerProgress, cancellationToken).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error syncing new media", ex);
                }

                numComplete++;
                startingPercent = numComplete;
                startingPercent /= jobItems.Count;
                startingPercent *= 100;
                progress.Report(startingPercent);
            }
        }
コード例 #3
0
        private async Task Sync(List<ServerInfo> servers, bool syncOnlyOnLocalNetwork, IProgress<double> progress, CancellationToken cancellationToken = default(CancellationToken))
        {
            var numComplete = 0;
            double startingPercent = 0;
            double percentPerServer = 1;
            if (servers.Count > 0)
            {
                percentPerServer /= servers.Count;
            }

            _logger.Debug("Beginning MultiServerSync with {0} servers", servers.Count);

            foreach (var server in servers)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var currentPercent = startingPercent;
                var serverProgress = new DoubleProgress();
                serverProgress.RegisterAction(pct =>
                {
                    var totalProgress = pct * percentPerServer;
                    totalProgress += currentPercent;
                    progress.Report(totalProgress);
                });

                // Grab the latest info from the connection manager about that server
                var serverInfo = await _connectionManager.GetServerInfo(server.Id).ConfigureAwait(false);

                if (serverInfo == null)
                {
                    serverInfo = server;
                }

                if (syncOnlyOnLocalNetwork)
                {
                    var result = await _connectionManager.Connect(server, new ConnectionOptions
                    {
                        EnableWebSocket = false,
                        ReportCapabilities = false,
                        UpdateDateLastAccessed = false

                    }, cancellationToken).ConfigureAwait(false);

                    var apiClient = result.ApiClient;

                    var endpointInfo = await apiClient.GetEndPointInfo(cancellationToken).ConfigureAwait(false);

                    _logger.Debug("Server: {0}, Id: {1}, IsInNetwork:{2}", server.Name, server.Id, endpointInfo.IsInNetwork);

                    if (!endpointInfo.IsInNetwork)
                    {
                        continue;
                    }
                }

                await new ServerSync(_connectionManager, _logger, _localAssetManager, _fileTransferManager, _connectionManager.ClientCapabilities)
                    .Sync(serverInfo, serverProgress, cancellationToken).ConfigureAwait(false);

                numComplete++;
                startingPercent = numComplete;
                startingPercent /= servers.Count;
                startingPercent *= 100;
                progress.Report(startingPercent);
            }

            progress.Report(100);
        }
コード例 #4
0
        private async Task SyncInternal(ServerInfo server, IApiClient apiClient, IProgress<double> progress, CancellationToken cancellationToken)
        {
            const double cameraUploadTotalPercentage = .25;

            var uploadProgress = new DoubleProgress();
            uploadProgress.RegisterAction(p => progress.Report(p * cameraUploadTotalPercentage));
            await new ContentUploader(apiClient, _logger)
                .UploadImages(uploadProgress, cancellationToken).ConfigureAwait(false);

            if (_clientCapabilities.SupportsOfflineAccess)
            {
                await new OfflineUserSync(_localAssetManager, _logger)
                    .UpdateOfflineUsers(server, apiClient, cancellationToken).ConfigureAwait(false);
            }

            var syncProgress = new DoubleProgress();
            syncProgress.RegisterAction(p => progress.Report((cameraUploadTotalPercentage * 100) + (p * (1 - cameraUploadTotalPercentage))));

            await new MediaSync(_localAssetManager, _logger, _fileTransferManager)
                .Sync(apiClient, server, uploadProgress, cancellationToken).ConfigureAwait(false);
        }
コード例 #5
0
ファイル: MediaSync.cs プロジェクト: daltekkie/Emby.ApiClient
        private async Task GetItem(IApiClient apiClient,
            ServerInfo server,
            SyncedItem jobItem,
            IProgress<double> progress,
            CancellationToken cancellationToken)
        {
            var libraryItem = jobItem.Item;

            var localItem = _localAssetManager.CreateLocalItem(libraryItem, server, jobItem.SyncJobItemId, jobItem.OriginalFileName);

            // Create db record
            await _localAssetManager.AddOrUpdate(localItem).ConfigureAwait(false);

            var fileTransferProgress = new DoubleProgress();
            fileTransferProgress.RegisterAction(pct => progress.Report(pct * .92));

            // Download item file
            await _fileTransferManager.GetItemFileAsync(apiClient, server, localItem, jobItem.SyncJobItemId, fileTransferProgress, cancellationToken).ConfigureAwait(false);
            progress.Report(92);

            // Download images
            await GetItemImages(apiClient, localItem, cancellationToken).ConfigureAwait(false);
            progress.Report(95);

            // Download subtitles
            await GetItemSubtitles(apiClient, jobItem, localItem, cancellationToken).ConfigureAwait(false);
            progress.Report(99);

            // Let the server know it was successfully downloaded
            await apiClient.ReportSyncJobItemTransferred(jobItem.SyncJobItemId).ConfigureAwait(false);
            progress.Report(100);
        }