/// <summary> /// Updates the relationship for associated contents. /// </summary> /// <param name="contentDetails">Details of the content.</param> /// <param name="content">Content which has to be updated.</param> private static void UpdateAssociateContents(ContentDetails contentDetails, Content content) { var deletedById = content.ModifiedByID.Value; // Get all Existing files list. var newFilesIDs = contentDetails.AssociatedFiles .Where(af => (af.ContentID.HasValue) && (af.ContentID.Value > 0)) .Select(af => af.ContentID.Value); // Delete all existing associated files which are not part of the new associated file list. var removeAssociatedFiles = from cr in content.ContentRelation where cr.ContentRelationshipTypeID == (int)AssociatedContentRelationshipType.Associated && !newFilesIDs.Contains(cr.Content1.ContentID) select cr; foreach (var item in Enumerable.ToList(removeAssociatedFiles)) { item.Content1.IsDeleted = true; item.Content1.DeletedByID = deletedById; item.Content1.DeletedDatetime = DateTime.UtcNow; content.ContentRelation.Remove(item); } // Create new associated files. CreateAssociateContents(content, contentDetails); }
/// <summary> /// Creates the relationship for associated contents. /// </summary> /// <param name="content">Content which has to be updated.</param> /// <param name="contentDetails">Details of the content.</param> private static void CreateAssociateContents(Content content, ContentDetails contentDetails) { if (contentDetails.AssociatedFiles != null && contentDetails.AssociatedFiles.Count() > 0) { foreach (var dataDetails in contentDetails.AssociatedFiles) { // Create new associated file only if contentId is not set if (!dataDetails.ContentID.HasValue || dataDetails.ContentID.Value <= 0) { var associatedContent = new Content(); associatedContent.SetValuesFrom(contentDetails, dataDetails); // Note that Modifying user is the one who is creating the associated contents. associatedContent.CreatedByID = content.ModifiedByID.Value; var associatedRelation = new ContentRelation() { Content = content, Content1 = associatedContent, ContentRelationshipTypeID = (int)AssociatedContentRelationshipType.Associated }; content.ContentRelation.Add(associatedRelation); } } } }
/// <summary> /// Takes MHT content and converts it into an HTML document /// </summary> /// <param name="mhtContent">The mht content to convert.</param> /// <returns></returns> public string ConvertToHTMLDocument(string mhtContent) { Dictionary <string, ContentDetails> splitContent = new Dictionary <string, ContentDetails>(); if (string.IsNullOrWhiteSpace(mhtContent)) { return(null); } var boundary = GetBoundary(mhtContent); string[] parts = mhtContent.Split(new string[] { boundary }, StringSplitOptions.RemoveEmptyEntries); foreach (string part in parts) { ContentDetails contentDetails = ContentDetails.ExtractContentDetails(part); if (contentDetails.HasAllContentHeaders) { splitContent.Add(contentDetails.ContentLocation, contentDetails); } } // WORK IN PROGRESS return(splitContent.First(k => k.Key.Contains(".htm")).Value.Content); }
/// <summary> /// This function retrieves the contents uploaded by the user. /// </summary> /// <param name="userId">User identity.</param> /// <returns>Payload details.</returns> public async Task <PayloadDetails> GetUserContents(long userId) { PayloadDetails payloadDetails = null; Expression <Func <Content, bool> > condition = c => c.CreatedByID == userId && c.IsDeleted == false && Enumerable.FirstOrDefault(c.CommunityContents) != null && !(bool)Enumerable.FirstOrDefault(c.CommunityContents).Community.IsDeleted; Func <Content, object> orderBy = c => c.ModifiedDatetime; var contents = _contentRepository.GetItems(condition, orderBy, true); // Get Content Details object from Contents so that it has permission details var contentDetailsList = new List <ContentDetails>(); foreach (Content content in contents) { var userRole = GetContentUserRole(content, userId); // For private contents, user's who have not assigned explicit permission will not have access. if (userRole != UserRole.None) { var contentDetails = new ContentDetails(userRole.GetPermission()); contentDetails.SetValuesFrom(content); contentDetailsList.Add(contentDetails); } } payloadDetails = PayloadDetailsExtensions.InitializePayload(); payloadDetails.Name = "My Contents"; payloadDetails.SetValuesFrom(contentDetailsList); return(payloadDetails); }
/// <summary> /// Extracts the content into a new ContentDetails object. /// </summary> /// <param name="content">The content to extract from.</param> /// <returns></returns> public static ContentDetails ExtractContentDetails(string content) { ContentDetails details = new ContentDetails(); Match match; match = ContentLocationRegex.Match(content); if (match.Success) { details.ContentLocation = match.Groups[1].Value.RemoveNewLines(false); } match = ContentTransferEncodingRegex.Match(content); if (match.Success) { details.ContentTransferEncoding = match.Groups[1].Value.RemoveNewLines(false); } match = ContentTypeRegex.Match(content); if (match.Success) { details.ContentType = match.Groups[1].Value.RemoveNewLines(false); } match = ContentRegex.Match(content); if (match.Success) { details.Content = match.Groups[2].Value.RemoveNewLines(false); } return(details); }
public void SaveContent_GivenValidContentDetails_ExpectSuccess() { string url = "api/SaveContent"; var details = new ContentDetails { Id = 1, AuthorId = "*****@*****.**", Category = "test category", ContentValue = "test content", Title = "test title", Type = "test type" }; var json = JsonConvert.SerializeObject(details); var content = new StringContent(json, Encoding.UTF8, "application/json"); var httpResponse = _fixture.Client.PostAsync(url, content).Result; httpResponse.StatusCode.Should().Be(HttpStatusCode.OK); var jsonResponse = httpResponse.Content.ReadAsStringAsync().Result; var status = JsonConvert.DeserializeObject <Status>(jsonResponse); status.Should().NotBeNull(); status.StatusCode.Should().Be(Status.SUCCESS_STATUS_CODE); status.StatusDesc.Should().Be(Status.SUCCESS_STATUS_TEXT); }
private long CreateTour(string filename, Stream fileContent, ProfileDetails profileDetails, CommunityDetails parentCommunity) { var tourDoc = new XmlDocument(); ContentDetails content = null; // NetworkStream is not Seek able. Need to load into memory stream so that it can be sought using (Stream writablefileContent = new MemoryStream()) { fileContent.CopyTo(writablefileContent); writablefileContent.Position = 0; content = GetContentDetail(filename, writablefileContent, profileDetails, parentCommunity); writablefileContent.Position = 0; tourDoc = tourDoc.SetXmlFromTour(writablefileContent); } if (tourDoc != null) { // Note that the spelling of Description is wrong because that's how WWT generates the WTT file. content.Name = tourDoc.GetAttributeValue("Tour", "Title"); content.Description = tourDoc.GetAttributeValue("Tour", "Descirption"); content.DistributedBy = tourDoc.GetAttributeValue("Tour", "Author"); content.TourLength = tourDoc.GetAttributeValue("Tour", "RunTime"); } var contentService = DependencyResolver.Current.GetService(typeof(IContentService)) as IContentService; var contentId = content.ID = contentService.CreateContent(content); if (contentId > 0) { var notificationService = DependencyResolver.Current.GetService(typeof(INotificationService)) as INotificationService; notificationService.NotifyNewEntityRequest(content, BaseUri() + "/"); } return(contentId); }
/// <summary> /// Notify the user about the new Content. /// </summary> /// <param name="contentDetails">Content details</param> /// <param name="server">Server details.</param> public void NotifyNewEntityRequest(ContentDetails contentDetails, string server) { if (Constants.CanSendNewEntityMail) { SendNewContentMail(contentDetails, server); } }
private ContentDetails GetCurrentContentDetails() { ContentDetails details = (ContentDetails)CacheService.Get("ContentDetails", CacheScope.Context) ?? new ContentDetails() { PageName = "default" }; if (PublicApi.Url.CurrentContext != null && details.PageName == "default") { details.PageName = PublicApi.Url.CurrentContext.PageName; ContextualItem(coa => { details.ContentId = coa.ContentId; details.ContentTypeId = coa.ContentTypeId; }, a => { details.ApplicationId = a.ApplicationId; details.ApplicationTypeId = a.ApplicationTypeId; }, c => { details.ContainerId = c.ContainerId; details.ContainerTypeId = c.ContainerTypeId; }); } CacheService.Put("ContentDetails", details, CacheScope.Context); return(details); }
public async Task <IActionResult> FilterContent ( [HttpTrigger(AuthorizationLevel.Anonymous, "get")] FilterResultsRequest filter, HttpRequest req, ILogger log ) { var details2 = new ContentDetails { Id = 1, AuthorId = "*****@*****.**", Category = "test category", ContentValue = "test content", Title = "test title", Type = "test type" }; var status = await _manager.SaveAsync(details2); log.LogInformation("C# HTTP FilterContent trigger function processed a request."); var details = await _manager.List(filter); return(new OkObjectResult(details)); }
private ContentDetails GetContentDetails(Guid contentId, Guid contentTypeId) { string cacheKey = string.Format("ContentDetails::{0}::{1}", contentId, contentTypeId); ContentDetails details = CacheService.Get(cacheKey, CacheScope.Distributed) as ContentDetails; if (details == null) { details = new ContentDetails() { PageName = "default" }; var content = PublicApi.Content.Get(contentId, contentTypeId); if (content != null) { details.ContentId = content.ContentId; details.ContentTypeId = content.ContentTypeId; details.ApplicationId = content.Application.ApplicationId; details.ApplicationTypeId = content.Application.ApplicationTypeId; details.ContainerId = content.Application.Container.ContainerId; details.ContainerTypeId = content.Application.Container.ContainerTypeId; } } CacheService.Put(cacheKey, details, CacheScope.Distributed, TimeSpan.FromMinutes(5)); return(details); }
public void SaveMetaDataConfiguration(string title, string description, string keywords, bool inherit, IDictionary extendedTags) { if (CanEdit) { ContentDetails details = GetCurrentContentDetails(); string cacheKey = GetCacheKey(details.FileName); using (MemoryStream buffer = new MemoryStream(10000)) { var data = new MetaData() { InheritData = inherit, ApplicationId = details.ApplicationId.GetValueOrDefault(Guid.Empty), ContainerId = details.ContainerId.GetValueOrDefault(Guid.Empty), ContainerTypeId = details.ContainerTypeId.GetValueOrDefault(Guid.Empty), Title = title, Description = description, Keywords = keywords, ExtendedMetaTags = new SerializableDictionary <string, string>(extendedTags.Keys.Cast <string>() .ToDictionary(name => name, name => extendedTags[name] as string)) }; //Translate the URL's if any have been uploaded _metaDataSerializer.Serialize(buffer, data); buffer.Seek(0, SeekOrigin.Begin); MetaDataStore.AddFile("", details.FileName + ".xml", buffer, false); } CacheService.Remove(cacheKey, CacheScope.All); } }
public IActionResult AddContent(AddContentModel model) { try { if (ModelState.IsValid) { ContentDetails contentModel = ContentHelper.BindContentDetailsModel(model); long contentId = iContent.AddContent(contentModel); if (contentId > 0) { return(Ok(ResponseHelper.Success(MessageConstants.ContentAdded))); } else if (contentId == ReturnCode.AlreadyExist.GetHashCode()) { return(Ok(ResponseHelper.Error(MessageConstants.TryDifferentNameShortName))); } else { return(Ok(ResponseHelper.Error(MessageConstants.ContentNotAdded))); } } else { return(Ok(ResponseHelper.Error(MessageConstants.CompulsoryData))); } } catch (Exception ex) { LogHelper.ExceptionLog(ex.Message + " ::::: " + ex.StackTrace); return(Ok(ResponseHelper.Error(ex.Message))); } }
/// <summary> /// Uploads all files to azure. /// </summary> /// <param name="contentDetails">Details of the content.</param> private bool UploadFilesToAzure(ContentDetails contentDetails, Content content) { var uploadStatus = true; // Upload content data. var fileDetail = contentDetails.ContentData as FileDetail; if (fileDetail != null && content.ContentAzureID != fileDetail.AzureID) { // Move the content file from temporary container to file container. uploadStatus = MoveFile(fileDetail); } // Upload video. if (contentDetails.Video != null && uploadStatus) { var videoDetail = contentDetails.Video as FileDetail; if (videoDetail != null) { // Move the video file from temporary container to file container. uploadStatus = MoveFile(videoDetail); } } return(uploadStatus); }
private long CreateCollection(string filename, Stream fileContent, ProfileDetails profileDetails, CommunityDetails parentCommunity) { // Get name/ tags/ category from Tour. var collectionDoc = new XmlDocument(); ContentDetails content = null; // NetworkStream is not Seek able. Need to load into memory stream so that it can be sought using (Stream writablefileContent = new MemoryStream()) { fileContent.CopyTo(writablefileContent); writablefileContent.Position = 0; content = GetContentDetail(filename, writablefileContent, profileDetails, parentCommunity); writablefileContent.Seek(0, SeekOrigin.Begin); collectionDoc = collectionDoc.SetXmlFromWtml(writablefileContent); } if (collectionDoc != null) { content.Name = collectionDoc.GetAttributeValue("Folder", "Name"); } var contentService = DependencyResolver.Current.GetService(typeof(IContentService)) as IContentService; var contentId = content.ID = contentService.CreateContent(content); if (contentId > 0) { var notificationService = DependencyResolver.Current.GetService(typeof(INotificationService)) as INotificationService; notificationService.NotifyNewEntityRequest(content, BaseUri() + "/"); } return(contentId); }
/// <summary> /// Updates the content. /// </summary> /// <param name="contentModel">The model.</param> /// <returns></returns> public long UpdateContent(ContentDetails contentModel) { try { var contentDetails = context.ContentDetails.Where(x => (x.Name == contentModel.Name || x.ShortName == contentModel.ShortName) && x.IsDelete == false && x.ContentId != contentModel.ContentId).FirstOrDefault(); if (contentDetails == null) { var contentDetailsModel = context.ContentDetails.Where(x => x.ContentId == contentModel.ContentId && x.IsDelete == false).FirstOrDefault(); if (contentDetailsModel != null) { contentDetailsModel.ShortName = contentModel.ShortName; contentDetailsModel.Name = contentModel.Name; contentDetailsModel.Description = contentModel.Description; contentDetailsModel.ModifiedOn = DateTime.Now; contentDetailsModel.UpdatedBy = contentModel.UpdatedBy; context.SaveChanges(); return(contentModel.ContentId); } else { return(ReturnCode.NotExist.GetHashCode()); } } else { return(ReturnCode.AlreadyExist.GetHashCode()); } } catch (Exception ex) { LogHelper.ExceptionLog(ex.Message + " ::::: " + ex.StackTrace); return(0); } }
/// <summary> /// Populates the Place object's properties from the given content. /// </summary> /// <param name="thisObject">Place object</param> /// <param name="contentDetail">content Details object</param> /// <returns>Place instance</returns> public static Place SetValuesFrom(this Place thisObject, ContentDetails contentDetail) { if (contentDetail != null) { if (thisObject == null) { thisObject = new Place(); } thisObject.Name = contentDetail.Name; thisObject.MSRComponentId = contentDetail.ID; thisObject.FileType = contentDetail.ContentData.ContentType; if (contentDetail.ContentData is LinkDetail) { var linkDetail = contentDetail.ContentData as LinkDetail; thisObject.ContentLink = linkDetail.ContentUrl; thisObject.ContentAzureID = string.Empty; } else { var fileDetail = contentDetail.ContentData as FileDetail; thisObject.ContentLink = string.Empty; thisObject.ContentAzureID = fileDetail.AzureID.ToString(); } thisObject.Url = contentDetail.ContentData.Name; thisObject.Thumbnail = (contentDetail.Thumbnail != null && contentDetail.Thumbnail.AzureID != Guid.Empty) ? contentDetail.Thumbnail.AzureID.ToString() : null; thisObject.Permission = contentDetail.UserPermission; } return(thisObject); }
private void SendNewContentMail(ContentDetails contentDetails, string server) { try { // Send Mail. var request = new NewEntityRequest { EntityType = EntityType.Content, EntityID = contentDetails.ID, EntityName = contentDetails.Name, EntityLink = string.Format(CultureInfo.InvariantCulture, "{0}Content/Index/{1}", server, contentDetails.ID), UserID = contentDetails.CreatedByID, UserLink = string.Format(CultureInfo.InvariantCulture, "{0}Profile/Index/{1}", server, contentDetails.CreatedByID) }; SendMail(request); } catch (Exception) { // Ignore all exceptions. } }
public async Task <JsonResult> SaveEdits(string contentInputViewModel) { if (CurrentUserId == 0) { await TryAuthenticateFromHttpContext(_communityService, _notificationService); } //TODO: understand why can't cast the viewmodel directly the way we do with new content?? var viewModel = JsonConvert.DeserializeObject <ContentInputViewModel>(contentInputViewModel); var isValid = ModelState.IsValid; if (isValid) { if (CurrentUserId != 0 && viewModel.ID.HasValue) { var contentDetails = new ContentDetails(); contentDetails.SetValuesFrom(viewModel); // Update contents. _contentService.UpdateContent(contentDetails, CurrentUserId); return(Json(contentDetails)); } return(Json("error: User not logged in")); } return(Json("error: Could not save changes to content")); }
public Content GetNewContent(ContentDetails details, bool isFSTContent = false) { Content content = new Content(contents.Count, (short)contents.Count, details.entriesFlag, details.groupID, details.parentTitleID, details.isHashed, isFSTContent); contents.Add(content); return(content); }
private void DeleteTemporaryThumbnail(ContentDetails contentDetails) { var thumbnailBlob = new BlobDetails() { BlobID = contentDetails.Thumbnail.AzureID.ToString() }; // Delete thumbnail from azure. _blobDataRepository.DeleteThumbnail(thumbnailBlob); }
public async Task <IActionResult> SaveContent ( [HttpTrigger(AuthorizationLevel.Anonymous, "post")] ContentDetails details, HttpRequest req, ILogger log ) { log.LogInformation("C# HTTP FilterContent trigger function processed a request."); var status = await _manager.SaveAsync(details); return(new OkObjectResult(status)); }
/// <summary> /// Converts to content details model. /// </summary> /// <param name="contentDetails">The model.</param> /// <returns></returns> public static AddContentModel BindContentDetailsModel(ContentDetails contentDetails) { AddContentModel addContentModel = new AddContentModel(); if (contentDetails != null) { addContentModel.ContentId = contentDetails.ContentId; addContentModel.ShortName = contentDetails.ShortName; addContentModel.Name = contentDetails.Name; addContentModel.Description = contentDetails.Description; } return(addContentModel); }
/// <summary> /// Populates the Content object's properties from the given ContentDetails object's properties. /// </summary> /// <param name="thisObject">Current Content instance on which the extension method is called</param> /// <param name="contentDetails">ContentDetails model from which values to be read</param> public static void SetValuesFrom(this Content thisObject, ContentDetails contentDetails) { if (contentDetails != null && thisObject != null) { thisObject.Title = contentDetails.Name; thisObject.Description = contentDetails.Description; thisObject.Citation = contentDetails.Citation; thisObject.DistributedBy = contentDetails.DistributedBy; thisObject.AccessTypeID = contentDetails.AccessTypeID; thisObject.CategoryID = contentDetails.CategoryID; thisObject.TourRunLength = contentDetails.TourLength; thisObject.SetValuesFrom(contentDetails.ContentData); } }
public ContentDetails GetContentDetails(Guid azureId) { ContentDetails contentDetails = null; var content = _contentRepository.GetContent(azureId); if (content != null) { var userRole = UserRole.SiteAdmin; var userPermission = userRole.GetPermission(); contentDetails = new ContentDetails(userPermission); contentDetails.SetValuesFrom(content); } return(contentDetails); }
/// <summary> /// Converts to content details model. /// </summary> /// <param name="addContentModel">The model.</param> /// <returns></returns> public static ContentDetails BindContentDetailsModel(AddContentModel addContentModel) { ContentDetails contentDetails = new ContentDetails(); if (addContentModel != null) { contentDetails.ContentId = addContentModel.ContentId; contentDetails.ShortName = addContentModel.ShortName; contentDetails.Name = addContentModel.Name; contentDetails.Description = addContentModel.Description; contentDetails.CreatedOn = DateTime.Now; contentDetails.CreatedBy = DBHelper.ParseInt64(addContentModel.CreatedBy); contentDetails.UpdatedBy = DBHelper.ParseInt64(addContentModel.UpdatedBy); } return(contentDetails); }
public ContentDetails GetContentDetails(Guid azureId, bool?deleted) { var deletedCondition = deleted.HasValue ? deleted : false; ContentDetails contentDetails = null; var content = _contentRepository.GetContent(azureId, deletedCondition); if (content != null) { var userRole = UserRole.SiteAdmin; var userPermission = userRole.GetPermission(); contentDetails = new ContentDetails(userPermission); contentDetails.SetValuesFrom(content); } return(contentDetails); }
/// <summary> /// Populates the PayloadDetails object's properties from the given Content object's properties. /// </summary> /// <param name="thisObject">PayloadDetails object</param> /// <param name="contentDetail">Content Details object</param> /// <returns>PayloadDetails instance</returns> public static PayloadDetails SetValuesFrom(this PayloadDetails thisObject, ContentDetails contentDetail) { if (contentDetail != null) { if (thisObject == null) { thisObject = InitializePayload(); } if (contentDetail.ContentData is FileDetail) { var fileDetail = contentDetail.ContentData as FileDetail; if (contentDetail.ContentData.ContentType == ContentTypes.Tours) { var tour = new TourModel(); tour.SetValuesFrom(contentDetail); thisObject.Tours.Add(tour); } else if (contentDetail.ContentData.ContentType == ContentTypes.Wtml) { var childCollection = new PayloadDetails(); childCollection.Name = contentDetail.Name; childCollection.Id = fileDetail.AzureID.ToString(); childCollection.MSRComponentId = contentDetail.ID; childCollection.Group = "Explorer"; childCollection.IsCollection = true; childCollection.Thumbnail = (contentDetail.Thumbnail != null && contentDetail.Thumbnail.AzureID != Guid.Empty) ? contentDetail.Thumbnail.AzureID.ToString() : null; childCollection.Permission = contentDetail.UserPermission; thisObject.Children.Add(childCollection); } else { var place = new Place(); place.SetValuesFrom(contentDetail); thisObject.Links.Add(place); } } else { var place = new Place(); place.SetValuesFrom(contentDetail); thisObject.Links.Add(place); } } return(thisObject); }
public async Task <JsonResult> New(ContentInputViewModel contentInputViewModel, string id) { if (CurrentUserId == 0) { await TryAuthenticateFromHttpContext(_communityService, _notificationService); } if (ModelState.IsValid) { var contentDetails = new ContentDetails(); contentDetails.SetValuesFrom(contentInputViewModel); contentDetails.CreatedByID = CurrentUserId; contentInputViewModel.ID = contentDetails.ID = _contentService.CreateContent(contentDetails); } return(new JsonResult { Data = contentInputViewModel }); }
public async Task <ActionResult> ShowDetails(int IDcontent, string username, ContentDetails model) { using (ZavrsniEFentities db = new ZavrsniEFentities()) { var currentUser = User.Identity.GetUserName(); var cont = db.Content.FirstOrDefault(u => u.IDcontent.Equals(IDcontent)); var usernameAuthor = db.User.FirstOrDefault(u => u.IDuser.Equals(cont.IDauthor)); var usernameCurrent = db.User.FirstOrDefault(u => u.Username.Equals(currentUser)); if (Request["PageDropDown"].Any()) { var contCopy = db.Content.Create(); contCopy.IDcontentType = cont.IDcontentType; contCopy.IDauthor = usernameCurrent.IDuser; contCopy.Text = cont.Text; contCopy.Title = cont.Title; contCopy.IsCopied = true; contCopy.IDeditor = usernameCurrent.IDuser; contCopy.TimeChanged = DateTime.Now; db.Content.Add(contCopy); db.SaveChanges(); var contCopyLoc = (from l in db.LocationContent where l.IDcontent == cont.IDcontent select l.IDlocation).ToList(); foreach (var a in contCopyLoc) { var contLoc = db.LocationContent.Create(); contLoc.IDlocation = a; contLoc.IDcontent = contCopy.IDcontent; contLoc.TimeChanged = DateTime.Now; db.LocationContent.Add(contLoc); db.SaveChanges(); } var contPage = db.ContentPage.Create(); contPage.IDcontent = contCopy.IDcontent; contPage.IDuser = usernameCurrent.IDuser; var pageSel = Request["PageDropDown"]; contPage.IDpage = Convert.ToInt32(pageSel); db.ContentPage.Add(contPage); db.SaveChanges(); } } return(RedirectToAction("Details", new { IDcontent = IDcontent, Username = username })); }
private string GetBestImageUrlForContentDetails(ContentDetails details) { string imageUrl = string.Empty; if (details.ContentId.HasValue && details.ContentTypeId.HasValue) { //Look for first image in content Content content = PublicApi.Content.Get(details.ContentId.Value, details.ContentTypeId.Value); if (!content.HasErrors()) { imageUrl = ExtractImage(content.HtmlDescription("")); } } if (details.ApplicationId.HasValue && string.IsNullOrWhiteSpace(imageUrl)) { //Look for first image in application description var app = PublicApi.Applications.Get(details.ApplicationId.Value, details.ApplicationTypeId.Value); if (!app.HasErrors()) { imageUrl = ExtractImage(app.HtmlDescription("")); } } if (details.ContainerId.HasValue && details.ContainerTypeId.HasValue && string.IsNullOrWhiteSpace(imageUrl)) { //Get image from group avatar //Look for first image in application description var container = PublicApi.Containers.Get(details.ContainerId.Value, details.ContainerTypeId.Value); if (!container.HasErrors()) { imageUrl = ExtractImage(container.AvatarUrl); } } return imageUrl; }
private ContentDetails GetContentDetails(Guid contentId, Guid contentTypeId) { string cacheKey = string.Format("ContentDetails::{0}::{1}", contentId, contentTypeId); ContentDetails details = CacheService.Get(cacheKey, CacheScope.Distributed) as ContentDetails; if (details == null) { details = new ContentDetails() { PageName = "default" }; var content = PublicApi.Content.Get(contentId, contentTypeId); if (content != null) { details.ContentId = content.ContentId; details.ContentTypeId = content.ContentTypeId; details.ApplicationId = content.Application.ApplicationId; details.ApplicationTypeId = content.Application.ApplicationTypeId; details.ContainerId = content.Application.Container.ContainerId; details.ContainerTypeId = content.Application.Container.ContainerTypeId; } } CacheService.Put(cacheKey, details, CacheScope.Distributed, TimeSpan.FromMinutes(5)); return details; }
private MetaData GetCurrentMetaData(ContentDetails details) { string cacheKey = GetCacheKey(details.FileName); MetaData result = CacheService.Get(cacheKey, CacheScope.All) as MetaData; if (result == null && MetaDataStore != null) { ICentralizedFile file = MetaDataStore.GetFile("", details.FileName + ".xml"); if (file != null) { using (Stream stream = file.OpenReadStream()) { result = ((MetaData)_metaDataSerializer.Deserialize(stream)); //FIlter out any tags that have oreviously been configured but then removed var lookup = _metaConfig.ExtendedEntries.ToLookup(f => f); foreach (var tag in result.ExtendedMetaTags.Keys) { if (!lookup.Contains(tag)) result.ExtendedMetaTags.Remove(tag); } } } if (result == null) { result = new MetaData() { InheritData = true, ContainerId = details.ContainerId.GetValueOrDefault(Guid.Empty), ContainerTypeId = details.ContainerTypeId.GetValueOrDefault(Guid.Empty) }; } CacheService.Put(cacheKey, result, CacheScope.All); } return result; }