Skip to content

Instantly share code, notes, and snippets.

View SirRufo's full-sized avatar

Sir Rufo SirRufo

  • 23:03 (UTC +02:00)
View GitHub Profile
@SirRufo
SirRufo / sample.cs
Created March 26, 2023 09:35
IServiceScopeFactory
public class FooService
{
private readonly IServiceScopeFactory _scopeFactory;
public FooService( IServiceScopeFactory scopeFactory )
{
_scopeFactory = scopeFactory;
}
public void DoSomething()
@SirRufo
SirRufo / Program.cs
Created October 9, 2019 10:18
Async Await sample
static async Task Main(string[] args)
{
args = new string[] { "ARGUMENT1" };//test
if (args != null && args.Length > 0)
{
var task = args[0];
if (task == "ARGUMENT1")
{
var form = new SerializerForm();
try
@SirRufo
SirRufo / AzureBlobFileClient.cs
Last active March 3, 2021 10:07
IFileClient
public class AzureBlobFileClient : IFileClient
{
private CloudBlobClient _blobClient;
public AzureBlobFileClient(string connectionString)
{
var account = CloudStorageAccount.Parse(connectionString);
_blobClient = account.CreateCloudBlobClient();
}
using System;
using System.Collections.Generic;
namespace ConsoleApp19
{
static class Program
{
static void Main( string[] args )
{
var lst = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
@SirRufo
SirRufo / LongRunningOperationWithCancellationTokenAsync.cs
Last active May 3, 2018 09:58
LongRunningOperationWithCancellationTokenAsync
private static async Task<decimal> LongRunningOperationWithCancellationTokenAsync( int loop, CancellationToken cancellationToken )
{
// We create a TaskCompletionSource of decimal
var taskCompletionSource = new TaskCompletionSource<decimal>();
// Registering a lambda into the cancellationToken
cancellationToken.Register( () =>
{
// We received a cancellation message, cancel the TaskCompletionSource.Task
taskCompletionSource.TrySetCanceled();
@SirRufo
SirRufo / FormatThis.cs
Created November 30, 2017 14:14
Try format this
public class Foo
{
public string GetValue()
{
return @"start of text
{
with some lines
}
end of text";
}
static void Main(string[] args)
{
var cts = new CancellationTokenSource();
var token = cts.Token;
var queryTask = QueryWebServiceInLoop("http://webapi/endpoint", token)
.ContinueWith(t =>
{
if (t.Status == TaskStatus.Faulted)
Console.WriteLine("faulted.");
});
@SirRufo
SirRufo / program.cs
Created July 21, 2017 09:17
MVCE for so45220678
using Castle.Windsor;
using System;
namespace SimpleWindsorTest
{
class Program
{
static void Main(string[] args)
{
var container = new WindsorContainer();