Created
October 5, 2015 21:52
-
-
Save gregwiechec/be9d1ed8ff0fd9671cfc to your computer and use it in GitHub Desktop.
EPiServer Admin plugin - Reindex Soft Links
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SoftLinkIndexerTool.aspx.cs" Inherits="ChildrenGridView.Plugins.SoftLinkIndexerTool" %> | |
<asp:Content ContentPlaceHolderID="MainRegion" runat="server"> | |
<asp:Button runat="server" Text="Run" OnClick="OnClick"/> | |
<asp:Label ID="lblResult" runat="server" Text=""></asp:Label> | |
</asp:Content> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Globalization; | |
using EPiServer; | |
using EPiServer.Core; | |
using EPiServer.DataAbstraction; | |
using EPiServer.PlugIn; | |
using EPiServer.ServiceLocation; | |
using EPiServer.Shell.WebForms; | |
namespace ChildrenGridView.Plugins | |
{ | |
[GuiPlugIn(DisplayName = "Reindex Soft Links", Description = Description, Area = PlugInArea.AdminMenu, Url = "~/Plugins/SoftLinkIndexerTool.aspx")] | |
public partial class SoftLinkIndexerTool : WebFormsBase | |
{ | |
public const string Description = "Used to reindex all content"; | |
private readonly IContentRepository _contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>(); | |
private readonly ContentSoftLinkRepository _softLinkRepository = ServiceLocator.Current.GetInstance<ContentSoftLinkRepository>(); | |
private readonly ContentSoftLinkIndexer _contentSoftLinkIndexer = ServiceLocator.Current.GetInstance<ContentSoftLinkIndexer>(); | |
protected override void OnPreInit(EventArgs e) | |
{ | |
base.OnPreInit(e); | |
this.MasterPageFile = UriSupport.ResolveUrlFromUIBySettings("MasterPages/EPiServerUI.master"); | |
this.SystemMessageContainer.Heading = "Reindex Soft Links"; | |
this.SystemMessageContainer.Description = Description; | |
} | |
protected void OnClick(object sender, EventArgs e) | |
{ | |
var stopwatch = Stopwatch.StartNew(); | |
var numberOfPages = this.UpdateSoftLinks(this._contentRepository.Get<IContent>(ContentReference.RootPage)); | |
this.lblResult.Text = $"Total time: {stopwatch.Elapsed.ToString("g")}. Number of links found: {numberOfPages}"; | |
} | |
public int UpdateSoftLinks(IContent content) | |
{ | |
var links = _contentSoftLinkIndexer.GetLinks(content); | |
var localizable = content as ILocalizable; | |
IEnumerable<IContent> children = null; | |
if (localizable != null) | |
{ | |
this._softLinkRepository.Save(content.ContentLink.ToReferenceWithoutVersion(), localizable.Language, links); | |
foreach (var existingLanguage in localizable.ExistingLanguages) | |
{ | |
children = this._contentRepository.GetChildren<IContent>(content.ContentLink, existingLanguage); | |
} | |
} | |
else | |
{ | |
this._softLinkRepository.Save(content.ContentLink.ToReferenceWithoutVersion(), null, links); | |
children = | |
this._contentRepository.GetChildren<IContent>(content.ContentLink, CultureInfo.InvariantCulture); | |
} | |
var numberOfLinks = 0; | |
foreach (var childContent in children) | |
{ | |
numberOfLinks += UpdateSoftLinks(childContent); | |
} | |
return links.Count + numberOfLinks; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------------------------------------ | |
// <auto-generated> | |
// This code was generated by a tool. | |
// | |
// Changes to this file may cause incorrect behavior and will be lost if | |
// the code is regenerated. | |
// </auto-generated> | |
//------------------------------------------------------------------------------ | |
namespace ChildrenGridView.Plugins { | |
public partial class SoftLinkIndexerTool { | |
/// <summary> | |
/// lblResult control. | |
/// </summary> | |
/// <remarks> | |
/// Auto-generated field. | |
/// To modify move field declaration from designer file to code-behind file. | |
/// </remarks> | |
protected global::System.Web.UI.WebControls.Label lblResult; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
just wondering, what is the purpose of this loop:
foreach (var existingLanguage in localizable.ExistingLanguages)
{
children = this._contentRepository.GetChildren(content.ContentLink, existingLanguage);
}
if you never use the value of children inbetween ?