Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code tidy up for you #1

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2f4a92a
Fixed all references with nuget, enabled nuget restore
timabell Mar 22, 2012
f3b4104
Added xml doc for module
timabell Mar 22, 2012
d2cca23
Inverted logic to match function naming
timabell Mar 22, 2012
9c35109
Code doc for GetChildrenOrganizer(), and made static.
timabell Mar 22, 2012
8abca82
Code doc for ListContains
timabell Mar 22, 2012
7f59385
Clearer name for ListContains
timabell Mar 22, 2012
bf18d84
Code doc for ParentAlreadyQueried() from blog entry
timabell Mar 22, 2012
5f68a68
Code doc for GetNewParent()
timabell Mar 22, 2012
b259e54
Code doc for StructureHelper class
timabell Mar 22, 2012
028b3c2
StructureHelper code cleanup and null-ref proofing.
timabell Mar 22, 2012
5037af6
removed unused using
timabell Mar 22, 2012
3325e99
Updated to v2 of PageTypeBuilder dependency
timabell Mar 23, 2012
f2d45ca
code doc for class DateStructureBase
timabell Mar 23, 2012
0dd60df
Code doc for IOrganizeChildren
timabell Mar 23, 2012
3ade421
Code doc for AlphabeticalStructureBase
timabell Mar 23, 2012
938db1e
Code doc for SingleLevelStructureBase
timabell Mar 23, 2012
32e0b39
Code doc for PageTypeStructureBase
timabell Mar 23, 2012
4ce5372
Code formatting of PageTypeStructureBase
timabell Mar 23, 2012
13f8fb7
Converted StructureHelper child methods to extensions for PageReference
timabell Mar 23, 2012
118a18f
Renamed StructureHelper class to PageReferenceChildExtensions
timabell Mar 23, 2012
97cc5ea
Organised types into namespaces & folders.
timabell Mar 23, 2012
138bb2e
Code doc for SingleLevelStructureBase.GetContainerPageName()
timabell Mar 23, 2012
4ac8c8c
Made event handling methods static.
timabell Mar 23, 2012
19077a1
Code cleanup - reordered methods of PageStructureBuilderModule
timabell Mar 23, 2012
06460be
More code doc fro PageStructureBuilderModule class
timabell Mar 23, 2012
9f7e627
Refactored Event handler methods for readability.
timabell Mar 23, 2012
6c5303a
More descriptive name for GetChildrenOrganizer()
timabell Mar 23, 2012
b59d2df
Code layout
timabell Mar 23, 2012
84f7689
//todo added
timabell Mar 23, 2012
e3838c3
Added rudimentary readme for github front page.
timabell Mar 23, 2012
30f39eb
Moved everything to top level of repo
timabell Mar 23, 2012
0329ab1
Added readme to sln for easy editing
timabell Mar 23, 2012
2acbfe8
Clearer name for param GetNewParent(PageReference originalParentLink …
timabell Mar 23, 2012
1701960
removed todo
timabell Mar 26, 2012
976898f
readme - admin user side info
timabell Mar 26, 2012
858a6d3
dll version => 1.1
timabell Mar 26, 2012
d871b36
Build info added to readme
timabell Mar 26, 2012
16f25b4
Added recursion info to GetNewParent() code doc.
timabell Mar 26, 2012
7f5e8e7
Reference part 3 of the blog, in the code doc and the readme.
timabell Mar 26, 2012
135d501
Readme typo fixed.
timabell Mar 26, 2012
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ _ReSharper*
*.resharper.user
*.suo
*.cache
http%3a%2f%2fmirrors.dotsrc.org%2fcygwin%2f
packages
6 changes: 6 additions & 0 deletions .nuget/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
Binary file added .nuget/NuGet.exe
Binary file not shown.
52 changes: 52 additions & 0 deletions .nuget/NuGet.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
<NuGetExePath>$(NuGetToolsPath)\nuget.exe</NuGetExePath>
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
<PackagesDir>$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir>
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>

<!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config -->
<PackageSources>""</PackageSources>

<!-- Enable the restore command to run before builds -->
<RestorePackages Condition="$(RestorePackages) == ''">false</RestorePackages>

<!-- Property that enables building a package from a project -->
<BuildPackage Condition="$(BuildPackage) == ''">false</BuildPackage>

<!-- Commands -->
<RestoreCommand>"$(NuGetExePath)" install "$(PackagesConfig)" -source $(PackageSources) -o "$(PackagesDir)"</RestoreCommand>
<BuildCommand>"$(NuGetExePath)" pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand>

<!-- Make the build depend on restore packages -->
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
RestorePackages;
$(BuildDependsOn);
</BuildDependsOn>

<!-- Make the build depend on restore packages -->
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
$(BuildDependsOn);
BuildPackage;
</BuildDependsOn>
</PropertyGroup>

<Target Name="CheckPrerequisites">
<!-- Raise an error if we're unable to locate nuget.exe -->
<Error Condition="!Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
</Target>

<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)"
LogStandardErrorAsError="true"
Condition="Exists('$(PackagesConfig)')" />
</Target>

