Пример #1
0
        public void Export(Repository repository, string baseFolder, string[] folders, string[] docs, Stream outputStream)
        {
            ZipFile zipFile    = new ZipFile();
            var     basePrefix = StorageNamesEncoder.EncodeContainerName(repository.Name) + "/" + MediaBlobHelper.MediaDirectoryName + "/";

            if (!string.IsNullOrEmpty(baseFolder))
            {
                var baseMediaFolder = ServiceFactory.MediaFolderManager.Get(repository, baseFolder);
                basePrefix = baseMediaFolder.GetMediaFolderItemPath(null) + "/";
            }

            var blobClient = CloudStorageAccountHelper.GetStorageAccount().CreateCloudBlobClient();

            //add file
            if (docs != null)
            {
                foreach (var doc in docs)
                {
                    var blob = blobClient.GetBlockBlobReference(basePrefix + StorageNamesEncoder.EncodeBlobName(doc));

                    var bytes = blob.DownloadByteArray();
                    zipFile.AddEntry(doc, bytes);
                }
            }
            //add folders
            if (folders != null)
            {
                foreach (var folder in folders)
                {
                    var folderName = folder.Split('~').LastOrDefault();
                    zipFolder(blobClient, basePrefix, folderName, "", ref zipFile);
                }
            }
            zipFile.Save(outputStream);
        }
Пример #2
0
        public static void DeleteRepositoryContainer(Repository repository)
        {
            var blobClient = CloudStorageAccountHelper.GetStorageAccount().CreateCloudBlobClient();

            var container = blobClient.GetContainerReference(StorageNamesEncoder.EncodeContainerName(repository.Name));

            container.Delete();
        }
Пример #3
0
        public static string GetTextContentDirectoryPath(this TextContent textContent)
        {
            var textFolder = textContent.GetFolder();

            return(UrlUtility.Combine(new string[] { StorageNamesEncoder.EncodeContainerName(textFolder.Repository.Name), TextContentFileDirectoryName }
                                      .Concat(textFolder.NamePaths.Select(it => StorageNamesEncoder.EncodeBlobName(it)))
                                      .Concat(new[] { StorageNamesEncoder.EncodeBlobName(textContent.UUID) })
                                      .ToArray()));
        }
Пример #4
0
        public static CloudBlobContainer InitializeRepositoryContainer(Repository repository)
        {
            var blobClient = CloudStorageAccountHelper.GetStorageAccount().CreateCloudBlobClient();

            var container = blobClient.GetContainerReference(StorageNamesEncoder.EncodeContainerName(repository.Name));

            var created = container.CreateIfNotExist();

            if (created)
            {
                container.SetPermissions(new BlobContainerPermissions()
                {
                    PublicAccess = BlobContainerPublicAccessType.Blob
                });
            }

            return(container);
        }
Пример #5
0
 public static string GetMediaDirectoryPath(this MediaFolder mediaFolder)
 {
     return(UrlUtility.Combine(new string[] { StorageNamesEncoder.EncodeContainerName(mediaFolder.Repository.Name), MediaDirectoryName }
                               .Concat(mediaFolder.NamePaths)
                               .ToArray()));
 }