Skip to content

Instantly share code, notes, and snippets.

View stefanolsen's full-sized avatar

Stefan Holm Olsen stefanolsen

View GitHub Profile
@stefanolsen
stefanolsen / SampleScheduledJob.cs
Last active August 15, 2023 19:45
Code listings for blog post about log correlation with Optimizely scheduled jobs and Application Insights. Read more at https://stefanolsen.com/posts/correlate-telemetry-for-scheduled-jobs-in-optimizely-cms/
using System;
using EPiServer.PlugIn;
using EPiServer.Scheduler;
using EPiServer.ServiceLocation;
using Microsoft.ApplicationInsights;
namespace DemoSite.ScheduledJobs;
[ScheduledPlugIn(
DisplayName = "Sample job",
@stefanolsen
stefanolsen / ApplicationInsightsJobFilter.cs
Last active March 21, 2023 20:37
Code listings for blog post about Hangfire and Optimizely. Read about it here: https://stefanolsen.com/posts/4-tips-and-tricks-for-hangfire-on-optimizely-cms/
using System;
using System.Text.Json;
using Hangfire.Server;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
namespace DemoSite.Hangfire;
public class ApplicationInsightsJobFilter : IServerFilter
@stefanolsen
stefanolsen / CollectionExtensions.cs
Last active June 2, 2019 18:29
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/
// 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 April 20, 2019 09:25
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/
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 April 18, 2023 07:28
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/
// 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
// 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 January 22, 2019 17:02
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/
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 October 30, 2018 17:54
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/
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 July 29, 2018 08:13
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/
{
"query":"mutation AddToCartMutation($input: AddToCartInput!) {
addToCart(input: $input) {
cart {
total {
amount
currencyCode
formattedAmount
}
}
@stefanolsen
stefanolsen / GoogleFeedMapping.xml
Last active November 26, 2017 21:50
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/
<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"/>