Пример #1
0
 /// <summary>
 /// Updates the a specific users permissions to a workroom.
 /// To remove a user as member of a workroom supply the <see cref="MembershipLevel.None"/>.
 /// </summary>
 /// <param name="page">The start page for a workroom.</param>
 /// <param name="membership">A <see cref="MembershipEntry"/> containing the user name and new membership level.</param>
 public static void ModifyPermission(PageData page, MembershipEntry membership)
 {
     if (page.ACL.IsReadOnly)
     {
         PageData writeblePage = page.CreateWritableClone();
         ModifyPermission(writeblePage, membership.Name, ConvertAccessLevel(membership.Membership));
         writeblePage.ACL.Save(SecuritySaveType.RecursiveReplace);
     }
     else
     {
         ModifyPermission(page, membership.Name, ConvertAccessLevel(membership.Membership));
         page.ACL.Save(SecuritySaveType.RecursiveReplace);
     }
 }
Пример #2
0
        /// <summary>
        /// Updates the CurrentPage with the values entered by the user and saves the page to the database.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Save_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }
            try
            {
                PageData curPage = CurrentPage.CreateWritableClone();

                DateTime startDate = StartDatePicker.Value;
                DateTime stopDate  = StopDatePicker.Value;


                if (startDate > stopDate)
                {
                    Page.Validators.Add(new StaticValidator(Translate("/workroom/calendar/latestarttime")));
                    return;
                }

                curPage.PageName    = EditPageName.Text.ToSafeString();
                curPage["MainBody"] = EditMainBody.Text.ToSafeString();
                if (curPage.LanguageBranch != curPage.MasterLanguageBranch)
                {
                    PageReference curPageRef = DataFactory.Instance.Save(curPage, SaveAction.Publish);

                    curPage = DataFactory.Instance.GetLanguageBranches(curPageRef)
                              .Cast <PageData>().First(page => page.LanguageID == page.MasterLanguageBranch);
                    curPage = curPage.CreateWritableClone();
                }
                curPage["EventStartDate"] = startDate;
                curPage["EventStopDate"]  = stopDate;

                DataFactory.Instance.Save(curPage, SaveAction.Publish);
                Response.Redirect(DataFactory.Instance.GetPage(CurrentPageLink).LinkURL);
            }
            catch (FormatException ex)
            {
                Page.Validators.Add(new StaticValidator(ex.Message));
            }
            catch (Exception x)
            {
                Page.Validators.Add(new StaticValidator(x.Message));
            }
        }
        /// <summary>
        /// Clones a page to make it appear to come from where the content provider is attached
        /// </summary>
        /// <param name="originalPage">
        /// The original Page.
        /// </param>
        /// <returns>
        /// The <see cref="PageData"/>.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// originalPage;No page to clone specified
        /// </exception>
        private PageData ClonePage(PageData originalPage)
        {
            if (originalPage == null)
            {
                throw new ArgumentNullException("originalPage", "No page to clone specified");
            }

            Logger.DebugFormat("Cloning page {0}...", originalPage.PageLink);

            PageData clone = originalPage.CreateWritableClone();

            // If original page was under the clone root, we make it appear to be under the entry root instead
            if (originalPage.ParentLink.CompareToIgnoreWorkID(this.CloneRoot))
            {
                clone.ParentLink = this.EntryRoot;
            }

            // All pages but the entry root should appear to come from this content provider
            if (!clone.PageLink.CompareToIgnoreWorkID(this.EntryRoot))
            {
                clone.ContentLink.ProviderName = this.ProviderKey;
            }

            // Unless the parent is the entry root, it should appear to come from this content provider
            if (!clone.ParentLink.CompareToIgnoreWorkID(this.EntryRoot))
            {
                PageReference parentLinkClone = clone.ParentLink.CreateWritableClone();

                parentLinkClone.ProviderName = this.ProviderKey;

                clone.ParentLink = parentLinkClone;
            }

            // This is integral to map the cloned page to this content provider
            clone.LinkURL =
                this.ConstructContentUri(originalPage.PageTypeID, clone.ContentLink, clone.ContentGuid).ToString();

            return(clone);
        }
