Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
namespace RunProcessAsTask
{
public static partial class ProcessEx
{
@Legends
Legends / Startup.cs
Last active October 13, 2019 18:46
Swagger UI setup
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@Legends
Legends / ScrapePage.cs
Created October 18, 2019 22:06
Puppeteer Sharp - Scarping
private async Task<DtoEst> LoadEinkommenssteuerAsync()
{
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
DtoEst dto = new DtoEst();
var url = "https://www.bmf-steuerrechner.de/ekst/eingabeformekst.xhtml";
#region SELECTORS
// https://stackoverflow.com/questions/45110893/select-elements-by-attributes-with-colon
// use css escapes: https://mothereff.in/css-escapes
@Legends
Legends / ScrapePage.cs
Last active June 22, 2020 11:49
Puppeteer Sharp - Scraping using C# and puppeteer
private async Task<DtoEst> LoadXXXAsync()
{
// downloads chromium to the local project, needed by Puppeteer Sharp for execution, takes about 2 min!
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
DtoEst dto = new DtoEst();
var url = "https://www.xxxxxx.xhtml";
#region SELECTORS
// https://stackoverflow.com/questions/45110893/select-elements-by-attributes-with-colon
var path = @"C:\Users\Admin\Documents\Visual Studio 2019\Projects\PuppeteerCSarpTest\bin\Debug\PuppeteerCSarpTest.exe";
AssemblyName an = AssemblyName.GetAssemblyName(path);
byte[] pt = an.GetPublicKeyToken();
pt = an.GetPublicKeyToken();
var length = pt.GetLength(0);
Console.WriteLine("9ad46d957f307217".Length);
// Server.exe:
var s = new Semaphore(0, 1, Constants.SemaphoreName); // public static readonly string SemaphoreName = @"Global\semName";
var p = Process.Start(@"C:\Users\...\Debug\IpcChannelClient.exe");
p.EnableRaisingEvents = true;
p.Exited += P_Exited;
//p.WaitForExit();
Console.WriteLine("Entering waitone at: " + DateTime.Now.ToLocalTime());
// If you are using **IIS Express** as host, then use `Server features` to increase the `MaxRequestBodySize`
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.Use(async (context, next) =>
{
context.Features.Get<IHttpMaxRequestBodySizeFeature>().MaxRequestBodySize = null; // unlimited I guess
await next.Invoke();
});
// UploadController Action:
[HttpPost]
[DisableFormValueModelBinding]
[ValidateAntiForgeryToken]
[DisableRequestSizeLimit]
public async Task<IActionResult> UploadPhysicalStreamed()
{
if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
{
ModelState.AddModelError("File", $"The request couldn't be processed (Error 1).");
// Upload string base64 encoded image to MVC action
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
base64 = (() => {
const encodeAsync = async (str, mimeType = { type: 'text/html' }) => {
return new Promise((resolve, reject) => {
// Create the Blob object (of course, it can be of any type and defined in any way)
var blob = new Blob([str], mimeType); // , { type: 'text/html' } is default if not specified
// Define the FileReader which is able to read the contents of Blob
var reader = new FileReader();
// The magic always begins after the Blob is successfully loaded
reader.onload = () => {
// Since it contains the Data URI, we should remove the prefix and keep only Base64 string