Enabling Web Api Tracing

By default ,Tracing is disabled in web api , tracing incoming request might help to track issues in production environment.

Enabling Tracing :

Install the following package from Nuget :

Microsoft.AspNet.WebApi.Tracing

and have the startup .cs configured as below

config.EnableSystemDiagnosticsTracing();

Trace/Log of incoming request to a controller

Capture

Object Comparisons — Difference between Equals method and ==

When we compare two objects with same content,there is a difference between “Equals and  == “.

Equals :

The Equals method does the content based comparison between two objects.

== :

“==” compares only object references.

Scenarios :


Sample s = new Sample () { a = "Hey" };
Sample s1 = s;
Sample s4 = new Sample () { a = "Hey" };

 Console.WriteLine(s1==s);  // True --Compares the instances 

Console.WriteLine(s==s4); // False ---Eventhough content is same,still == looks only for reference.

Console.WriteLine(s.Equals(s4)); // True --- Compares the value in field "a"  in both object and returns true.

String is an exceptional case and its immutable. It behaves with == as Equals.

 

 

 

 

 

 

Dynamic Linq

There are cases where you might need to use dynmaic linq in your Linq Queries, for instance filtering of items based on multiple where clause.

Assume you have list of following Items :


var listofmobiles = new List<Mobile>()

{ 

new Mobile(){ModelNo=1,MobileType= "Android"}

new Mobile(){ModelNo=2,MobileType= "Android"}

new Mobile(){ModelNo=3,MobileType= "BlackBerry"}

new Mobile(){ModelNo=4,MobileType= "Symbian"}

new Mobile(){ModelNo=5,MobileType= "IOS"

}

 }

public class Mobile

{

public long ModelNo {get;set;}

public string MobileType {get;set;}

}

We would write a simple linq query if we where suppose to query only one of mobiletype,assume a case where there can be more than one mobiletype(Android,Ios) the list should still return the items under Android and Ios.

Expression Trees :

To write Dynamic Linq queries,we must construct expression tress that matches the where clause.I am not going to explain more about expression tree but instead usage of System.Dynamic.Linq feature provided by framework which uses expression trees.

Using Dynamic Linq in where clause :

Given different mobiletype (Ios,Android,Symbain ) filter out the above list that matches the mobiletype.


var filterresult =listofmobiles.where("mobiletye @0 or mobiletye @1 or mobiletye @2","Android","IOS","Symbain").Tolist();

#Bitcoin C#:Creating Bitcoin address using NBitCoin

1.Get NBitcoin from Nuget package.

Bitcoin Address : 

It is payment address which either begins with 1 or 3 ,its more of a combination of secure private and public key hash that is generated using cryptographic algorithm.To end user,its simply an address which is useful for sending/receiving bitcoins.

Generating Bitcoin using NBitcoin :


 Key bitcoin = new Key();
 var bitcoinaddress=bitcoin.PubKey.GetAddress(Network.TestNet);
 Console.WriteLine(bitcoinaddress);

Its as simple as that, you create a key and decide which network to generate bitcoin address.There are two networks MainNet(Real world) and TestNet(Test Environment).

 

WebHook in .NET

What is WebHook ?

A webhook is a provider that helps you to get data from external system  as and whenit flows into the system.These are real time data that is exposed over HTTP as and when data flows into system.

Components in WebHook :

Receiver : This type of webhook pulls the data  from external system to your server.

Sender  : This type of webhook is responsible for exposing your data to external system.

WebHook with .NET :

.NET does support web hook and there are various type of web hook that is customized  according to business need.

Types of WebHook Libraries provided by .NET :

  1. GitHubWebHook.
  2. SlackWebHook.
  3. GenericWebHook (This is the one which you use at custom level,the webhook is not tied to any providers like github,stripe instead you can define/customize  to your needs)

References :

https://github.com/aspnet/WebHooks

Inputs in Angular 2

Inputs helps pass the data dynamically to the component. There are situations where you pass data to component and in turn component would invoke the service and fetch the desired result.Inputs are ideally suitable for such situation.

Defining Inputs in Component :

  1. @Input  directive in the Component which is imported from angular2/core.
  2. Defining Inputs in Component MetaData.

Example  of Inputs with directive:


import {Component,Input} from 'angular2/core'

@Component({

'selector':inputsample,

'template':"<span>{{Name}} </span>"

})

export class InputsampleComponent

{

@Input Name ;

}

Using  Input in Root/App Component :


<inputsample [Name ]="somename"> </inputsample>

#Bitcoins-Programming Bitcoins in C#-Resources.

I have started using Bitcoins and Block Chain technologies and with the .NET Stack had found the following libraries quite useful.

What is Bitcoins ?

 

They are nothing more than virtual currencies which are accepted worldwide.They use the Block Chain technology which holds the transaction in distributed servers.

Libraries in C# :

Bitcoin itself is in the initial phase of evolution,there are only few libraries and I am listing the one which was pretty useful for me,

Nicolas Dorier- BitCoin libraries:

BitCoin-Client   : https://github.com/NicolasDorier/BlockchainProgramming

BitCoin-Server :  https://github.com/NicolasDorier/BlockchainProgramming

GeorgeKimionis-Bitcoin libraries:

https://github.com/GeorgeKimionis/BitcoinLib

They both are transaction oriented.