Monday, 29 January 2018

Azure AD: Tenant and Audience


The single parameter passed to the middleware, WindowsAzureActiveDirectoryBearerAuthenticationOptions, supplies the settings for determining a token’s validity. It captures the raw values during project creation and stores them in the web.config file. The Audience value is the identifier by which the Web API is known to Windows Azure AD. Any tokens carrying a different Audience are meant for another resource and should be rejected.


The Tenant property indicates the Windows Azure AD tenant used to outsource authentication. The middleware uses that information to access the tenant and read all the other properties (such as which key should be used to verify the token’s signatures) that determine the validity of a token.

Friday, 26 January 2018

Simple Multi Tasking program in C#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks; 

namespace multitasking
{
    class Program
    {
        static void Main(string[] args)
        {
            execute();
            Console.WriteLine("end of the program");
            Console.Read();
        } 

        static async Task execute()
        {
            Program p1 = Activator.CreateInstance(typeof(multitasking.Program)) as Program;
            Task t = p1.run1();
            Task t1 = p1.run2();
            await Task.WhenAll(t, t1);
            Console.WriteLine("end of the program class");
        }

        async Task run1()
        {
            await Task.Run(() =>
             {
                 for (int i = 0; i < 100; i++)
                 {
                     Console.WriteLine("Run 1:" + i);
                     Task.Delay(5000);
                 }
             });
        }

        async Task run2()
        {
            await Task.Run(() =>
             {
                 for (int i = 0; i < 100; i++)
                 {
                     Console.WriteLine("Run 2:" + i);
                     Task.Delay(1000);
                 }
             });
        }
    }
}

 

Sunday, 21 January 2018

Lambda Expression VS Delegates

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Practice
{
    class Program
    {
        delegate int Mysetup(int q, int p);
        static void Main(string[] args)
        {
            Expression<Mysetup> exp = (x, y) =>  y + x ; // using lambda expression to create a expression tree
            Mysetup mysetup = (x, y) => { return y + x; }; //using lambda expression creating a method
            Mysetup mysetupAnonymous = delegate(int s,int t){ return s + t; }; // using delegates creating anonymous method

            Mysetup seup = exp.Compile();
            int result = seup(10, 20);
            int result1 = mysetup(10, 20);
            int result2 = mysetupAnonymous(10, 20);

        }
    }
}


Wednesday, 17 January 2018

Running unit tests (MS Test) using Console commands in windows

1.navigate to the testproject.dll folder in solution\project\bin\debug
2.run below command
MSTest /testcontainer:TestProject.dll