-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mantas Janulionis
committed
Jul 12, 2016
1 parent
748ddef
commit 762443b
Showing
15 changed files
with
246 additions
and
19 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,3 +96,4 @@ npm-debug.log | |
*.sass-cache | ||
*.idea | ||
Modules/BetterCms.Module.Root/Scripts/bcms.knockout-3.3.0.min.js | ||
/.vs/config |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace BetterCms.Core.Services | ||
{ | ||
/// <summary> | ||
/// Interface designed to control redirects | ||
/// </summary> | ||
public interface IRedirectControl | ||
{ | ||
/// <summary> | ||
/// Finds the redirect. | ||
/// </summary> | ||
/// <param name="source">The source url.</param> | ||
/// <returns>Destination url</returns> | ||
string FindRedirect(string source); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Modules/BetterCms.Module.Pages/Content/Resources/PagesGlobalization.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
73 changes: 73 additions & 0 deletions
73
Modules/BetterCms.Module.Pages/Services/DefaultRedirectControl.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
using BetterCms.Core.Services; | ||
using BetterCms.Module.Pages.Models; | ||
|
||
using BetterModules.Core.Web.Services.Caching; | ||
using BetterModules.Events; | ||
|
||
namespace BetterCms.Module.Pages.Services | ||
{ | ||
/// <summary> | ||
/// Class responsible for controlling redirect strategy | ||
/// </summary> | ||
public class DefaultRedirectControl : IRedirectControl | ||
{ | ||
private readonly IRedirectService redirectService; | ||
|
||
private readonly ICacheService cacheService; | ||
|
||
private readonly ICmsConfiguration cmsConfiguration; | ||
|
||
private readonly IUrlService urlService; | ||
|
||
private string cacheKey = "CMS_redirect_control_all"; | ||
|
||
public DefaultRedirectControl(IRedirectService redirectService, ICacheService cacheService, ICmsConfiguration cmsConfiguration, IUrlService urlService) | ||
{ | ||
this.redirectService = redirectService; | ||
this.cacheService = cacheService; | ||
this.cmsConfiguration = cmsConfiguration; | ||
this.urlService = urlService; | ||
|
||
Events.PageEvents.Instance.RedirectCreated += InvalidateCache; | ||
Events.PageEvents.Instance.RedirectUpdated += InvalidateCache; | ||
Events.PageEvents.Instance.RedirectDeleted += InvalidateCache; | ||
} | ||
|
||
/// <summary> | ||
/// Finds the redirect. | ||
/// </summary> | ||
/// <param name="source">The source url.</param> | ||
/// <returns> | ||
/// Destination url | ||
/// </returns> | ||
public string FindRedirect(string source) | ||
{ | ||
string redirectDestinationUrl = null; | ||
var useCache = cmsConfiguration.Cache.Enabled; | ||
if (urlService.ValidateInternalUrl(source)) | ||
{ | ||
source = urlService.FixUrl(source); | ||
} | ||
if (useCache) | ||
{ | ||
var redirects = cacheService.Get(cacheKey, cmsConfiguration.Cache.Timeout, () => redirectService.GetAllRedirects()); | ||
redirectDestinationUrl = redirects.Where(x => x.PageUrl.Equals(source, StringComparison.InvariantCultureIgnoreCase)).Select(x => x.RedirectUrl).FirstOrDefault(); | ||
} | ||
else | ||
{ | ||
return redirectService.GetRedirect(source); | ||
} | ||
|
||
return redirectDestinationUrl; | ||
} | ||
|
||
private void InvalidateCache(SingleItemEventArgs<Redirect> args) | ||
{ | ||
cacheService.Remove(cacheKey); | ||
} | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.