Esempio n. 1
0
        public bool Execute()
        {
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Downloading blobs (press ESC to cancel)...");
            Console.ResetColor();
            Console.WriteLine();

            var blobs     = (new ListBlobsHelper(this.listing)).ListBlobsFromArgs();
            var cts       = new CancellationTokenSource();
            var completed = false;

            if (string.IsNullOrEmpty(ArgSettings.SourceConnection))
            {
                ArgSettings.SourceConnection = "UseDevelopmentStorage=true";
            }

            var task = Task.Factory.StartNew(() =>
            {
                downloader.DownloadFiles(string.Empty,
                                         blobs,
                                         ArgSettings.Destination,
                                         ArgSettings.SourceConnection,
                                         cts.Token,
                                         (f) =>
                {
                    Console.WriteLine(f);
                },
                                         (f, e) =>
                {
                    Console.Error.WriteLine("Failed to download {0}: {1}", f, e.ToString());
                },
                                         () =>
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine();
                    Console.WriteLine("Finished downloading files.");
                    Console.ResetColor();
                    completed = true;
                });
            }, cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);

            while (!completed)
            {
                if (ArgumentsHelper.IsKeyAvailable())
                {
                    if (Console.ReadKey(true).Key == ConsoleKey.Escape)
                    {
                        cts.Cancel();
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine("Cancelled!");
                        Console.ResetColor();

                        return(false);
                    }
                }
            }

            return(true);
        }