Example #1
0
        private void EditComment(object sender, ContentEventArgs e)
        {
            Comment comment;

            try
            {
                comment = this.forumData.CommentsRepository.GetCommentById(e.Id);
            }
            catch (Exception)
            {
                throw new HttpException(500, "Internal Server Error");
            }

            var content = e.Content.Trim();

            if (Validator.IsContentValid(content))
            {
                comment.Contents = content;
            }
            else
            {
                this.View.Model.Error = $"Content must be between {GlobalConstants.ContentMinLength} and {GlobalConstants.ContentMaxLength} characters long!";
                return;
            }

            try
            {
                this.forumData.CommentsRepository.UpdateComment(comment);
                this.forumData.Save();
            }
            catch (Exception)
            {
                throw new HttpException(500, "Internal Server Error");
            }
        }
        /// <summary>
        /// Add the cordinates to the block.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="ContentEventArgs"/> instance containing the event data.</param>
        private void SavingContent(object sender, ContentEventArgs e)
        {
            if (!(e.Content is MapBlock))
            {
                return;
            }

            var block   = e.Content as MapBlock;
            var address = block.Address;

            if (string.IsNullOrWhiteSpace(address) || address.Length <= 2)
            {
                return;
            }

            var addressResult = _mapService.Service.GetAddress(address);

            if (!addressResult.Features.Any())
            {
                e.CancelAction = true;
                e.CancelReason = "Not a valid address.";
                return;
            }

            block.Latitude  = addressResult.Features[0].Geometry.Coordinates[0];
            block.Longitude = addressResult.Features[0].Geometry.Coordinates[1];
        }
Example #3
0
 public virtual void OnPublishedContent(ContentEventArgs e)
 {
     if (PublishedContent != null)
     {
         PublishedContent.Invoke(this, e);
     }
 }
Example #4
0
 public virtual void OnSavedContent(ContentEventArgs e)
 {
     if (SavedContent != null)
     {
         SavedContent.Invoke(this, e);
     }
 }
Example #5
0
 private void CreatingContent(object sender, ContentEventArgs e)
 {
     if (e.Content is ImageData image)
     {
         ImageAnalyzer.AnalyzeImageAndUpdateMetaData(image);
     }
 }
Example #6
0
 public virtual void OnCreatedContent(ContentEventArgs e)
 {
     if (CreatedContent != null)
     {
         CreatedContent.Invoke(this, e);
     }
 }
