Exemplo n.º 1
0
        public static ContentFolder ToContentModel(this BlobFolder blobFolder)
        {
            var retVal = new ContentFolder();

            retVal.InjectFrom(blobFolder);
            return(retVal);
        }
Exemplo n.º 2
0
        public static webModels.ThemeAssetFolder ToThemeFolderWebModel(this BlobFolder blobFolder)
        {
            var retVal = new webModels.ThemeAssetFolder();

            retVal.FolderName = blobFolder.Name;
            return(retVal);
        }
Exemplo n.º 3
0
        public static BlobFolder ToBlobModel(this ContentFolder folder)
        {
            var retVal = new BlobFolder();

            retVal.InjectFrom(folder);
            return(retVal);
        }
Exemplo n.º 4
0
 public override void CreateFolder(BlobFolder folder)
 {
     if (folder.ParentUrl.IsNullOrEmpty())
     {
         folder.Name = NormalizeUrl(folder.Name);
     }
     base.CreateFolder(folder);
 }
Exemplo n.º 5
0
        public static webModels.Theme ToThemeWebModel(this BlobFolder folder)
        {
            var retVal = new webModels.Theme();

            retVal.Name = folder.Name;
            retVal.Path = folder.Url;
            return(retVal);
        }
        public ContentFolder ToContentModel(BlobFolder blobFolder)
        {
            var result = AbstractTypeFactory <ContentFolder> .TryCreateInstance();



            return(result);
        }
        public BlobFolder ToBlobModel(BlobFolder blobFolder)
        {
            blobFolder.Name        = Name;
            blobFolder.Url         = Url;
            blobFolder.ParentUrl   = ParentUrl;
            blobFolder.RelativeUrl = RelativeUrl;

            return(blobFolder);
        }
Exemplo n.º 8
0
 static void Download(BlobFolder folder, string inputname, string outputname)
 {
     using (var input = folder.OpenRead(inputname))
     {
         using (var output = File.OpenWrite(outputname))
         {
             input.CopyTo(output);
         }
     }
 }
        public override Task CreateFolderAsync(BlobFolder folder)
        {
            if (folder == null)
            {
                throw new ArgumentNullException(nameof(folder));
            }

            if (folder.ParentUrl.IsNullOrEmpty())
            {
                folder.Name = NormalizeUrl(folder.Name);
            }
            return(base.CreateFolderAsync(folder));
        }
        public override void CreateFolder(BlobFolder folder)
        {
            if (folder == null)
            {
                throw new ArgumentNullException(nameof(folder));
            }

            if (folder.ParentUrl.IsNullOrEmpty())
            {
                folder.Name = NormalizeUrl(folder.Name);
            }
            base.CreateFolder(folder);
        }
        public void BlobFolder_Name_DashesPoliticsTaken_ShouldPass(string name)
        {
            // Arrange
            var instance = new BlobFolder
            {
                Name = name
            };

            // Act
            var result = _validator.Validate(instance);

            // Assert
            result.IsValid.Should().BeTrue();
        }
        public void BlobFolder_Name_IsEmpty_ShouldFail()
        {
            // Arrange
            var instance = new BlobFolder
            {
                Name = string.Empty
            };

            // Act
            var result = _validator.Validate(instance);

            // Assert
            result.IsValid.Should().BeFalse();
            result.Errors.Should().ContainSingle(x => x.PropertyName == "Name" && x.ErrorCode == NOT_EMPTY_VALIDATOR_ERROR_CODE);
        }
Exemplo n.º 13
0
        static int Main(string[] args)
        {
            if (args.Length == 0)
            {
                return(-1);
            }

            string storageUrl = args[0];

            var blobFolder = new BlobFolder(storageUrl);

            Loop(blobFolder);

            return(0);
        }
