private void SaveDownloadingFile(IDownloadingFile result)
        {
            _downloadingFiles.Add(result);
            ArddFilePaths.Add(result.ArddFilePath);

            result.DownloadInfo.Subscribe(_ => { }, OnCompleted);
            Subscribe(result.DownloadInfo.Where(item => item.Status == TransferStatus.Suspended || item.Status == TransferStatus.Faulted));
            Subscribe(result.DownloadInfo.Sample(TimeSpan.FromMilliseconds(5000)));

            File.WriteAllText(result.ArddFilePath, result.ToJsonString());

            if (result.DownloadInfo.Status == TransferStatus.Completed)
            {
                OnCompleted();
            }

            void Subscribe(IObservable <TransferNotification> observable)
            {
                observable.Subscribe(_ => File.WriteAllText(result.ArddFilePath, result.ToJsonString()));
            }

            void OnCompleted()
            {
                if (File.Exists(result.ArddFilePath))
                {
                    File.Delete(result.ArddFilePath);
                }
                ArddFilePaths.Remove(result.ArddFilePath);

                var localDiskFile = LocalDiskFile.Create(result);

                _downloadingFiles.Remove(result);
                _localDiskFiles.Add(localDiskFile);
            }
        }
        private void SaveDownloadingFile(IDownloadingFile result)
        {
            _downloadingFiles.Add(result);
            ArddFilePaths.Add(result.ArddFilePath);

            var disposable1 = Subscribe(result.DownloadInfo.Where(item => item.Status == TransferStatus.Suspended || item.Status == TransferStatus.Faulted));
            var disposable2 = Subscribe(result.DownloadInfo.Sample(TimeSpan.FromMilliseconds(5000)));

            result.DownloadInfo
            .Where(item => item.Status == TransferStatus.Disposed)
            .Subscribe(async _ =>
            {
                await ClearDownloadInfo(true);

                Logger.Info($"Download Cancelled: {result.DownloadInfo.Context.LocalPath}. ");
            }, OnCompleted);

            File.WriteAllText(result.ArddFilePath.EnsureFileFolder(), result.ToJsonString());

            if (result.DownloadInfo.Status == TransferStatus.Completed)
            {
                OnCompleted();
            }

            async void OnCompleted()
            {
                await ClearDownloadInfo(false);

                var localDiskFile = LocalDiskFile.Create(result);

                _localDiskFiles.Add(localDiskFile);

                Logger.Info($"Download Completed: {result.DownloadInfo.Context.LocalPath}. ");
            }

            IDisposable Subscribe(IObservable <TransferNotification> observable)
            {
                return(observable.Subscribe(_ => File.WriteAllText(result.ArddFilePath, result.ToJsonString())));
            }

            async Task ClearDownloadInfo(bool isCancelled)
            {
                disposable1.Dispose();
                disposable2.Dispose();

                ArddFilePaths.Remove(result.ArddFilePath);
                _downloadingFiles.Remove(result);

                await result.ArddFilePath.TryDeleteAsync();

                if (isCancelled)
                {
                    await result.DownloadInfo.Context.LocalPath.TryDeleteAsync();
                }
            }
        }