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 EFLinqExtensions | |
{ | |
public static IQueryable<TResult> LeftJoin<TOuter, TInner, TKey, TResult>(this IQueryable<TOuter> outer, IQueryable<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<JoinTuple<TOuter, TInner>, TResult>> resultSelector) | |
{ | |
return outer.GroupJoin(inner, outerKeySelector, innerKeySelector, (b, @is) => new { b, @is }).SelectMany(i => [email protected](), (b, i) => new JoinTuple<TOuter, TInner> { Outer = b.b, Inner = i }).Select(resultSelector); | |
} | |
public static IEnumerable<TResult> LeftJoin<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<JoinTuple<TOuter, TInner>, TResult> resultSelector) | |
{ |
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
// ef core 5 | |
// after add/modify/delete some entities at a sync api, i recommend logging changes deeply. | |
// also it is best practice that returning the `changes` to client throw responce both in seccess and fail situation. | |
private object logContextChanges() | |
{ | |
var changes = _context.ChangeTracker.Entries() | |
.Where(i => i.State != EntityState.Unchanged).Select(t => new | |
{ | |
state = t.State.ToString(), | |
type = t.Entity.GetType().FullName, |
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
private void sync<TEntity, TKey>(TEntity[] items, Func<TEntity, TKey> getId, TKey[] currentItemIds, out TKey[] keysToDelete, Action<TEntity> onAdd = null, Action<TEntity> onUpdate = null) where TEntity : class | |
{ | |
foreach (var item in items) | |
{ | |
if (currentItemIds.Contains(getId(item))) | |
{ | |
_context.Entry(item).State = EntityState.Modified; | |
onUpdate?.Invoke(item); | |
} | |
else |
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.Http; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.Logging; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace TVS.Web.DataReceiverService.Middlewares |
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 class Program | |
{ | |
private static DateTime _startupTimestamp; | |
public static void Main(string[] args) | |
{ | |
_startupTimestamp = DateTime.Now; | |
CreateHostBuilder(args).Build().Run(); | |
} |
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
declare @myutcdate as datetime2 = CAST('2021-03-17 22:00' AS datetime2); | |
select | |
FORMAT(SWITCHOFFSET(@myutcdate, '+03:30'), 'yyyy-MM-dd', 'fa') as 'get iran date', | |
FORMAT(SWITCHOFFSET(@myutcdate, '+03:30'), 'yyyy-MM', 'fa') as 'get iran year-month', | |
CAST(FORMAT(SWITCHOFFSET(@myutcdate, '+03:30'), 'dd', 'fa') as int) as 'get iran day', | |
CAST(FORMAT(@myutcdate, 'dd', 'fa') as int) as 'invalid time-zone results in invalid date.' | |
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
// a query on db without any think on database data structure: | |
// (NullIfEmpty is my function on T[].) | |
var shardsBounds = context.Storages | |
.Select(i => new ShardBounds | |
{ | |
StorageCode = i.StorageCode, | |
StartDateTime = i.StartDateTime, | |
EndDateTime = i.EndDateTime, | |
PlateReaderIds = i.StoragePlateReaders.Select(i => i.PlateReaderId).ToArray().NullIfEmpty(), | |
}); |
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.Linq; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Authentication.JwtBearer; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.DependencyInjection.Extensions; | |
using Microsoft.Extensions.Options; | |
namespace SignalRWebApp |
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
import { HubConnection, HubConnectionBuilder, IHttpConnectionOptions, LogLevel, MessageHeaders } from '@microsoft/signalr'; | |
import { Observable } from 'rxjs'; | |
import { Subject } from 'rxjs'; | |
import { map } from 'rxjs/operators'; | |
import { AuthService } from '../auth.service'; | |
import { RetryCanceledError, RetryPolicy } from './retry-policy'; | |
export abstract class SignalRHubBase { | |
constructor(private authService: AuthService) { |
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
export class RetryPolicy<T> { | |
constructor( | |
private action: () => Promise<T>, | |
private retryDelays: number[]) { | |
} | |
private retryNumber; |
OlderNewer