Example #7
0
        //private void SettingsPublishing(object sender, ContentEventArgs e)
        //{
        //}

        protected virtual void SettingsPublished(object sender, ContentEventArgs e)
        {
            try
            {
                if (e.ContentLink.CompareToIgnoreWorkID(ConfigurationPageLink))
                {
                    var page     = (AzureAdSecuritySettingsPage)e.Content;
                    var newRoles = page.Settings?.Roles ?? new List <string>();

                    var previousVersion = ContentVersionRepository.List(ConfigurationPageLink)
                                          .Where(x => x.Status == VersionStatus.PreviouslyPublished)
                                          .OrderByDescending(x => x.Saved)
                                          .FirstOrDefault();

                    var previousPage = previousVersion != null?ContentRepository.Get <AzureAdSecuritySettingsPage>(previousVersion.ContentLink, DefaultLoaderOptions) : null;

                    var diff = Diff(newRoles, previousPage?.Settings?.Roles ?? new List <string>());

                    if (!diff.IsEmpty)
                    {
                        RolesWatcher.RolesChanged(diff);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error($"Error handling roles update (published page #{e.ContentLink.ID}): {ex}");
            }
        }
Example #8
0
 private void OnPublishedContent(object sender, ContentEventArgs contentEventArgs)
 {
     if (contentEventArgs.Content is IFacetConfiguration facetConfiguration)
     {
         InitializeFacets(facetConfiguration.SearchFiltersConfiguration);
     }
 }
        public static void RemoveRelationalContent(object sender, ContentEventArgs args)
        {
            // Only work magic on waste basket
            if (!args.TargetLink.Equals(ContentReference.WasteBasket))
            {
                return;
            }

            //can't really do anything without a contentlink in the args...
            if (ContentReference.IsNullOrEmpty(args.ContentLink))
            {
                return;
            }

            // Remove all elements in association properties and publish page. Publish event will handle the rest
            var contentRepository = ServiceLocator.Current.GetInstance <IContentRepository>();
            var content           = contentRepository.Get <IContent>(args.ContentLink) as IReadOnly;

            var contentClone = content?.CreateWritableClone() as IAssociationContent;

            if (contentClone == null)
            {
                return;
            }

            var contentAssociationsHelper = ServiceLocator.Current.GetInstance <ContentInspector>();
            var associationProperties     = contentAssociationsHelper.GetAssociationProperties(contentClone);

            foreach (var associationProperty in associationProperties)
            {
                contentClone.Property[associationProperty.Name].Clear();
            }

            contentRepository.Save(contentClone, SaveAction.Publish | SaveAction.SkipValidation, AccessLevel.NoAccess);
        }
Example #10
0
        private void OnMovedContent(object sender, ContentEventArgs e)
        {
            Logger.Debug("OnPublishedContent raised.");

            if (!(e.Content is CatalogContentBase catalogContentBase))
            {
                Logger.Debug("Moved content is not a catalog entry.");
                return;
            }

            switch (catalogContentBase)
            {
            case EntryContentBase entryContent:
                ICollection <ProductContent> entries = GetProductsAffected(entryContent);
                foreach (ProductContent productContent in entries)
                {
                    _productExportService.ExportProduct(productContent, null);
                }

                break;

            case NodeContent nodeContent:
                _productExportService.ExportChildProducts(nodeContent);
                _categoryExportService.StartFullCategoryExport();
                break;
            }
        }
Example #11
0
 private void OnSavedContent(object sender, ContentEventArgs e)
 {
     if (e.Content is ISavedContentHandler)
     {
         ((ISavedContentHandler)e.Content).SavedContent(sender, e);
     }
 }
Example #12
0
 private static bool ContentIsInvalid(ContentEventArgs contentEventArgs)
 {
     // ignore root page, if it is not the start page
     if (contentEventArgs.ContentLink.Equals(ContentReference.RootPage, true) && !ContentReference.RootPage.Equals(ContentReference.StartPage, true)) return true;
     // ignore items in the waste basket
     return contentEventArgs.TargetLink == ContentReference.WasteBasket;
 }
        private void SavingContentHandler(object sender, ContentEventArgs e)
        {
            if (Configuration.Configuration.AddAutomaticRedirects == false)
            {
                return;
            }

            var transition = (e as SaveContentEventArgs)?.Transition;

            if (transition.Value.CurrentStatus == VersionStatus.NotCreated)
            {
                return;
            }

            // create redirects only if page is unpublished
            // because child objects may have been already published so their URL changes
            if (ContentVersionRepository
                .Service
                .List(e.ContentLink)
                .Any(p => p.Status == VersionStatus.Published || p.Status == VersionStatus.PreviouslyPublished))
            {
                return;
            }

            var oldUrl = UrlResolver.Service.GetUrl(e.ContentLink, null);

            e.Items.Add(OldUrlKey, oldUrl);
        }
Example #14
0
 private void OnPublishedContent(object sender, ContentEventArgs e)
 {
     if (e.Content is IPublishedContentHandler)
     {
         ((IPublishedContentHandler)e.Content).PublishedContent(sender, e);
     }
 }
Example #15
0
 private void Events_PublishedContent(object sender, ContentEventArgs e)
 {
     if (e.Content is PageData || e.Content is BlockData || e.Content is MediaData)
     {
         Task.Run(() => this._contentSyncService.ExportItem(e.Content, _dataExporterAccessor(), _contentLoader));
     }
 }
 private void ContentEvents_PublishedContent(object sender, ContentEventArgs e)
 {
     if (e.Content.GetOriginalType() == typeof(VirtualTemplateContent))
     {
         _templateRepository.ResetState();
     }
 }
Example #17
0
        private void OnPublishedContent(object sender, ContentEventArgs e)
        {
            var content = e.Content;

            CleanupOldTags(content);

            var contentType = _contentTypeRepository.Load(content.ContentTypeID);

            var tagProperties = contentType.PropertyDefinitions.Where(p => p.TemplateHint == "Tags").ToArray();

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

            foreach (var tagProperty in tagProperties)
            {
                var tagPropertyInfo = contentType.ModelType.GetProperty(tagProperty.Name);
                var tags = GetPropertyTags(content as ContentData, tagProperty);

                if (tagPropertyInfo == null)
                {
                    return;
                }

                var groupKeyAttribute =
                    tagPropertyInfo.GetCustomAttribute(typeof(TagsGroupKeyAttribute)) as TagsGroupKeyAttribute;
                var cultureSpecificAttribute
                    = tagPropertyInfo.GetCustomAttribute(typeof(CultureSpecificAttribute)) as CultureSpecificAttribute;

                var groupKey = TagsHelper.GetGroupKeyFromAttributes(groupKeyAttribute, cultureSpecificAttribute, content);

                _tagService.Save(content.ContentGuid, tags, groupKey);
            }
        }
Example #18
0
 private void Instance_PublishingPage(object sender, ContentEventArgs e)
 {
     if (e.Content is SBRobotsTxt content)
     {
         Task.Run(async() => await SeoHelper.AddRoute());
     }
 }
Example #19
0
 private void ContentEvents_DeletingContent(object sender, ContentEventArgs e)
 {
     if (e.Content is SBRobotsTxt)
     {
         Task.Run(async() => await SeoHelper.RemoveRoute());
     }
 }
Example #20
0
        private void MLogObserver_OnNewContentEvent(object sender, EventArgs e)
        {
            ContentEventArgs args = e as ContentEventArgs;

            if (args != null)
            {
                ListViewItem newMsg = new ListViewItem();
                newMsg.Text = args.Content.TimeStamp.ToString("yyyy/MM/dd HH:mm:ss.ffff");
                newMsg.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Text = args.Content.Message
                });

                if (args.Content.MessageType == MessageType.Alarm)
                {
                    newMsg.BackColor = Color.Red;
                }
                else if (args.Content.MessageType == MessageType.Inform)
                {
                    newMsg.BackColor = Color.White;
                }

                lock (mNewMessages)
                {
                    mNewMessages.Add(newMsg);
                }
            }
        }
