Exemplo n.º 1
0
        /// <inheritdoc/>
        public IMediaFile GetMediaFile(int mediaFileId)
        {
            MediaFileInfo file = MediaFileInfoProvider.GetMediaFileInfo(mediaFileId);

            file = SetFileBinary(file);
            return(file?.ActLike <IMediaFile>());
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public IMediaFile UpdateMediaFile(IMediaFile file)
        {
            MediaFileInfo mediaFileInfo = MediaFileInfoProvider.GetMediaFileInfo(file.FileID);

            if (mediaFileInfo == null)
            {
                return(null);
            }

            MediaFileInfoProvider.SetMediaFileInfo(mediaFileInfo);

            return(mediaFileInfo.ActLike <IMediaFile>());
        }
Exemplo n.º 3
0
        /// <inheritdoc/>
        public IMediaFile GetMediaFile(IMediaLibrary library, string folder, string fileName)
        {
            MediaFileInfo mediaFile = null;

            // Gets the media library
            var existingLibrary = GetMediaLibrary(library);

            if (existingLibrary != null)
            {
                // Gets the media file
                mediaFile = MediaFileInfoProvider.GetMediaFileInfo(existingLibrary.LibraryID, $"{folder}/{fileName}");
            }

            return(mediaFile.ActLike <IMediaFile>());
        }
Exemplo n.º 4
0
        /// <inheritdoc/>
        public IMediaFile CreateMediaFile(int librarySiteID, string libraryName, string localFilePath, string fileName, string fileTitle, string fileDesc, string folder)
        {
            // Gets the media library
            string siteName        = SiteInfoProvider.GetSiteName(librarySiteID);
            var    existingLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo(libraryName, siteName);

            if (existingLibrary != null)
            {
                // Prepares a CMS.IO.FileInfo object representing the local file
                CMS.IO.FileInfo file = CMS.IO.FileInfo.New(localFilePath);
                if (file != null)
                {
                    // Creates a new media library file object
                    MediaFileInfo mediaFile = new MediaFileInfo(localFilePath, existingLibrary.LibraryID)
                    {
                        // Sets the media library file properties
                        FileName        = fileName,
                        FileTitle       = fileTitle,
                        FileDescription = fileDesc,
                        FilePath        = $"{folder}/{fileName}", // Sets the path within the media library's folder structure
                        FileExtension   = file.Extension,
                        FileMimeType    = MimeTypeHelper.GetMimetype(file.Extension),
                        FileSiteID      = librarySiteID,
                        FileLibraryID   = existingLibrary.LibraryID,
                        FileSize        = file.Length,
                    };

                    // Saves the media library file
                    MediaFileInfoProvider.SetMediaFileInfo(mediaFile);

                    return(mediaFile.ActLike <IMediaFile>());
                }
            }

            return(null);
        }