Skip to content

Instantly share code, notes, and snippets.

Avatar

Jan Hebnes janhebnes

View GitHub Profile
@janhebnes
janhebnes / Common.targets
Last active Jul 28, 2017
MSBuild - Just include in project file. Detects on project folder level latest TFS or Git Revision using tf.exe history or git rev-list count HEAD for a revision number and git log -1 pretty=format:%h . for hash and replaces the Revision in AssemblyVersion and AssemblyFileVersion for AssemblyInfo.cs prior to building the project with CustomTasks…
View Common.targets
<!--
***********************************************************************************************
Embed in csproj with import and the build events are hooked up automatically
<Import Project="..\..\..\Common.targets" Condition="Exists('..\..\..\Common.targets')" />
PreBuild - Handling revision on build so the source control revision number of the project folder is embeded in the last numeric of the projects AssemblyInfoVersion and AssemblyInfoFileVersion
PostBuild - Sets revision to 0 and reverts the file with a copy upon finishing for not introducing change on version control for the assemblyInfo.cs
In debug mode the revision detection is disabled, and notification is shown instead.
View BatchCommands.cs
/// <summary>
/// Handle Database operations
/// </summary>
/// <remarks>The default network packet size is 4,096 bytes. More information at http://technet.microsoft.com/en-us/library/ms177437.aspx </remarks>
public class BatchCommands
{
private StringBuilder _query = new StringBuilder();
private int _bufferLength = 0;
public static string ConnectionString
{
@janhebnes
janhebnes / UnitTestIHttpActionResult.cs
Last active Jun 24, 2016
Sample Unit test looking at a Controller returning the WebAPI 2 pattern IHttpActionResult for reference.
View UnitTestIHttpActionResult.cs
[TestMethod]
public void Study_DatetimeOffsets_in_DayViewModel()
{
// http://www.asp.net/web-api/overview/testing-and-debugging/unit-testing-controllers-in-web-api
// The controller is returning IHttpActionResult, so look at the sample in the bottom of the ms article.
// Using OkNegotiatedContentResult safecast resulted in a null in my case.
var controller = new DayController();
controller.Request = new HttpRequestMessage();
controller.Configuration = new HttpConfiguration();
@janhebnes
janhebnes / DefaultDocumentsHttpModule.cs
Last active Jun 20, 2016
HttpHandler that helps respect the Request flow and serves the default documents of a directory instead of allowing e.g. Umbraco to kidnap the request for there purposes.
View DefaultDocumentsHttpModule.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
/// <summary>
/// Respect the DefaultDocuments even when Umbraco takes over the HttpModule pipeline
/// Add file to App_Code (or compile with your project) and
/// Add to web.config on system.web > httpModules add name="MyDefaultDocumentsHttpModule" type="DefaultDocumentsHttpModule"
@janhebnes
janhebnes / SitecoreNantWebService.asmx.cs
Last active Dec 19, 2015
Sitecore Webservice for creating a package and downloading it from webservice level. Part of the CruiseControl NANT Build Tasks that 1508 used back in 2010 on the phmetropol.dk project that won Sitecore Site of the Year two years in a row in the Educational category.
View SitecoreNantWebService.asmx.cs
namespace FemtenNulOtte.NAnt.WebService
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Services;
using System.Xml.Serialization;
@janhebnes
janhebnes / MailEncryption.cs
Created Dec 18, 2015
Allowing to sign an email with a private certificate and encrypting the email with a receivers public certificate key, taking care of handling potential issues arising when certificates are close to expiration or have expired
View MailEncryption.cs
namespace FemtenNulOtte.Client.Logic.Utilities
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Mail;
using System.Net.Mime;
using System.Security.Cryptography.Pkcs;
using System.Security.Cryptography.X509Certificates;
@janhebnes
janhebnes / SteamGroupRelationsProgram.cs
Created Dec 16, 2015
D3 visualization of Steam Group relations between friends and games using Steam API - see the results at http://netbyte.dk/steam/games/ and http://netbyte.dk/steam/
View SteamGroupRelationsProgram.cs
using System.IO;
namespace ConsoleApplication4_steamapi
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Security.Policy;
using System.Text;
@janhebnes
janhebnes / FTPLocalSync.cmd
Last active Dec 16, 2015
WinSCP script for syncronizing remote FTP folder with local folder (example)
View FTPLocalSync.cmd
"C:\Program Files (x86)\WinSCP\winscp" /console /script="FTPLocalSync.winscp"
@janhebnes
janhebnes / AutoGenerated Sitecore Entity Classes (sample).cs
Last active Dec 16, 2015
Sitecore Code Generation based on T4 and extending the sitecore base template fields with class information for mapping the c# code to correct types.
View AutoGenerated Sitecore Entity Classes (sample).cs
namespace Client.Logic.Entities.Client.Pages.Blog
{
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Text;
using FemtenNulOtte.Core.Entities;
using FemtenNulOtte.Core.Entities.Context;
@janhebnes
janhebnes / DatabaseStorageUsageQuery.sql
Created Dec 9, 2015
Purpose is to monitor health on mssql database installations and send one report to an email with detailed attached (Uses the opensource utilities bmail.exe, mpack.exe and munpack.exe )
View DatabaseStorageUsageQuery.sql
SET NOCOUNT ON
SELECT '$(ServerName)' AS ServerName
,CAST( DB_NAME(mf.database_id) AS varchar) AS databaseName
,CAST(size_on_disk_bytes AS varchar(15)) as size_on_disk
,CAST(dbs.state_desc AS varchar(10)) as [state]
,CAST(dbs.recovery_model_desc AS varchar(10)) as rec_model
,CAST(dbusers.name AS varchar(10)) as [Owner]
,CAST(num_of_reads AS varchar(15)) as num_of_reads
,CAST(num_of_bytes_read AS varchar(15)) as num_of_bytes_read
,CAST(io_stall_read_ms AS varchar(15)) as io_stall_read_ms