Example #21
0
        private void OnPublishedContent(object sender, ContentEventArgs e)
        {
            Logger.Debug("OnPublishedContent raised.");

            if (!(e.Content is CatalogContentBase catalogContentBase))
            {
                Logger.Debug("Published content is not catalog content.");
                return;
            }

            switch (catalogContentBase)
            {
            case EntryContentBase entryContent:
                ICollection <ProductContent> products = GetProductsAffected(entryContent);

                foreach (ProductContent product in products)
                {
                    _productExportService.ExportProduct(product, null);
                }

                _productExportService.ExportProductAssets(products);
                _productExportService.ExportProductRecommendations(products, null);

                break;

            case NodeContent nodeContent:
                _categoryExportService.StartFullCategoryExport();
                _productExportService.ExportChildProducts(nodeContent);
                break;
            }
        }
Example #22
0
 private void OnCreatedContent(object sender, ContentEventArgs e)
 {
     if (e.Content is ICreatedContentHandler)
     {
         ((ICreatedContentHandler)e.Content).CreatedContent(sender, e);
     }
 }
Example #23
0
        private void OnCreatingContent_News_BlogPage(object sender, ContentEventArgs e)
        {
            var contentRepository = ServiceLocator.Current.GetInstance <IContentRepository>();

            var currentPage = e.Content as SitePageData;


            if (currentPage != null)
            {
                var parentLink = currentPage != null ? currentPage.ParentLink : null;
                if (parentLink == null)
                {
                    return;
                }
                SitePageData parentPage;
                if (contentRepository.TryGet(parentLink, out parentPage))
                {
                    if (parentPage is NewsListingPage || parentPage is BlogListingPage)
                    {
                        currentPage.BackgroundImage     = parentPage.BackgroundImage;
                        currentPage.MediumBackgroundUrl = parentPage.MediumBackgroundUrl;
                        currentPage.SmallBackgroundUrl  = parentPage.SmallBackgroundUrl;
                        currentPage.Heading             = parentPage.Heading;
                    }
                }
            }
        }
Example #24
0
 private void OnPublishingContent(object sender, ContentEventArgs e)
 {
     if (e.Content.Name.Contains("BlockType"))
     {
         e.Content.Name = e.Content.Name.Replace("BlockType", "NewName");
     }
 }
