Skip to content

Instantly share code, notes, and snippets.

View TanmayDharmaraj's full-sized avatar
🏠
Working from home

Tanmay Dharmaraj TanmayDharmaraj

🏠
Working from home
View GitHub Profile
@TanmayDharmaraj
TanmayDharmaraj / revision.cs
Last active December 20, 2017 06:15
Read manifest JSON and return revised filename created via gulp-rev
public static class Revision
{
public static string Version(string path)
{
if (HttpRuntime.Cache[path] == null)
{
using (StreamReader sr = new StreamReader(HostingEnvironment.MapPath("~/Scripts/rev-manifest.json")))
{
Dictionary<string, string> rev = JsonConvert.DeserializeObject<Dictionary<string, string>>(sr.ReadToEnd());
string revedFile = rev.Where(s => path.Contains(s.Key)).Select(g => g.Value).FirstOrDefault();
@TanmayDharmaraj
TanmayDharmaraj / rev-manifest.json
Last active December 20, 2017 06:16
A revision manifest created by gulp-rev
{
"assets/css/site.compiled.css": "assets/css/site-1db21d418d.compiled.css",
"js/site.min.js": "js/site-ff3eec37bc.min.js",
"vendors/vendors.js": "vendors/vendors-ebd24a3d51.js"
}
@TanmayDharmaraj
TanmayDharmaraj / gulp-revision.task.js
Created December 20, 2017 06:18
Sample gulp task to create revisioned file
const gulp = require('gulp');
const rev = require('gulp-rev');
gulp.task("revision", function () {
return gulp.src(["./Scripts/dist/**/*.js", "./Scripts/dist/**/*.css"])
.pipe(rev())
.pipe(gulp.dest("./Scripts/dist"))
.pipe(rev.manifest())
.pipe(gulp.dest("./Scripts"));
});
@TanmayDharmaraj
TanmayDharmaraj / IGlobalStore.cs
Created December 20, 2017 06:26
Global store interface
public interface IGlobalStore
{
string GetCorrelationId();
string GetRequestId();
}
@TanmayDharmaraj
TanmayDharmaraj / GlobalStore.cs
Created December 20, 2017 06:26
Implementation of IGlobalStore
public class GlobalStore : IGlobalStore
{
private string CorrelationId { get; set; }
private string RequestId { get; set; }
public GlobalStore() { }
public GlobalStore(CorrelationContext correlation_context)
{
if (correlation_context != null)
@TanmayDharmaraj
TanmayDharmaraj / Startup.DI.cs
Created December 20, 2017 06:28
Sample DI setup
var builder = new ContainerBuilder();
var config = GlobalConfiguration.Configuration;
//This provides HTTPContext
builder.RegisterModule(new AutofacWebTypesModule());
//..
//Other registrations
//..
builder.RegisterType&amp;lt;GlobalStore&amp;gt;()
@TanmayDharmaraj
TanmayDharmaraj / ApiExceptionFilter.cs
Created December 20, 2017 06:29
Exception filter
public class ApiExceptionFilter : ExceptionFilterAttribute
{
private IGlobalStore _gStore { get; set; }
public override void OnException(HttpActionExecutedContext actionExecutedContext)
{
var scope = actionExecutedContext.Request.GetDependencyScope();
var _gStoreFactory = scope.GetService(typeof(IGlobalStore)) as IGlobalStore;
string correlationId = "";
//Good to check if _gStore is null to avoid null exception.
@TanmayDharmaraj
TanmayDharmaraj / gulp-html-revision-task.js
Created January 31, 2018 13:47
A gulp task to create revisions for angular tempaltes
const gulp = require('gulp');
const rev = require('gulp-rev');
const b2v = require('buffer-to-vinyl');
const ngConfig = require('gulp-ng-config');
gulp.task("revision-html", function () {
return gulp.src(["./Scripts/dist/**/*.html"])
.pipe(rev())
.pipe(gulp.dest("./Scripts/dist"))
.pipe(rev.manifest("rev-manifest-html.json"))
@TanmayDharmaraj
TanmayDharmaraj / rev-manifest-html.js
Created January 31, 2018 14:05
Angular config constant.
(function () {
return angular.module("my.constants").constant("HTML", {
"views/modules/applications/applications.html": "views/modules/applications/applications.html",
"views/modules/home/home.html": "views/modules/home/home.html"
});
})();
@TanmayDharmaraj
TanmayDharmaraj / ng-interceptor.js
Created January 31, 2018 14:09
http interceptor
(function (angular) {
angular.module('my')
.factory('customHttpInterceptor', ['HTML', function (html) {
return {
request: function (config) {
if (config.url.indexOf('views/') > 0) {
if(config.url.indexOf('deployments-history/history.html') > 0){
console.log("called history");
}
var key = config.url.replace("Scripts/dist/", "")