Exemple #1
0
        public void Publish(PageEntity item)
        {
            _eventManager.Trigger(Events.OnPagePublishing, item);
            string pageId = item.ID;

            BeginTransaction(() =>
            {
                item.IsPublish   = true;
                item.PublishDate = DateTime.Now;
                base.Update(item);

                var zones       = _zoneService.GetByPage(item);
                var layoutHtmls = _layoutHtmlService.GetByPage(item);


                item.ReferencePageID = item.ID;
                item.IsPublishedPage = true;
                item.PublishDate     = DateTime.Now;

                var widgets = _widgetService.GetByPageId(item.ID);
                Add(item);
                zones.Each(m =>
                {
                    m.PageId = item.ID;
                    _zoneService.Add(m);
                });
                layoutHtmls.Each(m =>
                {
                    m.PageId = item.ID;
                    _layoutHtmlService.Add(m);
                });
                widgets.Each(m =>
                {
                    using (var widgetService = _widgetActivator.Create(m))
                    {
                        m        = widgetService.GetWidget(m);
                        m.PageID = item.ID;
                        widgetService.IsNeedNotifyChange = false;
                        widgetService.Publish(m);
                    }
                });
            });
            const int keepVersions        = 6;
            var       allPublishedVersion = Get(m => m.ReferencePageID == pageId && m.IsPublishedPage == true).OrderByDescending(m => m.PublishDate).ToList();

            if (allPublishedVersion.Count > keepVersions)
            {
                for (int i = keepVersions; i < allPublishedVersion.Count; i++)
                {
                    DeleteVersion(allPublishedVersion[i].ID);
                }
            }
            _widgetService.RemoveCache(pageId);
            _zoneService.RemoveCache(pageId);
            _layoutHtmlService.RemoveCache(pageId);
            _eventManager.Trigger(Events.OnPagePublished, item);
        }
        public void Handle(object entity, EventArg e)
        {
            PageEntity page = entity as PageEntity;

            if (page != null)
            {
                _widgetService.RemoveCache(page.ReferencePageID);
                _zoneService.RemoveCache(page.ReferencePageID);
                _layoutHtmlService.RemoveCache(page.ReferencePageID);
            }
        }