Example #25
0
        private void OnMovedContent(object sender, ContentEventArgs e)
        {
            if (!(e.Content is PageData page))
            {
                return;
            }

            var moveContentEvent = e as MoveContentEventArgs;

            var movedToWasteBasket = moveContentEvent.TargetLink.ID == ContentReference.WasteBasket.ID;

            // TODO: Sadly this is a syncronized event, look if we can thread this so we are not locking user interface until generation of pages are done

            var staticWebService  = ServiceLocator.Current.GetInstance <IStaticWebService>();
            var contentRepository = ServiceLocator.Current.GetInstance <IContentRepository>();

            var configuration = StaticWebConfiguration.CurrentSite;

            if (!movedToWasteBasket)
            {
                // Moved somewhere, generate pages again
                staticWebService.GeneratePageInAllLanguages(contentRepository, configuration, page, IGNORE_HTML_DEPENDENCIES);

                var descendents = moveContentEvent.Descendents.ToList();
                foreach (ContentReference contentReference in descendents)
                {
                    if (contentRepository.TryGet <PageData>(contentReference, out PageData subPage))
                    {
                        staticWebService.GeneratePageInAllLanguages(contentRepository, configuration, subPage, IGNORE_HTML_DEPENDENCIES);
                    }
                }

                // create redirect pages in old location(s)
                var oldUrls             = e.Items["StaticWeb-OldLanguageUrls"] as Dictionary <string, string>;
                var newContentReference = new ContentReference(e.Content.ContentLink.ID);
                var newUrls             = staticWebService.GetPageLanguageUrls(contentRepository, newContentReference);
                if (oldUrls != null && newUrls != null && oldUrls.Count == newUrls.Count)
                {
                    foreach (KeyValuePair <string, string> pair in oldUrls)
                    {
                        if (newUrls.ContainsKey(pair.Key))
                        {
                            var newUrl = newUrls[pair.Key];
                            staticWebService.CreateRedirectPages(configuration, pair.Value, newUrl);
                        }
                    }
                }
            }
            else
            {
                // Remove page as it was added to WasteBasket
                if (e.Items["StaticWeb-OldLanguageUrls"] is Dictionary <string, string> oldUrls)
                {
                    foreach (KeyValuePair <string, string> pair in oldUrls)
                    {
                        staticWebService.RemoveGeneratedPage(configuration, pair.Value, true);
                    }
                }
            }
        }
        //Event handler for moving pages and moving pages and blocks to WasteBasket
        public void OnMovedContent(object sender, ContentEventArgs contentEventArgs)
        {
            var content = contentEventArgs.Content;

            switch (content)
            {
            case PageData _:
                if (contentEventArgs.TargetLink == ContentReference.WasteBasket)
                {
                    DeletePageTreeFromIndex(content);
                }
                else
                {
                    UpdatePageTreeInIndex(content);
                }
                break;

            case BlockData _:
                if (contentEventArgs.TargetLink == ContentReference.WasteBasket)
                {
                    UpdateBlockParentPagesInIndex(content);
                }

                var isContentMovedFromWasteBasket = contentEventArgs.Items[IsContentMovedFromWasteBasketKey];
                if (isContentMovedFromWasteBasket != null && (bool)isContentMovedFromWasteBasket)
                {
                    UpdateBlockParentPagesInIndex(content);
                }
                break;
            }
        }
            private void PublishedContent(object sender, ContentEventArgs e)
            {
                // Clear the cache because some content has been updated
                ObjectCache cache = MemoryCache.Default;

                cache.Remove("myCorpPageJson");
            }
Example #28
0
        /*
         * When a page gets created lets see if it is a blog post and if so lets create the date page information for it
         */
        void Instance_SavingContent(object sender, ContentEventArgs e)
        {
            var      contentRepository = ServiceLocator.Current.GetInstance <IContentRepository>();
            PageData page = contentRepository.Get <PageData>(e.ContentLink);

            if (page != null &&
                string.Equals(page.PageTypeName, typeof(CategoryPage).GetPageType().Name, StringComparison.OrdinalIgnoreCase) &&
                page.Name != e.Content.Name)
            {
                //renaming name of the page!
                string oldName = page.Name;
                string newName = e.Content.Name;

                var categoryRepository = ServiceLocator.Current.GetInstance <CategoryRepository>();
                var category           = CategoryHelper.FindCompareCategory(categoryRepository, oldName);
                if (category != null)
                {
                    category      = category.CreateWritableClone();
                    category.Name = newName;
                    categoryRepository.Save(category);
                }
                else
                {
                    CategoryHelper.SaveCompareCategory(categoryRepository, newName, newName);
                }
            }
        }
Example #29
0
 public void ConstructorThrowsOnNullArguments(string line, string content)
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         var _ = new ContentEventArgs(0, line, content);
     });
 }
 private void E2_PublishedContent(object sender, ContentEventArgs e)
 {
     if (e.Content.GetOriginalType().Name == "ShirtNode")
     {
         EventReciever.RecordCatalogItemApprovalRequest(sender, e);
     }
 }
