Skip to content

Instantly share code, notes, and snippets.

View Shazwazza's full-sized avatar

Shannon Deminick Shazwazza

View GitHub Profile
@Shazwazza
Shazwazza / CultureIsoCodeFieldNameMatchExpression.cs
Last active May 7, 2021 17:36
ExamineX Dynamic Language Analyzer Value Type
/// <summary>
/// Borrowed From Umbraco Source. Matches a culture iso name suffix
/// </summary>
/// <remarks>
/// myFieldName_en-us will match the "en-us"
/// </remarks>
public static readonly Regex CultureIsoCodeFieldNameMatchExpression = new Regex("^([_\\w]+)_([a-z]{2}-[a-z0-9]{2,4})$", RegexOptions.Compiled);
@Shazwazza
Shazwazza / FlowingExecutionContext-AsyncLocal.cs
Last active August 12, 2021 15:42
Flowing ExecutionContext
// These tests show the various ways to spawn child threads
// and in what scenarios the value in the AsyncLocal or
// logical CallContext will flow to the child threads.
// All of the below test results are identical if you
// use the old CallContext.LogicalSetData CallContext.LogicalGetData
void Main()
{
// Set the AsyncLocal value and we'll see where this flows
@Shazwazza
Shazwazza / MyHttpModule.cs
Last active December 15, 2020 13:43
How to change HttpRequest.IsSecureConnection
// Install this http module which will replace the HttpContext.Current at the beginning
// of the request with a wrapped one
public class MyHttpModule : IHttpModule
{
private static Lazy<FieldInfo> _workerRequestType = new Lazy<FieldInfo>(()
=> typeof(HttpContext).GetField("_wr", BindingFlags.NonPublic | BindingFlags.Instance));
public void Init(HttpApplication context)
{
context.BeginRequest += Context_BeginRequest;
@Shazwazza
Shazwazza / CheckAndFixPaths.sql
Last active November 16, 2022 11:05
Checks and fixes invalid path data in umbracoNode table
-- NOTES:
-- The COMMIT TRANSACTION is commented out at the bottom.
-- Running this script as-is will produce a report of problems if any are found.
-- If no problems are found, nothing is reported.
-- To commit the changes, uncomment the COMMIT TRANSACTION and comment out ROLLBACK TRANSACTION.
-- Once committed, re-run the script and no errors should be detected.
-- This is a SQL port of the c# code: https://github.com/umbraco/Umbraco-CMS/pull/7907/files#diff-83e79f7101cd6797ca42ad8ed07f5835R480
-- By default is this execute for MEDIA but you should execute it for CONTENT too, to do that
-- see the SQL statement below that does this WHERE nodeObjectType = @mediaObjectType and change it
-- to WHERE nodeObjectType = @contentObjectType
@Shazwazza
Shazwazza / IProductService.cs
Created September 26, 2019 13:43
Example of creating a custom lucene index in Umbraco 8
/// <summary>
/// Custom service to work with products
/// </summary>
public interface IProductService
{
IEnumerable<Product> GetAll();
}
@Shazwazza
Shazwazza / DisableUserPermissionsNodes.cs
Created May 18, 2017 02:00
For Umbraco, the ability to not render any user permissions tree nodes based on the current user
using System.Threading;
using umbraco.cms.presentation.Trees;
using Umbraco.Core;
using Umbraco.Core.Security;
namespace Test
{
public class MyStartup : ApplicationEventHandler
{
/// <summary>
@Shazwazza
Shazwazza / UserAdminCreateOnly.cs
Created May 18, 2017 01:51
Using Umbraco events to enforce a specific user to only being allowed to create users but not update them
using System.Threading;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Core.Security;
namespace Test
{
public class MyStartup : ApplicationEventHandler
{
@Shazwazza
Shazwazza / UsingUmbracoRelationService.cs
Created May 18, 2017 01:22
Using the Umbraco Relation Service to relate items on a saved event based on property values
using System;
using System.Linq;
using System.Text.RegularExpressions;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using HtmlAgilityPack;
using Umbraco.Web;
using Umbraco.Web.Templates;
@Shazwazza
Shazwazza / cast-vs-oftype.md
Last active January 4, 2017 07:06
Linq Cast vs OfType

With BencharkDot net, this benchmark creates a list of 10,000 strings then tests either OfType<T> or Cast<T>

Here's the benchmark code:

/// <summary>
/// Want to check what is faster OfType or Cast when a enurable all has the same items
/// </summary>
[Config(typeof(Config))]
public class LinqCastBenchmarks
@Shazwazza
Shazwazza / gist:6d75bca3f98d7ef98378
Created June 11, 2015 14:57
Umbraco 7.3 - Enable DatabaseServerMessenger
public class LoadBalancingConfigurationEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
//Replace the server messenger:
ServerMessengerResolver.Current.SetServerMessenger(new BatchedDatabaseServerMessenger(
applicationContext,
true,
//You can customize some options by setting the options parameters here: