Exemple #1
0
        public void FileBlobTests_FailedWrite()
        {
            var      testFile = new FileInfo(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
            FileBlob blob     = new FileBlob(testFile.FullName);

            Assert.Null(blob.Write(null));
        }
Exemple #2
0
        public void FileBlobTests_LeaseAfterDelete()
        {
            var             testFile = new FileInfo(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
            IPersistentBlob blob     = new FileBlob(testFile.FullName);

            var data = Encoding.UTF8.GetBytes("Hello, World!");

            blob.Write(data);
            blob.Delete();

            // Lease should return null
            Assert.Null(blob.Lease(1000));
        }
Exemple #3
0
        public void FileBlobTests_Lease()
        {
            var             testFile = new FileInfo(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
            IPersistentBlob blob     = new FileBlob(testFile.FullName);

            var             data = Encoding.UTF8.GetBytes("Hello, World!");
            var             leasePeriodMilliseconds = 1000;
            IPersistentBlob blob1      = blob.Write(data);
            IPersistentBlob leasedBlob = blob1.Lease(leasePeriodMilliseconds);

            Assert.Contains(".lock", ((FileBlob)leasedBlob).FullPath);

            blob1.Delete();
            Assert.False(testFile.Exists);
        }
Exemple #4
0
        public void FileBlobTests_E2E_Test()
        {
            var             testFile = new FileInfo(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
            IPersistentBlob blob     = new FileBlob(testFile.FullName);

            var             data        = Encoding.UTF8.GetBytes("Hello, World!");
            IPersistentBlob blob1       = blob.Write(data);
            var             blobContent = blob.Read();

            Assert.Equal(testFile.FullName, ((FileBlob)blob1).FullPath);
            Assert.Equal(data, blobContent);

            blob1.Delete();
            Assert.False(testFile.Exists);
        }
        private async void DownloadAndSave(FileBlob blob, string rawurl)
        {
            var response = await _httpClient.GetAsync(ProdUrl + rawurl);

            if (response.StatusCode == HttpStatusCode.OK
                ) //yeah, sometimes not published or deleted, or wrong url //todo: display default image? no, it may be a temporary error or internet is offline
            {
                Stream dataStream = await response.Content.ReadAsStreamAsync();

                blob.Write(dataStream); //thats it
                Logger.Debug("BlobFile downloaded: " + ProdUrl + rawurl);
            }
            else
            {
                Logger.Error("BlobFile could not be downloaded: " + ProdUrl + rawurl);
            }
        }
Exemple #6
0
        public void FileBlobTests_LeaseFailsOnAlreadyLeasedFileByOtherObject()
        {
            var      testFile = new FileInfo(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
            FileBlob blob1    = new FileBlob(testFile.FullName);
            FileBlob blob2    = new FileBlob(testFile.FullName);
            var      data     = Encoding.UTF8.GetBytes("Hello, World!");

            blob1.Write(data);
            var leasePeriodMilliseconds = 10000;

            // Leased by another thread/process/object
            blob2.Lease(leasePeriodMilliseconds);

            // Lease should fail as already leased
            Assert.Null(blob1.Lease(10));

            // Clean up
            blob2.Delete();
        }
Exemple #7
0
        /// <summary>
        /// Adds the image to the cache in an asynchronous manner.
        /// </summary>
        /// <param name="stream">The stream containing the image data.</param>
        /// <param name="contentType">The content type of the image.</param>
        /// <returns>
        /// The <see cref="Task"/> representing an asynchronous operation.
        /// </returns>
        public override Task AddImageToCacheAsync(Stream stream, string contentType)
        {
            //DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(CachedPath));
            //if (!directoryInfo.Exists)
            //{
            //    directoryInfo.Create();
            //}

            //using (FileStream fileStream = File.Create(CachedPath))
            //{
            //    await stream.CopyToAsync(fileStream);
            //}

            var      uri  = new Uri(string.Format("{0}://{1}/{2}/{3}", Blob.BlobUriScheme, Blob.DefaultProvider, container, cachedFilename));
            FileBlob blob = new FileBlob(uri, CachedPath);

            blob.Write(stream);

            return(Task.CompletedTask);
        }
Exemple #8
0
        public void FileBlobTests_LeaseTimeIsUpdatedWhenLeasingAlreadyLeasedFile()
        {
            var      testFile = new FileInfo(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
            FileBlob blob     = new FileBlob(testFile.FullName);
            var      data     = Encoding.UTF8.GetBytes("Hello, World!");

            blob.Write(data);

            var leasePeriodMilliseconds = 10000;

            blob.Lease(leasePeriodMilliseconds);

            var leaseTime = PersistentStorageHelper.GetDateTimeFromLeaseName(blob.FullPath);

            Assert.NotNull(blob.Lease(10000));

            var newLeaseTime = PersistentStorageHelper.GetDateTimeFromLeaseName(blob.FullPath);

            Assert.NotEqual(leaseTime, newLeaseTime);

            blob.Delete();
        }