Skip to content

Instantly share code, notes, and snippets.

View Maarten88's full-sized avatar

Maarten Sikkema Maarten88

View GitHub Profile
// Defined separately from the grain, this reducer can be taken out and shared with
// a Xamarin / XAML app using Redux.NET as the clientside store
public static CounterState Reducer(CounterState state, IAction action)
{
switch (action)
{
case IncrementCounterAction a:
return new CounterState(state) { Count = (state?.Count ?? 0) + 1 };
case DecrementCounterAction a:
[HttpPost("~/incrementcounter")]
public async Task<ActionResult> IncrementCounter()
{
var grain = GrainClient.GrainFactory.GetGrain<ICounterGrain>(this.sessionId);
await grain.IncrementCounter();
return Ok();
}
async function postEffect(url: string, xsrfToken: string, data: any = {}) {
let response = await fetch(url, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'X-XSRF-TOKEN': xsrfToken
},
body: JSON.stringify(data)
});
{
"AcmeSettings": {
"PfxPassword": "yoursupersecretpassword",
"EmailAddress": "[email protected]"
}
}
{
"urls": "https://06478ca8.ngrok.io",
"ConnectionStrings": {
"DataConnectionString": "UseDevelopmentStorage=true"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
public static string GetAddHostNamePortCertCommand(string hostname, int port, string thumbprint)
{
return $"netsh http add sslcert hostnameport={hostname}:{port} certhash={thumbprint} appid={Guid.Empty.ToString("B")} certstorename=MY";
}
public static string GetDeleteHostNamePortCertCommand(string hostname, int port)
{
return $"netsh http delete sslcert hostnameport={hostname}:{port}";
}
.UseKestrel(async options => {
if (secureUrls.Any())
{
var certificateManager = options.ApplicationServices.GetService<ICertificateManager>();
var certificate = await certificateManager.GetCertificate(httpsDomains);
if (certificate != null)
options.UseHttps(certificate);
}
})
// Register a certitificate manager, supplying methods to store and retreive certificates and acme challenge responses
services.AddAcmeCertificateManager(options => {
options.DomainNames = httpsDomains;
options.GetChallengeResponse = async (challenge) =>
{
var cacheGrain = GrainClient.GrainFactory.GetGrain<ICacheGrain<string>>(challenge);
var response = await cacheGrain.Get();
return response.Value;
};
options.SetChallengeResponse = async (challenge, response) =>
acmeHost = new WebHostBuilder()
[...]
.Configure(app => {
app.UseAcmeResponse();
})
.Build();
acmeHost.Start();
@Maarten88
Maarten88 / Program.cs
Last active March 16, 2017 13:34
Template Program.cs
X509Certificate2 certificate = [some certificate including key];
var host = new WebHostBuilder()
.UseKestrel(options => options.UseHttps(certificate))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();