MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

RelatedContent Calles DB even if EntityType is None  (Mono Support )

Viewed 7082 time(s), 8 post(s) 1/8/2014 6:23:27 AMby Dinesh.Sajwan
Dinesh-Sajwan

Dinesh.Sajwan

1/8/2014 6:23:28 AM
Hi
Blog,Groups and Discussions using RelatedContent feature in monox .
RelatedContent finally calls RelatedContentBLL.GetRelatedContent method that
takes sourceContentId and sourceContentEntityType as a parameter. If sourceContentEntityType
is passing None then is this function should called or not ?  Actually for performance I am
putting check sourceContentEntityType!=SnEntityType.None  then only this
function should called .Am I doing right thing or is it going to impact
something?

This content has not been rated yet. 
1284 Reputation 156 Total posts
imarusic

imarusic

1/8/2014 9:45:04 AM
Hi,

you should set sourceContentEntityType in your parent page/control. That way you will get items related to the type specified. If you do not set contentEntityType  RelatedContentBLL.GetRelatedContent method will be called, but will not be fully executed and you should not see any items.

Regards.
This content has not been rated yet. 
3016 Reputation 428 Total posts
Dinesh-Sajwan

Dinesh.Sajwan

1/8/2014 10:45:00 AM
I did not change any functionality related to this user control(RelatedContent ) . I just put a simple check(sourceContentEntityType != SnEntityType.None   then function should called further  otherwise will return from here) in RelatedContentBLL.GetRelatedContent  method .
Is this change will impact anything else ? I should put this check or not ?
This content has not been rated yet. 
1284 Reputation 156 Total posts
imarusic

imarusic

1/8/2014 10:50:31 AM
It should not affect anything else because its called only from the related content user control. Do you have MonoX source code?
This content has not been rated yet. 
3016 Reputation 428 Total posts
Dinesh-Sajwan

Dinesh.Sajwan

1/8/2014 11:35:47 AM
yes I have source code of Monox.
I have made changes in below function only . Changes are highlighted Bold .

