/// <exclude />
        public T GetData <T>(IDataId dataId) where T : class, IData
        {
            if (dataId == null)
            {
                throw new ArgumentNullException("dataId");
            }
            CheckInterface(typeof(T));

            MediaDataId mediaDataId = dataId as MediaDataId;

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


            if (mediaDataId.MediaType == MediaElementType.Folder)
            {
                if (typeof(T) != typeof(IMediaFileFolder))
                {
                    throw new ArgumentException("The dataId specifies a IMediaFileFolder, but the generic method was invoked with different type");
                }

                IMediaFolderData folder = DataFacade.GetData <IMediaFolderData>().FirstOrDefault(x => x.Id == mediaDataId.Id);
                if (folder == null)
                {
                    return(null);
                }
                return(new MediaFileFolder(folder, Store.Id,
                                           _context.CreateDataSourceId(new MediaDataId {
                    MediaType = MediaElementType.Folder, Id = folder.Id
                }, typeof(IMediaFileFolder))) as T);
            }

            if (mediaDataId.MediaType == MediaElementType.File)
            {
                if (typeof(T) != typeof(IMediaFile))
                {
                    throw new ArgumentException("The dataId specifies a IMediaFile, but the generic method was invoked with different type");
                }

                IMediaFileData file = DataFacade.GetData <IMediaFileData>().FirstOrDefault(x => x.Id == mediaDataId.Id);
                if (file == null)
                {
                    return(null);
                }

                string internalPath = Path.Combine(_workingDirectory, file.Id.ToString());
                return(new MediaFile(file, Store.Id,
                                     _context.CreateDataSourceId(new MediaDataId {
                    MediaType = MediaElementType.File, Id = file.Id
                }, typeof(IMediaFile)), internalPath) as T);
            }

            return(Store as T);
        }
Beispiel #2
0
        public MediaFileFolder(IMediaFolderData folder, string storeId, DataSourceId dataSourceId)
        {
            _dataSourceId = dataSourceId;

            Id = folder.Id;
            Description = folder.Description;
            Title = folder.Title;
            StoreId = storeId;
            Path = folder.Path;
        }
Beispiel #3
0
        public MediaFileFolder(IMediaFolderData folder, string storeId, DataSourceId dataSourceId)
        {
            DataSourceId = dataSourceId;

            Id          = folder.Id;
            Description = folder.Description;
            Title       = folder.Title;
            StoreId     = storeId;
            Path        = folder.Path;
        }
Beispiel #4
0
        private void DeleteMediaFolder(Guid mediaFolderId)
        {
            IMediaFolderData folder = DataFacade.GetData <IMediaFolderData>(x => x.Id == mediaFolderId).First();

            string folderPath = folder.Path;
            string innerElementsPathPrefix = $"{folderPath}/";

            var files = (from item in DataFacade.GetData <IMediaFileData>()
                         where item.FolderPath.StartsWith(innerElementsPathPrefix) || item.FolderPath == folderPath
                         select item).ToList();

            DeleteMediaFiles(files);

            DataFacade.Delete <IMediaFolderData>(x => x.Path.StartsWith(innerElementsPathPrefix));
            DataFacade.Delete(folder);
        }
        private void UpdateMediaFileFolder(IMediaFileFolder updatedFolder)
        {
            Guid             mediaFolderId     = updatedFolder.Id;
            IMediaFolderData currentFolderData = DataFacade.GetData <IMediaFolderData>(x => x.Id == mediaFolderId).First();

            if (updatedFolder.Path != currentFolderData.Path)
            {
                ValidateFolderData(updatedFolder);
            }

            string oldPath          = currentFolderData.Path;
            string oldPathWithSlash = oldPath + "/";
            List <IMediaFolderData> foldersToUpdatePath =
                (from item in DataFacade.GetData <IMediaFolderData>()
                 where item.Path.StartsWith(oldPathWithSlash) && item.Id != currentFolderData.Id
                 select item).ToList();

            if (foldersToUpdatePath.Count > 0)
            {
                foreach (IMediaFolderData item in foldersToUpdatePath)
                {
                    item.Path = updatedFolder.Path + item.Path.Substring(oldPath.Length);
                }

                DataFacade.Update(foldersToUpdatePath);
            }


            List <IMediaFileData> filesToUpdatePath =
                (from item in DataFacade.GetData <IMediaFileData>()
                 where item.FolderPath == oldPath ||
                 item.FolderPath.StartsWith(oldPathWithSlash)
                 select item).ToList();

            if (filesToUpdatePath.Count > 0)
            {
                foreach (IMediaFileData mediaFileData in filesToUpdatePath)
                {
                    mediaFileData.FolderPath = updatedFolder.Path + mediaFileData.FolderPath.Substring(oldPath.Length);
                }
                DataFacade.Update(filesToUpdatePath);
            }


            CopyFolderData(updatedFolder, currentFolderData);
            DataFacade.Update(currentFolderData);
        }
        private void DeleteMediaFolder(Guid mediaFolderId)
        {
            IMediaFolderData folder = DataFacade.GetData <IMediaFolderData>(x => x.Id == mediaFolderId).First();

            string folderPath = folder.Path;
            string innerElementsPathPrefix = string.Format("{0}/", folderPath);

            var files = (from item in DataFacade.GetData <IMediaFileData>()
                         where item.FolderPath.StartsWith(innerElementsPathPrefix) || item.FolderPath == folderPath
                         select item).ToList();

            DataFacade.Delete <IMediaFolderData>(x => x.Path.StartsWith(innerElementsPathPrefix));
            DataFacade.Delete(folder);

            foreach (IMediaFileData file in files)
            {
                DeleteMediaFile(file.Id);
            }
        }
 private void CopyFolderData(IMediaFileFolder from, IMediaFolderData to)
 {
     to.Description = from.Description;
     to.Path        = from.Path;
     to.Title       = from.Title;
 }