Skip to content

Instantly share code, notes, and snippets.

View casper-rasmussen's full-sized avatar

Casper Aagaard Rasmussen casper-rasmussen

View GitHub Profile
public static class AjaxHelperExtensions
{
private static string GetLanguage()
{
if (HttpContext.Current == null || HttpContext.Current.Request.RequestContext == null)
return null;
return RequestContextExtension.GetLanguage(HttpContext.Current.Request.RequestContext);
}
"bool":{
"must":[
{
"query_string":{
"fields":[
"PageTitle$$string.standard",
"MainBody$$string.standard"
],
"query":"Manage On-Premise License",
"default_operator":"AND"
public static IQueriedSearch<T> AddMatchingQueryStringFor<T>(this ITypeSearch<T> search, string queryString, Expression<Func<T, string>> fieldSelector)
{
var fieldName = search.Client.Conventions.FieldNameConvention
.GetFieldNameForAnalyzed(fieldSelector);
//Split words by space
string[] words = queryString.Split(' ');
return new Search<T, WildcardQuery>(search, context =>
{
this._query = this._query.For(searchQuery)
.InField((content) => content.Title) //Include important field
.AndInField((content) => content.MainBody) //Include important field
this._query = this._query.For(searchQuery)
.InField((content) => content.Title) //Include important field
.AndInField((content) => content.MainBody) //Include important field
.AddMatchingQueryStringFor(searchQuery, (content) => content.SupportingText) //Inclue non-important field and require that all words are within
void PurgeOutputCacheByContent(IContent content)
{
IEnumerable<TemplateModel> templateModels = this._templateModelRepository.List(content.GetOriginalType());
RouteValueDictionary routeValues = new RouteValueDictionary();
routeValues.Add("currentcontent", content);
foreach (TemplateModel model in templateModels)
{
//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)
{
public void StartListen()
{
//Bind our local publish events
DataFactory.Instance.PublishedContent += (sender, args) => this.PurgeOutputCacheByContent(args.Content);
if (!this._eventRegistry.Enabled)
return;
//Finding the event for EPiServers RemoteCacheSynchronization-RemoveFromCache
public void StartListen()
{
//Bind our local publish events
DataFactory.Instance.PublishedContent += (sender, args) => this.PurgeOutputCacheByContent(args.Content);
//More code comes here in later snippet...
}
public class ContentDonutOutputCacheAttribute : DonutOutputCacheAttribute
{
public ContentDonutOutputCacheAttribute()
: base(new KeyGenerator(new EPiServerAwareKeyBuilder()), new OutputCacheManager(OutputCache.Instance, new EPiServerAwareKeyBuilder()), (IDonutHoleFiller)new DonutHoleFiller((IActionSettingsSerialiser)new EncryptingActionSettingsSerialiser((IActionSettingsSerialiser)new ActionSettingsSerialiser(), (IEncryptor)new Encryptor())), (ICacheSettingsManager)new CacheSettingsManager(), (ICacheHeadersHelper)new CacheHeadersHelper())
{
}
}