Skip to content

Instantly share code, notes, and snippets.

View LucGosso's full-sized avatar
😀

Luc Gosso LucGosso

😀
View GitHub Profile
using EPiServer;
using EPiServer.Cms.UI.AspNetIdentity;
using EPiServer.Core;
using EPiServer.Logging;
using EPiServer.Notification;
using EPiServer.ServiceLocation;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
@LucGosso
LucGosso / tracking.js
Last active April 4, 2023 18:42
Google analytics Gist tracking mailto, download, external links and Episerver Form. https://devblog.gosso.se/?p=1232
function epiGat(settings) {
if (settings.downloads || settings.external || settings.mailto) {
var isinternal = new RegExp('^' + window.location.protocol + '\/\/' + window.location.host, 'i');
function addEvent(obj, type, fn) {
if (obj.addEventListener)
obj.addEventListener(type, fn, false);
else if (obj.attachEvent) {
obj['e' + type + fn] = fn;
obj[type + fn] = function () { obj['e' + type + fn](window.event); }
@LucGosso
LucGosso / GetPopularItemsFromAnalyticsJob.cs
Last active May 10, 2022 09:08
Google Analytics Service v4 C# .netframework example with Episerver. Blogpost https://devblog.gosso.se/?p=766
using Gosso.Web.Business.Services;
using EPiServer.DataAbstraction;
using EPiServer.PlugIn;
using EPiServer.Scheduler;
using EPiServer.ServiceLocation;
//Episerver Schedual job to update the cache with fresh data from Google Analytics
namespace Gosso.Web.Business.Jobs
{
[ScheduledPlugIn(DisplayName = "Get Statistics from Analytics (api v4)",
@LucGosso
LucGosso / counter.razor
Last active April 14, 2022 13:28
Different razor component approaches
<component type="typeof(Counter)" render-mode="ServerPrerendered"
param-Count="@Model.StartCount" />
___above in cshtml________below in razor____________
@using Microsoft.AspNetCore.Components
<p>Current count: @Count</p>
<button @onclick="IncrementCount" class="btn btn-primary">Click me</button>
using Azure.Storage.Blobs;
public string UploadJsonToAzureBlobStorage(string json)
{
// Name of the share, directory, and file
string shareName = ConfigurationManager.AppSettings.Get("inRiver.StorageAccountShareReference");
string storageAccountName = ConfigurationManager.AppSettings.Get("inRiver.StorageAccountName");
string storageAccountKey = ConfigurationManager.AppSettings.Get("inRiver.StorageAccountKey");
@LucGosso
LucGosso / GetFromAzureFileShare.cs
Last active April 1, 2022 05:48
Example how to access share in azure
using Azure.Storage.Files.Shares;
using Azure.Storage.Files.Shares.Models;
public StockInventory[] GetFromAzureFileShare()
{
// Name of the share, directory, and file
string shareName = ConfigurationManager.AppSettings.Get("inRiver.StorageAccountShareReference");
string storageAccountName = ConfigurationManager.AppSettings.Get("inRiver.StorageAccountName");
string storageAccountKey = ConfigurationManager.AppSettings.Get("inRiver.StorageAccountKey");
@LucGosso
LucGosso / MailToHelper.cs
Last active February 5, 2022 17:37
Mailto email obfuscation helper
using System.Text.RegularExpressions;
namespace Gosso.Mvc.Helpers
{
public class MailToHelper
{
private static readonly string replaceTemplate = @"#"" onclick=""window.location = 'mailto:' + ['{0}'].join(''); return false;";
public static string TransformMailToLinks(string text)
@LucGosso
LucGosso / FeatureConvention.cs
Created November 26, 2021 10:01
ViewEngine code example for featurefolders solutions .net5
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using System;
using System.Linq;
using System.Reflection;
namespace Foundation.Infrastructure.Display
{
public class FeatureConvention : IControllerModelConvention
{
public void Apply(ControllerModel controller)
@LucGosso
LucGosso / PriceJob.cs
Created November 29, 2020 17:36
Properly update price in episerver commerce https://devblog.gosso.se/?p=1486
/// <summary>
/// Iterates the prices from ERP into Episerver Commerce
/// </summary>
/// <param name="variant"></param>
/// <param name="item">Custom Entity from ERP system</param>
private static void AddUpdatePrice(VariationContent variant, PriceMessage item)
{
//no need to delete any prices, IPriceService optimizes the prices from the new prices
var priceService = ServiceLocator.Current.GetInstance<IPriceService>();
List<IPriceValue> priceValues = new List<IPriceValue>();
@LucGosso
LucGosso / ContentRendererService.cs
Created October 27, 2020 21:31
Render Episerver Blocks and ContentArea for use in web api https://devblog.gosso.se/?p=1463
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.Framework.Web;
using EPiServer.Globalization;
using EPiServer.Logging;
using EPiServer.ServiceLocation;
using EPiServer.Web;
using EPiServer.Web.Mvc;
using System.Collections.Generic;