Skip to content

Instantly share code, notes, and snippets.

Erik Henningson ErikHen

Block or report user

Report or block ErikHen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ImageTypes.cs
namespace MyEpiSite.Business.Rendering
{
public class ImageType
{
public int? DefaultImgWidth { get; set; } //this size will be used in browsers that don't support the picture element
public int[] SrcSetWidths { get; set; } // the different image widths you want the browser to select from
public string[] SrcSetSizes { get; set; }
}
public static class ImageTypes
View EnvironmentInitialization.cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Linq;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.ServiceLocation;
using EPiServer.Web;
View run.ps1
Import-Module "D:\home\site\wwwroot\ScaleDownDevEnvironments\LoginToAzure.ps1"
Import-Module "D:\home\site\wwwroot\ScaleDownDevEnvironments\NotifySlack.ps1"
Login
#scale down web app to "D1 Shared"
Set-AzureRmAppServicePlan -Name "<your sesrvice plan name>" -ResourceGroupName "<your resource group name>" -Tier Shared
#scale down database to "B1 Basic"
Set-AzureRmSqlDatabase -ResourceGroupName "<your resource group name>" -ServerName "<sql server name>" -DatabaseName "<database name>" -Edition Basic
@ErikHen
ErikHen / NotifySlack.ps1
Last active Nov 22, 2017
PowerShell function that sends a message to Slack
View NotifySlack.ps1
function NotifySlack($webhookurl, $channel, $message)
{
$payload = @{
"channel" = $channel
"icon_emoji" = ":robot_face:"
"text" = $message
"username" = "Mr. Robot"
}
Invoke-WebRequest -UseBasicParsing -Body (ConvertTo-Json -Compress -InputObject $payload) -Method Post -Uri $webhookurl | Out-Null
}
View LoginToAzure.ps1
function Login() {
$azureappid ="45d6472e-0526-4a12-8c58-959f697eb296" #your Azure application id
$azurepassword = ConvertTo-SecureString "YourSecretPassword" -AsPlainText -Force
$pscred = New-Object System.Management.Automation.PSCredential($azureappid, $azurepassword)
Login-AzureRmAccount -Credential $pscred -ServicePrincipal -TenantId "31d2b6c6-a122-456c-b9a5-af2d7e3fbf0f" #you Azure subscription Tenant id
}
@ErikHen
ErikHen / run.ps1
Last active Sep 17, 2019
PowerShell scale down azure resources
View run.ps1
$azurePassword = ConvertTo-SecureString "<your azure portal password>" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential("<your azure email address>", $azurePassword)
Login-AzureRmAccount -Credential $psCred
#scale down web app to "D1 Shared"
Set-AzureRmAppServicePlan -Name "<your sesrvice plan name>" -ResourceGroupName "<your resource group name>" -Tier Shared
#scale down database to "B1 Basic"
Set-AzureRmSqlDatabase -ResourceGroupName "<your resource group name>" -ServerName "<sql server name>" -DatabaseName "<database name>" -Edition Basic
#how to scale a web app to "B2 Basic"
View SetupEpiAzureEnvironment.ps1
$webappname = "myepienvironment" # Application name (lowercase alphanumeric only)
$subscriptionname = "My subscription name"
$resourcegroupname ="$($webappname)-resourcegroup"
$location="West Europe"
$sqlservername = "$($webappname)-sqlserver"
$sqladminlogin = "SaUser"
$sqlpassword = "YourSecretAdminPassword1"
# The ip address range that you want to allow to access your SQL server - change as appropriate
$startip = "111.112.113.114"
View GoogleMapsGeoCoding
namespace MyNamespace
{
[ServiceConfiguration(typeof(ISelectionQuery))]
public class GoogleMapsGeocoding : ISelectionQuery
{
private readonly string _googleApiKey;
public GoogleMapsGeocoding()
{
//get key from config
_googleApiKey = ConfigurationManager.AppSettings["GoogleGeocodingApiKey"];
View MapBlock.cs
[Display(Name = "Address or coordinates", Description = "Coordinates must be separated by white-space (e.g. \"55.5615205 12.9749824\")", Order = 40)]
[AutoSuggestSelection(typeof(GoogleMapsGeocoding), AllowCustomValues = false)]
public virtual string MapCoordinates { get; set; }
@ErikHen
ErikHen / LoginViewModel.cs
Created May 11, 2017
Episerver Mixed-mode auth. Login view
View LoginViewModel.cs
public class LoginViewModel
{
[Required]
[Display(Name = "Username")]
public string Username { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
[AllowHtml]
You can’t perform that action at this time.