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 async Task<string[]> ExecuteCommandAsync(string command) | |
{ | |
using var p = new Process(); | |
p.StartInfo = new ProcessStartInfo("cmd.exe") | |
{ | |
CreateNoWindow = true, | |
UseShellExecute = false, | |
RedirectStandardInput = true, | |
RedirectStandardOutput = true | |
}; |
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 ProcessExtensions | |
{ | |
public static async Task<(string output, string error)> RunAsync(this Process process, string command, | |
CancellationToken cancellationToken = default) | |
{ | |
if (string.IsNullOrEmpty(command)) throw new ArgumentNullException(nameof(command)); | |
var outputBuilder = new StringBuilder(); | |
var errorBuilder = new StringBuilder(); |
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.Diagnostics; | |
using System.Runtime.CompilerServices; | |
using System.Threading.Channels; | |
using var p = new Process(); | |
p.StartInfo.FileName = "ls"; | |
await foreach(var s in p.StartAndReadOutputAsync()){ | |
Console.WriteLine(s); | |
} |
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.Collections.Generic; | |
using System.Diagnostics; | |
using System.Text; | |
using System.Threading.Tasks; | |
/// <summary> | |
/// Process helper with asynchronous interface | |
/// - Based on https://gist.github.com/georg-jung/3a8703946075d56423e418ea76212745 | |
/// - And on https://stackoverflow.com/questions/470256/process-waitforexit-asynchronously | |
/// </summary> |
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 Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.AspNetCore; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.Extensions.DependencyInjection; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
using System.Linq; | |
using System; |
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
//regular implementation of Background/IHostedService. Nothing special. | |
public class MyBackgroundService : BackgroundService | |
{ | |
} | |
//Startup.cs or Program.cs | |
//Also standard. No extra code required. | |
services.AddHostedService<MyBackgroundService>(); | |
services.AddTransient<IMyService, MyService>(); |
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.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace CopyFolder | |
{ | |
class Program |
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 Microsoft.IdentityModel.Tokens; | |
using App.Common.Interfaces; // for ITokenGenerator - obvious | |
using System.IdentityModel.Tokens.Jwt; | |
using System.Security.Claims; | |
using System.Text; | |
namespace Ordering.Infrastructure.Services | |
{ | |
public class TokenGenerator : ITokenGenerator | |
{ |
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
https://learn.microsoft.com/en-us/dotnet/maui/data-cloud/database-sqlite | |
https://github.com/dotnet/maui-samples/tree/main/7.0/Data/TodoSQLite |
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 Microsoft.Extensions.Hosting; | |
using Microsoft.Extensions.Options; | |
using System.Threading; | |
public class MySingletonService : BackgroundService | |
{ | |
private IDisposable _optionsChangedListener; | |
private MyOptions _myCurrentOptions; |
NewerOlder