Skip to content

Instantly share code, notes, and snippets.

Avatar

Stefan Holm Olsen stefanolsen

View GitHub Profile
@stefanolsen
stefanolsen / CollectionExtensions.cs
Last active Jun 2, 2019
Extension method for materializing a LINQ method chain to an Array or List without resizing. Mentioned here: https://stefanolsen.com/posts/8-things-to-avoid-to-make-an-episerver-site-go-faster/
View CollectionExtensions.cs
// Copyright 2019 Stefan Holm Olsen
//
// Permission to use, copy, modify, and/or distribute this software for an
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@stefanolsen
stefanolsen / Startup.cs
Created Apr 20, 2019
Code listings for blog post about cache busting and long time caching. Read about it here: https://stefanolsen.com/posts/cache-busting-2-an-update-for-aspnet-core/
View Startup.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.Net.Http.Headers;
public class Startup
{
public void Configure(IApplicationBuilder app)
{
var staticFileOptions = new StaticFileOptions
{
OnPrepareResponse = context =>
@stefanolsen
stefanolsen / ArabicGlyphConverter.cs
Last active Jan 3, 2021
Code listings for blog post about converting Arabic letters to correct glyphs depending on their position. Read about it here: https://stefanolsen.com/posts/rendering-correct-arabic-glyphs-in-pdf-using-pdfsharp/
View ArabicGlyphConverter.cs
// Copyright 2019 Stefan Holm Olsen
//
// Permission to use, copy, modify, and/or distribute this software for an
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
View ConnectorStateData.cs
// Copyright 2019 Stefan Holm Olsen
//
// Permission to use, copy, modify, and/or distribute this software for an
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@stefanolsen
stefanolsen / DummyEntityListener.cs
Last active Jan 22, 2019
Code piece for blog post about applying Azure Application Insights to InRiver iPMC extensions. Read about it here: https://stefanolsen.com/posts/applying-cloud-logging-to-inriver-ipmc-extensions-for-easier-analytics/
View DummyEntityListener.cs
public class DummyEntityListener : IEntityListener
{
private LoggingScope _loggingScope;
public inRiverContext Context { get; set; }
public Dictionary<string, string> DefaultSettings => new Dictionary<string, string>
{
{ SettingsConstants.DisableTelemetry, "TRUE" },
{ SettingsConstants.InstrumentationKey, "REPLACE ME" }
};
@stefanolsen
stefanolsen / SendGridMailService.cs
Last active Oct 30, 2018
Code listings for blog post about using SendGrid with Episerver Commerce. Read about it here: https://stefanolsen.com/posts/sending-emails-from-episerver-commerce-using-sendgrid/
View SendGridMailService.cs
using System.Threading.Tasks;
using SendGrid;
using SendGrid.Helpers.Mail;
namespace EPiServer.Reference.Commerce.Site.Features.Mail.Services
{
public class SendGridMailService : ITemplateMailService
{
private readonly ISendGridSettings _settings;
private readonly ISendGridClient _sendGridClient;
@stefanolsen
stefanolsen / AddToCart_request.json
Last active Jul 29, 2018
GraphQL requests and responses for blog post about using GraphQL with Episerver Commerce. Read about it here: https://stefanolsen.com/posts/using-graphql-with-episerver-commerce/
View AddToCart_request.json
{
"query":"mutation AddToCartMutation($input: AddToCartInput!) {
addToCart(input: $input) {
cart {
total {
amount
currencyCode
formattedAmount
}
}
@stefanolsen
stefanolsen / GoogleFeedMapping.xml
Last active Nov 26, 2017
Code listings for blog post about generating and exporting catalog feeds from EPiServer Commerce. Read about it here: https://stefanolsen.com/posts/on-exporting-product-catalogs-to-google-or-facebook/
View GoogleFeedMapping.xml
<FieldMapping xmlns="http://stefanolsen.com/CatalogFeed.GoogleMerchant/MappingDocument.xsd">
<ContentType CommerceType="CatalogNode">
<Fields>
<MappedField MetaField="GoogleProductCategoryId" FeedField="google_product_category"/>
</Fields>
</ContentType>
<ContentType CommerceType="Product">
<Fields>
<MappedField MetaField="DisplayName" FeedField="title"/>
@stefanolsen
stefanolsen / EnsureAjaxLanguageMvcAttribute.cs
Last active Sep 12, 2017
Code listings for blog post about generically ensuring the right EPiServer content language for AJAX requests. Read about it here: https://stefanolsen.com/posts/ensuring-the-right-ajax-content-language-using-a-filter-attribute/
View EnsureAjaxLanguageMvcAttribute.cs
public class EnsureAjaxLanguageMvcAttribute : ActionFilterAttribute
{
private readonly Injected<Settings> _settings;
private readonly Injected<IUpdateCurrentLanguage> _updateCurrentLanguage;
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (_settings.Service.PageUseBrowserLanguagePreferences)
{
// If the PageUseBrowserLanguagePreferences setting is true, this is already handled everywhere.
@stefanolsen
stefanolsen / HandleErrorFriendlyAttribute.cs
Last active Aug 27, 2017
Code listings for blog post about generically handling exceptions in EPiServer, showing stack trace to those allowed to see them. Read about it here: https://stefanolsen.com/posts/a-custom-exception-handler-for-episerver-pages/
View HandleErrorFriendlyAttribute.cs
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public sealed class HandleErrorFriendlyAttribute : HandleErrorAttribute
{
internal Injected<LocalizationService> LocalizationService;
internal Injected<IPageRouteHelper> PageRouteHelper;
internal Injected<PageViewContextFactory> PageViewContextFactory;
internal Injected<PermissionService> PermissionService;
public string ErrorMessageTranslationKey { get; set; }
You can’t perform that action at this time.