Example #31
0
        private void Events_SavingContent(object sender, ContentEventArgs e)
        {
            if (e.Content is SpendAmountGetOrderDiscount)
            {
                ((SpendAmountGetOrderDiscount)e.Content).Condition.PartiallyFulfilledThreshold = 0.75m;
                return;
            }

            if (e.Content is SpendAmountGetGiftItems)
            {
                ((SpendAmountGetGiftItems)e.Content).Condition.PartiallyFulfilledThreshold = 0.75m;
                return;
            }

            if (e.Content is SpendAmountGetGiftItems)
            {
                ((SpendAmountGetGiftItems)e.Content).Condition.PartiallyFulfilledThreshold = 0.75m;
                return;
            }

            if (e.Content is SpendAmountGetItemDiscount)
            {
                ((SpendAmountGetItemDiscount)e.Content).Condition.PartiallyFulfilledThreshold = 0.75m;
                return;
            }

            if (e.Content is SpendAmountGetShippingDiscount)
            {
                ((SpendAmountGetShippingDiscount)e.Content).Condition.PartiallyFulfilledThreshold = 0.75m;
                return;
            }
        }
Example #32
0
        private void OnPublishedContent(object sender, ContentEventArgs e)
        {
            var content = e.Content;

            CleanupOldTags(content.ContentGuid);

            var contentType = _contentTypeRepository.Load(content.ContentTypeID);

            var tagProperties = contentType.PropertyDefinitions.Where(p => p.TemplateHint == "Tags");

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

            foreach (var tagProperty in tagProperties)
            {
                var tagPropertyInfo = contentType.ModelType.GetProperty(tagProperty.Name);
                var tags = GetPropertyTags(content as ContentData, tagProperty);

                if (tagPropertyInfo == null)
                {
                    return;
                }

                var groupKeyAttribute = tagPropertyInfo.GetCustomAttribute(typeof(TagsGroupKeyAttribute)) as TagsGroupKeyAttribute;
                var cultureSpecificAttribute = tagPropertyInfo.GetCustomAttribute(typeof(CultureSpecificAttribute)) as CultureSpecificAttribute;

                string groupKey = TagsHelper.GetGroupKeyFromAttributes(groupKeyAttribute, cultureSpecificAttribute);

                _tagService.Save(content.ContentGuid, tags, groupKey);
            }
        }
 private void RepoOnMovingContent(object sender, ContentEventArgs contentEventArgs)
 {
     if (contentEventArgs.TargetLink == ContentReference.WasteBasket)
     {
         contentEventArgs.CancelAction = true;
         contentEventArgs.CancelReason = "Just testing delete";
     }
 }
Example #34
0
        private void LogInfo(string type, ContentEventArgs e)
        {
            log4net.ILog log =
                log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            var msg = string.Format("EventType: {0}, PageId: {1}, Name:{2}", type, e.ContentLink.ID, e.Content.Name);
            log.Error(msg);
        }
        public static void CreatingContent(object sender, ContentEventArgs e)
        {
            var content = e.Content as ICreatingContent;
            if (content == null)
                return;

            content.CreatingContent(sender, e);
        }
        public void OnContentDeleted(object sender, ContentEventArgs e)
        {
            var contentRef = e.ContentLink.ToReferenceWithoutVersion();
            var categoryRepo = ServiceLocator.Current.GetInstance<ICategoryRepository>();

            // We'll delete in both directions, so this method is valid for both categories and assigned content
            categoryRepo.DeleteAssignmentsByCategory(contentRef);
            categoryRepo.DeleteAssignmentsByContent(contentRef);
        }
Example #37
0
        private static void LogInfo(string type, ContentEventArgs e)
        {
            log4net.ILog log =
                log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            var msg = string.Format("EventType: {0}, PageId: {1}, Name: {2}", type, e.ContentLink.ID, e.Content.Name);

            log.Error(msg);
            //log.Error($"Publish Event: //n Page Name {e.Page.PageName.ToString()} //n Page ID: {e.PageLink.ID.ToString()}");
        }
        private void ContentEventsOnCreatingContent(object sender, ContentEventArgs contentEventArgs)
        {
            if (!(contentEventArgs.Content is PageData))
                return;

            var parentLink = contentEventArgs.Content.ParentLink;
            var page = contentEventArgs.Content as PageData;
            parentLink = GetNewParent(parentLink as PageReference, page);

            contentEventArgs.Content.ParentLink = parentLink;
        }