<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(BuildCommand)"
LogStandardErrorAsError="true" />
</Target>
</Project>
76 changes: 76 additions & 0 deletions Extensions/PageReferenceChildExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Linq;
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAccess;
using EPiServer.Security;
using PageTypeBuilder;

namespace PageStructureBuilder.Extensions
{
/// <summary>
/// Contains extension methods for PageReference to simplify finding / creating child pages.<br/>
/// Allows code to be agnostic as to whether the page already exists.<br/>
/// See also <a href="http://joelabrahamsson.com/entry/automatically-organize-episerver-pages">http://joelabrahamsson.com/entry/automatically-organize-episerver-pages</a>
/// </summary>
public static class PageReferenceChildExtensions
{
/// <summary>
/// Gets the existing child page or create it and return it if it is new.
/// </summary>
/// <typeparam name="TChildType">The type of page to find / create.</typeparam>
/// <param name="parent">The parent link.</param>
/// <param name="pageName">Name of the page to find / create.</param>
/// <param name="action">Whether to publish the page immediately if it is new.</param>
/// <returns>The new / existing page at the specified location.</returns>
public static TChildType GetOrCreateChildPage<TChildType>(this PageReference parent, string pageName, SaveAction action = SaveAction.Publish)
where TChildType : PageData
{
return parent.GetExistingChild<TChildType>(pageName) ?? parent.CreateChild<TChildType>(pageName, action);
}

/// <summary>
/// Find an existing child page by type and name.
/// </summary>
/// <typeparam name="TChildType">The type of the result.</typeparam>
/// <param name="parent">The parent.</param>
/// <param name="pageName">Name of the page to find.</param>
/// <returns></returns>
public static TChildType GetExistingChild<TChildType>(this PageReference parent, string pageName)
where TChildType : PageData
{
var children = DataFactory.Instance.GetChildren(parent);
return children
.OfType<TChildType>()
.FirstOrDefault(c => c.PageName.Equals(
pageName, StringComparison.InvariantCulture));
}

/// <summary>
/// Creates a child page of the specified type.
/// </summary>
/// <typeparam name="TChildType">The type of the result.</typeparam>
/// <param name="parent">The parent.</param>
/// <param name="pageName">Name of the new page.</param>
/// <param name="action">Whether to publish the page immediately.</param>
/// <returns></returns>
public static TChildType CreateChild<TChildType>(this PageReference parent, string pageName, SaveAction action = SaveAction.Publish)
where TChildType : PageData
{
var resultPageTypeId = PageTypeResolver.Instance.GetPageTypeID(typeof(TChildType));
if (resultPageTypeId == null)
{
throw new Exception(String.Format("PageTypeID not found for {0}", typeof(TChildType)));
}
var child = DataFactory.Instance.GetDefaultPageData(parent, resultPageTypeId.Value) as TChildType;
if (child == null)
{
throw new Exception(string.Format(
"Failed to GetDefaultPageData for parent {0} and PageTypeID {1}", parent, resultPageTypeId));
}
child.PageName = pageName;
DataFactory.Instance.Save(child, action, AccessLevel.NoAccess);
return child;
}
}
}
21 changes: 21 additions & 0 deletions IOrganizeChildren.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using EPiServer.Core;

namespace PageStructureBuilder
{
/// <summary>
/// Implement this interface to create a folder (really just a page)
/// that will automatically organise child pages of the same type into a
/// desired hierarchy.
/// </summary>
public interface IOrganizeChildren
{
/// <summary>
/// Gets the corrected parent page for new / moved page.<br/>
/// This will possibly be a new folder in the hierarchy.<br/>
/// The location is defined by the implementing class.
/// </summary>
/// <param name="page">The page to get a corrected parent page.</param>
/// <returns></returns>
PageReference GetParentForPage(PageData page);
}
}
19 changes: 19 additions & 0 deletions OrganizationTypes/AlphabeticalStructureBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using EPiServer.Core;

