Skip to content

Instantly share code, notes, and snippets.

View BenjaminAbt's full-sized avatar

BEN ABT BenjaminAbt

View GitHub Profile
@BenjaminAbt
BenjaminAbt / MicrosoftDefenderBearerTokenClientProvider.cs
Created August 26, 2022 09:44
Microsoft Defender Bearer Token Sample Provider
public class MicrosoftDefenderBearerTokenClientProvider
{
private const string _authority = "https://login.microsoftonline.com";
private const string _audience = "https://api.securitycenter.microsoft.com";
private static string[] s_scopes = new[] { $"{_audience}/.default" };
public async Task<AuthenticationResult> GetToken
(string tenantId, string clientId, string secret)
{
@BenjaminAbt
BenjaminAbt / sb-vs-sbpooled.cs
Created October 29, 2021 20:06
.NET 6 - StringBuilder vs. String Builder ObjectPool
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BenchmarkDotNet.Attributes;
using Microsoft.Extensions.ObjectPool;
namespace Benchmarks;
[MemoryDiagnoser]
public class Benchmark
@BenjaminAbt
BenjaminAbt / Evolving-ArgumentNullException.cs
Last active September 30, 2021 15:55
Better C# ArgumentNullExceptions
// C# 5
public void MyMethod(string name)
{
if (name == null) throw new ArgumentNullException("name", "name cannot be null.");
}
// C# 6 - nameof() to avoid magic strings
public void MyMethod(string name)
{
if (name == null) throw new ArgumentNullException(nameof(name), $"{nameof(name)} cannot be null.");
@BenjaminAbt
BenjaminAbt / ApplicationInsightsBehavior.cs
Last active January 25, 2023 16:16
Application Insights MediatR Operation Behavior
using System;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
namespace BenjaminAbt.ApplicationInsights.MediatR
{
@BenjaminAbt
BenjaminAbt / keybase.md
Created April 21, 2020 11:53
keybase.md

Keybase proof

I hereby claim:

  • I am benjaminabt on github.
  • I am benjaminabt (https://keybase.io/benjaminabt) on keybase.
  • I have a public key ASCApkKXr5BbmOMdy5NbZwHzb_kcd3X_m_X-Nro9gtyCDgo

To claim this, I am signing this object:

@BenjaminAbt
BenjaminAbt / QueueDemoService.cs
Created March 6, 2016 12:47
Azure Service Bus Queue Demo Service
// QueueClient des NuGet Pakets WindowsAzure.ServiceBus
_queueClient = QueueClient.CreateFromConnectionString( connectionString, queueName );
// Senden von Nachrichten
// Es empfiehlt sich hier die Serialisierung der Daten, bei Strings zb. als Json
_queueClient.Send( new BrokeredMessage( JsonConvert.SerializeObject( payload ) ) );
// Nachrichten werden über Callbacks empfangen
// Der Einfachheit halber biete ich den QueueService Empfängern die Informationen als Event an
// Niemand muss dabei periodische die Queue anfragen, ob es neue Nachrichten gibt
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using Newtonsoft.Json;
namespace ConsoleApp6
{
public class Program
{
"@odata.context":"http://services.odata.org/V4/OData/OData.svc/$metadata#Products/ODataDemo.FeaturedProduct/$entity",
"@odata.type":"#ODataDemo.FeaturedProduct",
"ID":9,
"Name":"Lemonade",
"Description":"Classic, refreshing lemonade (Single bottle)",
"ReleaseDate":"1970-01-01T00:00:00Z",
"DiscontinuedDate":null,
"Rating":7,
"Price":1.01
{
"@odata.context":"http://services.odata.org/V4/OData/OData.svc/$metadata#Products(ID,Name,Price)",
"value":[
{
"ID":0,
"Name":"Bread",
"Price":2.5
},
{
"ID":1,
@BenjaminAbt
BenjaminAbt / ODataorg_Samples_Products_IDName.json
Created February 13, 2016 13:43
ODataorg_Samples_Products_IDName.json
{
"@odata.context":"http://services.odata.org/V4/OData/OData.svc/$metadata#Products(ID,Name)",
"value":[
{
"ID":0,
"Name":"Bread"
},
{
"ID":1,
"Name":"Milk"