Skip to content

Instantly share code, notes, and snippets.

View dataneek's full-sized avatar

Nic Myers dataneek

View GitHub Profile
@dataneek
dataneek / HttpClientAfterSample.cs
Created July 16, 2018 11:59
Example use of HttpClient - before and after.
namespace ConsoleApplication
{
public class Program
{
private static HttpClient client = new HttpClient();
public static async Task Main(string[] args)
{
Console.WriteLine("Starting connections");
@dataneek
dataneek / Example.cs
Created November 1, 2017 13:17
Example of PaginableCollections and Dapper
using (var connection = connectionFactory.GetConnection())
{
using(var reader =
connection.QueryMultiple("<stored procedure>", new { }, CommandType.StoredProcedure))
{
var metadata = reader.Read<Metadata>().First();
var items = reader.Read<Foo>();
return
new StaticPaginable<Foo>(
@dataneek
dataneek / DbContextTransactionFilter.cs
Last active October 1, 2017 12:51
Single Connection per Page Request in Razor Pages 2.0
namespace WebApp.Models
{
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Filters;
public class DbContextTransactionFilter : IAsyncPageFilter
{
async Task IAsyncPageFilter.OnPageHandlerExecutionAsync(
PageHandlerExecutingContext context,
Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
var projects = GetFiles("./**/*.csproj").ToPaginable(1, 10);
foreach(var project in projects)
{
Information($"{project.ItemNumber}, {project.Item.ToString()}");
// DotNetCoreBuild(
// project.FullPath,
@dataneek
dataneek / something.cs
Created March 9, 2017 18:32
FluentValidation with Child Collections
class Program
{
static void Main(string[] args)
{
var command = new CreateCommand
{
Items = new List<CreateCommand.Item>()
{
new CreateCommand.Item { Email = "test@test.com", NameFirst = "Test", NameLast = "Test"},
new CreateCommand.Item { Email = "testtest.com", NameFirst = "Test", NameLast = "Test"},
public static void Main(string[] args)
{
var configurationBuilder =
ConfigurationBuilder
.With<SomeBatchRecord>()
.ReadAsConsolidated(t=>
{
.Read<ExcelFileReader>(t=> t.Read("c:\\somefile.xls"))
.Read<TextFileReadr>(t=> t.Read("somefile.txt"));
})
@dataneek
dataneek / CachePrototype.cs
Last active October 14, 2016 18:19
Cache Prototype
public class TripsByDateQuery : IQuery<IEnumerable<Trip>>
{
public DateTime? Lowerbound { get;set; }
public DateTime? UpperBound { get; set; }
}
public class TripsByDateQueryHandler : IQueryHandler<TripsByDateQuery, IEnumerable<Trip>>, ICachable
{
public IEnumerable<Trip> Handle(TripsByDateQuery query)
{
function getPaginableFilters() {
var result = [];
$('.paginable-filter').each(function () {
var filterType = $(this).data('filter-key');
$(':checkbox:checked', this).each(function () {
var item = {};
public static class ControllerExtensions
{
public static string RenderRazorViewToString(this Controller c, string viewName, object model)
{
c.ViewData.Model = model;
using (var sw = new StringWriter())
{
var viewResult = ViewEngines.Engines.FindPartialView(c.ControllerContext, viewName);
var viewContext = new ViewContext(c.ControllerContext, viewResult.View, c.ViewData, c.TempData, sw);
public static class SortQueryableExtensions
{
public static IQueryable<T> ApplySort<T>(this IQueryable<T> queryable, string sort)
{
if (queryable == null)
throw new ArgumentNullException();
if (string.IsNullOrWhiteSpace(sort))
return queryable;