public MediaRepository(IScopeUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax, IMediaTypeRepository mediaTypeRepository, ITagRepository tagRepository, IContentSection contentSection)
     : base(work, cache, logger, sqlSyntax, contentSection)
 {
     if (mediaTypeRepository == null)
     {
         throw new ArgumentNullException("mediaTypeRepository");
     }
     if (tagRepository == null)
     {
         throw new ArgumentNullException("tagRepository");
     }
     _mediaTypeRepository       = mediaTypeRepository;
     _tagRepository             = tagRepository;
     _contentXmlRepository      = new ContentXmlRepository <IMedia>(work, CacheHelper.NoCache, logger, sqlSyntax);
     _contentPreviewRepository  = new ContentPreviewRepository <IMedia>(work, CacheHelper.NoCache, logger, sqlSyntax);
     _mediaByGuidReadRepository = new MediaByGuidReadRepository(this, work, cache, logger, sqlSyntax);
     EnsureUniqueNaming         = contentSection.EnsureUniqueNaming;
 }
Example #2
0
 protected RepositoryBase(IScopeUnitOfWork work, CacheHelper cache, ILogger logger)
 {
     if (work == null)
     {
         throw new ArgumentNullException("work");
     }
     if (cache == null)
     {
         throw new ArgumentNullException("cache");
     }
     if (logger == null)
     {
         throw new ArgumentNullException("logger");
     }
     Logger       = logger;
     _work        = work;
     _globalCache = cache;
 }
Example #3
0
        Attempt <PublishStatus> IPublishingStrategy2.UnPublish(IScopeUnitOfWork uow, IContent content, int userId)
        {
            // content should (is assumed to ) be the newest version, which may not be published
            // don't know how to test this, so it's not verified
            // NOTE
            // if published != newest, then the published flags need to be reseted by whoever is calling that method
            // at the moment it's done by the content service

            var evtMsgs = _eventMessagesFactory.Get();

            //Fire UnPublishing event
            if (uow.Events.DispatchCancelable(UnPublishing, this, new PublishEventArgs <IContent>(content, evtMsgs), "UnPublishing"))
            {
                _logger.Info <PublishingStrategy>(
                    string.Format("Content '{0}' with Id '{1}' will not be unpublished, the event was cancelled.", content.Name, content.Id));
                return(Attempt.Fail(new PublishStatus(content, PublishStatusType.FailedCancelledByEvent, evtMsgs)));
            }

            //If Content has a release date set to before now, it should be removed so it doesn't interrupt an unpublish
            //Otherwise it would remain released == published
            if (content.ReleaseDate.HasValue && content.ReleaseDate.Value <= DateTime.Now)
            {
                content.ReleaseDate = null;

                _logger.Info <PublishingStrategy>(
                    string.Format("Content '{0}' with Id '{1}' had its release date removed, because it was unpublished.",
                                  content.Name, content.Id));
            }

            // if newest is published, unpublish
            if (content.Published)
            {
                content.ChangePublishedState(PublishedState.Unpublished);
            }

            _logger.Info <PublishingStrategy>(
                string.Format("Content '{0}' with Id '{1}' has been unpublished.",
                              content.Name, content.Id));

            return(Attempt.Succeed(new PublishStatus(content, evtMsgs)));
        }
 private RelationTypeRepository CreateRepository(IScopeUnitOfWork unitOfWork)
 {
     return(new RelationTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of <ILogger>(), SqlSyntax));
 }
 protected VersionableRepositoryBase(IScopeUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax, IContentSection contentSection)
     : base(work, cache, logger, sqlSyntax)
 {
     _contentSection = contentSection;
 }
 public DictionaryByKeyRepository(DictionaryRepository dictionaryRepository, IScopeUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax)
     : base(work, cache, logger, sqlSyntax)
 {
     _dictionaryRepository = dictionaryRepository;
 }
 private EntityContainerRepository CreateContainerRepository(IScopeUnitOfWork unitOfWork, Guid containerEntityType)
 {
     return(new EntityContainerRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of <ILogger>(), SqlSyntax, containerEntityType));
 }
