Skip to content

Instantly share code, notes, and snippets.

View Blind-Striker's full-sized avatar

Deniz İrgin Blind-Striker

View GitHub Profile
@Blind-Striker
Blind-Striker / ApiActor.cs
Last active September 5, 2017 10:06
Sample code for Akka.Net Medium Article
public class ApiActor : ReceiveActor
{
private readonly IActorRef _watchedVideoActor;
private readonly IActorRef _videoActor;
private readonly IActorRef _recommandationActor;
public ApiActor(IActorRef watchedVideoActor)
{
_watchedVideoActor = watchedVideoActor;
_recommandationActor = Context.ActorOf(Props.Create<RecommandationActor>(watchedVideoActor));
@Blind-Striker
Blind-Striker / FooActor.cs
Created September 5, 2017 10:12
Example Actor Lifecycle events for Akka.Net Medium Article
public class FooActor : UntypedActor
{
protected override void OnReceive(object message)
{
}
protected override void PreStart()
{
}
@Blind-Striker
Blind-Striker / SupervisorStrategy.cs
Last active December 17, 2022 17:18
SupervisorStrategy example for Akka.Net Medium Article
protected override SupervisorStrategy SupervisorStrategy()
{
return new OneForOneStrategy(// or AllForOneStrategy
maxNumberOfRetries: 10, // opsiyonel
duration: TimeSpan.FromSeconds(30), // opsiyonel
decider: x =>
{
// ArithmeticException Actor durduracak kadar kritik bir hata değil
// dolayısıyla devam etmesinde bir sakınca yok.
if (x is ArithmeticException) return Directive.Resume;
@Blind-Striker
Blind-Striker / Tuple.cs
Created September 6, 2017 12:03
C# 7.0 example for blog article
public Tuple<int, string, string, string> GetUserById(int userId)
{
// TODO : verilerin datareader veya datatable'da geldiğini ve sonrasında Tuple nesnesini oluşturduğumuzu düşünün.
// (Evet ORM kullanılmadığımız bir projeydi)
var user = new Tuple<int, string, string, string>(1, "Deniz", "İrgin", "deniz@denizirgin.com");
return user;
}
// -------- Kullanımı
Tuple<int, string, string, string> user = GetUserById(1);
@Blind-Striker
Blind-Striker / TupleType.cs
Created September 6, 2017 12:09
Tuple Type, Tuple Literal Example for blog
public (int, string, string, string) GetUserById(int userId) // Tuple Type
{
// verilerin bir datasource'dan geldiğini düşünelim
int id = 1;
string firstName = "Deniz";
string lastName = "İrgin";
string email = "deniz@denizirgin.com";
return (id, firstName, lastName, email); // Tuple Literal
}
@Blind-Striker
Blind-Striker / TupleType1.cs
Created September 6, 2017 12:11
Tuple Type, Tuple Literal Example for blog
public (int Id, string FirstName, string LastName, string Email) GetUserById(int userId) // Tuple Type
{
// verilerin bir datasource'dan geldiğini düşünelim
int id = 1;
string firstName = "Deniz";
string lastName = "İrgin";
string email = "deniz@denizirgin.com";
return (id, firstName, lastName, email); // Tuple Literal
}
@Blind-Striker
Blind-Striker / OldOut.cs
Created September 6, 2017 12:18
Old out example for blog
public void UpdateUserBalance(int userId, string balance) // harici bir sistemden gelen string data
{
decimal userBalance;
if(decimal.TryParse(balance, out userBalance))
{
Console.WriteLine($"{userId} id'li kullanıcının bakiyesi {userBalance}");
}
else
{
@Blind-Striker
Blind-Striker / NewOut.cs
Created September 6, 2017 12:19
New out example for blog
public void UpdateUserBalance(int userId, string balance) // harici bir sistemden gelen string data
{
if (decimal.TryParse(balance, out decimal userBalance)) // decimal yerine var'da kullanabiliriz
{
Console.WriteLine($"{userId} id'li kullanıcının bakiyesi {userBalance}");
}
else
{
Console.WriteLine("Geçerisiz bir değer girildi");
}
@Blind-Striker
Blind-Striker / si.cs
Created September 6, 2017 13:08
EF Core 2.0 String Interpolation Example for Article
var city = "İstanbul";
using (var context = CreateContext())
{
context.Customers.FromSql($@"
SELECT *
FROM Customers
WHERE City = {city}");
}
@Blind-Striker
Blind-Striker / PatternMatching.cs
Created September 6, 2017 16:04
C# 7.0 Pattern Matching example for blog
public static void ShowUserBalance(object balance)
{
if (balance is null) // constant pattern "null"
{
return;
}
if (balance is decimal userBalance) // type pattern "decimal userBalance"
{
Console.WriteLine($"Kullanıcının bakiyesi {userBalance}");