Skip to content

Instantly share code, notes, and snippets.

View eatskolnikov's full-sized avatar
🏠
Working from home

Enmanuel Toribio eatskolnikov

🏠
Working from home
View GitHub Profile
public class HttpLoggingHandler : DelegatingHandler
{
public HttpLoggingHandler(HttpMessageHandler innerHandler = null)
: base(innerHandler ?? new HttpClientHandler())
{ }
async protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var req = request;
var id = Guid.NewGuid().ToString();
var msg = $"[{id} - Request]";
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<appSettings>
<add key="ida:ClientId" value="f22b1f74-9333-4f96-a5e3-5a175120c6c6" />
<add key="ida:AADInstance" value="https://login.microsoftonline.com/" />
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Threading.Tasks;
using System.Linq;
using System.Web;
using Microsoft.Owin.Extensions;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
<validate-jwt header-name="Authorization" failed-validation-httpcode="401" require-expiration-time="false" require-scheme="Bearer" require-signed-tokens="false">
<openid-config url="https://login.microsoftonline.com/{Tenant Id}/v2.0/.well-known/openid-configuration" />
<issuers>
<issuer>https://sts.windows.net/{Tenant Id}/</issuer>
</issuers>
<required-claims>
<claim name="aud" match="all">
<value>{Backend application id}</value>
</claim>
</required-claims>
foreach(var property in item.GetType().GetProperties())
{
if(property.PropertyType.FullName == "System.String")
{
if(property.GetValue(item) == null)
property.SetValue(item, string.Empty);
}
}
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/*Original source https://github.com/Azure/Azure-Functions/issues/717#issuecomment-400098791*/
public static string GetSqlConnectionString(string name)
{
string conStr = System.Environment.GetEnvironmentVariable($"ConnectionStrings:{name}", EnvironmentVariableTarget.Process);
if (string.IsNullOrEmpty(conStr)) // Azure Functions App Service naming convention
conStr = System.Environment.GetEnvironmentVariable($"SQLCONNSTR_{name}", EnvironmentVariableTarget.Process);
return conStr;
}
public static string GetSqlAzureConnectionString(string name)
@eatskolnikov
eatskolnikov / NpoiExample.cs
Created January 13, 2020 23:18
Taken directly from the NPOI repository https://github.com/dotnetcore/NPOI
var newFile = @"newbook.core.xlsx";
using (var fs = new FileStream(newFile, FileMode.Create, FileAccess.Write)) {
IWorkbook workbook = new XSSFWorkbook();
ISheet sheet1 = workbook.CreateSheet("Sheet1");
sheet1.AddMergedRegion(new CellRangeAddress(0, 0, 0, 10));
var rowIndex = 0;
var mapper = new Mapper(file);
var data = mapper.Take<MyClass>(0).ToList();
//Data contains a List of IRowData<MyClass>
//To access the objects instance you need to iterate over the list and reference the Value property
@eatskolnikov
eatskolnikov / SetNullPropertyToStringEmpty.cs
Created January 13, 2020 23:02
Describes a method to use reflection to change null strings to empty strings
foreach(var property in item.GetType().GetProperties())
{
if(property.PropertyType.FullName == "System.String")
{
if(property.GetValue(item) == null)
property.SetValue(item, string.Empty);
}
}