Example #8
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="work"></param>
 /// <param name="cacheHelper"></param>
 /// <param name="logger"></param>
 /// <param name="sqlSyntax"></param>
 /// <param name="passwordConfiguration">
 /// A dictionary specifying the configuration for user passwords. If this is null then no password configuration will be persisted or read.
 /// </param>
 public UserRepository(IScopeUnitOfWork work, CacheHelper cacheHelper, ILogger logger, ISqlSyntaxProvider sqlSyntax,
                       IDictionary <string, string> passwordConfiguration = null)
     : base(work, cacheHelper, logger, sqlSyntax)
 {
     _passwordConfiguration = passwordConfiguration;
 }
 private ITemplateRepository CreateRepository(IScopeUnitOfWork unitOfWork, ITemplatesSection templatesSection = null)
 {
     return(new TemplateRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of <ILogger>(), SqlSyntax, _masterPageFileSystem, _viewsFileSystem,
                                   templatesSection ?? Mock.Of <ITemplatesSection>(t => t.DefaultRenderingEngine == RenderingEngine.Mvc)));
 }
Example #10
0
 public virtual IPublicAccessRepository CreatePublicAccessRepository(IScopeUnitOfWork uow)
 {
     return(new PublicAccessRepository(uow,
                                       _cacheHelper,
                                       _logger, _sqlSyntax));
 }
Example #11
0
 public virtual IExternalLoginRepository CreateExternalLoginRepository(IScopeUnitOfWork uow)
 {
     return(new ExternalLoginRepository(uow,
                                        _cacheHelper,
                                        _logger, _sqlSyntax));
 }
Example #12
0
 public MediaByGuidReadRepository(MediaRepository outerRepo,
                                  IScopeUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax)
     : base(work, cache, logger, sqlSyntax)
 {
     _outerRepo = outerRepo;
 }
Example #13
0
        void IPublishingStrategy2.UnPublishingFinalized(IScopeUnitOfWork uow, IEnumerable <IContent> content)
        {
            var evtMsgs = _eventMessagesFactory.Get();

            uow.Events.Dispatch(UnPublished, this, new PublishEventArgs <IContent>(content, false, false, evtMsgs), "UnPublished");
        }
Example #14
0
 /// <summary>
 /// Unpublishes a list of Content
 /// </summary>
 /// <param name="uow"></param>
 /// <param name="content">An enumerable list of <see cref="IContent"/></param>
 /// <param name="userId">Id of the User issueing the unpublish operation</param>
 /// <returns>A list of publish statuses</returns>
 private IEnumerable <Attempt <PublishStatus> > UnPublishInternal(IScopeUnitOfWork uow, IEnumerable <IContent> content, int userId)
 {
     return(content.Select(x => ((IPublishingStrategy2)this).UnPublish(uow, x, userId)));
 }
