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
// GET: api/Cave | |
[HttpGet] | |
public async Task<ActionResult<IEnumerable<CaveDto>>> GetCave([FromQuery]Pager pager) | |
{ | |
var caveQuery = | |
from cave in context.Cave | |
join user in context.User on cave.AuthorId equals user.Id | |
join map in context.Map on cave.Id equals map.CaveId | |
let score = | |
( |
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
// You need Prism though :) | |
public class AdaptiveCommand : DelegateCommand | |
{ | |
private const double DefaultInvocationDelay = 0.7; | |
public double InvocationDelayInSeconds { get; set; } | |
private DateTime lastInvokeTime = DateTime.MinValue; | |
private readonly Func<bool>? canExecute; |
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
<html> | |
<head> | |
<style> | |
#customers { | |
font-family: Arial, Helvetica, sans-serif; | |
border-collapse: collapse; | |
width: 100%; | |
} | |
#customers td, #customers th { |
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
IProductGet : IGet<List<Product>> | |
IProductPost : IPost<Product, Product> | |
IProductDelete : IDelete<Product, long> | |
class ProductRest : | |
IProductGet, | |
IProductPost, | |
IProductDelete | |
{ | |
public async Task<List<Product>> Get(CancellationToken cancellationToken) |
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
//Startup.cs | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
app.UseIpRateLimiting(); | |
app.UseClientRateLimiting(); | |
// the rest | |
} | |
public void ConfigureServices(IServiceCollection services) |
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 async Task<T?> GetValue<T>(string path, JsonSerializerOptions? options, CancellationToken cancellationToken) | |
{ | |
using var stream = GetStream(); | |
using var jsonDocument = await JsonDocument.ParseAsync(stream, cancellationToken: cancellationToken); | |
var root = jsonDocument.RootElement; | |
var jsonPath = JsonPath.Parse(path); | |
var pathResult = jsonPath.Evaluate(root); | |
if (pathResult.Error != null) | |
throw new InvalidOperationException(pathResult.Error); |
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
private void ScheduleDisposeResourceStreams() | |
{ | |
_ = Task.Factory.StartNew(async () => | |
{ | |
await Task.Delay(TimeSpan.FromMinutes(1)); | |
// `stream` creation happens right after the invocation of this | |
// They are in the same thread so no lock needed | |
jsonStream?.Dispose(); | |
jsonDocument?.Dispose(); | |
jsonStream = 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 class Configuration : IConfiguration | |
{ | |
private readonly string assemblyResourceFile; | |
private AutoDisposeJsonDocument? smartJsonDocument; | |
public Configuration(string assemblyResourceFile) | |
{ | |
this.assemblyResourceFile = assemblyResourceFile; | |
} |
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
class LoggingInterceptor : HttpClientHandler | |
{ | |
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | |
{ | |
Debug.Log("Request {0}", request.RequestUri.PathAndQuery); | |
if (request.Content != null) | |
{ | |
var contentRequest = await request.Content.ReadAsStringAsync(); | |
} |
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
class Observable | |
{ | |
private object actionCollection = null!; | |
private MethodInfo? methodInfo; | |
public ActionCollection<TModel> From<TModel>(TModel target) where TModel : INotifyPropertyChanged | |
{ | |
RegisterPropertyChanged(target); | |
return BuildActionCollection<TModel>(); | |
} |