Beispiel #1
0
 public static int HandleSilentDownload(DownloadBookOptions options)
 {
     // This task will be all the program does. We need to do enough setup so that
     // the download code can work, then tear it down.
     Program.SetUpErrorHandling();
     try
     {
         using (var applicationContainer = new ApplicationContainer())
         {
             Program.SetUpLocalization(applicationContainer);
             Browser.SetUpXulRunner();
             Browser.XulRunnerShutdown += Program.OnXulRunnerShutdown;
             LocalizationManager.SetUILanguage(Settings.Default.UserInterfaceLanguage, false);
             var transfer = new BookTransfer(new BloomParseClient(), ProjectContext.CreateBloomS3Client(),
                                             applicationContainer.BookThumbNailer, new BookDownloadStartingEvent()) /*not hooked to anything*/;
             // Since Bloom is not a normal console app, when run from a command line, the new command prompt
             // appears at once. The extra newlines here are attempting to separate this from our output.
             Console.WriteLine("\nstarting download");
             transfer.HandleDownloadWithoutProgress(options.Url, options.DestinationPath);
             Console.WriteLine(("\ndownload complete\n"));
         }
         return(0);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
         Console.WriteLine(ex.Message);
         Console.WriteLine(ex.StackTrace);
         return(1);
     }
 }
Beispiel #2
0
        public static int Handle(UploadParameters options)
        {
            bool valid = true;

            if (String.IsNullOrWhiteSpace(options.UploadUser))
            {
                valid = String.IsNullOrWhiteSpace(options.UploadPassword);
            }
            else
            {
                valid = !String.IsNullOrWhiteSpace(options.UploadPassword);
            }
            if (!valid)
            {
                Console.WriteLine("Error: upload -u user and -p password must be used together");
                return(1);
            }
            IsUploading = true;

            // This task will be all the program does. We need to do enough setup so that
            // the upload code can work, then tear it down.
            Program.SetUpErrorHandling();
            try
            {
                using (var applicationContainer = new ApplicationContainer())
                {
                    Program.SetUpLocalization(applicationContainer);
                    Browser.SetUpXulRunner();
                    Browser.XulRunnerShutdown += Program.OnXulRunnerShutdown;
                    LocalizationManager.SetUILanguage(Settings.Default.UserInterfaceLanguage, false);
                    var transfer = new BookTransfer(new BloomParseClient(), ProjectContext.CreateBloomS3Client(),
                                                    applicationContainer.BookThumbNailer, new BookDownloadStartingEvent());

                    // Since Bloom is not a normal console app, when run from a command line, the new command prompt
                    // appears at once. The extra newlines here are attempting to separate this from our output.
                    Console.WriteLine("\nstarting upload");
                    transfer.UploadFolder(options.Path, applicationContainer, options.ExcludeNarrationAudio, options.UploadUser, options.UploadPassword, options.SingleBookshelfLevel, options.PreserveThumbnails);
                    Console.WriteLine(("\nupload complete\n"));
                }
                return(0);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                return(1);
            }
        }
        public static int Handle(UploadParameters options)
        {
            try
            {
                Console.OutputEncoding = Encoding.UTF8;
            }
            catch (Exception)
            {
                // swallow. The above throws a handle error when run in Visual Studio
            }

            IsUploading = true;
            // -u user, and <path> are all required, so they must contain strings.
            // -d destination has a default value, so it also must contain a string.
            options.Path = options.Path.TrimEnd(new[] { '/', '\\', System.IO.Path.PathSeparator });             // remove any trailing slashes
            // validate the value for the upload destination.
            options.Dest = options.Dest.ToLowerInvariant();
            switch (options.Dest)
            {
            case UploadDestination.DryRun:
            case UploadDestination.Development:
            case UploadDestination.Production:
                break;

            default:
                Console.WriteLine($"Error: if present, upload destination (-d) must be one of {UploadDestination.DryRun}, {UploadDestination.Development}, or {UploadDestination.Production}");
                return(1);
            }
            BookUpload.Destination = options.Dest;                // must be set before calling SetupErrorHandling() (or BloomParseClient constructor)

            // This task will be all the program does. We need to do enough setup so that
            // the upload code can work, then tear it down.
            Program.SetUpErrorHandling();
            try
            {
                using (var applicationContainer = new ApplicationContainer())
                {
                    Program.SetUpLocalization(applicationContainer);
                    LocalizationManager.SetUILanguage(Settings.Default.UserInterfaceLanguage, false);
                    var singleBookUploader = new BookUpload(new BloomParseClient(), ProjectContext.CreateBloomS3Client(),
                                                            applicationContainer.BookThumbNailer);
                    var uploader = new BulkUploader(singleBookUploader);


                    // Since Bloom is not a normal console app, when run from a command line, the new command prompt
                    // appears at once. The extra newlines here are attempting to separate this from our output.
                    switch (options.Dest)
                    {
                    case UploadDestination.DryRun:
                        Console.WriteLine($"\nThe following actions would happen if you set destination to '{(BookUpload.UseSandboxByDefault ? UploadDestination.Development : UploadDestination.Production)}'.");
                        break;

                    case UploadDestination.Development:
                        Console.WriteLine("\nThe upload will go to dev.bloomlibrary.org.");
                        break;

                    case UploadDestination.Production:
                        Console.WriteLine("\nThe upload will go to bloomlibrary.org.");
                        break;
                    }
                    Console.WriteLine("\nStarting upload...");
                    uploader.BulkUpload(applicationContainer, options);
                    Console.WriteLine(("\nBulk upload complete.\n"));
                }
                return(0);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                return(1);
            }
        }