private void ParseSingleAlbum(List <DocumentTreeNode> nodes, LibrariesManager manager, DocumentLibrary album) { DocumentTreeNode rootNode = new DocumentTreeNode(); rootNode.Title = album.Title; rootNode.Expanded = this.Expanded; this.SetImage(rootNode); rootNode.Id = album.Id; rootNode.IsFolder = true; rootNode.CssClass += " album"; nodes.Add(rootNode); //Get Documents for this Library var docsInLibrary = manager.GetDocuments().Where(x => x.Parent.Id == album.Id && x.FolderId == null).Where(this.FilterExpressionForDocuments); foreach (var doc in docsInLibrary) { DocumentTreeNode docNode = this.CreateDocNode(album, doc); rootNode.Nodes.Add(docNode); } //Create nodes for all the folders var folders = manager.GetAllFolders(album); //Loop through all root folders foreach (var folder in folders.Where(x => x.ParentId == null)) { var folderNode = new DocumentTreeNode(); folderNode.Title = folder.Title; folderNode.Expanded = this.Expanded; this.SetImage(folderNode); folderNode.Id = folder.Id; folderNode.IsFolder = true; folderNode.CssClass += " folder"; //Load Documents var docsInFolder = manager.GetDocuments().Where(x => x.Parent.Id == album.Id && x.FolderId == folder.Id).Where(this.FilterExpressionForDocuments); foreach (var doc in docsInFolder) { DocumentTreeNode docNode = this.CreateDocNode(album, doc); folderNode.Nodes.Add(docNode); } //Load Children foreach (var child in folders.Where(x => x.ParentId == folder.Id)) { folderNode.Nodes.Add(this.GetChildNodes(child, folders, album, manager, docsInLibrary)); } rootNode.Nodes.Add(folderNode); } }
private DocumentTreeNode GetChildNodes(IFolder folder, IQueryable <IFolder> folders, DocumentLibrary album, LibrariesManager manager, IQueryable <Document> docsInLibrary) { var folderNode = new DocumentTreeNode(); folderNode.Expanded = this.Expanded; folderNode.Title = folder.Title; this.SetImage(folderNode); folderNode.Id = folder.Id; folderNode.IsFolder = true; folderNode.CssClass += " folder"; //Load Documents var docsInFolder = manager.GetDocuments().Where(x => x.Parent.Id == album.Id && x.FolderId == folder.Id).Where(this.FilterExpressionForDocuments); foreach (var doc in docsInFolder) { DocumentTreeNode docNode = this.CreateDocNode(album, doc); folderNode.Nodes.Add(docNode); } //Load Children foreach (var child in folders.Where(x => x.ParentId == folder.Id)) { folderNode.Nodes.Add(this.GetChildNodes(child, folders, album, manager, docsInLibrary)); } return(folderNode); }
/// <summary> /// Gets the document. /// </summary> /// <returns></returns> protected virtual bool TryGetDocument(out SfDocument document) { LibrariesManager librariesManager = LibrariesManager.GetManager(this.ProviderName); document = librariesManager.GetDocuments() .Where(i => i.Id == this.Id) .Where(PredefinedFilters.PublishedItemsFilter <SfDocument>()) .FirstOrDefault(); return(document != null); }
public void SetTorrentFile(LibrariesManager torrentManager, DynamicContent torrentItem) { var torrentFileItem = torrentManager .GetDocuments() .FirstOrDefault(i => i.Status == ContentLifecycleStatus.Master); if (torrentFileItem != null) { torrentFileItem.SetValue("FileType", torrentFileItem.MimeType); torrentItem.CreateRelation(torrentFileItem, "TorrentFile"); } }
private bool UploadFileToS3(Guid masterDocumentId, string providerName, string libraryName, string fileName, MemoryStream fileStream) { LibrariesManager librariesManager = LibrariesManager.GetManager(providerName); Document document = librariesManager.GetDocuments().Where(i => i.Id == masterDocumentId).FirstOrDefault(); if (document == null) { //The document is created as master. The masterDocumentId is assigned to the master version. document = librariesManager.CreateDocument(masterDocumentId); //Set the parent document library. DocumentLibrary documentLibrary = librariesManager.GetDocumentLibraries().Where(d => d.Title == libraryName).SingleOrDefault(); document.Parent = documentLibrary; //Set the properties of the document. string documentTitle = masterDocumentId.ToString() + "_" + fileName; document.Title = documentTitle; document.DateCreated = DateTime.UtcNow; document.PublicationDate = DateTime.UtcNow; document.LastModified = DateTime.UtcNow; document.UrlName = Regex.Replace(documentTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-"); document.MediaFileUrlName = Regex.Replace(documentTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-"); document.ApprovalWorkflowState = "Published"; //Upload the document file. string fileExtension = fileName.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries).Last(); librariesManager.Upload(document, fileStream, fileExtension ?? string.Empty); //Recompiles and validates the url of the document. librariesManager.RecompileAndValidateUrls(document); //Save the changes. librariesManager.SaveChanges(); //Publish the DocumentLibraries item. The live version acquires new ID. var bag = new Dictionary <string, string>(); bag.Add("ContentType", typeof(Document).FullName); WorkflowManager.MessageWorkflow(masterDocumentId, typeof(Document), null, "Publish", false, bag); return(true); } else { return(false); } }
public void Upload(TorrentUploaderWidgetModel torrent) { string torrentExtention = Path.GetExtension(torrent.TorrentFile.FileName); string torrentTitle = Path.GetFileNameWithoutExtension(torrent.TorrentFile.FileName); Guid torrentFileId = this._documentService.UploadTorrentFile(torrentTitle, torrent.TorrentFile.InputStream, torrent.TorrentFile.FileName, torrentExtention, TORRENT_FILE_LIBRARY); string imageExtention = Path.GetExtension(torrent.CoverImage.FileName); string imageTitle = Path.GetFileNameWithoutExtension(torrent.CoverImage.FileName); Guid torrentImageId = this._imageService.Upload(imageTitle, torrent.CoverImage.InputStream, torrent.CoverImage.FileName, imageExtention, TORRENT_COVER_IMAGE_ALBUM); // Set the provider name for the DynamicModuleManager here. All available providers are listed in // Administration -> Settings -> Advanced -> DynamicModules -> Providers var providerName = String.Empty; // Set a transaction name and get the version manager var transactionName = "someTransactionName"; var versionManager = VersionManager.GetManager(null, transactionName); DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName, transactionName); Type torrentType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Torrents.Torrent"); DynamicContent torrentItem = dynamicModuleManager.CreateDataItem(torrentType); // This is how values for the properties are set torrentItem.SetValue("Title", torrent.Title); torrentItem.SetValue("Description", torrent.Description); LibrariesManager torrentFileManager = LibrariesManager.GetManager(); var torrentFileItem = torrentFileManager.GetDocuments().FirstOrDefault(i => i.Id == torrentFileId && i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master); if (torrentFileItem != null) { torrentItem.CreateRelation(torrentFileItem, "TorrentFile"); } LibrariesManager imageManager = LibrariesManager.GetManager(); var imageItem = imageManager.GetImages().FirstOrDefault(i => i.Id == torrentImageId && i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master); if (imageItem != null) { torrentItem.CreateRelation(imageItem, "Image"); } torrentItem.SetString("UrlName", Guid.NewGuid().ToString()); torrentItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); torrentItem.SetValue("PublicationDate", DateTime.UtcNow); // Create a version and commit the transaction in order changes to be persisted to data store torrentItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft"); // Create a version and commit the transaction in order changes to be persisted to data store versionManager.CreateVersion(torrentItem, false); // We can now call the following to publish the item ILifecycleDataItem publishedTorrentItem = dynamicModuleManager.Lifecycle.Publish(torrentItem); // You need to set appropriate workflow status torrentItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published"); // Create a version and commit the transaction in order changes to be persisted to data store versionManager.CreateVersion(torrentItem, true); TransactionManager.CommitTransaction(transactionName); }