Skip to content

Instantly share code, notes, and snippets.

View danielmackay's full-sized avatar

Daniel Mackay [SSW] danielmackay

View GitHub Profile
@danielmackay
danielmackay / ContainerBuilder.cs
Created May 14, 2019 01:56
ASP.NET Core Configuration.
/// <summary>
/// Inspired from: https://platform.deloitte.com.au/articles/dependency-injections-on-azure-functions-v2
/// </summary>
public class ContainerBuilder : IContainerBuilder
{
private readonly IServiceCollection services;
public ContainerBuilder()
{
services = new ServiceCollection();
using System;
using System.IO;
using ExcelDataReader;
using System.Text;
using Newtonsoft.Json;
namespace AzureFridayToJson
{
class Program
{
@danielmackay
danielmackay / AddressInfo.cs
Last active February 25, 2019 01:24
Episerver Forms Address Control with validation. Based on: https://github.com/episerver/EPiServer.Forms.Samples
public class AddressInfo
{
public string address { get; set; }
public string streetNumber { get; set; }
public string street { get; set; }
public string city { get; set; }
public string state { get; set; }
public string postalCode { get; set; }
public string country { get; set; }
}
@danielmackay
danielmackay / GlobalPage.cs
Created February 21, 2019 22:26
Dynamic Page Type Selector
[ContentType(
DisplayName = "Global Search",
GUID = "1B83AF7C-BC4B-4A13-8AAB-B9313D25D284",
GroupName = Global.PageGroups.Content,
Description = "")]
public class GlobalSearchPage : SitePageBase, IAllowedPageType
{
[Display(
Name = "Page Types",
GroupName = SystemTabNames.Content,
public class DatabaseMigrator : IDatabaseMigrator
{
private readonly ILog log = LogManager.GetLogger(typeof(DatabaseMigrator));
private UpgradeEngine engine;
private readonly string connectionString;
private const string JournalSchema = "dbo";
private const string JournalTable = "__SchemaVersions";
public DatabaseMigrator(string connectionString)
{
@danielmackay
danielmackay / Total Database Size.sql
Created May 2, 2015 01:58
Displays the total size for a SQL DB. #sql
SELECT
database_name = DB_NAME(database_id)
, log_size_mb = CAST(SUM(CASE WHEN type_desc = 'LOG' THEN size END) * 8. / 1024 AS DECIMAL(8,2))
, row_size_mb = CAST(SUM(CASE WHEN type_desc = 'ROWS' THEN size END) * 8. / 1024 AS DECIMAL(8,2))
, total_size_mb = CAST(SUM(size) * 8. / 1024 AS DECIMAL(8,2))
FROM sys.master_files WITH(NOWAIT)
WHERE database_id = DB_ID() -- for current db
GROUP BY database_id
@danielmackay
danielmackay / Large SQL Tables.sql
Created May 2, 2015 01:57
Displays larges tables with their number of rows and sizes in MB/GB. #sql
-- Displays larges tables with their number of rows and sizes in MB/GB
CREATE TABLE #temp (
table_name sysname ,
row_count INT,
reserved_size VARCHAR(50),
data_size VARCHAR(50),
index_size VARCHAR(50),
unused_size VARCHAR(50))
SET NOCOUNT ON
@danielmackay
danielmackay / Web API Exception Logger.cs
Created April 20, 2015 04:01
Web API Exception Logger. #webapi
internal class TraceExceptionLogger : ExceptionLogger
{
private readonly Log _log;
public TraceExceptionLogger()
{
_log = new Log();
}
public override void Log(ExceptionLoggerContext context)
@danielmackay
danielmackay / Model State Collection.cs
Created March 16, 2015 06:10
Extension methods that help convert Fluent Validation errors into MVC Model State errors.
public static class ModelStateCollectionExt
{
public static void Update(this ModelStateDictionary modelState, ValidationResult result, bool usePropertyNames = false)
{
if (result.IsValid)
return;
foreach (var error in result.Errors)
{
// If we exclude the property name the error will show up in the validation summary
@danielmackay
danielmackay / Multilevel JS Index.js
Last active August 29, 2015 14:16
Javascript function to dynamically index though an object based on a string index
function (target, field) {
var path
if (field) {
path = field.split('.');
path.forEach(function (key) {
if (target && target[key]) {
target = target[key];
}
});
}