Exemplo n.º 1
0
        /// <summary>
        /// アイテム発行後に実行されるイベント
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void Document_Published(IPublishingStrategy sender, PublishEventArgs <IContent> e)
        {
            e.PublishedEntities.ForEach(x => Automation.PublishedAutoOparations(x));

            // sitemap.xmlを生成
            SiteMapCreator.GenerateXml();
        }
Exemplo n.º 2
0
        private void ContentService_UnPublished(IPublishingStrategy sender, PublishEventArgs <IContent> e)
        {
            var user             = GetUserSignature(CurrentUser);
            var contentSignature = GetContentSignatures(e.PublishedEntities);

            HistoryHelper.AddHistoryItem($"{user} unpublished the following content: {contentSignature}");
        }
        /// <summary>
        /// Handles the content service unpublished event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e"> The <see cref="PublishEventArgs{IContent}"/> containing information about the event.</param>
        private void ContentServiceUnPublished(IPublishingStrategy sender, PublishEventArgs <IContent> e)
        {
            string        alias  = BloodhoundPropertyEditor.PropertyEditorAlias;
            UmbracoHelper helper = new UmbracoHelper(UmbracoContext.Current);

            // Loop through the items and remove the url, value pair from the cache.
            foreach (IContent content in e.PublishedEntities)
            {
                IPublishedContent publishedVersion = helper.TypedContent(content.Id);

                IPublishedProperty rewriteProperties =
                    publishedVersion
                    .Properties
                    .FirstOrDefault(p => publishedVersion.ContentType.GetPropertyType(p.PropertyTypeAlias).PropertyEditorAlias.Equals(alias));

                if (rewriteProperties != null)
                {
                    List <BloodhoundUrlRewrite> rewrites = rewriteProperties.GetValue <List <BloodhoundUrlRewrite> >();
                    foreach (BloodhoundUrlRewrite rewrite in rewrites)
                    {
                        UrlRewriteCache.RemoveItem(rewrite.RewriteUrl);
                    }
                }
            }
        }