Example #15
0
        /// <summary>
        /// Publishes a list of content items
        /// </summary>
        /// <param name="uow"></param>
        /// <param name="content"></param>
        /// <param name="userId"></param>
        /// <param name="includeUnpublishedDocuments">
        /// By default this is set to true which means that it will publish any content item in the list that is completely unpublished and
        /// not visible on the front-end. If set to false, this will only publish content that is live on the front-end but has new versions
        /// that have yet to be published.
        /// </param>
        /// <returns></returns>
        /// <remarks>
        ///
        /// This method becomes complex once we start to be able to cancel events or stop publishing a content item in any way because if a
        /// content item is not published then it's children shouldn't be published either. This rule will apply for the following conditions:
        /// * If a document fails to be published, do not proceed to publish it's children if:
        /// ** The document does not have a publish version
        /// ** The document does have a published version but the includeUnpublishedDocuments = false
        ///
        /// In order to do this, we will order the content by level and begin by publishing each item at that level, then proceed to the next
        /// level and so on. If we detect that the above rule applies when the document publishing is cancelled we'll add it to the list of
        /// parentsIdsCancelled so that it's children don't get published.
        ///
        /// Its important to note that all 'root' documents included in the list *will* be published regardless of the rules mentioned
        /// above (unless it is invalid)!! By 'root' documents we are referring to documents in the list with the minimum value for their 'level'.
        /// In most cases the 'root' documents will only be one document since under normal circumstance we only publish one document and
        /// its children. The reason we have to do this is because if a user is publishing a document and it's children, it is implied that
        /// the user definitely wants to publish it even if it has never been published before.
        ///
        /// </remarks>
        IEnumerable <Attempt <PublishStatus> > IPublishingStrategy2.PublishWithChildren(IScopeUnitOfWork uow,
                                                                                        IEnumerable <IContent> content, int userId, bool includeUnpublishedDocuments)
        {
            var statuses = new List <Attempt <PublishStatus> >();

            //a list of all document ids that had their publishing cancelled during these iterations.
            //this helps us apply the rule listed in the notes above by checking if a document's parent id
            //matches one in this list.
            var parentsIdsCancelled = new List <int>();

            //group by levels and iterate over the sorted ascending level.
            //TODO: This will cause all queries to execute, they will not be lazy but I'm not really sure being lazy actually made
            // much difference because we iterate over them all anyways?? Morten?
            // Because we're grouping I think this will execute all the queries anyways so need to fetch it all first.
            var fetchedContent = content.ToArray();

            var evtMsgs = _eventMessagesFactory.Get();

            //We're going to populate the statuses with all content that is already published because below we are only going to iterate over
            // content that is not published. We'll set the status to "AlreadyPublished"
            statuses.AddRange(fetchedContent.Where(x => x.Published)
                              .Select(x => Attempt.Succeed(new PublishStatus(x, PublishStatusType.SuccessAlreadyPublished, evtMsgs))));

            int?firstLevel = null;

            //group by level and iterate over each level (sorted ascending)
            var levelGroups = fetchedContent.GroupBy(x => x.Level);

            foreach (var level in levelGroups.OrderBy(x => x.Key))
            {
                //set the first level flag, used to ensure that all documents at the first level will
                //be published regardless of the rules mentioned in the remarks.
                if (!firstLevel.HasValue)
                {
                    firstLevel = level.Key;
                }

                /* Only update content thats not already been published - we want to loop through
                 * all unpublished content to write skipped content (expired and awaiting release) to log.
                 */
                foreach (var item in level.Where(x => x.Published == false))
                {
                    //Check if this item should be excluded because it's parent's publishing has failed/cancelled
                    if (parentsIdsCancelled.Contains(item.ParentId))
                    {
                        _logger.Info <PublishingStrategy>(
                            string.Format("Content '{0}' with Id '{1}' will not be published because it's parent's publishing action failed or was cancelled.", item.Name, item.Id));
                        //if this cannot be published, ensure that it's children can definitely not either!
                        parentsIdsCancelled.Add(item.Id);
                        continue;
                    }

                    //Check if this item has never been published (and that it is not at the root level)
                    if (item.Level != firstLevel && !includeUnpublishedDocuments && !item.HasPublishedVersion())
                    {
                        //this item does not have a published version and the flag is set to not include them
                        parentsIdsCancelled.Add(item.Id);
                        continue;
                    }

                    //Fire Publishing event
                    if (uow.Events.DispatchCancelable(Publishing, this, new PublishEventArgs <IContent>(item, evtMsgs), "Publishing"))
                    {
                        //the publishing has been cancelled.
                        _logger.Info <PublishingStrategy>(
                            string.Format("Content '{0}' with Id '{1}' will not be published, the event was cancelled.", item.Name, item.Id));
                        statuses.Add(Attempt.Fail(new PublishStatus(item, PublishStatusType.FailedCancelledByEvent, evtMsgs)));

                        //Does this document apply to our rule to cancel it's children being published?
                        CheckCancellingOfChildPublishing(item, parentsIdsCancelled, includeUnpublishedDocuments);

                        continue;
                    }

                    //Check if the content is valid if the flag is set to check
                    if (item.IsValid() == false)
                    {
                        _logger.Info <PublishingStrategy>(
                            string.Format("Content '{0}' with Id '{1}' will not be published because some of it's content is not passing validation rules.",
                                          item.Name, item.Id));
                        statuses.Add(Attempt.Fail(new PublishStatus(item, PublishStatusType.FailedContentInvalid, evtMsgs)
                        {
                            InvalidProperties = ((ContentBase)item).LastInvalidProperties
                        }));

                        //Does this document apply to our rule to cancel it's children being published?
                        CheckCancellingOfChildPublishing(item, parentsIdsCancelled, includeUnpublishedDocuments);

                        continue;
                    }

                    //Check if the Content is Expired to verify that it can in fact be published
                    if (item.Status == ContentStatus.Expired)
                    {
                        _logger.Info <PublishingStrategy>(
                            string.Format("Content '{0}' with Id '{1}' has expired and could not be published.",
                                          item.Name, item.Id));
                        statuses.Add(Attempt.Fail(new PublishStatus(item, PublishStatusType.FailedHasExpired, evtMsgs)));

                        //Does this document apply to our rule to cancel it's children being published?
                        CheckCancellingOfChildPublishing(item, parentsIdsCancelled, includeUnpublishedDocuments);

                        continue;
                    }

                    //Check if the Content is Awaiting Release to verify that it can in fact be published
                    if (item.Status == ContentStatus.AwaitingRelease)
                    {
                        _logger.Info <PublishingStrategy>(
                            string.Format("Content '{0}' with Id '{1}' is awaiting release and could not be published.",
                                          item.Name, item.Id));
                        statuses.Add(Attempt.Fail(new PublishStatus(item, PublishStatusType.FailedAwaitingRelease, evtMsgs)));

                        //Does this document apply to our rule to cancel it's children being published?
                        CheckCancellingOfChildPublishing(item, parentsIdsCancelled, includeUnpublishedDocuments);

                        continue;
                    }

                    //Check if the Content is Trashed to verify that it can in fact be published
                    if (item.Status == ContentStatus.Trashed)
                    {
                        _logger.Info <PublishingStrategy>(
                            string.Format("Content '{0}' with Id '{1}' is trashed and could not be published.",
                                          item.Name, item.Id));
                        statuses.Add(Attempt.Fail(new PublishStatus(item, PublishStatusType.FailedIsTrashed, evtMsgs)));

                        //Does this document apply to our rule to cancel it's children being published?
                        CheckCancellingOfChildPublishing(item, parentsIdsCancelled, includeUnpublishedDocuments);

                        continue;
                    }

                    item.ChangePublishedState(PublishedState.Published);

                    _logger.Info <PublishingStrategy>(
                        string.Format("Content '{0}' with Id '{1}' has been published.",
                                      item.Name, item.Id));

                    statuses.Add(Attempt.Succeed(new PublishStatus(item, evtMsgs)));
                }
            }

            return(statuses);
        }