Example #39
0
 private static void ContentEventsOnPublishedContent(object sender, ContentEventArgs contentEventArgs)
 {
     var solrContentRepository = ServiceLocator.Current.GetInstance<ISolrContentRepository>();
     if (ContentIsInvalid(contentEventArgs))
     {
         // remove
         StartAndWait(solrContentRepository.RemoveAsync(contentEventArgs.ContentLink));
     }
     else
     {
         // update index at new url
         StartAndWait(solrContentRepository.AddAsync(SiteDefinition.Current.Id, contentEventArgs.ContentLink, contentEventArgs.Content));
     }
 }
        private void ContentEventsOnSavingContent(object sender, ContentEventArgs contentEventArgs)
        {
            var indexablePageData = contentEventArgs.Content as IIndexablePageData;
            if (indexablePageData == null)
                return;

            if (!indexablePageData.ShouldIndex())
                return;

            var indexResponse = _pageDataIndexer.Index(indexablePageData);
            if (!indexResponse.IsValid)
                throw new InvalidOperationException(
                    $"Failed to index pagedata server error {indexResponse.ServerError}, requestInfo {indexResponse.DebugInformation}");
        }
        private void ContentEventsOnMovingContent(object sender, ContentEventArgs contentEventArgs)
        {
            if (!(contentEventArgs.Content is PageData))
                return;

            var parentLink = contentEventArgs.TargetLink;
            var page = GetPage(contentEventArgs.ContentLink) as PageData;
            parentLink = GetNewParent(parentLink as PageReference, page);

            if (!PageReference.IsValue(parentLink as PageReference) || contentEventArgs.TargetLink.CompareToIgnoreWorkID(parentLink))
                return;

            var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
            contentRepository.Move(page.ContentLink, parentLink, AccessLevel.NoAccess, AccessLevel.NoAccess);
        }
        void Instance_CreatingPage(object sender, ContentEventArgs e)
        {
            var page = e.Content as PageData;
            var hasDateContainer = page as IHasDateContainer;

            if (e.Content == null || hasDateContainer == null)
                return;

            DateTime startPublish = page.StartPublish;
            PageData parentPage = _contentRepository.Get<PageData>(page.ParentLink);

            if (parentPage is IDateContainerRoot)
            {
                page.ParentLink = GetDatePageRef(hasDateContainer, parentPage, startPublish, _contentRepository);
            }
        }
        public void OnPublishingContent(object sender, ContentEventArgs e)
        {
            QuickPollBlock quickPollBlockData = e.Content as QuickPollBlock;
            var quickPoll = ServiceLocator.Current.GetInstance<IQuickPollService>();

            if (quickPollBlockData != null)
            {
                int blockID = (quickPollBlockData as IContent).ContentLink.ID;

                if (quickPollBlockData.ResetPoll)
                {
                    quickPoll.ResetPollVoting(blockID);
                }
                quickPoll.SaveQuickPoll(quickPollBlockData);
            }
        }
