Skip to content

Instantly share code, notes, and snippets.

View mesuttalebi's full-sized avatar

Mesut Talebi mesuttalebi

View GitHub Profile
@mesuttalebi
mesuttalebi / ExceptionConverter.cs
Created September 11, 2024 08:20
A JsonConverter for serializing Exceptions using System.Text.Json.JsonSerializer
public class ExceptionConverter<TExceptionType> : JsonConverter<TExceptionType> where TExceptionType : Exception
{
public override bool CanConvert(Type typeToConvert) => typeof(Exception).IsAssignableFrom(typeToConvert);
public override TExceptionType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
=> throw new NotSupportedException("Deserializing exceptions is not allowed");
public override void Write(Utf8JsonWriter writer, TExceptionType value, JsonSerializerOptions options)
{
var serializableProperties = value.GetType()
@mesuttalebi
mesuttalebi / schools.sql
Created February 28, 2024 13:39
Schools of Turkey - Old - Not Complete
/*
Navicat SQL Server Data Transfer
Source Server : SqlServer_MesutTalebi
Source Server Version : 105000
Target Server Type : SQL Server
Target Server Version : 105000
File Encoding : 65001
@mesuttalebi
mesuttalebi / states.sql
Created February 28, 2024 13:35
States of Turkey
/*
Navicat SQL Server Data Transfer
Source Server : SqlServer_MesutTalebi
Source Server Version : 105000
Target Server Type : SQL Server
Target Server Version : 105000
File Encoding : 65001
@mesuttalebi
mesuttalebi / cities.sql
Created February 28, 2024 13:33
cities of Turkey
/*
Source Server : SqlServer_MesutTalebi
Source Server Version : 105000
Target Server Type : SQL Server
Target Server Version : 105000
File Encoding : 65001
Date: 2014-07-17 16:09:37
*/
@mesuttalebi
mesuttalebi / SwitchGreenToBlue.ps1
Last active December 22, 2023 18:24
switch IIS Binding to achieve Blue-Green Deployment.
param (
[string]$blueSiteName = "testblue.mydomain.com",
[string]$greenSiteName = "testgreen.mydomain.com",
[string]$ipAddress = "192.168.1.108",
[int]$httpPort = 80,
[int]$httpsPort = 443,
[string]$certificateThumbprint = "20437383726bb2e609619ee345825c4854ab0598",
[string]$certificateStore = "My"
)
@mesuttalebi
mesuttalebi / SwitchBlueToGreen.ps1
Last active December 22, 2023 18:25
IIS binding switch for Blue-Green Deployment
param (
[string]$blueSiteName = "testblue.mydomain.com",
[string]$greenSiteName = "testgreen.mydomain.com",
[string]$ipAddress = "192.168.1.108",
[int]$httpPort = 80,
[int]$httpsPort = 443,
[string]$certificateThumbprint = "20437383726bb2e609619ee345825c4854ab0598",
[string]$certificateStore = "My"
)
@mesuttalebi
mesuttalebi / up.html
Created December 15, 2023 06:24
Blue-Green Deployment - Up.html
<html>
<body>
UP - Blue
</body>
</html>
@mesuttalebi
mesuttalebi / PredicateBuilder.cs
Created April 15, 2021 08:26
Predicate Builder to join predicates with "AND" and "OR"
public static class PredicateBuilder
{
public static Expression<Func<T, bool>> True<T>() { return f => true; }
public static Expression<Func<T, bool>> False<T>() { return f => false; }
public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1,
Expression<Func<T, bool>> expr2)
{
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
return Expression.Lambda<Func<T, bool>>
@mesuttalebi
mesuttalebi / TransactionService.cs
Created February 25, 2020 12:36
Transaction Business service able to handle nested transactions
public class TransactionService : ITransactionService
{
private IDbContextTransaction _transaction;
private readonly IUnitOfWork _unitOfWork;
private Queue _transactions;
public TransactionService(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
_transactions = new Queue();
@mesuttalebi
mesuttalebi / BaseRepository.cs
Created February 25, 2020 09:41
GetByIdNotracking Method added.
public virtual T GetByIdNoTracking(params object[] id)
{
_context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
var item = DbSet.Find(id);
if (item != null)
if (typeof(ISoftDeleteEnabled).IsAssignableFrom(typeof(T)))
item = (bool)typeof(T).GetProperty("IsDeleted").GetValue(item) == false ? item : null;
_context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.TrackAll;