Exemplo n.º 4
0
 private void ContentServicePublished(IPublishingStrategy sender, PublishEventArgs <IContent> args)
 {
     if (args.PublishedEntities.Any(IsNavigationItem))
     {
         ClearNavigationCache();
     }
 }
        protected void UpdateContentIdToUrlCache(IPublishingStrategy strategy, PublishEventArgs <IContent> e)
        {
            UmbracoHelper uh = new UmbracoHelper(UmbracoContext.Current);

            foreach (IContent c in e.PublishedEntities)
            {
                if (c.HasPublishedVersion)
                {
                    IEnumerable <string> urls = UmbracoFlareDomainManager.Instance.GetUrlsForNode(c, false);

                    if (urls.Contains("#"))
                    {
                        //When a piece of content is first saved, we cannot get the url, if that is the case then we need to just
                        //invalidate the who ContentIdToUrlCache, that way when we request all of the urls agian, it will pick it up.
                        UmbracoUrlWildCardManager.Instance.DeletedContentIdToUrlCache();
                    }
                    else
                    {
                        UmbracoUrlWildCardManager.Instance.UpdateContentIdToUrlCache(c.Id, urls);
                    }
                }


                //TODO: Does this need to be here?
                //We also need to update the descendants now because their urls changed
                IEnumerable <IContent> descendants = c.Descendants();

                foreach (IContent desc in descendants)
                {
                    IEnumerable <string> descUrls = UmbracoFlareDomainManager.Instance.GetUrlsForNode(desc.Id, false);

                    UmbracoUrlWildCardManager.Instance.UpdateContentIdToUrlCache(c.Id, descUrls);
                }
            }
        }
 private void OnPublishedAssert(IPublishingStrategy sender, PublishEventArgs <IContent> args)
 {
     if (_onPublishedAssertAction != null)
     {
         _onPublishedAssertAction();
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Content nodes were published.
        /// </summary>
        private void ContentService_Published(IPublishingStrategy sender,
                                              PublishEventArgs <IContent> e)
        {
            var nodes = e.PublishedEntities;

            HandleChangedContent(nodes);
        }
Exemplo n.º 8
0
        public void OnUnpublish(IPublishingStrategy sender, PublishEventArgs <IContent> e)
        {
            base.ReturnOtherThanRestricted(e);

            foreach (var entity in base._restrictedEntities)
            {
                //element not at the root level
                if (entity.ParentId != -1)
                {
                    continue;
                }

                //umbraco context is already defined as we are in one of the pluggins
                var siblingsAliases = Umbraco.Web.UmbracoContext.Current.ContentCache.GetAtRoot()
                                      .Where(x => x.Id != entity.Id)
                                      .Select(x => x.DocumentTypeAlias)
                                      .ToList();

                //any siblings with the same doc type ?
                var noOther = !base._restrictedEntities.Any(x => siblingsAliases.Contains(x.ContentType.Alias));

                //documents with the restriction have been found
                if (noOther)
                {
                    e.CancelOperation(new EventMessage("Content Restriction", base._rule.ErrorMessage, EventMessageType.Error));
                }
            }
        }
Exemplo n.º 9
0
 private void ContentService_Published(IPublishingStrategy sender, PublishEventArgs <IContent> e)
 {
     foreach (var entity in e.PublishedEntities)
     {
         this.Update(this._umbracoHelper.TypedContent(entity.Id));
     }
 }
Exemplo n.º 10
0
        private void PurgeAll(IPublishingStrategy strategy, PublishEventArgs <IContent> e)
        {
            var appId = WebConfigurationManager.AppSettings[FastlyApplicationIdKey];

            using (var task = Client.PostAsync($"service/{appId}/purge_all", new StringContent("")))
                task.Wait();
        }
        /// <summary>
        /// Код, выполняющийся при публикации и распубликации узлов.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void ContentPublishedUnpublishedEventHandler(IPublishingStrategy sender, PublishEventArgs<IContent> args)
        {
            if (args.PublishedEntities.Any(x => x.ContentType.Alias == SiteSettings.DocumentTypeAlias))
            {
                SiteSettings.Referesh(); //сброс синглетона настроек
            }
            if (args.PublishedEntities.Any(x => x.ContentType.Alias == Unico.Etechno.OrderAdmin.OrdersController.OrderStatusDoctypeAlias))
            {
                Unico.Etechno.OrderAdmin.OrderModel.InvalidateStatusCache(); //сброс кэша статусов заказов
            }
            if (args.PublishedEntities.Any(x => x.ContentType.Alias == Product.ProductDocumentTypeAlias || x.ContentType.Alias == Category.CategoryDocumentTypeAlias || x.ContentType.Alias == Brand.BrandDocumentTypeAlias))
            {
                Unico.Etechno.Catalog.Filter.InvalidateCache(); //сброс кэша фильтров
                Unico.Etechno.Searcher.Invalidate(); //сброс поисковика
            }
            if (args.PublishedEntities.Any(x => x.ContentType.Alias == "catProduct"))
            {
                Unico.Etechno.Catalog.Filter.GetPriceMax();
            }

            var promoEvents = args.PublishedEntities.Where(x => x.ContentType.Alias == Unico.Etechno.PromoEvent.PromoEventDocumentTypeAlias);
            if (promoEvents.Any())
            {
                foreach (var promoEvent in promoEvents)
                {
                    Unico.Etechno.PromoEvent.EnsureOthersDontHave(promoEvent);
                }
                Unico.Etechno.PromoEvent.InvalidateCache(); //сброс кэша акций
            }
        }
Exemplo n.º 12
0
 private void ContentService_UnPublished(IPublishingStrategy sender, PublishEventArgs <IContent> e)
 {
     foreach (var entity in e.PublishedEntities)
     {
         this.Remove(entity.Id);
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// Unpublish the parent of any nodes of certain type that have no published children.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnUnpublish(IPublishingStrategy sender, PublishEventArgs <IContent> e)
        {
            base.ReturnOtherThanRestricted(e);
            if (base._restrictedEntities == null)
            {
                return;
            }

            var parents = base._restrictedEntities.Select(x => x.Parent());

            if (!parents.Any())
            {
                return;
            }

            foreach (var parent in parents)
            {
                // if parent has any published children leave it.
                if (parent.Children().Where(x => x.Published).Any())
                {
                    return;
                }
                var cs = ApplicationContext.Current.Services.ContentService;
                cs.UnPublish(parent);
            }
        }
        protected void PurgeCloudflareCache(IPublishingStrategy strategy, PublishEventArgs <IContent> e)
        {
            var umbracoFlareConfigModel = _configurationService.LoadConfigurationFile();

            if (!umbracoFlareConfigModel.PurgeCacheOn)
            {
                return;
            }

            var urls          = new List <string>();
            var currentDomain = UmbracoFlareUrlHelper.GetCurrentDomain();

            foreach (var content in e.PublishedEntities)
            {
                if (content.GetValue <bool>(ApplicationConstants.UmbracoFlareBackendProperties.CloudflareDisabledOnPublishPropertyAlias))
                {
                    continue;
                }

                urls.AddRange(_umbracoFlareDomainService.GetUrlsForNode(content.Id, currentDomain));
            }

            var result = _cloudflareService.PurgePages(urls);

            e.Messages.Add(result.Success
                ? new EventMessage(ApplicationConstants.EventMessageCategory.CloudflareCaching,
                                   "Successfully purged the cloudflare cache.", EventMessageType.Success)
                : new EventMessage(ApplicationConstants.EventMessageCategory.CloudflareCaching,
                                   "We could not purge the Cloudflare cache. Please check the logs to find out more.",
                                   EventMessageType.Warning));
        }
Exemplo n.º 15
0
        // when something is published or unpublished from umbraco, we clear the atoz cache.

        private void ContentService_PublishEvent(IPublishingStrategy sender, PublishEventArgs <IContent> e)
        {
            if (_runtimeCache != null)
            {
                _runtimeCache.ClearCacheByKeySearch("atozpages");
            }
        }
Exemplo n.º 16
0
 static void PublishingStrategyPublishing(IPublishingStrategy sender, PublishEventArgs <IContent> e)
 {
     foreach (var i in e.PublishedEntities.Where(i => i.Name == "Text Page 2"))
     {
         e.Cancel = true;
     }
 }
 private void ContentService_Publishing(IPublishingStrategy sender, PublishEventArgs <IContent> e)
 {
     foreach (var content in e.PublishedEntities)
     {
         if (content.ContentType.Alias == Keys.DocumentTypes.GoogleAnalyticsEventItem)
         {
             if (content.HasProperty(Keys.PropertyAliases.Label))
             {
                 string labelTemplate = content.GetValue <string>(Keys.PropertyAliases.Label);
                 if (!string.IsNullOrEmpty(labelTemplate))
                 {
                     var matches = Regex.Matches(labelTemplate, Keys.LabelPlaceholderRegex);
                     foreach (Match match in matches)
                     {
                         if (!Keys.LabelPlaceholders.ContainsValue(match.Value))
                         {
                             e.Cancel = true;
                             e.Messages.Add(new EventMessage("Cannot publish GA Event", "One of the Placeholders entered does not match our standard list of placeholders.", EventMessageType.Warning));
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 18
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="dbUnitOfWorkProvider"></param>
		/// <param name="fileUnitOfWorkProvider"></param>
		/// <param name="publishingStrategy"></param>
		internal ServiceContext(IDatabaseUnitOfWorkProvider dbUnitOfWorkProvider, IUnitOfWorkProvider fileUnitOfWorkProvider, IPublishingStrategy publishingStrategy)
		{
			BuildServiceCache(dbUnitOfWorkProvider, fileUnitOfWorkProvider, publishingStrategy, 
				//this needs to be lazy because when we create the service context it's generally before the
				//resolvers have been initialized!
				new Lazy<RepositoryFactory>(() => RepositoryResolver.Current.Factory));
		}
 public void ProcessContentUnPublished(IPublishingStrategy sender, PublishEventArgs <IContent> args)
 {
     foreach (var entity in args.PublishedEntities)
     {
         _contentIndexer.DeleteFromIndex(entity.Id);
     }
 }
Exemplo n.º 20
0
 public void ProcessContentUnPublished(IPublishingStrategy sender, PublishEventArgs <IContent> unPublishEventArgs)
 {
     foreach (var entity in unPublishEventArgs.PublishedEntities)
     {
         UpdatePagePromotionCache(entity);
     }
 }
Exemplo n.º 21
0
        private void ContentServicePublishing(IPublishingStrategy sender, PublishEventArgs <IContent> args)
        {
            var umbracoHelper  = new UmbracoHelper(UmbracoContext.Current);
            var contentService = ApplicationContext.Current.Services.ContentService;

            foreach (var node in args.PublishedEntities)
            {
                if (node.ContentType.Alias == "contact")
                {
                    var publishedContent = node.ToPublishedContent();
                    var fields           = publishedContent.GetPropertyValue <IEnumerable <IPublishedContent> >("fieldList");
                    var ncItems          = new List <dynamic>();
                    foreach (var field in fields)
                    {
                        dynamic ncItem = new ExpandoObject();
                        ((IDictionary <string, object>)ncItem).Add("ncContentTypeAlias", field.DocumentTypeAlias);
                        ((IDictionary <string, object>)ncItem).Add("fieldName", field.DocumentTypeAlias);
                        var type = GetFieldType(field.DocumentTypeAlias);
                        ((IDictionary <string, object>)ncItem).Add("type", type);
                        ((IDictionary <string, object>)ncItem).Add("placeholder", field.GetPropertyValue <string>("placeholder"));
                        ((IDictionary <string, object>)ncItem).Add("errorMsg", field.GetPropertyValue <string>("errorMsg"));
                        ncItems.Add(ncItem);
                    }

                    node.SetValue("fieldList", JsonConvert.SerializeObject(ncItems));
                    contentService.Save(node);
                }
            }
        }
 void ContentService_Published(IPublishingStrategy sender, PublishEventArgs <IContent> e)
 {
     foreach (IContent content in e.PublishedEntities)
     {
         UrlTrackerRepository.Convert410To301(content.Id);
     }
 }
Exemplo n.º 23
0
        private static void ContentServiceUnPublished(IPublishingStrategy sender, PublishEventArgs <IContent> args)
        {
            foreach (var node in args.PublishedEntities)
            {
                var publishedContentEnum = (ResetUmbracoContentTypesEnum)Enum.Parse(typeof(ResetUmbracoContentTypesEnum), node.ContentType.Alias);
                switch (publishedContentEnum)
                {
                case ResetUmbracoContentTypesEnum.aktualnosciSzczegoly:
                    ClearRelatedCache(publishedContentEnum);
                    ClearLazyNewsCache();
                    break;

                case ResetUmbracoContentTypesEnum.galeriaSzczegoly:
                case ResetUmbracoContentTypesEnum.projektySzczegoly:
                case ResetUmbracoContentTypesEnum.kontaktNode:
                case ResetUmbracoContentTypesEnum.ofertyPracyNode:
                    ClearRelatedCache(publishedContentEnum);
                    break;

                case ResetUmbracoContentTypesEnum.galeria:
                case ResetUmbracoContentTypesEnum.home:
                case ResetUmbracoContentTypesEnum.kontakt:
                case ResetUmbracoContentTypesEnum.layout:
                case ResetUmbracoContentTypesEnum.ofertyPracy:
                case ResetUmbracoContentTypesEnum.projekty:
                    ClearRelatedCache(publishedContentEnum);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Exemplo n.º 24
0
        private static void ContentService_Publishing(IPublishingStrategy sender, PublishEventArgs <IContent> e)
        {
            IContent doc = e.PublishedEntities.First();
            ILog     log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

            // we might want to cancel the publish event if it came from a scheduled publish
            // we can check if the node has an active workflow, in which case it should not publish, and it's likely from the scheduler
            // if the publish is scheduled, there is no httpContext

            try
            {
                // if a context exists, sweet, let it go
                if (null != HttpContext.Current)
                {
                    return;
                }

                // ensure we have http context for queries
                HttpContext httpContext = new HttpContext(
                    new HttpRequest(string.Empty, "http://tempuri.org", string.Empty),
                    new HttpResponse(new StringWriter()));

                HttpContextBase httpContextBase = new HttpContextWrapper(httpContext);

                UmbracoContext.EnsureContext(
                    httpContextBase,
                    ApplicationContext.Current,
                    new WebSecurity(httpContextBase, ApplicationContext.Current),
                    UmbracoConfig.For.UmbracoSettings(),
                    UrlProviderResolver.Current.Providers,
                    false);

                var instancesService = new InstancesService();
                IEnumerable <WorkflowInstancePoco> instances = instancesService.GetForNodeByStatus(doc.Id, new List <int>
                {
                    (int)WorkflowStatus.PendingApproval,
                    (int)WorkflowStatus.Rejected,
                    (int)WorkflowStatus.Resubmitted
                });

                List <WorkflowInstancePoco> orderedInstances = instances.OrderByDescending(i => i.CompletedDate).ToList();

                // if any incomplete workflows exists, cancel the publish
                // this will clear the release date, which is ok as it has passed
                // and the change will be released when the workflow completes
                if (!orderedInstances.Any())
                {
                    return;
                }

                e.Cancel = true;

                log.Info($"Scheduled publish for {doc.Name} cancelled due to active workflow");
            }
            catch (Exception ex)
            {
                log.Error($"Error in scheduled publish validation for {doc.Name}", ex);
            }
        }
Exemplo n.º 25
0
 public void FilterEvent(IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs <Umbraco.Core.Models.IContent> e)
 {
     //check if this is a valid content type
     if (e.PublishedEntities.Select(c => c.ContentType.Alias).Intersect(ContentTypeAliases).Count() > 0)
     {
         MethodToBind.Invoke(null, new object[] { sender, e });
     }
 }
Exemplo n.º 26
0
 //every time we save a document, we rewrite the urls
 void ContentService_Published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
 {
     IContentService contentService = ApplicationContext.Current.Services.ContentService;
     foreach(var entity in e.PublishedEntities)
     {
         UrlRewriter.RewriteUrl(entity, contentService);
     }
 }
Exemplo n.º 27
0
        private static void ProcessContentUnPublished(IPublishingStrategy sender, PublishEventArgs <IContent> e)
        {
            var services = DependencyResolver.Current.GetServices <IUmbracoContentUnPublishedEventService>();

            foreach (var service in services)
            {
                service.ProcessContentUnPublished(sender, e);
            }
        }
 public void UpdateIndeces(IPublishingStrategy sender, PublishEventArgs <IContent> args)
 {
     foreach (var node in args.PublishedEntities.Where(x => x.ContentType.Alias == Blogpost.ModelTypeAlias))
     {
         MongoIndexer.Index(node.Id);
         LuceneIndexer.Index(node.Id);
         PetaPocoIndexer.Index(node.Id);
     }
 }
Exemplo n.º 29
0
        public ContentService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, IPublishingStrategy publishingStrategy)
        {
	        if (provider == null) throw new ArgumentNullException("provider");
	        if (repositoryFactory == null) throw new ArgumentNullException("repositoryFactory");
	        if (publishingStrategy == null) throw new ArgumentNullException("publishingStrategy");
	        _uowProvider = provider;
	        _publishingStrategy = publishingStrategy;
            _repositoryFactory = repositoryFactory;
        }
Exemplo n.º 30
0
        private void PublishingStrategyOnUnPublished(IPublishingStrategy sender, PublishEventArgs <IContent> publishEventArgs)
        {
            if (!publishEventArgs.PublishedEntities.Any <IContent>())
            {
                return;
            }
            IndexingRepository indexingRepository = new IndexingRepository((ICmsIndexer) new UmbracoIndexer(), (ILogFacade) new LogFacade(typeof(IndexingRepository)));

            using (IEnumerator <IContent> enumerator1 = publishEventArgs.PublishedEntities.GetEnumerator())
            {
                while (((IEnumerator)enumerator1).MoveNext())
                {
                    IContent current1 = enumerator1.Current;
                    try
                    {
                        using (IEnumerator <PropertyType> enumerator2 = ((IContentBase)current1).PropertyTypes.GetEnumerator())
                        {
                            while (((IEnumerator)enumerator2).MoveNext())
                            {
                                PropertyType current2 = enumerator2.Current;
                                try
                                {
                                    if (current2.DataTypeDefinitionId == -90)
                                    {
                                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("{0} was detected as upload property, will remove file from index", (object)current2.Alias), (Exception)null);
                                        Property property = ((KeyedCollection <string, Property>)((IContentBase)current1).Properties)[current2.Alias];
                                        if (property.Value != null && property.Value.ToString() != string.Empty)
                                        {
                                            string standaloneMediaId = MediaResolver.GetStandaloneMediaId(property.Value.ToString());
                                            if (!string.IsNullOrWhiteSpace(standaloneMediaId))
                                            {
                                                indexingRepository.DeleteMediaFromIndex("media" + standaloneMediaId);
                                                MediaResolver.RemoveStandAloneMedia(standaloneMediaId);
                                            }
                                        }
                                        else
                                        {
                                            this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Property value is empty, nothing to remove", (Exception)null);
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Error, "Error removing upload property media item from index.", ex);
                                }
                            }
                        }
                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Unpublishing document \"" + ((IUmbracoEntity)current1).Name + "\", removing from Solr index.", (Exception)null);
                        indexingRepository.DeleteFromPublishedIndex((object)((IEntity)current1).Id);
                    }
                    catch (Exception ex)
                    {
                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Error, "Error removing node " + (object)((IEntity)current1).Id + " from index, are you sure Solr is running?", ex);
                    }
                }
            }
        }
Exemplo n.º 31
0
        private void ContentService_Published(IPublishingStrategy sender, PublishEventArgs <IContent> e)
        {
            // Invalidate JSON cache
            var jsonCachePath    = HostingEnvironment.MapPath(Constants.JsonCachePath);
            var jsonCacheMd5Path = HostingEnvironment.MapPath(Constants.JsonCacheMd5Path);

            System.IO.File.Delete(jsonCachePath);
            System.IO.File.Delete(jsonCacheMd5Path);
        }
Exemplo n.º 32
0
        public void ProcessContentPublished(IPublishingStrategy sender, PublishEventArgs <IContent> args)
        {
            var contentPagesWithTags = ParseUserTags(args.PublishedEntities);

            foreach (var(_, tagIds, entityId) in contentPagesWithTags)
            {
                _userTagService.Replace(entityId, tagIds);
            }
        }
Exemplo n.º 33
0
 //After publish / unpublish
 private async void PurgeUrl(IPublishingStrategy sender, PublishEventArgs <IContent> e)
 {
     foreach (Uri url in urlsToPurge)
     {
         LogHelper.Info(this.GetType(), "Fastly - Purge URL Called - " + url);
         await SendAsync(url);
     }
     urlsToPurge.Clear();
 }
        private void ContentServicePublished(IPublishingStrategy sender, PublishEventArgs <IContent> e)
        {
            var azureSearchServiceClient = AzureSearchContext.Instance.SearchIndexClient;

            foreach (var entity in e.PublishedEntities)
            {
                azureSearchServiceClient.ReIndexContent(entity);
            }
        }
Exemplo n.º 35
0
        void ContentServicePublishedEvent(IPublishingStrategy sender, PublishEventArgs<IContent> e)
        {
            // Clear all AtoZs

            // could be cleverer - the cache has the root ID in it, so you could just clear caches where
            // the ID is a parent of the current page - not sure it makes much diffrence, because the
            // rebuild only happens once, and it doesn't take 'that' long to rebuild
            ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch("AtoZPages");           
        }
Exemplo n.º 36
0
        void ContentServicePublished(IPublishingStrategy sender, PublishEventArgs<IContent> e)
        {
            if (HttpContext.Current == null)
                return;

            foreach (var entity in e.PublishedEntities)
            {
                UnVersionContext.Instance.UnVersionService.UnVersion(entity);
            }
        }
Exemplo n.º 37
0
 void DeleteNodesFromTimetable(IPublishingStrategy sender, PublishEventArgs<IContent> e)
 {
     if (e.PublishedEntities.Any())
     {
         foreach (var entity in e.PublishedEntities)
         {
             if (entity.ContentType.Alias == "Service")
             {
                 TimetableHelper.Delete(entity.Id);
             }
         }
     }
 }
Exemplo n.º 38
0
      /// <summary>
      /// Called when an item is published
      /// </summary>
      /// <param name="sender"></param>
      /// <param name="publishEventArgs"></param>
      private void ContentServiceOnPublished(IPublishingStrategy sender, PublishEventArgs<IContent> publishEventArgs)
      {
         if (!publishEventArgs.PublishedEntities.Any()) return;
         foreach (var entity in publishEventArgs.PublishedEntities)
         {
            DbProvider.RemoveMediaTrack(entity.Id);
            if (_verbose)
            {
               LogHelper.Info<MediaTrackerHandler>(string.Format("All previous tracking for the page '{0}' was removed because the page is about to be published.", entity.Name));
            }
            var content = ApplicationContext.Current.Services.ContentService.GetById(entity.Id);
            var validProperties = content.Properties.Where(x => _trackedProperties.Contains(x.Alias)).ToList();
            foreach (var property in validProperties)
            {
               var propertyType = entity.PropertyTypes.Single(x => x.Alias == property.Alias);
               var editorType = GetInstanceField(typeof (PropertyType), propertyType, "PropertyEditorAlias").ToString();
               var propertyVal = property.Value.ToString();
               if (string.IsNullOrEmpty(propertyVal)) continue;

               switch (editorType)
               {
                  case "Umbraco.MediaPicker":
                     CreateMediaRecord(
                        EnsureModel(content.Id, Convert.ToInt32(propertyVal), propertyType.Id)
                        , content, property);
                     break;
                  case "Umbraco.MultipleMediaPicker":
                     var mediaIds = propertyVal.Split(new[] {','});
                     foreach (var mediaId in mediaIds)
                     {
                        CreateMediaRecord(
                           EnsureModel(content.Id, Convert.ToInt32(mediaId), propertyType.Id)
                           , content, property);
                     }
                     break;
                  default: // assume content with embedded image links
                     var matches = _imgtagRegex.Matches(propertyVal);
                     foreach (Match m in matches)
                     {
                        var imgTag = m.Value;
                        var src = _imgsrcRegex.Match(imgTag).Groups["src"].Value;
                        var id = _dataidRegex.Match(imgTag).Groups["dataid"].Value;
                        CreateMediaRecord(
                           EnsureModel(content.Id, EvaluateDataId(id, src), propertyType.Id)
                           , content, property);
                     }
                     break;
               }
            }
         }
      }
Exemplo n.º 39
0
 void ContentService_Published(IPublishingStrategy sender, PublishEventArgs<Umbraco.Core.Models.IContent> e)
 {
     const string publishedDateKey = "publishedDate";
     var contentService = ApplicationContext.Current.Services.ContentService;
     foreach (var content in e.PublishedEntities.Where(x => x.HasProperty(publishedDateKey)))
     {
         var existingValue = content.GetValue(publishedDateKey);
         if (existingValue == null)
         {
             content.SetValue(publishedDateKey, DateTime.Now.ToString());
             contentService.SaveAndPublishWithStatus(content, raiseEvents: false);
         }
     }
 }
Exemplo n.º 40
0
        public static void Published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
        {
            foreach (var content in e.PublishedEntities)
            {
                switch (content.ContentType.Alias)
                {
                    case ContentTypeAliases.ServerError:
                        if (content.Published)
                        {
                            PublishErrorPage(e, content);
                        }

                        break;
                }
            }
        }
Exemplo n.º 41
0
 private void Content_AfterPublish(IPublishingStrategy sender, PublishEventArgs<IContent> args)
 {
     foreach (var content in args.PublishedEntities)
     {
         if (content.ContentType.Alias == "Dealer")
         {
             var typedContent = ((Content)content);
             var addressJson = typedContent.GetValue<string>("address");
             var addressObj = Newtonsoft.Json.Linq.JObject.Parse(addressJson);
             var sql = "spUpdateDealerLocation @0, @1, @2";
             var sqlArgs = new List<object>();
             sqlArgs.Add(typedContent.Id);
             sqlArgs.Add(addressObj.Value<decimal>("long"));
             sqlArgs.Add(addressObj.Value<decimal>("lat"));
             ApplicationContext.Current.DatabaseContext.Database.Execute(sql, sqlArgs.ToArray());
         }
     }
 }
 void PublishingStrategy_UnPublished(IPublishingStrategy sender, PublishEventArgs<IContent> e)
 {
     if (e.PublishedEntities.Any())
     {
         if (e.PublishedEntities.Count() > 1)
         {
             foreach (var c in e.PublishedEntities)
             {
                 UnPublishSingle(c);
             }
         }
         else
         {
             var content = e.PublishedEntities.FirstOrDefault();
             UnPublishSingle(content);
         }
     }
 }
        void PublishingStrategy_Published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
        {
            if (e.PublishedEntities.Any())
            {
                if (e.IsAllRepublished)
                {
                    UpdateEntireCache();
                    return;
                }

                if (e.PublishedEntities.Count() > 1)
                {
                    UpdateMultipleContentCache(e.PublishedEntities);
                }
                else
                {
                    var content = e.PublishedEntities.FirstOrDefault();
                    UpdateSingleContentCache(content);
                }
            }
        }
        void ContentService_Publishing(IPublishingStrategy sender, PublishEventArgs<IContent> e)
        {
            // When content is renamed or 'umbracoUrlName' property value is added/updated
            foreach (IContent content in e.PublishedEntities)
            {
#if !DEBUG
                try
#endif
                {
                    Node node = new Node(content.Id);
                    if (node.Name != content.Name && !string.IsNullOrEmpty(node.Name)) // If name is null, it's a new document
                    {
                        // Rename occurred
                        UrlTrackerRepository.AddUrlMapping(content, node.GetDomainRootNode().Id, node.NiceUrl, AutoTrackingTypes.Renamed);

                        if (ClientTools != null)
                            ClientTools.ChangeContentFrameUrl(string.Concat("/umbraco/editContent.aspx?id=", content.Id));
                    }
                    if (content.HasProperty("umbracoUrlName"))
                    {
                        string contentUmbracoUrlNameValue = content.GetValue("umbracoUrlName") != null ? content.GetValue("umbracoUrlName").ToString() : string.Empty;
                        string nodeUmbracoUrlNameValue = node.GetProperty("umbracoUrlName") != null ? node.GetProperty("umbracoUrlName").Value : string.Empty;
                        if (contentUmbracoUrlNameValue != nodeUmbracoUrlNameValue)
                        {
                            // 'umbracoUrlName' property value added/changed
                            UrlTrackerRepository.AddUrlMapping(content, node.GetDomainRootNode().Id, node.NiceUrl, AutoTrackingTypes.UrlOverwritten);

                            if (ClientTools != null)
                                ClientTools.ChangeContentFrameUrl(string.Concat("/umbraco/editContent.aspx?id=", content.Id));
                        }
                    }
                }
#if !DEBUG
                catch (Exception ex)
                {
                    ex.LogException();
                }
#endif
            }
        }
Exemplo n.º 45
0
        protected void PurgeCloudflareCache(IPublishingStrategy strategy, PublishEventArgs<IContent> e)
        {
            //If we have the cache buster turned off then just return.
            if (!CloudflareConfiguration.Instance.PurgeCacheOn) { return; }

            List<string> urls = new List<string>();
            //Else we can continue to delete the cache for the saved entities.
            foreach(IContent content in e.PublishedEntities)
            {
                try
                {
                    //Check to see if the page has cache purging on publish disabled.
                    if(content.GetValue<bool>("cloudflareDisabledOnPublish"))
                    {
                        //it was disabled so just continue;
                        continue;
                    }
                }
                catch(Exception ex)
                {
                    //continue;
                }

                urls.AddRange(UmbracoFlareDomainManager.Instance.GetUrlsForNode(content, false));
            }

            List<StatusWithMessage> results = CloudflareManager.Instance.PurgePages(urls);

            if (results.Any() && results.Where(x => !x.Success).Any())
            {
                e.Messages.Add(new EventMessage("Cloudflare Caching", "We could not purge the Cloudflare cache. \n \n" + CloudflareManager.PrintResultsSummary(results), EventMessageType.Warning));
            }
            else if (results.Any())
            {
                e.Messages.Add(new EventMessage("Cloudflare Caching", "Successfully purged the cloudflare cache.", EventMessageType.Success));
            }
        }
Exemplo n.º 46
0
        /// <summary>
        /// Builds the various services
        /// </summary>
		private void BuildServiceCache(
			IDatabaseUnitOfWorkProvider dbUnitOfWorkProvider, 
			IUnitOfWorkProvider fileUnitOfWorkProvider, 
			IPublishingStrategy publishingStrategy, 
			Lazy<RepositoryFactory> repositoryFactory)
        {
            var provider = dbUnitOfWorkProvider;
            var fileProvider = fileUnitOfWorkProvider;

			if (_userService == null)
				_userService = new Lazy<UserService>(() => new UserService(provider, repositoryFactory.Value));

            if (_contentService == null)
				_contentService = new Lazy<ContentService>(() => new ContentService(provider, repositoryFactory.Value, publishingStrategy));

            if(_mediaService == null)
                _mediaService = new Lazy<MediaService>(() => new MediaService(provider, repositoryFactory.Value));

            if(_macroService == null)
				_macroService = new Lazy<MacroService>(() => new MacroService(fileProvider, repositoryFactory.Value));

            if(_contentTypeService == null)
				_contentTypeService = new Lazy<ContentTypeService>(() => new ContentTypeService(provider, repositoryFactory.Value, _contentService.Value, _mediaService.Value));

            if(_dataTypeService == null)
				_dataTypeService = new Lazy<DataTypeService>(() => new DataTypeService(provider, repositoryFactory.Value));

            if(_fileService == null)
				_fileService = new Lazy<FileService>(() => new FileService(fileProvider, provider, repositoryFactory.Value));

            if(_localizationService == null)
				_localizationService = new Lazy<LocalizationService>(() => new LocalizationService(provider, repositoryFactory.Value));

            if(_packagingService == null)
                _packagingService = new Lazy<PackagingService>(() => new PackagingService(_contentService.Value, _contentTypeService.Value, _mediaService.Value, _dataTypeService.Value, _fileService.Value, repositoryFactory.Value, provider));
        }
        private void ContentService_Published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
        {
            //// Check if PurgeHomepage setting is set
            var useCloudFlare = Config.GetSettingValue("EnableCloudflare");
            if (useCloudFlare == null || !(bool)useCloudFlare) return;

            if ((bool) useCloudFlare)
            {
                foreach (var entity in e.PublishedEntities)
                {
                    Purge(entity.Id);

                    //// Check if PurgeHomepage setting is set
                    var purgeHomepage = Config.GetSettingValue("PurgeHomepage");
                    if (purgeHomepage == null || !(bool) purgeHomepage) continue;

                    //// Get Homepage node
                    var homepage = Config.GetSettingValue("Homepage");
                    int homepageNodeId;

                    if (homepage != null && int.TryParse(homepage.ToString(), out homepageNodeId))
                    {
                        Purge(homepageNodeId);
                    }
                }
            }
        }
Exemplo n.º 48
0
 private void Commentable_published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
 {
     foreach (IContent node in e.PublishedEntities)
       {
     if (node.ContentType.AllowedContentTypes.Where(x => x.Alias == "Commenttree").Any())
     {
       IContentService cs = new ContentService();
       IContent comment_tree = node.Children().Where(x => x.ContentType.Alias == "Commenttree").First();
       if (comment_tree != null)
     cs.SaveAndPublishWithStatus(comment_tree);
     }
       }
 }
Exemplo n.º 49
0
 void ContentService_Published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
 {
     RefreshArticles(e.PublishedEntities);
 }
Exemplo n.º 50
0
        protected void UpdateContentIdToUrlCache(IPublishingStrategy strategy, PublishEventArgs<IContent> e)
        {
            UmbracoHelper uh = new UmbracoHelper(UmbracoContext.Current);

            foreach(IContent c in e.PublishedEntities)
            {
                if(c.HasPublishedVersion)
                {
                    IEnumerable<string> urls = UmbracoFlareDomainManager.Instance.GetUrlsForNode(c, false);

                    if(urls.Contains("#"))
                    {
                        //When a piece of content is first saved, we cannot get the url, if that is the case then we need to just
                        //invalidate the who ContentIdToUrlCache, that way when we request all of the urls agian, it will pick it up.
                        UmbracoUrlWildCardManager.Instance.DeletedContentIdToUrlCache();
                    }
                    else
                    {
                        UmbracoUrlWildCardManager.Instance.UpdateContentIdToUrlCache(c.Id, urls);
                    }

                }

                //TODO: Does this need to be here?
                //We also need to update the descendants now because their urls changed
                IEnumerable<IContent> descendants = c.Descendants();

                foreach(IContent desc in descendants)
                {
                    IEnumerable<string> descUrls = UmbracoFlareDomainManager.Instance.GetUrlsForNode(desc.Id, false);

                    UmbracoUrlWildCardManager.Instance.UpdateContentIdToUrlCache(c.Id, descUrls);
                }
            }
        }
 private void Content_Unpublished(IPublishingStrategy sender, PublishEventArgs<IContent> e)
 {
     ClearCache();
 }
 static void PublishingStrategyPublishing(IPublishingStrategy sender, PublishEventArgs<IContent> e)
 {
     foreach (var i in e.PublishedEntities.Where(i => i.Name == "Text Page 2"))
     {
         e.Cancel = true;
     }
 }
		private static void ContentService_Published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
		{
			var contents = e.PublishedEntities.Where(c => c.ContentType.Alias.StartsWith(Order.NodeAlias));
			sender.UnPublish(contents, 0);
		}
 private static void ContentServicePublished(IPublishingStrategy sender, PublishEventArgs<IContent> args)
 {
     foreach (var node in args.PublishedEntities)
     {
         var publishedContentEnum = (ResetUmbracoContentTypesEnum)Enum.Parse(typeof(ResetUmbracoContentTypesEnum), node.ContentType.Alias);
         switch (publishedContentEnum)
         {
             case ResetUmbracoContentTypesEnum.aktualnosciSzczegoly:
                 ClearRelatedCache(publishedContentEnum, umbraco.library.NiceUrl(node.Id));
                 ClearLazyNewsCache();
                 break;
             case ResetUmbracoContentTypesEnum.galeriaSzczegoly:
             case ResetUmbracoContentTypesEnum.projektySzczegoly:
             case ResetUmbracoContentTypesEnum.kontaktNode:
             case ResetUmbracoContentTypesEnum.ofertyPracyNode:
                 ClearRelatedCache(publishedContentEnum, umbraco.library.NiceUrl(node.Id));
                 break;
             case ResetUmbracoContentTypesEnum.galeria:
             case ResetUmbracoContentTypesEnum.home:
             case ResetUmbracoContentTypesEnum.kontakt:
             case ResetUmbracoContentTypesEnum.layout:
             case ResetUmbracoContentTypesEnum.ofertyPracy:
             case ResetUmbracoContentTypesEnum.projekty:
                 ClearRelatedCache(publishedContentEnum);
                 break;
             default:
                 throw new ArgumentOutOfRangeException();
         }
     }
 }
Exemplo n.º 55
0
        /// <summary>
        /// Adds relation between Content and Media when Content is published
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ContentService_Published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
        {
            // RelationService
            IRelationService rs = ApplicationContext.Current.Services.RelationService;

            // ContentService
            IContentService cs = ApplicationContext.Current.Services.ContentService;

            // RelationType
            IRelationType relationType = rs.GetRelationTypeByAlias(Constants.RelationTypeAlias);

            // Published Documents
            foreach (var contentNode in e.PublishedEntities)
            {
                // Content is child, query by child and RelationType
                var relations = rs.GetByChild(cs.GetById(contentNode.Id), Constants.RelationTypeAlias);

                // Remove current relations
                if (relations.Count() > 0)
                {
                    LogHelper.Info<MediaContentUsage>(String.Format("Removing all Media relations for published Content with id '{0}'", contentNode.Id));

                    foreach (var relation in relations)
                    {
                        rs.Delete(relation);

                        LogHelper.Debug<MediaContentUsage>(String.Format("Deleted relation: ParentId {0} ChildId {1}", relation.ParentId, relation.ChildId));
                    }
                }

                // Relate found Media to this Content
                foreach (var mediaNodeId in FindMedia(contentNode.Id))
                {
                    Relation relation = new Relation(mediaNodeId, contentNode.Id, relationType);
                    rs.Save(relation);

                    LogHelper.Debug<MediaContentUsage>(String.Format("Saved relation: ParentId {0} ChildId {1}", relation.ParentId, relation.ChildId));
                }
            }
        }
        void ContentServiceUnPublishing(IPublishingStrategy sender, PublishEventArgs<IContent> e)
        {
            Logger.Info("Received unoublish event");

            foreach (var publishedEntity in e.PublishedEntities)
            {
                var runtimeContentModel = RuntimeUmbracoContext.Instance.UmbracoContentSerialiser.Remove(publishedEntity);
                foreach (var adapter in RuntimeUmbracoContext.Instance.DeploymentAdapters)
                {
                    adapter.DeployContent(runtimeContentModel, DeploymentAction.Delete);
                }
            }
            
        }
Exemplo n.º 57
0
 private void PublishingStrategy_Published(IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs<Umbraco.Core.Models.IContent> e)
 {
     ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch("LEBLENDEREDITOR");
 }
Exemplo n.º 58
0
 public ContentService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, IPublishingStrategy publishingStrategy)
 {
     _uowProvider = provider;
     _publishingStrategy = publishingStrategy;
     _repositoryFactory = repositoryFactory;
 }