Example #16
0
 public ITaskTypeRepository CreateTaskTypeRepository(IScopeUnitOfWork uow)
 {
     return(new TaskTypeRepository(uow,
                                   _nullCache, //never cache
                                   _logger, _sqlSyntax));
 }
 public UserRepository(IScopeUnitOfWork work, CacheHelper cacheHelper, ILogger logger, ISqlSyntaxProvider sqlSyntax, IUserTypeRepository userTypeRepository)
     : base(work, cacheHelper, logger, sqlSyntax)
 {
     _userTypeRepository = userTypeRepository;
     _cacheHelper        = cacheHelper;
 }
Example #18
0
 public virtual IAuditRepository CreateAuditRepository(IScopeUnitOfWork uow)
 {
     return(new AuditRepository(uow,
                                _nullCache, //never cache
                                _logger, _sqlSyntax));
 }
        private DictionaryRepository CreateRepository(IScopeUnitOfWork unitOfWork)
        {
            var dictionaryRepository = new DictionaryRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of <ILogger>(), new SqlCeSyntaxProvider());

            return(dictionaryRepository);
        }
Example #20
0
 public virtual IDataTypeDefinitionRepository CreateDataTypeDefinitionRepository(IScopeUnitOfWork uow)
 {
     return(new DataTypeDefinitionRepository(
                uow,
                _cacheHelper,
                _logger, _sqlSyntax,
                CreateContentTypeRepository(uow)));
 }
        private MediaTypeRepository CreateMediaTypeRepository(IScopeUnitOfWork unitOfWork)
        {
            var contentTypeRepository = new MediaTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of <ILogger>(), SqlSyntax);

            return(contentTypeRepository);
        }
