Created
March 20, 2016 22:28
-
-
Save casper-rasmussen/514c7295a3a82a4637ba to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//We are only listening to. | |
private static IEnumerable<string> RemoteEventPatterns = new List<string>() | |
{ | |
"EPLanguageData:([0-9]+)$", | |
"EP:ContentVersion:([0-9]+)$", | |
@"EPContentVersion:([0-9_]+)$" | |
}; | |
private void ChangeEventOnRaised(object sender, EventNotificationEventArgs eventNotificationEventArgs) | |
{ | |
string context = eventNotificationEventArgs.Param as string; | |
if (String.IsNullOrWhiteSpace(context)) | |
return; | |
foreach (string pattern in RemoteEventPatterns) | |
{ | |
//Verify if the param matches one of our RemoteEvents | |
bool foundMatch = Regex.IsMatch(context, pattern); | |
//We will only do something when its a known event indicating content change | |
if (!foundMatch) | |
continue; | |
Match match = Regex.Match(context, pattern); | |
if (match.Groups.Count != 2) | |
continue; | |
var group = match.Groups[1]; | |
if (String.IsNullOrWhiteSpace(group.Value)) | |
continue; | |
string contentReferenceId = group.Value; | |
//Convert to a ContentReference | |
ContentReference contentReference = new ContentReference(contentReferenceId); | |
//Try and find a matching piece of content so we can resolve the template | |
IContent content; | |
bool found = this._contentRepository.TryGet(contentReference, out content); | |
if (!found) | |
continue; | |
//Raise a purge for this content | |
PurgeOutputCacheByContent(content); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment