void DownloadProgressUpdate(object sender, ProgressEventArgs e)
 {
     lock (MessageSyncLock)
     {
         ISyncItem syncItem = e.UserState as ISyncItem;
         if (e.ProgressPercentage % 10 == 0)
         {
             // only do every 10%
             var line = string.Format("{0} ({1} of {2}) {3}%", syncItem.EpisodeTitle,
                                      DisplayFormatter.RenderFileSize(e.ItemsProcessed),
                                      DisplayFormatter.RenderFileSize(e.TotalItemsToProcess),
                                      e.ProgressPercentage);
             Logger.Debug(() => line);
             MessageStore.StoreMessage(syncItem.Id, line);
             if (e.ProgressPercentage == 100)
             {
                 AnalyticsEngine.DownloadEpisodeEvent(ByteConverter.BytesToMegabytes(e.TotalItemsToProcess));
             }
             Observables.UpdateItemProgress?.Invoke(this, Tuple.Create(syncItem, e.ProgressPercentage));
         }
         var controlFile = ApplicationControlFileProvider.GetApplicationConfiguration();
         if (IsDestinationDriveFull(controlFile.GetSourceRoot(), controlFile.GetFreeSpaceToLeaveOnDownload()))
         {
             TaskPool?.CancelAllTasks();
         }
     }
 }
        private void AddFileSystem(string absolutePath)
        {
            long freeBytes  = FileSystemHelper.GetAvailableFileSystemSizeInBytes(absolutePath);
            long totalBytes = FileSystemHelper.GetTotalFileSystemSizeInBytes(absolutePath);
            long usedBytes  = totalBytes - freeBytes;

            string[] freeSize  = DisplayFormatter.RenderFileSize(freeBytes).Split(' ');
            string[] totalSize = DisplayFormatter.RenderFileSize(totalBytes).Split(' ');

            var view = DriveVolumeInfoViewFactory.GetNewView(ApplicationContext);

            view.Title = ConvertPathToTitle(absolutePath);
            view.SetSpace(
                Convert.ToInt32(ByteConverter.BytesToMegabytes(usedBytes)),
                Convert.ToInt32(ByteConverter.BytesToMegabytes(totalBytes)),
                freeSize[0], freeSize[1],
                totalSize[0], totalSize[1]);

            Observables?.AddInfoView?.Invoke(this, view.GetView());
        }
Exemple #3
0
        private bool IsDestinationDriveFull(string root, long freeSpaceToLeaveInMb)
        {
            var freeMb = ByteConverter.BytesToMegabytes(FileSystemHelper.GetAvailableFileSystemSizeInBytes(root));

            if (freeMb < freeSpaceToLeaveInMb)
            {
                var message = string.Format("Destination drive is full leaving {0:#,0.##} MB free", freeMb);
                Observables.DisplayMessage?.Invoke(this, message);
                Logger.Debug(() => message);
                return(true);
            }
            return(false);
        }