Exemplo 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);
            }
        }
Exemplo n.º 2
0
        public void Copy(string destPath, bool overwrite)
        {
            if (SynchronizationHelper.Synchronizing())
            {
                Reinitialize();
                if (!Exists())
                {
                    return;
                }
            }

            if (!Exists())
            {
                throw new FileNotFoundException($"Blob on path {Path} does not exist.");
            }

            var targetBlob = BlobCollection.Instance.GetOrCreate(destPath);

            if (!overwrite && targetBlob.Exists())
            {
                throw new InvalidOperationException($"Target blob on path {destPath} already exists.");
            }

            // must be synchronous as we delete asynchronously in MOVE
            lock (_lock)
            {
                _cloudBlobService.Copy(Path, targetBlob.Path);
            }
            targetBlob.SetExists(true);
        }
Exemplo n.º 3
0
        public void Move(string destPath)
        {
            if (SynchronizationHelper.Synchronizing())
            {
                BlobCollection.Instance.GetOrCreate(destPath).Reinitialize();
            }

            Copy(destPath, false);
            Delete();
        }
 public void Delete(bool flat)
 {
     if (SynchronizationHelper.Synchronizing())
     {
         Reinitialize();
     }
     else
     {
         GetBlobs(flat).ToList().ForEach(b => b.Delete());
         ResetExists();
     }
 }
Exemplo n.º 5
0
        public void Delete()
        {
            if (Exists())
            {
                lock (_lock)
                {
                    if (!SynchronizationHelper.Synchronizing() || _cloudBlobService.Exists(Path))
                    {
                        _cloudBlobService.Delete(Path);
                    }

                    SetExists(false);
                    _blobCacheService.Discard(Path);

                    BlobDirectoryCollection.Instance.GetOrCreate(AzurePathHelper.GetBlobDirectory(Path)).ResetExists();
                }
            }
        }
Exemplo n.º 6
0
        public void Upload(Stream stream)
        {
            if (SynchronizationHelper.Synchronizing())
            {
                Reinitialize();
                if (Exists())
                {
                    return;
                }
            }

            IDictionary <string, string> metadata;

            lock (_lock)
            {
                var exists = ExistsInternal();

                if (!exists)
                {
                    _attributes = new BlobAttributes
                    {
                        Metadata = new Dictionary <string, string> {
                            { BlobMetadataEnum.DateCreated.ToString(), DateTime.UtcNow.ToString() }
                        }
                    };
                    metadata = _attributes.Metadata;
                }
                else
                {
                    SetMetadataAttributeInternal(BlobMetadataEnum.DateCreated, DateTime.UtcNow.ToString());
                    metadata = GetAttributeInternal(a => a.Metadata);
                }

                _attributes = _cloudBlobService.Upload(Path, metadata, stream);

                stream.Seek(0, SeekOrigin.Begin);
                _blobCacheService.Add(Path, stream, _attributes.LastModified);

                SetExists(true);
                _attributesFetched = true;
            }
        }