Skip to content

Instantly share code, notes, and snippets.

View zfcflower's full-sized avatar

Jerry Chang zfcflower

  • China SuZhou
View GitHub Profile
@zfcflower
zfcflower / AUsage.cs
Created August 3, 2022 02:42 — forked from davidfowl/AUsage.cs
Header propagation HttpClientFactory middleware
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpClient("myclient");
// Global header propagation for any HttpClient that comes from HttpClientFactory
services.AddHeaderPropagation(options =>
{
options.HeaderNames.Add("Correlation-Id");
});
}
@zfcflower
zfcflower / Example.cs
Created May 1, 2022 04:14 — forked from davidfowl/Example.cs
An implementation of MessagePipe. Something like a channel but with buffer management so you can peek and advance the message that was read.
using System.Buffers;
using System.Net.WebSockets;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/ws", async (HttpContext context) =>
{
var ws = await context.WebSockets.AcceptWebSocketAsync();
var incomingMessages = new MessagePipe<WebSocketMessageType>();
@zfcflower
zfcflower / Example1.cs
Created April 28, 2018 10:00 — forked from davidfowl/Example1.cs
How .NET Standard relates to .NET Platforms
namespace Analogy
{
/// <summary>
/// This example shows that a library that needs access to target .NET Standard 1.3
/// can only access APIs available in that .NET Standard. Even though similar the APIs exist on .NET
/// Framework 4.5, it implements a version of .NET Standard that isn't compatible with the library.
/// </summary>INetCoreApp10
class Example1
{
public void Net45Application(INetFramework45 platform)
@zfcflower
zfcflower / ExampleUsage.cs
Created January 18, 2017 09:49 — forked from NickCraver/ExampleUsage.cs
Code to mark a SQL string before it's passed to Dapper.
public static List<T> Query<T>(this DataContext db, string sql, object param = null, int? commandTimeout = null, IDbTransaction transaction = null, [CallerFilePath]string fromFile = null, [CallerLineNumber]int onLine = 0, string comment = null)
{
using (db.Connection.EnsureOpen())
{
try
{
return db.Connection.Query<T>(MarkSqlString(sql, fromFile, onLine, comment), param, transaction ?? db.Transaction, true, commandTimeout).AsDapperList();
}
catch (SqlException ex) when (ex.Is(SqlErrorCode.DatabaseReadOnly_3906))
{
public class AES
{
//http://boywhy.blogspot.tw/2015/04/c-aes.html
public static Byte[] generateKey()
{
var AESObject = new RijndaelManaged() { KeySize = 128 };
AESObject.GenerateKey();
return AESObject.Key;
}
public static Byte[] encrypt(Byte[] data, Byte[] key)