Skip to content

Instantly share code, notes, and snippets.

View kendallmiller's full-sized avatar

Kendall Miller kendallmiller

View GitHub Profile
@kendallmiller
kendallmiller / ResolveErrorCategory.cs
Created June 7, 2016 03:41
ADO.NET SQL Server error category resolver for SQL Server and SQL Azure
/// <summary>
/// Examines exceptions for possible retry scenarios.
/// </summary>
public static DatabaseErrorCategory ResolveErrorCategory(SqlException ex)
{
bool isConnectionError = false;
bool isDeadlockError = false;
bool isTimeoutError = false;
@kendallmiller
kendallmiller / WebChannel.cs
Created December 29, 2015 23:22
WebClient Execute Request Wrapper
/// <summary>
/// Synchronously execute the provided request.
/// </summary>
/// <param name="newRequest"></param>
/// <param name="maxRetries">The maximum number of times to retry the connection. Use -1 to retry indefinitely.</param>
public void ExecuteRequest(IWebRequest newRequest, int maxRetries)
{
if (newRequest == null)
throw new ArgumentNullException("newRequest");
namespace Delegate_Perf_Test
{
[TestFixture]
public class Delegate_Performance_Comparision
{
[Test]
public void MeasureDelegate()
{
int n = 50000000;
Action<int> d = MethodNoInlining;
/// <summary>
/// Check every stinkin' session event to see if they're affected by the latest redaction rules
/// </summary>
public void ProcessRedactionRuleChange(CentralRepository repository)
{
Log.Write(LogMessageSeverity.Information, LogCategory, "Checking existing session events for candidates to update based on newest redaction rules",
"We will check the caption of the log event for each session event to determine if it may be affected by a redaction rule and if so queue it to be recalculated.");
//we need to be ready for millions and millions of log events, all of which could match.. So we have to
//be cautious about memory and locks.
@kendallmiller
kendallmiller / gist:8257393
Created January 4, 2014 16:59
DbContext constructor override to accept a standard ADO.NET connection string. In this case RamsCore was the name of our EF context.
/// <summary>
/// Create a new context with the specified named connection string from the application configuration
/// </summary>
/// <param name="connectionStringName"></param>
public RamsCore(string connectionStringName)
: base("name=RamsCore")
{
if (string.IsNullOrWhiteSpace(connectionStringName))
throw new ArgumentNullException("connectionStringName", "The name of a standard connection string in the config file must be supplied");
@kendallmiller
kendallmiller / gist:6023770
Created July 17, 2013 19:40
Query with no tracking
Guid[] logEventIds;
using (IDbContext ctx = repository.GetContext())
{
// find all session events that have changed since we last processed
logEventIds = ctx.Set<LogEvent>().AsNoTracking()
.OrderBy(e => e.LastOccurrence.Date)
.Select(e => e.Id)
.ToArray();
}
@kendallmiller
kendallmiller / EventQueueDispatcher.cs
Last active December 18, 2015 12:29
Somewhat fancier BlockingCollection<T> used to distribute work to multiple threads
#region File Header
// /*
// EventQueueDispatcher.cs
// Copyright 2013 Gibraltar Software, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@kendallmiller
kendallmiller / DatabaseCopyEngine.cs
Last active September 19, 2023 13:03
Quickie example of using BlockingCollection with multiple readers and one writer.
// /*
// DatabaseCopyEngine.cs
// Copyright 2013 Gibraltar Software, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//