Пример #4
0
        /// <summary>
        /// Handles the Click event of the SaveVisibility button.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void SaveVisibility_Click(object sender, EventArgs e)
        {
            bool itemsModified = false;

            PageDataCollection pages = GetChildren(PageLink);

            foreach (ListItem item in VisibilityList.Items)
            {
                PageData page = FindPage(pages, PageReference.Parse(item.Value));
                if (page != null && page.VisibleInMenu != item.Selected)
                {
                    page = page.CreateWritableClone();
                    page.VisibleInMenu = item.Selected;
                    DataFactory.Instance.Save(page, SaveAction.Publish | SaveAction.ForceCurrentVersion);
                    itemsModified = true;
                }
            }
            if (itemsModified)
            {
                _requiresDataBinding = true;
                OnVisibilityChanged(EventArgs.Empty);
            }
            DataBind();
        }
        /// <summary>
        ///     Raises the page event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="contentEventArgs">Event information to send to registered event handlers.</param>
        public void OnPublishingContent(object sender, ContentEventArgs contentEventArgs)
        {
            if (contentEventArgs == null)
            {
                return;
            }

            PageData page = contentEventArgs.Content as PageData;

            if (page == null)
            {
                return;
            }

            PropertyInfo addtionalSearchContentProperty = GetAddtionalSearchContentProperty(page);

            if (addtionalSearchContentProperty == null)
            {
                return;
            }

            if (addtionalSearchContentProperty.PropertyType != typeof(string))
            {
                return;
            }

            StringBuilder stringBuilder = new StringBuilder();

            ContentType contentType = this.ContentTypeRepository.Service.Load(page.ContentTypeID);

            foreach (PropertyDefinition current in
                     from d in contentType.PropertyDefinitions
                     where typeof(PropertyContentArea).IsAssignableFrom(d.Type.DefinitionType)
                     select d)
            {
                PropertyData propertyData = page.Property[current.Name];

                ContentArea contentArea = propertyData.Value as ContentArea;

                if (contentArea == null)
                {
                    continue;
                }

                foreach (ContentAreaItem contentAreaItem in contentArea.Items)
                {
                    IContent content;
                    if (!this.ContentRepository.Service.TryGet(contentAreaItem.ContentLink, out content))
                    {
                        continue;
                    }

                    // content area item can be null when duplicating a page
                    if (content == null)
                    {
                        continue;
                    }

                    // Check if the content is indeed a block, and not a page used in a content area
                    BlockData blockData = content as BlockData;

                    // Content area is not a block, but probably a page used as a teaser.
                    if (blockData == null)
                    {
                        Logger.Information(
                            "[Blocksearch] Contentarea item is not block data. Skipping update.",
                            content.Name);
                        continue;
                    }

                    IEnumerable <string> props = this.GetSearchablePropertyValues(content, content.ContentTypeID);
                    stringBuilder.AppendFormat(" {0}", string.Join(" ", props));
                }
            }

            if (addtionalSearchContentProperty.PropertyType != typeof(string))
            {
                return;
            }

            try
            {
                string additionalSearchContent = TextIndexer.StripHtml(stringBuilder.ToString(), 0);

                // When being "delayed published" the pagedata is readonly. Create a writable clone to be safe.
                PageData editablePage = page.CreateWritableClone();
                editablePage[addtionalSearchContentProperty.Name] = additionalSearchContent;

                // Save the writable pagedata, do not create a new version
                this.ContentRepository.Service.Save(
                    editablePage,
                    SaveAction.Save | SaveAction.ForceCurrentVersion,
                    AccessLevel.NoAccess);
            }
            catch (EPiServerException ePiServerException)
            {
                Logger.Error(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "[Blocksearch] Property {0} dose not exist on {1} .",
                        addtionalSearchContentProperty.Name,
                        page.Name),
                    ePiServerException);
            }
        }