/// <summary>
        /// Executes after Disqus comments add-on is installed to create default instance of Disqus comments block.
        /// </summary>
        public override void AfterInstall()
        {
            var blockType          = ContentTypeRepository.Load <CommentsBlock>();
            var defaultDisqusBlock = ContentRepository.GetDefault <IContent>(ContentReference.GlobalBlockFolder, blockType.ID, ContentLanguage.PreferredCulture);

            defaultDisqusBlock.Name = "Disqus comments";
            ContentRepository.Save(defaultDisqusBlock, SaveAction.Publish, AccessLevel.NoAccess);
        }
        /// <summary>
        /// Executes before Disqus comments add-on is uninstalled to remove all related data.
        /// </summary>
        public override void BeforeUninstall()
        {
            var blockType = ContentTypeRepository.Load <CommentsBlock>();

            ContentModelUsage.ListContentOfContentType(blockType)
            .Select(usage => usage.ContentLink).Distinct().ToList()
            .ForEach(contentLink => ContentRepository.Delete(contentLink, true, AccessLevel.NoAccess));

            ContentTypeRepository.Delete(blockType);

            ConfigurationProvider.Clear();
        }
Beispiel #3
0
        private IContent CreateAndAssignIdentity(MappedIdentity mappedIdentity, Type modelType, string name)
        {
            // Find parent
            var parentLink = EntryPoint;

            if (modelType == typeof(YouTubeVideo))
            {
                parentLink = SearchResultNode;
            }
            else if (modelType != typeof(YouTubeFolder))
            {
                parentLink = new ContentReference(int.Parse(RemoveEndingSlash(mappedIdentity.ExternalIdentifier.Segments[2])), ProviderKey);
            }

            // Set content type and content type Id.
            var contentType = ContentTypeRepository.Load(modelType);
            var content     = ContentFactory.CreateContent(contentType);

            content.ContentTypeID = contentType.ID;
            content.ParentLink    = parentLink;
            content.ContentGuid   = mappedIdentity.ContentGuid;
            content.ContentLink   = mappedIdentity.ContentLink;
            content.Name          = name;
            (content as IRoutable).RouteSegment = UrlSegment.GetUrlFriendlySegment(content.Name);

            var securable = content as IContentSecurable;

            securable.GetContentSecurityDescriptor().AddEntry(new AccessControlEntry(EveryoneRole.RoleName, AccessLevel.Read));

            var versionable = content as IVersionable;

            if (versionable != null)
            {
                versionable.Status = VersionStatus.Published;
            }

            var changeTrackable = content as IChangeTrackable;

            if (changeTrackable != null)
            {
                changeTrackable.Changed = DateTime.Now;
            }

            return(content);
        }
Beispiel #4
0
        public object GetValue(IContentData contentData, PropertyInfo property)
        {
            // define if property is required
            var requiredAnnotation = property.GetAttribute <RequiredAttribute>();

            // get annotation attribute
            var annotation = property.GetAnnotation <CmsReferenceAttribute>();

            // get reference property name set by attribute or default
            var referencePropertyName = annotation.LinkFieldName ?? property.Name + "Link";

            // lookup reference property
            var referenceProperty = contentData.Property[referencePropertyName] as PropertyPageReference;

            if (referenceProperty != null)
            // if reference property found
            {
                // get link to a referenced page
                var link = referenceProperty.ContentLink;

                if (!ContentReference.IsNullOrEmpty(link))
                // and if it's not empty
                {
                    // load referenced page and cast it to the target property type.
                    var result = ContentLoader.Get <PageData>(link).Cast(property.PropertyType);

                    if (result != null)
                    {
                        return(result);
                    }
                }
            }

            if (requiredAnnotation == null)
            // if property is not marked as required
            {
                return(null);
            }

            // otherwise get error message
            string errorMessageFormat;

            if (!string.IsNullOrEmpty(requiredAnnotation.ErrorMessageResourceName))
            {
                errorMessageFormat = LocalizationService.GetString(requiredAnnotation.ErrorMessageResourceName);
            }
            else if (!string.IsNullOrEmpty(requiredAnnotation.ErrorMessage))
            {
                errorMessageFormat = requiredAnnotation.ErrorMessage;
            }
            else
            {
                errorMessageFormat = LocalizationService.GetString("EPiProperties/PropertyRequiredFormat", "Required property '{0}' is not properly set on the page #{1} of type '{2}'. ");
            }

            var content = contentData as IContent;

            if (content != null)
            {
                var contentType = ContentTypeRepository.Load(content.ContentTypeID);

                var errorMessage = string.Format(errorMessageFormat,
                                                 property.Name,
                                                 content.ContentLink.ID,
                                                 contentType.DisplayName);

                throw new ApplicationException(errorMessage);
            }
            else
            {
                throw new ApplicationException(string.Format(errorMessageFormat,
                                                             property.Name,
                                                             "?",
                                                             "?")); // TODO
            }
        }