Beispiel #1
0
        public IBlogPost Select()
        {
            var serviceContext = BlogDependencies.GetServiceContext();

            var query = serviceContext.CreateQuery("adx_blogpost")
                        .Where(post => post.GetAttributeValue <Guid>("adx_blogpostid") == BlogPostReference.Id);

            if (!Security.UserHasAuthorPermission)
            {
                query = query.Where(post => post.GetAttributeValue <bool?>("adx_published") == true);
            }

            var entity = query.FirstOrDefault();

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

            var securityProvider = BlogDependencies.GetSecurityProvider();

            if (!securityProvider.TryAssert(serviceContext, entity, CrmEntityRight.Read))
            {
                return(null);
            }

            var urlProvider      = BlogDependencies.GetUrlProvider();
            var tagPathGenerator = new BlogArchiveApplicationPathGenerator(BlogDependencies);

            return(new BlogPostFactory(serviceContext, urlProvider, BlogDependencies.GetWebsite(), tagPathGenerator).Create(new [] { entity }).FirstOrDefault());
        }
        public IEnumerable <IBlogPostWeightedTag> SelectWeightedTags(int weights)
        {
            var serviceContext = BlogDependencies.GetServiceContext();

            var infos = serviceContext.FetchBlogPostTagCounts(Blog.Id)
                        .Select(c => new BlogPostTagInfo(c.Item1, c.Item2));

            var tagCloudData         = new TagCloudData(weights, TagInfo.TagComparer, infos);
            var archivePathGenerator = new BlogArchiveApplicationPathGenerator(BlogDependencies);

            return(tagCloudData.Select(e => new BlogPostWeightedTag(e.Name, archivePathGenerator.GetTagPath(e.Name, Blog), e.TaggedItemCount, e.Weight)));
        }
        public IEnumerable <IBlogArchiveMonth> SelectArchiveMonths()
        {
            var serviceContext = BlogDependencies.GetServiceContext();

            var counts = serviceContext.FetchBlogPostCountsGroupedByMonth(Blog.Id);
            var archivePathGenerator = new BlogArchiveApplicationPathGenerator(BlogDependencies);

            return(counts.Select(c =>
            {
                var month = new DateTime(c.Item1, c.Item2, 1, 0, 0, 0, DateTimeKind.Utc);

                return new BlogArchiveMonth(month, c.Item3, archivePathGenerator.GetMonthPath(month, Blog));
            }).OrderByDescending(e => e.Month));
        }
Beispiel #4
0
        public IDictionary <string, object> GetCommentAttributes(string content, string authorName = null, string authorEmail = null, string authorUrl = null, HttpContext context = null)
        {
            var post = Select();

            if (post == null)
            {
                throw new InvalidOperationException("Unable to load adx_blogpost {0}. Please ensure that this record exists, and is accessible by the current user.".FormatWith(BlogPostReference.Id));
            }

            var postedOn = DateTime.UtcNow;

            var attributes = new Dictionary <string, object>
            {
                { "regardingobjectid", post.Entity.ToEntityReference() },
                { "createdon", postedOn },
                { "adx_approved", post.CommentPolicy == BlogCommentPolicy.Open || post.CommentPolicy == BlogCommentPolicy.OpenToAuthenticatedUsers },
                { "title", StringHelper.GetCommentTitleFromContent(content) },
                { "adx_createdbycontact", authorName },
                { "adx_contactemail", authorEmail },
                { "comments", content },
                { "source", new OptionSetValue((int)FeedbackSource.Portal) }
            };

            var portalUser = BlogDependencies.GetPortalUser();

            if (portalUser != null && portalUser.LogicalName == "contact")
            {
                attributes[FeedbackMetadataAttributes.UserIdAttributeName] = portalUser;
            }
            else if (context != null && context.Profile != null)
            {
                attributes[FeedbackMetadataAttributes.VisitorAttributeName] = context.Profile.UserName;
            }

            if (authorUrl != null)
            {
                authorUrl = authorUrl.Contains(Uri.SchemeDelimiter) ? authorUrl : "{0}{1}{2}".FormatWith(Uri.UriSchemeHttp, Uri.SchemeDelimiter, authorUrl);

                if (Uri.IsWellFormedUriString(authorUrl, UriKind.Absolute))
                {
                    attributes["adx_authorurl"] = authorUrl;
                }
            }
            if (FeatureCheckHelper.IsFeatureEnabled(FeatureNames.TelemetryFeatureUsage))
            {
                PortalFeatureTrace.TraceInstance.LogFeatureUsage(FeatureTraceCategory.Blog, HttpContext.Current, "create_comment_blog", post.CommentCount, post.Entity.ToEntityReference(), "create");
            }

            return(attributes);
        }
Beispiel #5
0
        public virtual int SelectCommentCount()
        {
            var serviceContext            = BlogDependencies.GetServiceContext();
            var includeUnapprovedComments = Security.UserHasAuthorPermission;

            return(serviceContext.FetchCount("feedback", "feedbackid", addCondition =>
            {
                addCondition("regardingobjectid", "eq", BlogPostReference.Id.ToString());

                if (!includeUnapprovedComments)
                {
                    addCondition("adx_approved", "eq", "true");
                }
            }));
        }
        public IBlog Select()
        {
            var serviceContext = BlogDependencies.GetServiceContext();
            var security       = BlogDependencies.GetSecurityProvider();
            var urlProvider    = BlogDependencies.GetUrlProvider();

            var entity = serviceContext.RetrieveSingle("adx_blog", "adx_blogid", this.Blog.Id, FetchAttribute.All);

            if (entity == null || !security.TryAssert(serviceContext, entity, CrmEntityRight.Read))
            {
                return(null);
            }

            var path = urlProvider.GetApplicationPath(serviceContext, entity);

            return(path == null ? null : new Blog(entity, path, BlogDependencies.GetBlogFeedPath(entity.Id)));
        }
        public virtual IEnumerable <IBlogPost> SelectPosts(int startRowIndex, int maximumRows)
        {
            if (startRowIndex < 0)
            {
                throw new ArgumentException("Value must be a positive integer.", "startRowIndex");
            }

            if (maximumRows == 0)
            {
                return(new IBlogPost[] { });
            }

            var serviceContext = BlogDependencies.GetServiceContext();

            var query = serviceContext.CreateQuery("adx_blogpost")
                        .Where(post => post.GetAttributeValue <EntityReference>("adx_blogid") == Blog);

            if (!Security.UserHasAuthorPermission)
            {
                query = query.Where(post => post.GetAttributeValue <bool?>("adx_published") == true);
            }

            query = query.OrderByDescending(post => post.GetAttributeValue <DateTime?>("adx_date"));

            if (startRowIndex > 0)
            {
                query = query.Skip(startRowIndex);
            }

            if (maximumRows > 0)
            {
                query = query.Take(maximumRows);
            }

            var urlProvider      = BlogDependencies.GetUrlProvider();
            var tagPathGenerator = new BlogArchiveApplicationPathGenerator(BlogDependencies);

            return(new BlogPostFactory(serviceContext, urlProvider, BlogDependencies.GetWebsite(), tagPathGenerator).Create(query));
        }
        public virtual int SelectPostCount()
        {
            var serviceContext = BlogDependencies.GetServiceContext();

            return(serviceContext.FetchBlogPostCount(Blog.Id, !Security.UserHasAuthorPermission));
        }