This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DebuggerDisplay("Count = {" + nameof(Count) + "}")] | |
public sealed class TaskCompletionSourceDictionary | |
{ | |
private readonly TaskCompletionSourceDictionary<Type> _dictionary = new TaskCompletionSourceDictionary<Type>(); | |
public int Count => _dictionary.Count; | |
public bool TryGetValue<T>(out TaskCompletionSource<T> taskCompletionSource) => | |
_dictionary.TryGetValue(typeof(T), out taskCompletionSource); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Concurrent; | |
using System.Net; | |
using System.Reflection; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace OpenSource.Net | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal sealed class DailyFileLog : ILog | |
{ | |
readonly DailyFileLogWriter _eventLog; | |
readonly DailyFileLogWriter _messageLog; | |
public DailyFileLog(FileLogWriterOptions eventLog, FileLogWriterOptions messageLog) | |
{ | |
_eventLog = new DailyFileLogWriter(eventLog); | |
_messageLog = new DailyFileLogWriter(messageLog); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ====================== | |
# curl-download.sh v1.0 | |
# filename | |
# url | |
# ====================== | |
if [ -f "$1.etag" ]; then | |
HTTPCODE=$(curl --etag-compare $1.etag --url $2 -o $1 -sw '%{http_code}' --retry 9) | |
if [ "$HTTPCODE" = "304" ]; then | |
echo "$1: not modified" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static KeyValuePair<ushort, string>[] Parse(Span<byte> message) | |
{ | |
var values = new List<KeyValuePair<ushort, string>>(); | |
const byte Soh = 1; | |
const byte Equals = 61; | |
while (0 < message.Length) | |
{ | |
var soh = message.IndexOf(Soh); | |
if (-1 == soh) | |
break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class EnumerableExtensions | |
{ | |
public static bool IsOrderedSubsetOf<T>( | |
this IEnumerable<T> source, | |
IEnumerable<T> target, | |
out T missing, | |
IEqualityComparer<T> equalityComparer = null) | |
{ | |
if (null == equalityComparer) | |
equalityComparer = EqualityComparer<T>.Default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DataProtectionBuilderExtensions | |
{ | |
public static IDataProtectionBuilder PersistKeysToStackExchangeRedisCache(this IDataProtectionBuilder builder, RedisKey key) | |
{ | |
builder.Services.AddOptions<KeyManagementOptions>() | |
.Configure<IDistributedCache>((options, distributedCache) => options.XmlRepository = new RedisXmlRepository(() => GetDatabase(distributedCache), key)); | |
return builder; | |
} | |
private static IDatabase GetDatabase(IDistributedCache store) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class SessionIdDataFormat : ISecureDataFormat<AuthenticationTicket> | |
{ | |
private const string SessionIdClaim = "Microsoft.AspNetCore.Authentication.Cookies-SessionId"; | |
public string Protect(AuthenticationTicket data) => data.Principal.FindFirst(SessionIdClaim).Value; | |
public string Protect(AuthenticationTicket data, string purpose) => null != purpose ? null : Protect(data); | |
public AuthenticationTicket Unprotect(string protectedText) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddHttpClient<IRancherClient, RancherClient>(); | |
} | |
public interface IRancherClient | |
{ | |
Task<HttpResponseMessage> ProjectStackActionAsync(string project, string stack, string action, | |
HttpContent content = null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class FileTelemetryChannel : ITelemetryChannel | |
{ | |
private readonly ISerializationWriter _serializationWriter; | |
private readonly StreamWriter _streamWriter; | |
public FileTelemetryChannel(string fileName = null) | |
{ | |
EndpointAddress = fileName; | |
_streamWriter = new StreamWriter( | |
fileName ?? $"{Path.GetTempPath()}ai-{DateTime.Now:yyyy-M-d}.jsonl", |
NewerOlder