Example #22
0
 public virtual IServerRegistrationRepository CreateServerRegistrationRepository(IScopeUnitOfWork uow)
 {
     return(new ServerRegistrationRepository(
                uow,
                _cacheHelper.StaticCache,
                _logger, _sqlSyntax));
 }
 public DictionaryRepository(IScopeUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider syntax)
     : base(work, cache, logger, syntax)
 {
 }
Example #24
0
 internal virtual IMacroRepository CreateMacroRepository(IScopeUnitOfWork uow)
 {
     return(new MacroRepository(uow,
                                _cacheHelper,
                                _logger, _sqlSyntax));
 }
 public UserGroupWithUsersRepository(UserGroupRepository userGroupRepo, IScopeUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax)
     : base(work, cache, logger, sqlSyntax)
 {
     _userGroupRepo = userGroupRepo;
 }
Example #26
0
 public virtual IMemberGroupRepository CreateMemberGroupRepository(IScopeUnitOfWork uow)
 {
     return(new MemberGroupRepository(uow,
                                      _cacheHelper,
                                      _logger, _sqlSyntax));
 }
 public AuditRepository(IScopeUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax)
     : base(work, cache, logger, sqlSyntax)
 {
 }
Example #28
0
 public virtual IEntityRepository CreateEntityRepository(IScopeUnitOfWork uow)
 {
     return(new EntityRepository(uow));
 }
        ///// <summary>
        ///// Gets a list all available <see cref="IMacroPropertyType"/> plugins
        ///// </summary>
        ///// <returns>An enumerable list of <see cref="IMacroPropertyType"/> objects</returns>
        //public IEnumerable<IMacroPropertyType> GetMacroPropertyTypes()
        //{
        //    return MacroPropertyTypeResolver.Current.MacroPropertyTypes;
        //}

        ///// <summary>
        ///// Gets an <see cref="IMacroPropertyType"/> by its alias
        ///// </summary>
        ///// <param name="alias">Alias to retrieve an <see cref="IMacroPropertyType"/> for</param>
        ///// <returns>An <see cref="IMacroPropertyType"/> object</returns>
        //public IMacroPropertyType GetMacroPropertyTypeByAlias(string alias)
        //{
        //    return MacroPropertyTypeResolver.Current.MacroPropertyTypes.FirstOrDefault(x => x.Alias == alias);
        //}

        private void Audit(IScopeUnitOfWork uow, AuditType type, string message, int userId, int objectId)
        {
            var repository = RepositoryFactory.CreateAuditRepository(uow);

            repository.AddOrUpdate(new AuditItem(objectId, message, type, userId));
        }
Example #30
0
 public virtual IDomainRepository CreateDomainRepository(IScopeUnitOfWork uow)
 {
     return(new DomainRepository(uow, _cacheHelper, _logger, _sqlSyntax));
 }