-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor media library service into repository
TRAIN-1515
- Loading branch information
Jan Lenoch
committed
Nov 26, 2019
1 parent
40e67d5
commit e22b89a
Showing
7 changed files
with
145 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
namespace Business.Dto.MediaLibrary | ||
using System; | ||
|
||
namespace Business.Dto.MediaLibrary | ||
{ | ||
public class MediaLibraryFileDto : IDto | ||
{ | ||
public Guid Guid { get; set; } | ||
public string Title { get; set; } | ||
public string DirectUrl { get; set; } | ||
public string PermanentUrl { get; set; } | ||
public string Extension { get; set; } | ||
public int Width { get; set; } | ||
public int Height { get; set; } | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Business/Repository/MediaLibrary/IMediaLibraryRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Collections.Generic; | ||
|
||
using Business.Dto.MediaLibrary; | ||
|
||
namespace Business.Repository.MediaLibrary | ||
{ | ||
public interface IMediaLibraryRepository : IRepository | ||
{ | ||
string MediaLibraryName { get; set; } | ||
|
||
string MediaLibrarySiteName { get; set; } | ||
|
||
int? MediaLibraryId { get; set; } | ||
|
||
int? MediaLibrarySiteId { get; set; } | ||
|
||
IEnumerable<MediaLibraryFileDto> GetMediaLibraryDtos(params string[] extensions); | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
Business/Repository/MediaLibrary/MediaLibraryRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
using CMS.DataEngine; | ||
using CMS.MediaLibrary; | ||
using CMS.SiteProvider; | ||
|
||
using Business.Dto.MediaLibrary; | ||
|
||
namespace Business.Repository.MediaLibrary | ||
{ | ||
public class MediaLibraryRepository : IMediaLibraryRepository | ||
{ | ||
private int? _mediaLibraryId; | ||
private int? _mediaLibrarySiteId; | ||
private string _mediaLibraryName; | ||
private string _mediaLibrarySiteName; | ||
|
||
public int? MediaLibraryId | ||
{ | ||
get => _mediaLibraryId == null && !string.IsNullOrEmpty(_mediaLibraryName) && !string.IsNullOrEmpty(_mediaLibrarySiteName) | ||
? MediaLibraryInfoProvider | ||
.GetMediaLibraryInfo(_mediaLibraryName, _mediaLibrarySiteName)? | ||
.LibraryID | ||
: _mediaLibraryId; | ||
|
||
set | ||
{ | ||
_mediaLibraryId = value; | ||
} | ||
} | ||
|
||
public int? MediaLibrarySiteId | ||
{ | ||
get => _mediaLibrarySiteId == null && !string.IsNullOrEmpty(_mediaLibrarySiteName) | ||
? SiteInfoProvider.GetSiteID(_mediaLibrarySiteName) | ||
: _mediaLibrarySiteId; | ||
|
||
set | ||
{ | ||
_mediaLibrarySiteId = value; | ||
} | ||
} | ||
|
||
public string MediaLibraryName | ||
{ | ||
get => string.IsNullOrEmpty(_mediaLibraryName) && _mediaLibraryId.HasValue | ||
? MediaLibraryInfoProvider | ||
.GetMediaLibraryInfo(_mediaLibraryId.Value)? | ||
.LibraryName | ||
: _mediaLibraryName; | ||
|
||
set | ||
{ | ||
_mediaLibraryName = value; | ||
} | ||
} | ||
|
||
public string MediaLibrarySiteName | ||
{ | ||
get | ||
{ | ||
if (string.IsNullOrEmpty(_mediaLibrarySiteName) && _mediaLibrarySiteId.HasValue) | ||
{ | ||
var siteId = MediaLibraryInfoProvider | ||
.GetMediaLibraryInfo(_mediaLibrarySiteId.Value)? | ||
.LibrarySiteID; | ||
|
||
return siteId != null | ||
? SiteInfoProvider.GetSiteInfo(siteId.Value)?.SiteName | ||
: null; | ||
} | ||
else | ||
{ | ||
return _mediaLibrarySiteName; | ||
} | ||
} | ||
|
||
set | ||
{ | ||
_mediaLibrarySiteName = value; | ||
} | ||
} | ||
|
||
public IEnumerable<MediaLibraryFileDto> GetMediaLibraryDtos(params string[] extensions) => | ||
GetBaseQuery((baseQuery) => | ||
baseQuery.WhereIn("FileExtension", extensions)); | ||
|
||
protected IEnumerable<MediaLibraryFileDto> GetBaseQuery(Func<ObjectQuery<MediaFileInfo>, ObjectQuery<MediaFileInfo>> filter) | ||
{ | ||
var baseQuery = MediaFileInfoProvider.GetMediaFiles() | ||
.WhereEquals("FileLibraryID", MediaLibraryId); | ||
|
||
return filter(baseQuery).Select(file => Selector(file)); | ||
} | ||
|
||
protected MediaLibraryFileDto Selector(MediaFileInfo mediaFileInfo) => | ||
new MediaLibraryFileDto() | ||
{ | ||
Guid = mediaFileInfo.FileGUID, | ||
Title = mediaFileInfo.FileTitle, | ||
Extension = mediaFileInfo.FileExtension, | ||
DirectUrl = MediaLibraryHelper.GetDirectUrl(mediaFileInfo), | ||
PermanentUrl = MediaLibraryHelper.GetPermanentUrl(mediaFileInfo), | ||
Width = mediaFileInfo.FileImageWidth, | ||
Height = mediaFileInfo.FileImageHeight | ||
}; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters