Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ahmadalli
ahmadalli / load.cs
Last active January 27, 2017 22:02
Dynamically load Entity Configurations in EF CodeFirst
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
var typesToRegister = Assembly.GetAssembly(typeof(Context)).GetTypes()
.Where(type => type.Namespace != null)
.Where(type => type.BaseType.IsGenericType && type.BaseType.GetGenericTypeDefinition() == typeof(EntityTypeConfiguration<>)).ToList();
foreach (var type in typesToRegister)
{
dynamic configurationInstance = Activator.CreateInstance(type);
modelBuilder.Configurations.Add(configurationInstance);
@ahmadalli
ahmadalli / gist:386da39e4c5db3f8999e170d1b50783f
Last active March 13, 2020 01:51 — forked from JayBazuzi/gist:9e0de544cdfe0c7a4358
How to reformat all C# files in a solution, in Visual Studio
# How to reformat all C# files in a solution, in Visual Studio 2012.
#
# Open Tools->Library Package Manager->Package Manager Console, and run the
# command below. At the end, all documents will be open in the IDE. (Low-RAM
# machines will have problems with large solutions.) Changed files will be
# modified in the IDE, and not saved to disk. You can SaveAll, then Close All
# if you're ready.
#
# VS2012 removed the VB-like macro language that existed in previous version of
# Visual Studio. However, the underlying DTE interface is still there, and you
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace SummaryTool
{
public static class SummaryTool
#fill $ip, $user, $pass with right values
$ip = '192.168.1.1'
$user = 'user'
$pass = 'pass'
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
Authorization = $basicAuthValue
}
@ahmadalli
ahmadalli / BatchInstallLatestFaWordpess.ps1
Last active January 28, 2017 11:14
Installs latest version of Persian Translation of WordPress
$locations = @(
"location1",
"location2",
"location3")
#download
$salt = Get-Date
$salt = [math]::abs($salt.GetHashCode())
$url = "https://downloads.wordpress.org/release/fa_IR/latest.zip"
$zipFilePath = "$PSScriptRoot\wordpress-$salt.zip"
Import-Module BitsTransfer