public virtual List<RelatedContentDTO> GetRelatedContent(Guid sourceContentId, SnEntityType sourceContentEntityType, RelatedContentArgs args, int pageIndex, int pageSize, out int recordCount)
{
List<RelatedContentDTO> result = null;
result = cacheManager.Get<List<RelatedContentDTO>>(ParamRelatedContentItems, sourceContentEntityType, sourceContentId, pageIndex, pageSize);
recordCount = cacheManager.Get<int>(ParamRelatedContentItems, sourceContentEntityType, sourceContentId, pageIndex, pageSize, "recordCount");
if (result == null)
{
if (sourceContentEntityType != SnEntityType.None)
{

result = new List<RelatedContentDTO>();
RelationshipRepository relationships = RelationshipRepository.GetInstance();
RelationPredicateBucket filter = new RelationPredicateBucket();
List<string> tags = new List<string>();
//Get source and tags
EntityCollection<SnTagEntity> tagCollection = new EntityCollection<SnTagEntity>();
filter = relationships.ConstructSnEntityTypeRelations(SnEntityType.Tag, filter);
filter = relationships.ConstructSnEntityTypeFilter(sourceContentId, sourceContentEntityType, filter);
relationships.FetchEntityCollection(tagCollection, filter);
tags.AddRange(tagCollection.Select(p => p.Slug).ToList());

if (tags.Count > 0)
{
//Get related content via tags
IEntityCollection2 collection = null;
IPrefetchPath2 prefetch = null;
filter = new RelationPredicateBucket();

switch (sourceContentEntityType)
{
case SnEntityType.File:
filter.Relations.Add(SnFileEntity.Relations.SnRelationshipEntityUsingFileId);
break;
case SnEntityType.Album:
case SnEntityType.Message:
case SnEntityType.Note:
case SnEntityType.BlogPost:
case SnEntityType.DiscussionMessage:
case SnEntityType.Comment:
case SnEntityType.Tag:
case SnEntityType.Rating:
case SnEntityType.DiscussionBoard:
case SnEntityType.DiscussionTopic:
case SnEntityType.Document:
case SnEntityType.NewsItem:
case SnEntityType.ListItem:
case SnEntityType.Blog:
case SnEntityType.Group:
case SnEntityType.User:
case SnEntityType.Campaign:
case SnEntityType.NewsCategory:
case SnEntityType.Newsletter:
case SnEntityType.Page:
case SnEntityType.Poll:
filter = relationships.ConstructSnEntityTypeRelations(sourceContentEntityType, filter);
break;
case SnEntityType.None:
default:
break;
}

filter.Relations.Add(SnRelationshipEntity.Relations.SnTagEntityUsingRelationshipId, JoinHint.Left);
filter.PredicateExpression.Add(new FieldCompareRangePredicate(SnTagFields.Slug, null, tags.ToArray()));

switch (sourceContentEntityType)
{
case SnEntityType.Album:
collection = new EntityCollection<SnAlbumEntity>();
prefetch = AlbumRepository.GetInstance().GetPrefetchPath(true);
break;
case SnEntityType.Message:
collection = new EntityCollection<SnMessageEntity>();
break;
case SnEntityType.Note:
collection = new EntityCollection<SnNoteEntity>();
break;
case SnEntityType.BlogPost:
collection = new EntityCollection<BlogPostEntity>();
prefetch = BlogRepository.GetInstance().GetBlogPostPrefetchPath(false);
prefetch.Add(BlogPostEntity.PrefetchPathBlog);
break;
//case SnEntityType.Custom1:
// break;
//case SnEntityType.Custom2:
// break;
//case SnEntityType.Custom3:
// break;
case SnEntityType.File:
collection = new EntityCollection<SnFileEntity>();
prefetch = FileRepository.GetInstance().GetPrefetchPath(true);
break;
//case SnEntityType.DiscussionMessage:
// break;
//case SnEntityType.Comment:
// break;
//case SnEntityType.Tag:
// break;
//case SnEntityType.Rating:
// break;
case SnEntityType.DiscussionBoard:
collection = new EntityCollection<SnDiscussionBoardEntity>();
prefetch = DiscussionRepository.GetInstance().GetBoardPrefetchPath(true);
break;
case SnEntityType.DiscussionTopic:
collection = new EntityCollection<SnDiscussionTopicEntity>();
prefetch = DiscussionRepository.GetInstance().GetTopicPrefetchPath(true, -1);
break;
case SnEntityType.Document:
collection = new EntityCollection<DocumentEntity>();
prefetch = DocumentRepository.GetInstance().GetDocumentPrefetchPath(true);
break;
case SnEntityType.NewsItem:
collection = new EntityCollection<NewsItemEntity>();
prefetch = NewsRepository.GetInstance().GetNewsItemPrefetchPath(true);
break;
case SnEntityType.ListItem:
collection = new EntityCollection<ListItemEntity>();
break;
case SnEntityType.Blog:
collection = new EntityCollection<BlogEntity>();
prefetch = BlogRepository.GetInstance().GetBlogPrefetchPath(true);
break;
//case SnEntityType.Subscriber:
// break;
case SnEntityType.Group:
collection = new EntityCollection<SnGroupEntity>();
prefetch = GroupRepository.GetInstance().GetGroupPrefetch(true);
break;
case SnEntityType.User:
collection = new EntityCollection<AspnetUsersEntity>();
prefetch = UserRepository.GetInstance().GetUserPrefetchPath();
break;
case SnEntityType.Campaign:
collection = new EntityCollection<CampaignEntity>();
prefetch = AdRepository.GetInstance().GetCampaignPrefetchPath2(true);
break;
case SnEntityType.NewsCategory:
collection = new EntityCollection<NewsCategoryEntity>();
prefetch = new PrefetchPath2(EntityType.NewsCategoryEntity);
break;
case SnEntityType.Newsletter:
collection = new EntityCollection<NewsletterEntity>();
prefetch = NewsletterRepository.GetInstance().GetPrefetchPath(true);
break;
case SnEntityType.Page:
collection = new EntityCollection<PageEntity>();
prefetch = PageRepository.GetInstance().GetPagePrefetchPath();
break;
case SnEntityType.Poll:
collection = new EntityCollection<PollEntity>();
prefetch = PollRepository.GetInstance().GetPrefetchPath(true);
break;
case SnEntityType.None:
default:
return result;
}

relationships.FetchEntityCollection(collection, filter, 0, null, prefetch, pageIndex, pageSize);
recordCount = relationships.GetDbCount(collection, filter);

//TODO: Implement all mappings
foreach (IEntity2 item in collection)
{
AspnetUsersEntity aspnetUser = null;
RelatedContentDTO dtoEntity = null;

switch (sourceContentEntityType)
{
case SnEntityType.Album:
var album = (SnAlbumEntity)item;
dtoEntity = new RelatedContentDTO(album.Id, sourceContentId, sourceContentEntityType);
dtoEntity.DateCreated = album.DateCreated;
dtoEntity.Content = album.Name;
dtoEntity.UserId = album.UserId.GetValueOrDefault();
dtoEntity.ContentUrl = RewrittenUrlBuilder.SocialNetwork.PhotoGallery.GetPhotoListUrl(args.PhotoListUrlPattern, album.Id, args.PhotoListUrl).Url;
aspnetUser = album.AspnetUser;
break;
case SnEntityType.Message:
break;
case SnEntityType.Note:
break;
case SnEntityType.BlogPost:
var blogPost = (BlogPostEntity)item;
dtoEntity = new RelatedContentDTO(blogPost.Id, sourceContentId, sourceContentEntityType);
dtoEntity.DateCreated = blogPost.DateCreated.GetValueOrDefault();
dtoEntity.Content = blogPost.Title;
dtoEntity.UserId = blogPost.UserId;
dtoEntity.ContentUrl = RewrittenUrlBuilder.Blog.GetBlogPostUrl(args.BlogPostUrl, blogPost).Url;
aspnetUser = blogPost.AspnetUser;
break;
case SnEntityType.File:
var file = (SnFileEntity)item;
dtoEntity = new RelatedContentDTO(file.Id, sourceContentId, sourceContentEntityType);
dtoEntity.DateCreated = file.DateCreated;
dtoEntity.Content = String.IsNullOrEmpty(file.Description) ? file.Name : file.Description;
dtoEntity.UserId = file.UserId;
dtoEntity.ContentUrl = RewrittenUrlBuilder.SocialNetwork.Files.GetFileViewUrl(args.ViewFilePageUrl, file.Id, args.CurrentPageId, String.Empty).Url;
aspnetUser = file.AspnetUser;
break;
case SnEntityType.DiscussionBoard:
var entity = (SnDiscussionBoardEntity)item;
dtoEntity = new RelatedContentDTO(entity.Id, sourceContentId, sourceContentEntityType);
dtoEntity.DateCreated = entity.DateCreated;
dtoEntity.Content = entity.Name;
dtoEntity.ContentUrl = DiscussionBase.GenerateBoardUrl(entity);
dtoEntity.UserId = entity.UserId.GetValueOrDefault();
aspnetUser = entity.AspnetUser;
break;
case SnEntityType.DiscussionTopic:
var topic = (SnDiscussionTopicEntity)item;
dtoEntity = new RelatedContentDTO(topic.Id, sourceContentId, sourceContentEntityType);
dtoEntity.DateCreated = topic.DateCreated;
dtoEntity.Content = topic.Title;
dtoEntity.ContentUrl = DiscussionBase.GenerateTopicUrl(topic);
dtoEntity.UserId = topic.UserId.GetValueOrDefault();
aspnetUser = topic.AspnetUser;
break;
case SnEntityType.Document:
var document = (DocumentEntity)item;
dtoEntity = new RelatedContentDTO(document.Id, sourceContentId, sourceContentEntityType);
dtoEntity.DateCreated = document.DateModified;
dtoEntity.Content = document.Title;
dtoEntity.ContentUrl = DocumentRepository.GetInstance().GetDocumentUrl(document);
dtoEntity.UserId = document.UserId.GetValueOrDefault();
aspnetUser = document.AspnetUsers;
break;
case SnEntityType.NewsItem:
var newsItem = (NewsItemEntity)item;
dtoEntity = new RelatedContentDTO(newsItem.Id, sourceContentId, sourceContentEntityType);
dtoEntity.DateCreated = newsItem.PublishStart;
dtoEntity.Content = newsItem.Title;
dtoEntity.ContentUrl = NewsBLL.GetInstance().GetNewsReadMorePageUrl(args.NewsReadMorePageUrl, newsItem.Id);
dtoEntity.UserId = newsItem.UserId;
aspnetUser = newsItem.AspnetUser;
break;
case SnEntityType.ListItem:
break;
case SnEntityType.Blog:
break;
case SnEntityType.Group:
var group = (SnGroupEntity)item;
dtoEntity = new RelatedContentDTO(group.Id, sourceContentId, sourceContentEntityType);
dtoEntity.DateCreated = group.DateCreated;
dtoEntity.Content = group.Name;
dtoEntity.ContentUrl = UrlUtility.RewritePagePath(RewrittenPaths.GroupView.UrlPattern, String.Empty, group);
dtoEntity.UserId = Guid.Empty;
aspnetUser = null;
break;
case SnEntityType.User:
var user = (AspnetUsersEntity)item;
dtoEntity = new RelatedContentDTO(user.UserId, sourceContentId, sourceContentEntityType);
dtoEntity.DateCreated = user.AspnetMembership != null ? user.AspnetMembership.CreateDate : user.LastActivityDate;
dtoEntity.Content = user.UserName;
dtoEntity.ContentUrl = RewrittenUrlBuilder.UserProfile.GetUserProfileUrl(RewrittenPaths.Profile.UrlPattern, user).Url;
dtoEntity.UserId = user.UserId;
aspnetUser = user;
break;
case SnEntityType.Campaign:
var campaign = (CampaignEntity)item;
dtoEntity = new RelatedContentDTO(campaign.Id, sourceContentId, sourceContentEntityType);
dtoEntity.DateCreated = campaign.DateEntered;
dtoEntity.Content = campaign.Name;
dtoEntity.ContentUrl = String.Empty;
dtoEntity.UserId = Guid.Empty;
aspnetUser = null;
break;
case SnEntityType.NewsCategory:
var newsCategory = (NewsCategoryEntity)item;
dtoEntity = new RelatedContentDTO(newsCategory.Id, sourceContentId, sourceContentEntityType);
dtoEntity.DateCreated = newsCategory.DateEntered.GetValueOrDefault();
dtoEntity.Content = LocalizationTextHandler.GetText(newsCategory.NewsCategoryLocalizations, NewsCategoryLocalizationFields.Title, NewsCategoryLocalizationFields.LanguageId);
dtoEntity.ContentUrl = String.Empty;
dtoEntity.UserId = Guid.Empty;
aspnetUser = null;
break;
case SnEntityType.Newsletter:
var newsletter = (NewsletterEntity)item;
dtoEntity = new RelatedContentDTO(newsletter.Id, sourceContentId, sourceContentEntityType);
dtoEntity.DateCreated = newsletter.SentOn.GetValueOrDefault();
dtoEntity.Content = newsletter.TextContent;
dtoEntity.ContentUrl = String.Empty;
dtoEntity.UserId = newsletter.UserId;
aspnetUser = newsletter.AspnetUser;
break;
case SnEntityType.Page:
var page = (PageEntity)item;
dtoEntity = new RelatedContentDTO(page.Id, sourceContentId, sourceContentEntityType);
dtoEntity.DateCreated = page.DateCreated;
dtoEntity.Content = page.Url;
dtoEntity.ContentUrl = LocalizationUtility.RewriteLink(page.Url);
dtoEntity.UserId = page.UserId.GetValueOrDefault();
aspnetUser = page.AspnetUsers;
break;
case SnEntityType.Poll:
var poll = (PollEntity)item;
dtoEntity = new RelatedContentDTO(poll.Id, sourceContentId, sourceContentEntityType);
dtoEntity.DateCreated = poll.DateModified;
dtoEntity.Content = poll.Title;
dtoEntity.ContentUrl = String.Empty;
dtoEntity.UserId = poll.UserId;
aspnetUser = poll.AspnetUser;
break;
case SnEntityType.None:
default:
break;
}

if (aspnetUser != null)
{
dtoEntity.UserName = aspnetUser.UserName;
if (aspnetUser.UserProfile != null)
dtoEntity.Author = String.Format("{0} {1}", aspnetUser.UserProfile.LastName, aspnetUser.UserProfile.FirstName);
dtoEntity.UserProfileUrl = RewrittenUrlBuilder.UserProfile.GetUserProfileUrl(args.UserProfileUrl, aspnetUser).Url;
}
result.Add(dtoEntity);
}
}

RelatedContentDTO sourceItem = result.FirstOrDefault(p => p.Id.Equals(sourceContentId));
if (sourceItem != null)
result.Remove(sourceItem);

cacheManager.Store(result, ParamRelatedContentItems, sourceContentEntityType, sourceContentId, pageIndex, pageSize);
cacheManager.Store(recordCount, ParamRelatedContentItems, sourceContentEntityType, sourceContentId, pageIndex, pageSize, "recordCount");
}
}
return result;
}
This content has not been rated yet. 
1284 Reputation 156 Total posts
imarusic

imarusic

1/8/2014 12:00:38 PM
Can you please post a file instead of posting all the code here for the future posts? Its easier to view/monitor it. As far as I see your change should not be a problem, this way you prevented some DB calls.

Regards.
This content has not been rated yet. 
3016 Reputation 428 Total posts
Dinesh-Sajwan

Dinesh.Sajwan

1/8/2014 12:12:27 PM
Hi
I am attaching the code file of RelatedContentBLL . So as per your suggestion I should go ahead with these changes for better performance?
This content has not been rated yet. 
1284 Reputation 156 Total posts
imarusic

imarusic

1/8/2014 12:33:33 PM
It seems fine that way as I already mentioned. Just to check, where do you have that control without entityType set?
This content has not been rated yet. 
3016 Reputation 428 Total posts