Skip to content

Instantly share code, notes, and snippets.

View hidegh's full-sized avatar

balazs HIDEGHETY hidegh

View GitHub Profile
@hidegh
hidegh / auth.service.ts
Created October 25, 2021 12:48
authService - WorkFlowWise (wfw-ngx-adal - with acquireToken patch) and custom JWT.ts
import { Injectable } from "@angular/core";
import { Router } from "@angular/router";
import { JwtHelperService } from '@auth0/angular-jwt';
import { BehaviorSubject, from, Observable, of } from "rxjs";
import { distinctUntilChanged, take, tap } from "rxjs/operators";
import { RoleConsts } from "src/app/_core/security/roles-consts";
import { CurrentUserService } from "src/app/_services/current-user/current-user.service";
import { IUserProfile } from "src/app/_services/current-user/i.user.profile";
import { environment } from 'src/environments/environment';
import { AdalService } from "wfw-ngx-adal/dist/core";
@hidegh
hidegh / ProcessEx.cs
Created February 27, 2020 09:36
Process with redirected input/output/error streams (async) supporting timeout...
using System;
using System.Diagnostics;
using System.IO;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace R
{
@hidegh
hidegh / toggle-classes.js
Created July 30, 2019 07:43
Allows to toggle/add/remove classes of an HTML element...
$(document).on('click', '[data-toggle="class"]', function () {
var $target = $($(this).data('target'));
var toggleClasses = $(this).data('toggle-classes');
if (toggleClasses)
$target.toggleClass(toggleClasses);
var addClass = $(this).data('add-classes');
if (addClass)
$target.addClass(addClass);
@hidegh
hidegh / ExpressionInitialParameterRenamer.cs
Last active December 29, 2018 20:01
"Unifies" the expression, so we get same result if same expression is used (with different base parameter name)...
using System;
using System.Linq.Expressions;
/// <summary>
/// Usage:
/// var exp1 = (Expression<Func<Person, string>>) exp1 = i => i.Addresses[0].City;
/// var exp2 = (Expression<Func<Person, string>>) exp1 = j => j.Addresses[0].City;
/// var exp1String = new ExpressionInitialParameterRenamer().Rename(exp1).ToString();
/// /// </summary>
namespace ExpressionHelper
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNet.OData;
using Microsoft.AspNet.OData.Extensions;
using Microsoft.AspNet.OData.Query;
using System.Linq;
using System;
using Newtonsoft.Json;
namespace R.Web.Api
import {NgControl} from "@angular/forms";
import {Directive, ElementRef} from "@angular/core";
@Directive({
selector: '[ngModel]', // or 'input, select, textarea' - but then your controls won't be handled and also checking for undefined would be necessary
})
export class NativeElementInjectorDirective {
constructor(private el: ElementRef, private control : NgControl) {
(<any>control.control).nativeElement = el.nativeElement;
}
//
// COMMON DLL
//
public interface IStatusCode
{
int? StatusCode { get; set; }
}
public static class IStatusCodeEx
public static TransactionScope New(TransactionScopeOption transactionScopeOption = TransactionScopeOption.Required, IsolationLevel isolationLevel = IsolationLevel.ReadCommitted, TimeSpan? timeout = null)
{
// NOTE: this is a fix, to avoid inner transaction timeout's to shorten the outer one...
if (Transaction.Current != null && transactionScopeOption == TransactionScopeOption.Required)
timeout = TimeSpan.FromMinutes(15);
var options = new TransactionOptions
{
IsolationLevel = isolationLevel,
Timeout = timeout ?? TransactionManager.DefaultTimeout
/// <summary>
/// Depends on domain events...
/// Reason: wanted to de-couple it from the next job and so I do have DI objects accessible...
///
/// NOTE:
/// This is by default a PERMANENT failure notification filter, since the filter Order is so high, it get's surely executed after the AutomaticRetry filter.
/// Also if AutomaticRetry filter does delete the job on permanent fail, the PERMANENT failure notification won't occure.
///
/// If the HangfirePermanentFailureNotificationEvent.Order is less than the AutomaticRetry.Order, we will get a notification on each failure, not just the last one!
/// </summary>
/// <summary>
/// Usage: [JsonConverter(typeof(JsonDateTimeConverter), "MM\\/dd\\/yyyy")].
/// Dates created/set in JS had time-zones appended. By using string, this issue won't persist...
/// </summary>
public class JsonDateTimeConverter : DateTimeConverterBase
{
private string CustomFormat { get; }
public JsonDateTimeConverter(string customFormat)
{