예제 #1
0
        /// <summary>
        /// Main entry point
        /// </summary>
        /// <param name="args">Arguments to be passed to the application</param>
        public static void Main(string[] args)
        {
            try
            {
                Downloader.ProgressUpdateEvent += Print;
                string retry;
                do
                {
                    Print("How many parallel downloads do you want to execute?");
                    int            numOfParallelDownloads = int.Parse(Console.ReadLine());
                    DownloadResult result = Downloader.Download(ConfigurationManager.AppSettings["fileUrl"], ConfigurationManager.AppSettings["downloadLocation"], numOfParallelDownloads);

                    Print($"Download Summary:\n FileSize: {DisplayFormatHelper.FormatSize(result.Size)}\n Number of chunks: {numOfParallelDownloads}" +
                          $"\n Chunk size: {DisplayFormatHelper.FormatSize(result.ChunkSize)}\n Time taken : {DisplayFormatHelper.TimeSpanDisplayFormat(result.TimeTaken)} \n Downloaded File: {result.FilePath}");

                    Print("Try again? (Y/N)");
                    retry = Console.ReadLine();
                }while (!string.IsNullOrWhiteSpace(retry) && retry.ToLower() == "y");
            }
            catch (FriendlyException ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.Read();
        }
예제 #2
0
        private static void UpdateProgress(long chunkSize, TimeSpan chunkTime, TimeSpan totalTime, long total, int parallelDownloads)
        {
            if (ProgressUpdateEvent == null)
            {
                return;
            }
            StringBuilder sb = new StringBuilder();

            //Given the size of the chunk just downloaded and the chunks remaining, calculate the time remaining for the download to complete.
            sb.Append($"{downloadedChunks * 100 / total}% - Speed {DisplayFormatHelper.FormatSize((long)(chunkSize / chunkTime.TotalSeconds))}ps");
            if (total > downloadedChunks)
            {
                //Assuming all the downloads start at relatively the same time ((total - downloadedChunks) * chunkTime.Ticks) - chunkTime.Ticks))
                sb.Append($" - Estimated time remaining {DisplayFormatHelper.TimeSpanDisplayFormat((long)((total - downloadedChunks) * chunkTime.Ticks) - chunkTime.Ticks)}");
            }
            ProgressUpdateEvent(sb.ToString());
        }