Skip to content

Instantly share code, notes, and snippets.

@thuru-zz
thuru-zz / jwt claims based authorization.xml
Created April 22, 2018 10:15
jwt claims based authorization
<policies>
<inbound>
<!-- validates RS256 JWT token -->
<validate-jwt header-name="massrover_token" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized"
require-expiration-time="true" require-signed-tokens="true">
<audiences>
<audience>audience id</audience>
</audiences>
<issuers>
<issuer>issuer id</issuer>
@thuru-zz
thuru-zz / cosmos change feed azure function.csx
Created June 13, 2018 13:05
cosmos change feed azure function
using Microsoft.Azure.Documents;
using System.Collections.Generic;
using System;
public static async Task Run(IReadOnlyList<Document> input, TraceWriter log)
{
foreach(var changeInput in input)
{
if(changeInput.GetPropertyValue<string>("city") == "colombo")
{
@thuru-zz
thuru-zz / ChangeFeedSQLSDKProvider.cs
Created June 13, 2018 13:09
cosmos change feed sql sdk
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SQLSDK
{
@thuru-zz
thuru-zz / cosmos change feed processor library.cs
Created June 18, 2018 15:40
cosmos change feed processor library
public class ChangeFeedProcessorSDK
{
private readonly DocumentCollectionInfo _monitoredCollection;
private readonly DocumentCollectionInfo _leaseCollection;
public ChangeFeedProcessorSDK(DocumentCollectionInfo monitorCollection, DocumentCollectionInfo leaseCollection)
{
_monitoredCollection = monitorCollection;
_leaseCollection = leaseCollection;
}
@thuru-zz
thuru-zz / layered project.csproj
Last active July 2, 2018 07:52
layered project DV
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net471</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
@thuru-zz
thuru-zz / DV wrong reference.cs
Created July 2, 2018 07:54
DV wrong reference
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
// This is right
services.AddSingleton<IProductService, ProductService>();
// this is wrong and DV should fail
services.AddSingleton<IMyDbContext, MyDbContext>();
}
@thuru-zz
thuru-zz / httpsys listener.cs
Last active July 30, 2018 17:10
Http Sys and Static Port in SF
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new ServiceInstanceListener[]
{
new ServiceInstanceListener(serviceContext =>
new HttpSysCommunicationListener(serviceContext, "GatewayHttpSysServiceEnpoint", (url, listener) =>
{
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting HttpSys on {url}");
return new WebHostBuilder()
@thuru-zz
thuru-zz / ReverseProxyServiceResponseFilter.cs
Created August 1, 2018 15:53
Reverse Proxy Service Response Filter
public class ReverseProxyServiceResponseFilter : IResultFilter
{
public void OnResultExecuted(ResultExecutedContext context)
{
if(context.HttpContext.Response.StatusCode == 404)
{
context.HttpContext.Response.Headers.Add("X-ServiceFabric", "ResourceNotFound");
}
}
@thuru-zz
thuru-zz / reverse proxy call.cs
Created August 1, 2018 16:02
sf reverse proxy call
string reverseProxyUrl = "http://localhost:19801/ApplicationName/InternalServiceName/RestOfTheUri";
var httpClient = new HttpClient();
var response = await httpClient.GetAsync(reverseProxyUrl);
@thuru-zz
thuru-zz / reverse proxy call.cs
Created August 1, 2018 16:02
sf reverse proxy call
string reverseProxyUrl = "http://localhost:19801/ApplicationName/InternalServiceName/RestOfTheUri";
var httpClient = new HttpClient();
var response = await httpClient.GetAsync(reverseProxyUrl);