1717using  VirtoCommerce . Platform . Core . Events ; 
1818using  VirtoCommerce . Platform . Core . Exceptions ; 
1919using  VirtoCommerce . Platform . Core . Extensions ; 
20- using  VirtoCommerce . Platform . Core . Modularity ; 
2120using  BlobInfo  =  VirtoCommerce . AssetsModule . Core . Assets . BlobInfo ; 
2221
2322namespace  VirtoCommerce . AzureBlobAssetsModule . Core 
@@ -78,7 +77,8 @@ public virtual async Task<BlobInfo> GetBlobInfoAsync(string blobUrl)
7877            { 
7978                var  blob  =  GetBlockBlobClient ( blobUrl ) ; 
8079                var  props  =  await  blob . GetPropertiesAsync ( ) ; 
81-                 result  =  ConvertToBlobInfo ( blob ,  props . Value ) ; 
80+                 var  blobTagResult  =  await  blob . GetTagsAsync ( ) ; 
81+                 result  =  ConvertToBlobInfo ( blob ,  props . Value ,  blobTagResult . Value ? . Tags ) ; 
8282            } 
8383            catch 
8484            { 
@@ -424,82 +424,7 @@ public string GetAbsoluteUrl(string inputUrl)
424424
425425        #endregion IBlobUrlResolver Members
426426
427-         private  async  Task < BlobContainerClient >  CreateContainerIfNotExists ( string  blobUrl ) 
428-         { 
429-             var  container  =  GetBlobContainerClient ( blobUrl ) ; 
430- 
431-             if  ( ! await  container . ExistsAsync ( ) ) 
432-             { 
433-                 var  accessType  =  _allowBlobPublicAccess  ?  PublicAccessType . Blob  :  PublicAccessType . None ; 
434-                 await  container . CreateAsync ( accessType ) ; 
435-             } 
436- 
437-             return  container ; 
438-         } 
439- 
440-         /// <summary> 
441-         /// Return outline folder from absolute or relative URL 
442-         /// </summary> 
443-         /// <param name="url"></param> 
444-         /// <returns></returns> 
445-         private  static string [ ]  GetOutlineFromUrl ( string  url ) 
446-         { 
447-             var  relativeUrl  =  url ; 
448-             if  ( url . IsAbsoluteUrl ( ) ) 
449-             { 
450-                 relativeUrl  =  Uri . UnescapeDataString ( new  Uri ( url ) . AbsolutePath ) ; 
451-             } 
452- 
453-             var  start  =  0 ; 
454-             var  end  =  0 ; 
455-             if  ( relativeUrl . StartsWith ( Delimiter ) ) 
456-             { 
457-                 start ++ ; 
458-             } 
459-             if  ( relativeUrl . EndsWith ( Delimiter ) ) 
460-             { 
461-                 end ++ ; 
462-             } 
463-             relativeUrl  =  relativeUrl [ start ..^ end ] ; 
464- 
465-             return  relativeUrl . Split ( Delimiter [ 0 ] ,  '\\ ' ) ;  // name may be empty 
466-         } 
467- 
468-         private  static string  GetContainerNameFromUrl ( string  url ) 
469-         { 
470-             return  GetOutlineFromUrl ( url ) . First ( ) ; 
471-         } 
472- 
473-         private  static string  GetDirectoryPathFromUrl ( string  url ) 
474-         { 
475-             var  result  =  string . Join ( Delimiter ,  GetOutlineFromUrl ( url ) . Skip ( 1 ) . ToArray ( ) ) ; 
476-             return  ! string . IsNullOrEmpty ( result )  ?  HttpUtility . UrlDecode ( result )  +  Delimiter  :  null ; 
477-         } 
478- 
479-         private  static string  GetFilePathFromUrl ( string  url ) 
480-         { 
481-             var  result  =  string . Join ( Delimiter ,  GetOutlineFromUrl ( url ) . Skip ( 1 ) . ToArray ( ) ) ; 
482-             return  ! string . IsNullOrEmpty ( result )  ?  HttpUtility . UrlDecode ( result )  :  null ; 
483-         } 
484- 
485-         private  BlockBlobClient  GetBlockBlobClient ( string  blobUrl ) 
486-         { 
487-             var  filePath  =  GetFilePathFromUrl ( blobUrl ) ; 
488-             var  container  =  GetBlobContainerClient ( blobUrl ) ; 
489-             var  blob  =  container . GetBlockBlobClient ( filePath ) ; 
490- 
491-             return  blob ; 
492-         } 
493- 
494-         private  BlobContainerClient  GetBlobContainerClient ( string  blobUrl ) 
495-         { 
496-             var  containerName  =  GetContainerNameFromUrl ( blobUrl ) ; 
497-             var  container  =  _blobServiceClient . GetBlobContainerClient ( containerName ) ; 
498- 
499-             return  container ; 
500-         } 
501- 
502-         private  BlobInfo  ConvertToBlobInfo ( BlobBaseClient  blob ,  BlobProperties  props ) 
427+         protected  virtual  BlobInfo  ConvertToBlobInfo ( BlobBaseClient  blob ,  BlobProperties  props ,  IDictionary < string ,  string >  tags ) 
503428        { 
504429            var  blobInfo  =  AbstractTypeFactory < BlobInfo > . TryCreateInstance ( ) ; 
505430
@@ -518,7 +443,7 @@ private BlobInfo ConvertToBlobInfo(BlobBaseClient blob, BlobProperties props)
518443            return  blobInfo ; 
519444        } 
520445
521-         private  BlobInfo  ConvertToBlobInfo ( BlobItem  blob ,  Uri  baseUri ) 
446+         protected   virtual  BlobInfo  ConvertToBlobInfo ( BlobItem  blob ,  Uri  baseUri ) 
522447        { 
523448            var  blobInfo  =  AbstractTypeFactory < BlobInfo > . TryCreateInstance ( ) ; 
524449
@@ -537,7 +462,7 @@ private BlobInfo ConvertToBlobInfo(BlobItem blob, Uri baseUri)
537462            return  blobInfo ; 
538463        } 
539464
540-         private  BlobFolder  ConvertToBlobFolder ( BlobHierarchyItem  blobHierarchyItem ,  Uri  baseUri ,  BlobContainerProperties  containerProperties ) 
465+         protected   virtual  BlobFolder  ConvertToBlobFolder ( BlobHierarchyItem  blobHierarchyItem ,  Uri  baseUri ,  BlobContainerProperties  containerProperties ) 
541466        { 
542467            var  folder  =  AbstractTypeFactory < BlobFolder > . TryCreateInstance ( ) ; 
543468
@@ -552,7 +477,7 @@ private BlobFolder ConvertToBlobFolder(BlobHierarchyItem blobHierarchyItem, Uri
552477            return  folder ; 
553478        } 
554479
555-         private  BlobFolder  ConvertToBlobFolder ( BlobContainerItem  container ) 
480+         protected   virtual  BlobFolder  ConvertToBlobFolder ( BlobContainerItem  container ) 
556481        { 
557482            var  folder  =  AbstractTypeFactory < BlobFolder > . TryCreateInstance ( ) ; 
558483
@@ -567,6 +492,81 @@ private BlobFolder ConvertToBlobFolder(BlobContainerItem container)
567492            return  folder ; 
568493        } 
569494
495+         protected  async  Task < BlobContainerClient >  CreateContainerIfNotExists ( string  blobUrl ) 
496+         { 
497+             var  container  =  GetBlobContainerClient ( blobUrl ) ; 
498+ 
499+             if  ( ! await  container . ExistsAsync ( ) ) 
500+             { 
501+                 var  accessType  =  _allowBlobPublicAccess  ?  PublicAccessType . Blob  :  PublicAccessType . None ; 
502+                 await  container . CreateAsync ( accessType ) ; 
503+             } 
504+ 
505+             return  container ; 
506+         } 
507+ 
508+         protected  BlockBlobClient  GetBlockBlobClient ( string  blobUrl ) 
509+         { 
510+             var  filePath  =  GetFilePathFromUrl ( blobUrl ) ; 
511+             var  container  =  GetBlobContainerClient ( blobUrl ) ; 
512+             var  blob  =  container . GetBlockBlobClient ( filePath ) ; 
513+ 
514+             return  blob ; 
515+         } 
516+ 
517+         protected  BlobContainerClient  GetBlobContainerClient ( string  blobUrl ) 
518+         { 
519+             var  containerName  =  GetContainerNameFromUrl ( blobUrl ) ; 
520+             var  container  =  _blobServiceClient . GetBlobContainerClient ( containerName ) ; 
521+ 
522+             return  container ; 
523+         } 
524+ 
525+         /// <summary> 
526+         /// Return outline folder from absolute or relative URL 
527+         /// </summary> 
528+         /// <param name="url"></param> 
529+         /// <returns></returns> 
530+         private  static string [ ]  GetOutlineFromUrl ( string  url ) 
531+         { 
532+             var  relativeUrl  =  url ; 
533+             if  ( url . IsAbsoluteUrl ( ) ) 
534+             { 
535+                 relativeUrl  =  Uri . UnescapeDataString ( new  Uri ( url ) . AbsolutePath ) ; 
536+             } 
537+ 
538+             var  start  =  0 ; 
539+             var  end  =  0 ; 
540+             if  ( relativeUrl . StartsWith ( Delimiter ) ) 
541+             { 
542+                 start ++ ; 
543+             } 
544+             if  ( relativeUrl . EndsWith ( Delimiter ) ) 
545+             { 
546+                 end ++ ; 
547+             } 
548+             relativeUrl  =  relativeUrl [ start ..^ end ] ; 
549+ 
550+             return  relativeUrl . Split ( Delimiter [ 0 ] ,  '\\ ' ) ;  // name may be empty 
551+         } 
552+ 
553+         private  static string  GetContainerNameFromUrl ( string  url ) 
554+         { 
555+             return  GetOutlineFromUrl ( url ) . First ( ) ; 
556+         } 
557+ 
558+         private  static string  GetDirectoryPathFromUrl ( string  url ) 
559+         { 
560+             var  result  =  string . Join ( Delimiter ,  GetOutlineFromUrl ( url ) . Skip ( 1 ) . ToArray ( ) ) ; 
561+             return  ! string . IsNullOrEmpty ( result )  ?  HttpUtility . UrlDecode ( result )  +  Delimiter  :  null ; 
562+         } 
563+ 
564+         private  static string  GetFilePathFromUrl ( string  url ) 
565+         { 
566+             var  result  =  string . Join ( Delimiter ,  GetOutlineFromUrl ( url ) . Skip ( 1 ) . ToArray ( ) ) ; 
567+             return  ! string . IsNullOrEmpty ( result )  ?  HttpUtility . UrlDecode ( result )  :  null ; 
568+         } 
569+ 
570570        private  static string  GetParentUrl ( Uri  baseUri ,  string  blobPrefix ) 
571571        { 
572572            var  baseUriString  =  baseUri . GetLeftPart ( UriPartial . Path ) ; 
0 commit comments