public virtual MediaContent Add(Repository repository, MediaFolder mediaFolder, string fileName, Stream fileStream, bool @overrided, string userId, MediaContentMetadata metadata) { fileName = UrlUtility.ToUrlString(Path.GetFileNameWithoutExtension(fileName)) + Path.GetExtension(fileName); IsAllowExtension(fileName, mediaFolder.AllowedExtensions); var mediaContent = new MediaContent(repository.Name, mediaFolder.FullName); mediaContent.UserId = userId; mediaContent.Published = true; mediaContent.FileName = fileName; mediaContent.UserKey = fileName; mediaContent.UUID = fileName; mediaContent.ContentFile = new ContentFile() { Name = fileName, FileName = fileName, Stream = fileStream }; mediaContent.UtcLastModificationDate = mediaContent.UtcCreationDate = DateTime.UtcNow; mediaContent.Metadata = metadata; Provider.Add(mediaContent, @overrided); return mediaContent; }
public void Test_Add_Folder() { MediaFolder mediaFolder = new MediaFolder(repository, "Test_Add_Folder"); mediaFolder.DisplayName = "Test Add Folder"; mediaFolder.UserId = "admin"; provider.Add(mediaFolder); }
public static void RemoveFolder(MediaFolder folder) { locker.EnterWriteLock(); try { var storeList = GetList(folder.Repository); var mediaFolders = ToMediaFolders(folder.Repository, storeList); if (storeList.ContainsKey(folder.FullName)) { storeList.Remove(folder.FullName); foreach (var item in mediaFolders) { if (item.Parent == folder) { if (storeList.ContainsKey(item.FullName)) { storeList.Remove(item.FullName); } } } } SaveList(folder.Repository, storeList); } finally { locker.ExitWriteLock(); } }
public virtual ActionResult Create(MediaFolder model, string folderName) { var entry = new JsonResultEntry(); if (ModelState.IsValid) { try { MediaFolder parent = null; if (!string.IsNullOrEmpty(folderName)) { parent = FolderHelper.Parse<MediaFolder>(Repository, folderName).AsActual(); } model.Parent = parent; FolderManager.Add(Repository, model); } catch (Exception e) { entry.AddException(e); } } else { entry.AddModelState(ModelState); } return Json(entry); }
public void Import(Repository repository, MediaFolder folder, System.IO.Stream zipStream, bool @override) { using (ZipFile zipFile = ZipFile.Read(zipStream)) { foreach (ZipEntry item in zipFile) { if (item.IsDirectory) { } else { var path = Path.GetDirectoryName(item.FileName); var fileName = Path.GetFileName(item.FileName); var currentFolder = CreateMediaFolderByPath(folder, path); Add(currentFolder); var stream = new MemoryStream(); item.Extract(stream); stream.Position = 0; ServiceFactory.MediaContentManager.Add(repository, currentFolder, fileName, stream, true); } } } }
public virtual MediaContent Update(Repository repository, MediaFolder mediaFolder, string uuid, string fileName, Stream fileStream, string userid, MediaContentMetadata metadata) { IsAllowExtension(fileName, mediaFolder.AllowedExtensions); var binaryContent = mediaFolder.CreateQuery().WhereEquals("UUID", uuid).First(); var old = new MediaContent(binaryContent); binaryContent.UserId = userid; binaryContent.UtcLastModificationDate = DateTime.UtcNow; binaryContent.FileName = fileName; binaryContent.UserKey = fileName; binaryContent.UUID = fileName; if (fileStream != null) { binaryContent.ContentFile = new ContentFile() { Name = fileName, FileName = fileName, Stream = fileStream }; Provider.SaveContentStream(old, fileStream); } binaryContent.Metadata = metadata; Provider.Update(binaryContent, old); return binaryContent; }
public MediaContentProviderTest() { Kooboo.CMS.Content.Persistence.AzureBlobService.AssemblyInitializer.ResetProviders(); repository = new Repository(Kooboo.UniqueIdGenerator.GetInstance().GetBase32UniqueId(5)); mediaFolder = new MediaFolder(repository, "MediaFolder1/MediaFolder2"); Kooboo.CMS.Content.Persistence.Providers.DefaultProviderFactory.GetProvider<IRepositoryProvider>().Initialize(repository); }
public void Test_Delete_Folder() { MediaFolder mediaFolder = new MediaFolder(repository, "Test_Delete_Folder"); mediaFolder.DisplayName = "Test delete Folder"; mediaFolder.UserId = "admin"; provider.Add(mediaFolder); provider.Remove(mediaFolder); }
public void Test_Update_Folder() { MediaFolder mediaFolder = new MediaFolder(repository, "Test_Update_Folder"); mediaFolder.DisplayName = "Test Update Folder"; mediaFolder.UserId = "admin"; provider.Add(mediaFolder); mediaFolder.DisplayName = "Updated Folder"; provider.Update(mediaFolder, mediaFolder); }
public MediaFolder Get(MediaFolder dummy) { var folder = RemoteServiceFactory.CreateService<IMediaFolderService>() .Get(dummy.Repository.Name, dummy.FullName); if (folder != null) { ((IPersistable)folder).Init(dummy); } return folder; }
public void Delete(string repositoryName, string folderName, string fileName) { var mediaFolder = new MediaFolder(new Repository(repositoryName), folderName); var content = mediaFolder.CreateQuery().WhereEquals("FileName", fileName) .FirstOrDefault(); if (content != null) { mediaContentProvider.Delete(content); } }
public IEnumerable<MediaContent> All(string repositoryName, string folderName , int skip, int maxResult, string prefix) { var mediaFolder = new MediaFolder(new Repository(repositoryName), folderName); return mediaFolder.CreateQuery().WhereContains("FileName", prefix) .Skip(skip) .Take(maxResult) .ToArray() .Select(it => { it.VirtualPath = FileUrlHelper.ResolveUrl(it.VirtualPath); return it; }); }
public MediaContent Get(string repositoryName, string folderName, string fileName) { var mediaFolder = new MediaFolder(new Repository(repositoryName), folderName); var content = mediaFolder.CreateQuery().WhereEquals("FileName", fileName) .FirstOrDefault(); if (content != null) { content.VirtualPath = FileUrlHelper.ResolveUrl(content.VirtualPath); } return content; }
static BinaryContentProviderTests() { repository = new Repository("SimpleQueryTests"); binaryFolder = new MediaFolder(repository, "image"); ProviderFactory providerFactory = new ProviderFactory(); Providers.DefaultProviderFactory = providerFactory; providerFactory.GetProvider<IRepositoryProvider>().Add(repository); providerFactory.GetProvider<IMediaFolderProvider>().Add(binaryFolder); }
public void Test_Get_Folder() { MediaFolder mediaFolder = new MediaFolder(repository, "Test_Get_Folder"); mediaFolder.DisplayName = "Test get Folder"; mediaFolder.UserId = "admin"; provider.Add(mediaFolder); var gotFolder = provider.Get(mediaFolder); Assert.IsNotNull(gotFolder); Assert.AreEqual(mediaFolder.DisplayName, gotFolder.DisplayName); Assert.AreEqual(mediaFolder.UserId, gotFolder.UserId); }
public MediaContentProviderTests() { Providers.DefaultProviderFactory = new ProviderFactory(); repository = new Repository("MediaContentProviderTests"); Providers.RepositoryProvider.Add(repository); binaryFolder = new MediaFolder(repository, "images"); Providers.DefaultProviderFactory.GetProvider<IMediaFolderProvider>().Add(binaryFolder); binaryContentProvider = Providers.DefaultProviderFactory.GetProvider<IMediaContentProvider>(); }
public void Delete(MediaFolder mediaFolder) { var blobClient = CloudStorageAccountHelper.GetStorageAccount().CreateCloudBlobClient(); var contentBlob = blobClient.GetBlobDirectoryReference(mediaFolder.GetMediaDirectoryPath()); foreach (var item in contentBlob.ListBlobs(new BlobRequestOptions() { UseFlatBlobListing = true })) { var blobContent = item as CloudBlob; if (blobContent != null) { blobContent.DeleteIfExists(); } } }
public byte[] GetBytes(string repositoryName, string folderName, string fileName) { var mediaFolder = new MediaFolder(new Repository(repositoryName), folderName); var content = mediaFolder.CreateQuery().WhereEquals("FileName", fileName) .FirstOrDefault(); if (content == null) { return null; } using (var fs = File.Open(content.PhysicalPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { return fs.ReadData(); } }
public void SaveBytes(MediaContentParameter content) { var mediaContent = content.MediaContent; var mediaFolder = new MediaFolder(new Repository(mediaContent.Repository), mediaContent.FolderName); mediaContent = mediaFolder.CreateQuery().WhereEquals("FileName", mediaContent.FileName) .FirstOrDefault(); using (FileStream file = new FileStream(mediaContent.PhysicalPath, FileMode.Create, System.IO.FileAccess.Write)) { using (MemoryStream stream = new MemoryStream(content.FileData)) { stream.WriteTo(file); } } }
public void Test1() { Repository repository = new Repository("TextTranslatorTests"); MediaFolder binaryFolder = new MediaFolder(repository, "image"); var binaryQuery = binaryFolder.CreateQuery().WhereEquals("Title", "title1"); Assert.AreEqual("[MediaContent] SELECT * FROM [TextTranslatorTests.image] WHERE Title = title1 ORDER | OP:Unspecified PageSize:0 TOP:0 Skip:0 ", TextTranslator.Translate(binaryQuery)); Schema schema = new Schema(repository, "news") { IsDummy = false }; TextFolder textFolder = new TextFolder(repository, "news") { SchemaName = "news", IsDummy = false }; var textQuery = textFolder.CreateQuery().WhereEquals("Title", "title1").WhereCategory(textFolder.CreateQuery()); Assert.AreEqual("[TextContent] SELECT * FROM [TextTranslatorTests.news$news] WHERE Title = title1 Category:([TextContent] SELECT * FROM [TextTranslatorTests.news$news] WHERE Category:() ORDER | OP:Unspecified PageSize:0 TOP:0 Skip:0 ) ORDER | OP:Unspecified PageSize:0 TOP:0 Skip:0 ", TextTranslator.Translate(textQuery)); }
public static MediaFolder GetFolder(MediaFolder dummy) { locker.EnterReadLock(); try { var folders = GetList(dummy.Repository); if (folders.ContainsKey(dummy.FullName)) { return ToMediaFolder(dummy.Repository, dummy.FullName, folders[dummy.FullName]); } return null; } finally { locker.ExitReadLock(); } }
public static void AddFolder(MediaFolder folder) { locker.EnterWriteLock(); try { var folders = GetList(folder.Repository); var name = folder.FullName.TrimStart('~').TrimEnd('~'); if (!folders.ContainsKey(name)) { folders[name] = folder; SaveList(folder.Repository, folders); } } finally { locker.ExitWriteLock(); } }
public virtual ActionResult Create(MediaFolder model, string folderName) { var data = new JsonResultData(ModelState); if (ModelState.IsValid) { data.RunWithTry((resultData) => { MediaFolder parent = null; if (!string.IsNullOrEmpty(folderName)) { parent = FolderHelper.Parse<MediaFolder>(Repository, folderName).AsActual(); } model.Parent = parent; FolderManager.Add(Repository, model); }); } return Json(data); }
public IEnumerable<CloudBlob> Translate(IExpression expression, CloudBlobClient blobClient, MediaFolder mediaFolder) { this.Visite(expression); if (!string.IsNullOrEmpty(fileName)) { var blob = blobClient.GetBlockBlobReference(mediaFolder.GetMediaFolderItemPath(fileName)); if (!blob.Exists()) { return new CloudBlob[] { }; } blob.FetchAttributes(); return new[] { blob }; } else { var maxResult = 1000; if (Take.HasValue) { maxResult = Take.Value; } var take = maxResult; var skip = 0; if (Skip.HasValue) { skip = Skip.Value; maxResult += skip; } var blobPrefix = mediaFolder.GetMediaFolderItemPath(prefix); if (string.IsNullOrEmpty(prefix)) { blobPrefix += "/"; } return blobClient.ListBlobsWithPrefixSegmented(blobPrefix, maxResult, null, new BlobRequestOptions() { BlobListingDetails = Microsoft.WindowsAzure.StorageClient.BlobListingDetails.Metadata, UseFlatBlobListing = false }) .Results.Skip(skip).Select(it => it as CloudBlob).Take(take); } }
public static MediaContent ParseMediaContent(Repository repository, string virtualPath) { if (repository == null) { throw new ArgumentNullException("repository"); } if (Uri.IsWellFormedUriString(virtualPath, UriKind.Absolute)) { throw new NotSupportedException("Not support to parse absolute url path.".Localize()); } var mediaBaseVirtualPath = UrlUtility.Combine(new RepositoryPath(repository).VirtualPath, FolderPath.GetRootPath(typeof(MediaFolder))); var mediaFolderVirtualPath = UrlUtility.ResolveUrl(mediaBaseVirtualPath); if (virtualPath.Length > mediaFolderVirtualPath.Length) { var mediaContentPath = virtualPath.Substring(mediaBaseVirtualPath.Length - 1); var paths = mediaContentPath.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries); var mediaFolder = new MediaFolder(repository, paths.Take(paths.Length - 1)); var fileName = paths.Last(); return mediaFolder.CreateQuery().WhereEquals("UUID", fileName).FirstOrDefault(); } return null; }
public void TestBinaryContentFolder() { MediaFolderProvider repository = new MediaFolderProvider(); var folderName = "Images"; var folder = new MediaFolder(contentRepository, folderName) { AllowedExtensions = new[] { ".jpg", ".png" } }; repository.Add(folder); var all = repository.All(contentRepository); Assert.AreEqual(1, all.Count()); var item = (MediaFolder)repository.Get(all.First()); Assert.AreEqual(folder.Name, item.Name); Assert.AreEqual(folder.DisplayName, item.DisplayName); Assert.AreEqual(folder.Repository, item.Repository); Assert.AreEqual(folder.AllowedExtensions.Count(), item.AllowedExtensions.Count()); // repository.Remove(item); }
private void ImportMediaFolderDataCascading(MediaFolder mediaFolder) { Kooboo.CMS.Content.Persistence.Default.MediaContentProvider fileProvider = new Default.MediaContentProvider(); //add media folder MediaFolderProvider folderProvider = new MediaFolderProvider(); folderProvider.Add(mediaFolder); foreach (var item in fileProvider.All(mediaFolder)) { item.ContentFile = new ContentFile() { FileName = item.FileName }; using (var fileStream = new FileStream(item.PhysicalPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { item.ContentFile.Stream = fileStream; Add(item); } } Kooboo.CMS.Content.Persistence.Default.MediaFolderProvider fileMediaFolderProvider = new Default.MediaFolderProvider(); foreach (var item in fileMediaFolderProvider.ChildFolders(mediaFolder)) { ImportMediaFolderDataCascading(item); } }
public int Count(string repositoryName, string folderName, string prefix) { var mediaFolder = new MediaFolder(new Repository(repositoryName), folderName); return mediaFolder.CreateQuery().WhereContains("FileName", prefix) .Count(); }
protected virtual bool IfUserKeyExists(ContentBase content, string userKey) { var repository = new Repository(content.Repository); if (content is TextContent) { var textContent = (TextContent)content; var schema = new Schema(repository, textContent.SchemaName); var contentExists = schema.CreateQuery().WhereEquals("UserKey", userKey).FirstOrDefault(); if (contentExists != null) { return contentExists.UUID != content.UUID; } return false; } else if (content is MediaContent) { var mediaContent = (MediaContent)content; var folder = new MediaFolder(repository, mediaContent.FolderName); var contentExists = folder.CreateQuery().WhereEquals("UserKey", userKey).FirstOrDefault(); if (contentExists != null) { return contentExists.UUID != content.UUID; } return false; } return false; }
public void Move(MediaFolder sourceFolder, string oldFileName, MediaFolder targetFolder, string newFileName) { var oldMediaContent = new MediaContent() { Repository = sourceFolder.Repository.Name, FolderName = sourceFolder.FullName, UUID = oldFileName, FileName = oldFileName }; var newMediaContent = new MediaContent() { Repository = targetFolder.Repository.Name, FolderName = targetFolder.FullName, UUID = newFileName, FileName = newFileName }; MoveContent(oldMediaContent, newMediaContent); }