Example #44
0
        private void SetEventPageCoordinatesInDB(ContentEventArgs e)
        {
            var originalPage = DataFactory.Instance.GetPage(e.ContentLink.ToPageReference());
            var page = originalPage.CreateWritableClone() as EventPage;

            if (page != null)
            {
                if (page.Coordinates.IsNotNullOrEmpty())
                {

                    page.PageLatitude = double.Parse(page.Coordinates.Split(',')[0]);
                    page.PageLongitude = double.Parse(page.Coordinates.Split(',')[1]);
                }
                DataFactory.Instance.Save(page, SaveAction.Save);
            }
        }
        public void contentEvents_PublishingContent(object sender, ContentEventArgs e)
        {
            var content = e.Content;
            if (!(content is ImageData)) 
                return;
            
            var image = content as ImageData;
            Dimensions imageDimensions = ImageBlobUtility.GetDimensions(image.BinaryData);
            
            PropertyInfo[] properties = image.GetType().GetProperties();
            int requiredWidth = imageDimensions.Width;

            foreach (var propertyInfo in properties)
            {
                if (propertyInfo.PropertyType != typeof(Blob))
                    continue;

                //get attribute name
                var imageWidthAttribute = (ImageWidthDescriptorAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(ImageWidthDescriptorAttribute));
                var imageScaleAttribute = (ImageScaleDescriptorAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(ImageScaleDescriptorAttribute));

                if (imageWidthAttribute != null)
                {
                    requiredWidth = imageWidthAttribute.Width;
                }
                else if (imageScaleAttribute != null)
                {
                    requiredWidth = (int) (imageDimensions.Width*imageScaleAttribute.DimensionMultiplier);
                }
                else
                {
                    continue;
                }

                var calculatedDimensions = ImageResizeUtility.ResizeWidthMaintainAspectRatio(imageDimensions, requiredWidth);  
                var imageDescriptor = new ImageDescriptorAttribute(calculatedDimensions.Height, calculatedDimensions.Width);

                var thumbnailManager = ServiceLocator.Current.GetInstance<ThumbnailManager>();
                var resizedBlob = thumbnailManager.CreateImageBlob(image.BinaryData, propertyInfo.Name, imageDescriptor);

                //assign blob to current property
                propertyInfo.SetValue(image, resizedBlob, null);
            }
        }
        private void EventsOnCreatingContent(object sender, ContentEventArgs contentEventArgs)
        {
            if (IndexingEnabled == false)
                return;

            var content = contentEventArgs.Content;
            if (content != null)
            {
                SetPropertyValue(content, "Heading", content.Name);
                SetPropertyValue(content, "PageTitle", content.Name);
                SetPropertyValue(content, "Title", content.Name);
                SetPropertyValue(content, "Header", content.Name);
                SetPropertyValue(content, "PageName", content.Name);
            }
            //if (contentEventArgs.Content is ISetDefaults)
            //{

            //}
        }
        private void ContentEventsOnSavedContent(object sender, ContentEventArgs contentEventArgs)
        {
            PageData page = contentEventArgs.Content as PageData;
            if (page == null)
            {
                return;
            }

            var correctBase = page as INewsletterBase;
            if (correctBase != null)
            {
                Job job = Job.LoadByPageId(page.PageLink.ID);
                if (job != null)
                {
                    // Sync page name and job name
                    job.Name = page.PageName;
                    job.Save();
                }
            }
        }
Example #48
0
        private void OnPublishedContent(object sender, ContentEventArgs e)
        {
            var content = e.Content;

            // If there is tags property added and removed from a content type,
            // we may want to remove its content
            CleanupOldTags(content.ContentGuid);

            var contentType = _contentTypeRepository.Load(content.ContentTypeID);
            var tagsProperties = GetTagsProperties(contentType);
            if (!tagsProperties.Any())
                return;

            // TODO: What if there are more tags properties on the same page type?
            var tagsProp = contentType.ModelType.GetProperty(tagsProperties.First().Name);
            var groupKeyAttribute = (TagsGroupKeyAttribute)tagsProp.GetCustomAttribute(typeof(TagsGroupKeyAttribute));
            var cultureSpecificAttribute = (CultureSpecificAttribute)tagsProp.GetCustomAttribute(typeof(CultureSpecificAttribute));
            string groupKey = Helpers.TagsHelper.GetGroupKeyFromAttributes(groupKeyAttribute, cultureSpecificAttribute);

            var tags = GetContentTags(content, tagsProperties);
            _tagService.Save(content.ContentGuid, tags, groupKey);
        }
        private void ContentEventsOnCreatedContent(object sender, ContentEventArgs contentEventArgs)
        {
            PageData page = contentEventArgs.Content as PageData;
            if (page == null)
            {
                return;
            }

            var correctBase = page as INewsletterBase;
            if (correctBase != null)
            {
                Job job = Job.LoadByPageId(page.PageLink.ID);
                if (job == null)
                {
                    string name = page.PageName;
                    string desc = string.Empty;
                    // Create and Save
                    Job newJob = new Job(page.PageLink.ID, name, desc);
                    newJob.Save();
                }

            }
        }
        public void CanNotCreateMoreThanOnePage()
        {
            var initializationEngine = new InitializationEngine();
            var restrictMultipleAttributeInitialization = new RestrictMultipleAttributeInitialization();

            restrictMultipleAttributeInitialization.Initialize(initializationEngine);

            var content = new Mock<TestPage>();
            content.Setup(x => x.ContentTypeID).Returns(1);

            var contentLink = new ContentReference(1);
            var contentEventArgs = new ContentEventArgs(contentLink, content.Object);

            _contentEventsMock.Raise(x => x.CreatingContent += null, contentEventArgs);

            Assert.IsTrue(contentEventArgs.CancelAction);
            Assert.IsInstanceOfType(contentEventArgs.CancelReason, typeof(string));

            restrictMultipleAttributeInitialization.Uninitialize(initializationEngine);
        }
