Esempio n. 1
0
 private static bool TryLookupUrl(UrlType urlType, out string url)
 {
     url = null;
     // Once the internet has been found missing, don't bother trying it again for the duration of the program.
     if (!_internetAvailable)
     {
         return(false);
     }
     try
     {
         using (var s3Client = new BloomS3Client(null))
         {
             s3Client.Timeout          = TimeSpan.FromMilliseconds(2500.0);
             s3Client.ReadWriteTimeout = TimeSpan.FromMilliseconds(3000.0);
             s3Client.MaxErrorRetry    = 1;
             var  jsonContent = s3Client.DownloadFile(BloomS3Client.BloomDesktopFiles, kUrlLookupFileName);
             Urls urls        = JsonConvert.DeserializeObject <Urls>(jsonContent);
             url = urls.GetUrlById(urlType.ToJsonPropertyString());
             if (!string.IsNullOrWhiteSpace(url))
             {
                 return(true);
             }
             Logger.WriteEvent("Unable to look up URL type " + urlType);
         }
     }
     catch (Exception e)
     {
         _internetAvailable = false;
         Logger.WriteEvent("Exception while attempting look up of URL type " + urlType + ": " + e);
     }
     return(false);
 }
        public void Setup()
        {
            _workFolder = new TemporaryFolder("unittest");
            var workFolderPath = _workFolder.FolderPath;

            Assert.AreEqual(0, Directory.GetDirectories(workFolderPath).Count(), "Some stuff was left over from a previous test");
            Assert.AreEqual(0, Directory.GetFiles(workFolderPath).Count(), "Some stuff was left over from a previous test");

            _client = new BloomS3Client(BloomS3Client.UnitTestBucketName);
        }
Esempio n. 3
0
 private static bool TryGetUrlDataFromServer()
 {
     // Once the internet has been found missing, don't bother trying it again for the duration of the program.
     // And if we got the data once, it's very unlikely we'll get something new by trying again.
     if (!_internetAvailable || _gotJsonFromServer)
     {
         return(false);
     }
     // It's pathologically possible that two threads at about the same time come here and both send
     // the query. If so, no great harm done...they'll both put the same values into the dictionary.
     // And in practice, it won't happen...one call to this, and only one, happens very early in
     // Bloom's startup code, and after that _gotJsonFromServer will be true.
     // I don't think it's worth the effort to set up locks and guarantee that only on thread
     // sends the request.
     try
     {
         using (var s3Client = new BloomS3Client(null))
         {
             s3Client.Timeout          = TimeSpan.FromMilliseconds(2500.0);
             s3Client.ReadWriteTimeout = TimeSpan.FromMilliseconds(3000.0);
             s3Client.MaxErrorRetry    = 1;
             var  jsonContent = s3Client.DownloadFile(BloomS3Client.BloomDesktopFiles, kUrlLookupFileName);
             Urls urls        = JsonConvert.DeserializeObject <Urls>(jsonContent);
             // cache them all, so we don't have to repeat the server request.
             foreach (UrlType urlType in Enum.GetValues(typeof(UrlType)))
             {
                 var url = urls.GetUrlById(urlType.ToJsonPropertyString());
                 if (!string.IsNullOrWhiteSpace(url))
                 {
                     s_liveUrlCache.AddOrUpdate(urlType, url, (type, s) => s);
                 }
             }
             // Do this only after we populated the dictionary; we definitely don't want
             // another thread to return false because it thinks things are already loaded
             // when the value it wanted isn't in the dictionary.
             _gotJsonFromServer = true;
             return(true);                    // we did the retrieval, it's worth checking the dictionary again.
         }
     }
     catch (Exception e)
     {
         _internetAvailable = false;
         var msg = $"Exception while attempting get URL data from server";
         Logger.WriteEvent($"{msg}: {e.Message}");
         NonFatalProblem.ReportSentryOnly(e, msg);
     }
     return(false);
 }
Esempio n. 4
0
        static int Main(string[] arguments)
        {
            if (arguments.Length != 1)
            {
                Console.WriteLine("Usage: BloomBookDownloader keyOnAmazonS3");
                return(1);
            }

            var t = new BloomS3Client(BloomS3Client.SandboxBucketName);

            var destinationPath = Path.Combine(Path.GetTempPath(), "BloomBookDownloader");

            if (!Directory.Exists(destinationPath))
            {
                Directory.CreateDirectory(destinationPath);
            }

            t.DownloadBook(arguments[0], destinationPath);

            return(0);
        }
        public void SetupFixture()
        {
            // Basic setup
            _workFolder = new TemporaryFolder("unittest2");
            var workFolderPath = _workFolder.FolderPath;

            Assert.AreEqual(0, Directory.GetDirectories(workFolderPath).Count(), "Some stuff was left over from a previous test");

            _client = new BloomS3Client(BloomS3Client.UnitTestBucketName);

            // Now do standard upload/download. We save time by making this whole class do one upload/download sequence
            // on the assumption that things that should be uploaded were if they make it through the download process too.
            // Individual tests just compare what was uploaded with what came back through the download.
            // If we want to upload and download to separate (collection) folders, we need another layer for the actual book

            _storageKeyOfBookFolder = Guid.NewGuid().ToString();

            // First create folder to upload from
            var unittestGuid = Guid.NewGuid();
            var srcFolder    = new TemporaryFolder(_workFolder, "unittest-src-" + unittestGuid);

            _srcCollectionPath = srcFolder.FolderPath;

            // Then create standard book
            var book = MakeBookIncludingThumbs(srcFolder);

            // Upload standard book
            UploadBook(book);

            // Create folder to download to
            var destFolder = new TemporaryFolder(_workFolder, "unittest-dest-" + unittestGuid);

            _destCollectionPath = destFolder.FolderPath;

            // Download standard book
            DownloadBook();
        }
 public void AvoidThisFile_ShouldNotAvoid(string objectKey)
 {
     Assert.False(BloomS3Client.AvoidThisFile(objectKey));
 }
 internal HarvesterBookTransfer(BloomParseClient parseClient, BloomS3Client bloomS3Client, BookThumbNailer htmlThumbnailer)
     : base(parseClient, bloomS3Client, htmlThumbnailer, new Bloom.BookDownloadStartingEvent())
 {
 }