Exemplo n.º 14
0
        public virtual void CreateFolder(BlobFolder folder)
        {
            var path          = (folder.ParentUrl != null ? $"{folder.ParentUrl}/" : string.Empty) + folder.Name;
            var containerName = GetContainerNameFromUrl(path);
            var blobContainer = _cloudBlobClient.GetContainerReference(containerName);

            blobContainer.CreateIfNotExists(BlobContainerPublicAccessType.Blob);
            var directoryPath = GetDirectoryPathFromUrl(path);

            if (!string.IsNullOrEmpty(directoryPath))
            {
                //Need upload empty blob because azure blob storage not support direct directory creation
                blobContainer.GetBlockBlobReference(directoryPath).UploadText(string.Empty);
            }
        }
        public void BlobFolder_Name_ContainsSpecialСharacters_ShouldFail(string name)
        {
            // Arrange
            var instance = new BlobFolder
            {
                Name = name
            };

            // Act
            var result = _validator.Validate(instance);

            // Assert
            result.IsValid.Should().BeFalse();
            result.Errors.Should().ContainSingle(x => x.PropertyName == "Name" && x.ErrorMessage.Contains("specsymbols"));
        }
        public void BlobFolder_Name_DashesPoliticsViolated_ShouldFail(string name)
        {
            // Arrange
            var instance = new BlobFolder
            {
                Name = name
            };

            // Act
            var result = _validator.Validate(instance);

            // Assert
            result.IsValid.Should().BeFalse();
            result.Errors.Should().ContainSingle(x => x.PropertyName == "Name" && x.ErrorMessage.Contains("dash"));
        }
        public void BlobFolder_Name_TooLarge_ShouldFail()
        {
            // Arrange
            var instance = new BlobFolder
            {
                Name = string.Join(string.Empty, _fixture.CreateMany <char>(64))
            };

            // Act
            var result = _validator.Validate(instance);

            // Assert
            result.IsValid.Should().BeFalse();
            result.Errors.Should().ContainSingle(x => x.PropertyName == "Name" && x.ErrorCode == MAX_LENGTH_VALIDATOR_ERROR_CODE);
        }
        public void BlobFolder_Name_ContainsUpperCaseLetters_ShouldFail()
        {
            // Arrange
            var instance = new BlobFolder
            {
                Name = "BIGLETTERSNOTPASS"
            };

            // Act
            var result = _validator.Validate(instance);

            // Assert
            result.IsValid.Should().BeFalse();
            result.Errors.Should().ContainSingle(x => x.PropertyName == "Name");
        }
        public virtual async Task CreateFolderAsync(BlobFolder folder)
        {
            var path = (folder.ParentUrl != null ? folder.ParentUrl + "/" : string.Empty) + folder.Name;

            var containerName = GetContainerNameFromUrl(path);
            var blobContainer = _cloudBlobClient.GetContainerReference(containerName);
            await blobContainer.CreateIfNotExistsAsync(BlobContainerPublicAccessType.Blob, null, null);

            var directoryPath = GetDirectoryPathFromUrl(path);

            if (!string.IsNullOrEmpty(directoryPath))
            {
                //Need upload empty blob because azure blob storage not support direct directory creation
                await blobContainer.GetBlockBlobReference(directoryPath).UploadFromByteArrayAsync(new byte[0], 0, 0);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Search folders and blobs in folder
        /// </summary>
        /// <param name="folderUrl">absolute or relative path</param>
        /// <param name="keyword"></param>
        /// <returns></returns>
        public virtual BlobSearchResult Search(string folderUrl, string keyword)
        {
            var retVal = new BlobSearchResult();

            folderUrl = folderUrl ?? _basePublicUrl;

            var storageFolderPath = GetStoragePathFromUrl(folderUrl);

            ValidatePath(storageFolderPath);

            if (!Directory.Exists(storageFolderPath))
            {
                return(retVal);
            }
            var directories = String.IsNullOrEmpty(keyword) ? Directory.GetDirectories(storageFolderPath) : Directory.GetDirectories(storageFolderPath, "*" + keyword + "*", SearchOption.AllDirectories);

            foreach (var directory in directories)
            {
                var directoryInfo = new DirectoryInfo(directory);
                var folder        = new BlobFolder
                {
                    Name      = Path.GetFileName(directory),
                    Url       = GetAbsoluteUrlFromPath(directory),
                    ParentUrl = GetAbsoluteUrlFromPath(directoryInfo.Parent.FullName)
                };
                folder.RelativeUrl = GetRelativeUrl(folder.Url);
                retVal.Folders.Add(folder);
            }

            var files = String.IsNullOrEmpty(keyword) ? Directory.GetFiles(storageFolderPath) : Directory.GetFiles(storageFolderPath, "*" + keyword + "*.*", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                var fileInfo = new FileInfo(file);
                var blobInfo = new BlobInfo
                {
                    Url          = GetAbsoluteUrlFromPath(file),
                    ContentType  = MimeTypeResolver.ResolveContentType(fileInfo.Name),
                    Size         = fileInfo.Length,
                    FileName     = fileInfo.Name,
                    ModifiedDate = fileInfo.LastWriteTimeUtc
                };
                blobInfo.RelativeUrl = GetRelativeUrl(blobInfo.Url);
                retVal.Items.Add(blobInfo);
            }
            return(retVal);
        }
Exemplo n.º 21
0
        public async Task <ActionResult> CreateBlobFolderAsync([FromBody] BlobFolder folder)
        {
            var validation = new BlobFolderValidator().Validate(folder);

            if (!validation.IsValid)
            {
                return(BadRequest(new
                {
                    Message = string.Join(" ", validation.Errors.Select(x => x.ErrorMessage)),
                    Errors = validation.Errors
                }));
            }

            await _blobProvider.CreateFolderAsync(folder);

            return(NoContent());
        }
        public static ContentFolder ToContentModel(this BlobFolder blobFolder)
        {
            if (blobFolder == null)
            {
                throw new ArgumentNullException(nameof(blobFolder));
            }

            var contentFolder = AbstractTypeFactory <ContentFolder> .TryCreateInstance();

            contentFolder.Name        = blobFolder.Name;
            contentFolder.Url         = blobFolder.Url;
            contentFolder.ParentUrl   = blobFolder.ParentUrl;
            contentFolder.RelativeUrl = blobFolder.RelativeUrl;
            contentFolder.CreatedDate = blobFolder.CreatedDate;
            contentFolder.Type        = blobFolder.Type;

            return(contentFolder);
        }
Exemplo n.º 23
0
        static void Loop(BlobFolder blobFolder)
        {
            while (true)
            {
                string filename = Console.ReadLine();

                if (String.IsNullOrEmpty(filename))
                {
                    break;
                }

                string folder = GetFolderName(filename);

                CreateFolder(folder);

                Download(blobFolder, filename, filename);
            }
        }
Exemplo n.º 24
0
        public virtual async Task CreateFolderAsync(BlobFolder folder)
        {
            var path = folder.ParentUrl == null ?
                       folder.Name :
                       UrlHelperExtensions.Combine(folder.ParentUrl, folder.Name);

            var containerName = GetContainerNameFromUrl(path);
            var container     = _blobServiceClient.GetBlobContainerClient(containerName);
            await container.CreateIfNotExistsAsync(PublicAccessType.Blob);

            var directoryPath = GetDirectoryPathFromUrl(path);

            if (!string.IsNullOrEmpty(directoryPath))
            {
                //Need upload empty blob because azure blob storage not support direct directory creation
                using var stream = new MemoryStream(new byte[0]);
                await container.GetBlockBlobClient(directoryPath).UploadAsync(stream);
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Create folder in file system within to base directory
        /// </summary>
        /// <param name="folder"></param>
        public void CreateFolder(BlobFolder folder)
        {
            if (folder == null)
            {
                throw new ArgumentNullException("folder");
            }
            var path = _storagePath;

            if (folder.ParentUrl != null)
            {
                path = GetStoragePathFromUrl(folder.ParentUrl);
            }
            path = Path.Combine(path, folder.Name);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
        }
Exemplo n.º 26
0
        static IEnumerable <string> ListFiles(BlobFolder blob, string pattern)
        {
            string prefix = "";
            string suffix = "";

            if (pattern != null)
            {
                var filePatternComponents = pattern.Split("*");
                prefix = filePatternComponents[0];

                suffix = (filePatternComponents.Length == 2) ? filePatternComponents[1] : "";
            }

            var result = blob
                         .EnumItems(prefix)
                         .Where(name => name.EndsWith(suffix));

            return(result);
        }
Exemplo n.º 27
0
        private PageFolder LoadFolderRecursive(BlobFolder blobFolder, string path)
        {
            var retVal = new PageFolder
            {
                FolderName = blobFolder.Name
            };
            var result = _contentStorageProvider.Search(blobFolder.Url, null);

            foreach (var childFolder in result.Folders)
            {
                retVal.Folders.Add(LoadFolderRecursive(childFolder, path + "/" + childFolder.Name));
            }

            foreach (var item in result.Items)
            {
                var page = item.ToPageWebModel();
                page.Id = path + "/" + item.FileName;
                retVal.Pages.Add(page);
            }
            return(retVal);
        }
Exemplo n.º 28
0
        private ThemeAsset[] LoadFolderAssetRecursive(BlobFolder blobFolder, string path, int level = 0)
        {
            var retVal = new List <ThemeAsset>();

            var result = _contentStorageProvider.Search(blobFolder.Url, null);

            foreach (var childFolder in result.Folders)
            {
                retVal.AddRange(LoadFolderAssetRecursive(childFolder, path + "/" + childFolder.Name, level + 1));
            }
            foreach (var item in result.Items)
            {
                var themeAssetItem = item.ToThemeAssetWebModel();
                themeAssetItem.Id = path + "/" + item.FileName;
                if (level > 0)
                {
                    themeAssetItem.Name = blobFolder.Name + "/" + themeAssetItem.Name;
                }
                retVal.Add(themeAssetItem);
            }
            return(retVal.ToArray());
        }
Exemplo n.º 29
0
        /// <summary>
        /// Create folder in file system within to base directory
        /// </summary>
        /// <param name="folder"></param>
        public virtual Task CreateFolderAsync(BlobFolder folder)
        {
            if (folder == null)
            {
                throw new ArgumentNullException("folder");
            }
            var path = _storagePath;

            if (folder.ParentUrl != null)
            {
                path = GetStoragePathFromUrl(folder.ParentUrl);
            }
            path = Path.Combine(path, folder.Name);

            ValidatePath(path);

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

            return(Task.CompletedTask);
        }
Exemplo n.º 30
0
        static int Main(string[] args)
        {
            if (args.Length == 0)
            {
                return(-1);
            }

            if (args.Length == 1)
            {
                return(-1);
            }

            string storageUrl  = args[0];
            string filePattern = args[1];

            var blobFolder = new BlobFolder(storageUrl);

            foreach (var filename in ListFiles(blobFolder, filePattern))
            {
                Console.WriteLine(filename);
            }

            return(0);
        }
 /// <summary>
 /// Create new blob folder 
 /// </summary>
 /// <exception cref="VirtoCommerce.Platform.Client.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="folder"></param>
 /// <returns></returns>
 public void AssetsCreateBlobFolder(BlobFolder folder)
 {
      AssetsCreateBlobFolderWithHttpInfo(folder);
 }
        /// <summary>
        /// Create new blob folder 
        /// </summary>
        /// <exception cref="VirtoCommerce.Platform.Client.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="folder"></param>
        /// <returns>Task of void</returns>
        public async System.Threading.Tasks.Task AssetsCreateBlobFolderAsync(BlobFolder folder)
        {
             await AssetsCreateBlobFolderAsyncWithHttpInfo(folder);

        }
        /// <summary>
        /// Create new blob folder 
        /// </summary>
        /// <exception cref="VirtoCommerce.Platform.Client.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="folder"></param>
        /// <returns>Task of ApiResponse</returns>
        public async System.Threading.Tasks.Task<ApiResponse<object>> AssetsCreateBlobFolderAsyncWithHttpInfo(BlobFolder folder)
        {
            // verify the required parameter 'folder' is set
            if (folder == null)
                throw new ApiException(400, "Missing required parameter 'folder' when calling VirtoCommercePlatformApi->AssetsCreateBlobFolder");

            var localVarPath = "/api/platform/assets/folder";
            var localVarPathParams = new Dictionary<string, string>();
            var localVarQueryParams = new Dictionary<string, string>();
            var localVarHeaderParams = new Dictionary<string, string>(Configuration.DefaultHeader);
            var localVarFormParams = new Dictionary<string, string>();
            var localVarFileParams = new Dictionary<string, FileParameter>();
            object localVarPostBody = null;

            // to determine the Content-Type header
            string[] localVarHttpContentTypes = new string[] {
                "application/json", 
                "text/json", 
                "application/xml", 
                "text/xml", 
                "application/x-www-form-urlencoded"
            };
            string localVarHttpContentType = ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            string[] localVarHttpHeaderAccepts = new string[] {
            };
            string localVarHttpHeaderAccept = ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);
            if (localVarHttpHeaderAccept != null)
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);

            // set "format" to json by default
            // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
            localVarPathParams.Add("format", "json");
            if (folder.GetType() != typeof(byte[]))
            {
                localVarPostBody = ApiClient.Serialize(folder); // http body (model) parameter
            }
            else
            {
                localVarPostBody = folder; // byte array
            }


            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await ApiClient.CallApiAsync(localVarPath,
                Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (localVarStatusCode >= 400 && (localVarStatusCode != 404 || Configuration.ThrowExceptionWhenStatusCodeIs404))
                throw new ApiException(localVarStatusCode, "Error calling AssetsCreateBlobFolder: " + localVarResponse.Content, localVarResponse.Content);
            else if (localVarStatusCode == 0)
                throw new ApiException(localVarStatusCode, "Error calling AssetsCreateBlobFolder: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage);

            
            return new ApiResponse<object>(localVarStatusCode,
                localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                null);
        }