Example #51
0
 //content of element changed
 void element_ContentChanged(object sender, ContentEventArgs e)
 {
     RemoteContext.AddContentUpdate(sender as SvgElement);
 }
 public void OnContentPublished(object sender, ContentEventArgs e)
 {
     if (HasCategoryAssignments(e.Content))
     {
         IndexContentPage(e.Content);
     }
 }
        public static void DeletedContentLanguage(object sender, ContentEventArgs e)
        {
            var content = e.Content as IDeletedContentLanguage;
            if (content == null)
                return;

            content.DeletedContentLanguage(sender, e);
        }
        public static void LoadingDefaultContent(object sender, ContentEventArgs e)
        {
            var content = e.Content as ILoadingDefaultContent;
            if (content == null)
                return;

            content.LoadingDefaultContent(sender, e);
        }
        public static void SavedContent(object sender, ContentEventArgs e)
        {
            var content = e.Content as ISavedContent;
            if (content == null)
                return;

            content.SavedContent(sender, e);
        }
        public static void FailedLoadingContent(object sender, ContentEventArgs e)
        {
            var content = e.Content as IFailedLoadingContent;
            if (content == null)
                return;

            content.FailedLoadingContent(sender, e);
        }
        public static void DeletingContentVersion(object sender, ContentEventArgs e)
        {
            var content = e.Content as IDeletingContentVersion;
            if (content == null)
                return;

            content.DeletingContentVersion(sender, e);
        }
        /// <summary>
        /// Note! This method should not fail, it will prevent the product from 
        /// being saved.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void PublishedContent(object sender, ContentEventArgs e)
        {
            if (IndexingEnabled == false)
                return;

            if (e.Content is IIndexableContent)
            {
                try
                {
                    IndexProduct(e.Content as IIndexableContent);
                }
                catch (Exception exception)
                {
                    _log.Error("Cannot index: " + e.ContentLink.ToString(), exception);
                }
            }
            else if (e.Content is FashionItemContent)
            {
                EntryContentBase parent = GetParent(e.Content as EntryContentBase);

                FashionProductContent productContent = parent as FashionProductContent;
                if (productContent != null)
                {
                    try
                    {
                        IndexProduct(productContent);
                    }
                    catch (Exception exception)
                    {
                        _log.Error("Cannot index: " + e.ContentLink.ToString(), exception);
                    }

                }

            }
        }
        private void ServiceOnPublishedContent(object sender, ContentEventArgs contentEventArgs)
        {
            if (contentEventArgs == null)
            {
                return;
            }

            ContentData contentData = contentEventArgs.Content as ContentData;

            if (contentData == null)
            {
                return;
            }

            if (!this.FaviconService.Service.HasSettings(contentData))
            {
                return;
            }

            ContentReference faviconReference =
                this.FaviconService.Service.GetPropertyValue<WebsiteIconAttribute, ContentReference>(contentData);

            if (ContentReference.IsNullOrEmpty(faviconReference))
            {
                this.FaviconService.Service.DeleteFavicons();
                return;
            }

            // Remove the icons. More efficient than getting them one by one and updating them.
            this.FaviconService.Service.CleanUpFavicons();

            if (!this.FaviconService.Service.CreateFavicons(faviconReference))
            {
                return;
            }

            ContentReference mobileAppIconReference =
                this.FaviconService.Service.GetPropertyValue<MobileAppIconAttribute, ContentReference>(contentData);

            this.FaviconService.Service.CreateMobileAppicons(mobileAppIconReference);
        }
        /// <summary>
        /// Note! This method should not fail, it will prevent the product from 
        /// being saved.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void events_PublishedContent(object sender, ContentEventArgs e)
        {
            if(IndexingEnabled == false)
                return;

            FindHelper helper = ServiceLocator.Current.GetInstance<FindHelper>();

            if (e.Content is IIndexableContent)
            {
                try
                {
                    IndexProduct(helper, e.Content as IIndexableContent);
                }
                catch (Exception exception)
                {
                    _log.Error("Cannot index: " + e.ContentLink.ToString(), exception);
                }
            }
            else if (e.Content is FashionItemContent)
            {
                EntryContentBase parent = GetParent(e.Content as EntryContentBase);

                FashionProductContent productContent = parent as FashionProductContent;
                if (productContent != null)
                {
                    try
                    {
                        IndexProduct(helper, productContent);
                    }
                    catch (Exception exception)
                    {
                        _log.Error("Cannot index: " + e.ContentLink.ToString(), exception);
                    }

                }

            }
        }