namespace PageStructureBuilder.OrganizationTypes
{
/// <summary>
/// Inherit a page type from this to automatically organise pages into folders
/// named with the first letter of the page name.
/// </summary>
/// <typeparam name="TCharacter">The type page that will provide single character folders.</typeparam>
public abstract class AlphabeticalStructureBase<TCharacter>
: SingleLevelStructureBase<TCharacter>
where TCharacter : PageData, new()
{
protected override string GetContainerPageName(PageData childPage)
{
return childPage.PageName[0].ToString().ToUpperInvariant();
}
}
}
58 changes: 58 additions & 0 deletions OrganizationTypes/DateStructureBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using EPiServer.Core;
using PageStructureBuilder.Extensions;
using PageTypeBuilder;

namespace PageStructureBuilder.OrganizationTypes
{
/// <summary>
/// Inherit from this page type to make your pages automatically
/// move themselves to the date based folder structure of yyyy/mm/dd/pagename<br/>
/// The default date source is creation date. To change this override <see cref="GetStructureDate"/>.
/// </summary>
/// <typeparam name="TYear">Desired PageData type for year level container pages.</typeparam>
/// <typeparam name="TMonth">Desired PageData type for month level container pages.</typeparam>
/// <typeparam name="TDay">Desired PageData type for day level container pages.</typeparam>
/// <example>Usage: <code>
/// [PageType]
/// public class Container : TypedPageData { }
/// [PageType]
/// public class DateStructure : DateStructureBase&lt;Container, Container, Container&gt; { }
/// </code></example>
/// <remarks>
/// See also <a href="http://joelabrahamsson.com/entry/automatically-organize-episerver-pages-part-2/">http://joelabrahamsson.com/entry/automatically-organize-episerver-pages-part-2/</a>
/// </remarks>
public abstract class DateStructureBase<TYear, TMonth, TDay>
: TypedPageData, IOrganizeChildren
where TYear : PageData
where TMonth : PageData
where TDay : PageData
{
public PageReference GetParentForPage(PageData page)
{
if (page is TYear)
{
return PageLink;
}

var pageDate = GetStructureDate(page);
var yearPage = PageLink.GetOrCreateChildPage<TYear>(pageDate.Year.ToString());
var monthPage = yearPage.PageLink.GetOrCreateChildPage<TMonth>(pageDate.Month.ToString());
var dayPage = monthPage.PageLink.GetOrCreateChildPage<TDay>(pageDate.Day.ToString());
return dayPage.PageLink;
}

/// <summary>
/// Returns the date that will be used when creating the page's folder
/// hierarchy. Default implementation uses the Created property of the page.<br/>
/// Override this method to use a different date for the hierarchy.
/// </summary>
/// <param name="pageToGetParentFor">The page to get parent for.</param>
/// <returns></returns>
protected virtual DateTime GetStructureDate(
PageData pageToGetParentFor)
{
return pageToGetParentFor.Created;
}
}
}
20 changes: 20 additions & 0 deletions OrganizationTypes/PageTypeStructureBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using EPiServer.Core;
using EPiServer.DataAbstraction;

namespace PageStructureBuilder.OrganizationTypes
{
/// <summary>
/// Inherit a page type from this to automatically organise pages into folders
/// named with the first letter of the page name.
/// </summary>
/// <typeparam name="TContainer">The type page that will provide page type based folders.</typeparam>
public abstract class PageTypeStructureBase<TContainer> : SingleLevelStructureBase<TContainer>
where TContainer : PageData
{
protected override string GetContainerPageName(PageData childPage)
{
var pageType = PageType.Load(childPage.PageTypeID);
return pageType.Name;
}
}
}
39 changes: 39 additions & 0 deletions OrganizationTypes/SingleLevelStructureBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using EPiServer.Core;
using PageStructureBuilder.Extensions;
using PageTypeBuilder;

namespace PageStructureBuilder.OrganizationTypes
{
/// <summary>
/// Base class for all single folder based automatic page organisation.
/// </summary>
/// <typeparam name="TContainer">The type of the container (folder) pages.</typeparam>
public abstract class SingleLevelStructureBase<TContainer>
: TypedPageData, IOrganizeChildren
where TContainer : PageData
{
public virtual PageReference GetParentForPage(PageData page)
{
if (page is TContainer)
{
return PageLink;
}

if (string.IsNullOrEmpty(page.PageName))
{
return PageLink;
}

var container = PageLink.GetOrCreateChildPage<TContainer>(GetContainerPageName(page));
return container.PageLink;
}

/// <summary>
/// Derived classes should override this method to control
/// the naming convention of the generated containing pages (i.e. folders).
/// </summary>
/// <param name="childPage">The child page for which to find the folder name.</param>
/// <returns>The name of the folder this page should be placed in.</returns>
protected abstract string GetContainerPageName(PageData childPage);
}
}
Loading