Skip to content

Instantly share code, notes, and snippets.

@ErikHen
ErikHen / EditableCacheAttribute.cs
Last active August 13, 2021 09:25
Episerver CMS editable cache attribute.
namespace Demo
{
public class EditableCacheAttribute : ContentOutputCacheAttribute
{
public EditableCacheAttribute()
{
UseOutputCacheValidator = UseOutputCache;
}
private static bool UseOutputCache(IPrincipal principal, HttpContextBase context, TimeSpan duration)
$webappname = "myepienvironment" # Application name (lowercase alphanumeric only)
$subscriptionname = "My subscription name"
$resourcegroupname ="$webappname-ResourceGroup"
$location="West Europe"
$sqladminlogin = "SaUser"
$sqlpassword = "YourSecretAdminPassword1"
$startip = "111.112.113.114"
$endip = "111.112.113.114"
$storageaccountname = "$($webappname)media"
# DXC-S deploy from source environment to target environment. Step two, finish the deploy by swapping slots.
if (-not (Get-Module -Name EpiCloud -ListAvailable)) {
Install-Module EpiCloud -Scope CurrentUser -Force
Write-Host "Installed EpiCloud module."
}
Connect-EpiCloud -ClientKey $OctopusParameters["DXC-S API Key"] -ClientSecret $OctopusParameters["DXC-S API Secret"]
# Find a deployment that has the status "AwaitingVerification".
# DXC-S deploy from source environment to target environment. Step one that deploys to a slot on target.
# Install the EpiCloud module
if (-not (Get-Module -Name EpiCloud -ListAvailable)) {
Install-Module EpiCloud -Scope CurrentUser -Force
Write-Output "Installed EpiCloud module"
}
Connect-EpiCloud -ClientKey $OctopusParameters["DXC-S API Key"] -ClientSecret $OctopusParameters["DXC-S API Secret"]
namespace AlloyDemo.Controllers
{
[TemplateDescriptor(Inherited = true)]
public class DefaultPageController : PageControllerBase<SitePageData>
{
[EditableContentOutputCache]
public ViewResult Index(SitePageData currentPage)
{
var model = CreateModel(currentPage);
return View($"~/Views/{currentPage.GetOriginalType().Name}/Index.cshtml", model);
namespace AlloyDemo.Models.Pages
{
public abstract class SitePageData : PageData, ICustomCssInContentArea, IDisableOutputCache
{
[Display(Name = "Disable output cache", GroupName = SystemTabNames.Settings, Order = 500)]
public virtual bool? DisableOutputCache { get; set; }
...
namespace AlloyDemo.Business
{
public sealed class EditableContentOutputCacheAttribute : ContentOutputCacheAttribute
{
public EditableContentOutputCacheAttribute()
{
UseOutputCacheValidator = UseOutputCache;
}
private static bool UseOutputCache(IPrincipal principal, HttpContextBase context, TimeSpan duration)
namespace AlloyDemo.Business
{
public interface IDisableOutputCache
{
bool? DisableOutputCache { get; set; }
}
}
@ErikHen
ErikHen / ScaleDownResources
Created April 3, 2019 19:47
Azure Automation Powershell Runbook that scales Azure resources
.\LoginToAzure.ps1
#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
#scale a web app to "B2 Basic"
#Set-AzureRmAppServicePlan -Name "<your sesrvice plan name>" -ResourceGroupName "<your resource group name>" -Tier Basic -WorkerSize Medium
@ErikHen
ErikHen / LoginToAzure
Created April 3, 2019 19:40
Azure Automation Powershell Runbook that logs in to Azure
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `