Skip to content

Instantly share code, notes, and snippets.

View Krusen's full-sized avatar

Søren Kruse Krusen

View GitHub Profile
public static class Verify
{
/// <summary>
/// Verifies that the fluent assertions in the <paramref name="action" /> are correct.
/// </summary>
/// <param name="action">An action with one or more fluent assertions</param>
public static T That<T>(Action<T> action)
{
return ArgumentMatcher.Enqueue(new AssertionMatcher<T>(action));
}
@Krusen
Krusen / script.ps1
Created November 15, 2017 20:35
PowerShell - Enable running the script on a network drive
# Run as Administrator
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
# Load mapped network drives and replace with actual UNC path
$MappedDrives = @{}; Get-WmiObject win32_logicaldisk -Filter 'drivetype=4' | Foreach { $MappedDrives.($_.deviceID) = $_.ProviderName }
$networkFile = Get-Item $PSCommandPath | Select @{n='UncPath'; e= { $_.FullName.Replace( $_.Directory.Root, $MappedDrives.($_.Directory.Root.ToString().SubString(0,2)) +'\') }}
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$($networkFile.UncPath)`"" -Verb RunAs
exit
}
@Krusen
Krusen / SitecoreServiceExtensions.cs
Created July 13, 2017 06:31
Glass Mapper GetSharedItem<T> extension methods
using System;
using Glass.Mapper.Sc;
using Sitecore.Globalization;
namespace TranslatePlusModule.Extensions
{
public static class SitecoreServiceExtensions
{
/// <summary>
/// Returns an item with only the shared fields instead of null if the item does not have a version in the current language.
@Krusen
Krusen / AttachDatabases.ps1
Created March 22, 2017 13:39
Attach/dettach databases with powershell
# Run as Administrator
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
Set-Location $PSScriptRoot
# Load configuration XML file.
[xml]$config = Get-Content "DatabasesConfig.xml"
#Add-Type -AssemblyName "Microsoft.SqlServer.Smo, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
#Add-Type -AssemblyName "Microsoft.SqlServer.Smo, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
@Krusen
Krusen / FixWebforms.aspx
Last active February 4, 2017 13:06
Sitecore WFFM: Script for removing old "Save to database" save action and removing <host> and <from> parameters from forms after upgrading
<%@ Page Language="C#" %>
<%@ Import Namespace="Sitecore.Diagnostics" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
var formTemplateId = Sitecore.Data.ID.Parse("{FFB1DA32-2764-47DB-83B0-95B843546A7E}");
// The root item containing your web forms to be fixed
var webformsFolder = Sitecore.Configuration.Factory.GetDatabase("master").GetItem("{F1F7AAB6-C8CE-422F-A214-F610C109FA63}");
@Krusen
Krusen / Unicorn.t4
Last active March 13, 2016 11:56
Unicorn T4 templates
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Xml" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ import namespace="System.Xml" #>