Ejemplo n.º 1
0
        public override void Move(string sourceDirName, string destDirName)
        {
            var sourceDirPath = AzurePathHelper.GetBlobPath(sourceDirName);
            var destDirPath   = AzurePathHelper.GetBlobPath(destDirName);

            // if web farms are enabled, reinitialize source and destination folder to see if another web farm server has already moved the files
            if (SynchronizationHelper.Synchronizing())
            {
                BlobDirectoryCollection.Instance.GetOrCreate(sourceDirPath).Reinitialize();
                BlobDirectoryCollection.Instance.GetOrCreate(destDirPath).Reinitialize();
            }

            var sourceDirBlobs = Get(sourceDirName).GetBlobs(false);

            foreach (var blob in sourceDirBlobs)
            {
                blob.Move(destDirPath + "/" + blob.Path.Substring(sourceDirPath.Length + 1));
            }


            // we have to do this on file system too because of Dirs :(
            if (System.IO.Directory.Exists(sourceDirName))
            {
                System.IO.Directory.Move(sourceDirName, destDirName);
            }
        }
        public void DoesNotFailForInvalidDateFormat()
        {
            var appPath = AzurePathHelper.CurrentDirectory;
            var file    = new FileInfo(appPath + "\\FileInfoTests\\DoesNotFailForInvalidDateFormat\\test.txt");

            using (var writer = file.CreateText())
            {
                writer.Write("This is test");
            }

            file = new FileInfo(appPath + "\\FileInfoTests\\DoesNotFailForInvalidDateFormat\\test.txt");
            Assert.LessOrEqual(file.CreationTime, DateTime.UtcNow);

            BlobCollection.Instance.GetOrCreate(AzurePathHelper.GetBlobPath(appPath + "\\FileInfoTests\\DoesNotFailForInvalidDateFormat\\test.txt"))
            .SetMetadataAttributeAndSave(BlobMetadataEnum.DateCreated, "invalid date");

            Assert.AreEqual(file.CreationTime, DateTime.MinValue);
        }
        public void DoesNotGetsBlobCaseInvariantIfAlreadyExistsInBlob()
        {
            var temp = AzurePathHelper.ForceLowercase;

            AzurePathHelper.ForceLowercase = false;

            var appPath = AzurePathHelper.CurrentDirectory;
            var file    = new FileInfo(appPath + "\\GetsBlobCaseInvariantIfAlreadyExistsInBlob\\First.txt");

            using (var writer = file.CreateText())
            {
                writer.Write("This is test");
            }
            BlobCollection.Instance.GetOrCreate(AzurePathHelper.GetBlobPath(appPath + "\\GetsBlobCaseInvariantIfAlreadyExistsInBlob\\First.txt")).Uninitialize();

            AzurePathHelper.ForceLowercase = true;

            Assert.IsFalse(new FileInfo(appPath + "\\getsblobcaseinvariantifalreadyexistsinblob\\first.txt").Exists);

            AzurePathHelper.ForceLowercase = temp;
        }
        public void GetsBlobCaseInvariant()
        {
            var temp = AzurePathHelper.ForceLowercase;

            AzurePathHelper.ForceLowercase = true;

            var appPath = AzurePathHelper.CurrentDirectory;
            var file    = new FileInfo(appPath + "\\GetsBlobCaseInvariant\\First.txt");

            using (var writer = file.CreateText())
            {
                writer.Write("This is test");
            }

            // to make sure we will get hit in BLOB storage
            BlobCollection.Instance.GetOrCreate(AzurePathHelper.GetBlobPath(appPath + "\\GetsBlobCaseInvariant\\First.txt")).Uninitialize();

            Assert.IsTrue(new FileInfo(appPath + "\\geTSblobcaseiNVARiant\\first.txt").Exists);

            AzurePathHelper.ForceLowercase = temp;
        }
        public void InitializesBlobAsLowercase()
        {
            var temp = AzurePathHelper.ForceLowercase;

            AzurePathHelper.ForceLowercase = false;

            var appPath = AzurePathHelper.CurrentDirectory;
            var file    = new FileInfo(appPath + "\\initializesblobaslowercase\\TEST.txt");

            using (var writer = file.CreateText())
            {
                writer.Write("This is test");
            }
            BlobCollection.Instance.GetOrCreate(AzurePathHelper.GetBlobPath(appPath + "\\initializesblobaslowercase\\TEST.txt")).Uninitialize();

            AzurePathHelper.ForceLowercase = true;
            var files = BlobDirectoryCollection.Instance.GetOrCreate(AzurePathHelper.GetBlobPath(appPath + "\\initializesblobaslowercase")).GetBlobs(false);

            Assert.AreEqual(1, files.Count());
            Assert.AreEqual("test.txt", System.IO.Path.GetFileName(files.Single().Path));

            AzurePathHelper.ForceLowercase = temp;
        }
Ejemplo n.º 6
0
 private Blob Get(string path)
 {
     return(BlobCollection.Instance.GetOrCreate(AzurePathHelper.GetBlobPath(path)));
 }
        public void TranslatesPathsToBlob()
        {
            var path = AzurePathHelper.CurrentDirectory + "\\test.txt";

            Assert.AreEqual("test.txt", AzurePathHelper.GetBlobPath(path));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Copies an existing file to a new file. Overwriting a file of the same name is allowed.
 /// </summary>
 /// <param name="sourceFileName">Path to source file.</param>
 /// <param name="destFileName">Path to destination file.</param>
 /// <param name="overwrite">If destination file should be overwritten.</param>
 public override void Copy(string sourceFileName, string destFileName, bool overwrite)
 {
     Get(sourceFileName).Copy(AzurePathHelper.GetBlobPath(destFileName), overwrite);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Moves a specified file to a new location, providing the option to specify a new file name.
 /// </summary>
 /// <param name="sourceFileName">Source file name.</param>
 /// <param name="destFileName">Destination file name.</param>
 public override void Move(string sourceFileName, string destFileName)
 {
     Get(sourceFileName).Move(AzurePathHelper.GetBlobPath(destFileName));
 }
        protected override void ProcessRequestInternal(HttpContextBase context)
        {
            var hash = QueryHelper.GetString("hash", string.Empty);
            var path = QueryHelper.GetString("path", string.Empty);

            // Validate hash
            var settings = new HashSettings
            {
                Redirect = false
            };

            if (!ValidationHelper.ValidateHash("?path=" + URLHelper.EscapeSpecialCharacters(path), hash, settings))
            {
                RequestHelper.Respond403();
            }

            if (path.StartsWithCSafe("~"))
            {
                path = context.Server.MapPath(path);
            }

            var blobPath = AzurePathHelper.GetBlobPath(path);
            var blob     = BlobCollection.Instance.GetOrCreate(blobPath);

            if (!blob.Exists())
            {
                RequestHelper.Respond404();
            }

            CookieHelper.ClearResponseCookies();
            Response.Clear();

            SetRevalidation();

            var eTag         = blob.GetAttribute(a => a.Etag);
            var lastModified = ValidationHelper.GetDateTime(blob.GetAttribute(a => a.LastModified), DateTimeHelper.ZERO_TIME);

            SetResponseContentType(path);

            // Client caching - only on the live site
            if (AllowCache && AllowClientCache && ETagsMatch(eTag, lastModified))
            {
                // Set the file time stamps to allow client caching
                SetTimeStamps(lastModified);

                RespondNotModified(eTag);
                return;
            }

            SetDisposition(Path.GetFileName(path), Path.GetExtension(path));

            // Setup Etag property
            ETag = eTag;

            if (AllowCache)
            {
                // Set the file time stamps to allow client caching
                SetTimeStamps(lastModified);
                Response.Cache.SetETag(eTag);
            }
            else
            {
                SetCacheability();
            }

            WriteFile(path, CacheHelper.CacheImageAllowed(CurrentSiteName, Convert.ToInt32(blob.GetAttribute(a => a.Length))));

            CompleteRequest();
        }