How to check CLR Version Installed

In this article we will see “How to check how many CLRs installed on your local machine?”, “What is the use of having multiple CLRs?”

Let’s start with first questions: In my local machine I have installed VS2012 so if I go and check on “C:\Windows\Microsoft.NET\Framework” path

Framworks

it shows me these many .Net framework versions. So there should be 6 CLRs right? Answer for this question is no. Then how to find how many CLRs are installed on my local machine. The way is to go to VS command prompt and type “clrver” command it will list

down the CLRs installed on your local machine as shown in below screen.

CLRs

So, it is clear that on my local machine there are two CLRs, one is Version 2 and another one is Version 4.  Version 2 support .Net framework 3.5 also.  So if you go and check in VS2008 and run the same above command you will get only Version 2. Question will come in your mind “What is the use of having multiple CLRs?”: Answer is in .Net framework 4 and onward Microsoft has introduced dynamic language support which was not there in earlier version.

Advertisements

#clr

Copy one tree view to another – Recursive Method

Below is the practical example of recursive method to copy one tree view control’s nodes into another tree view.

aspx file code:
TreeView

CSharp file code:

private void IterateTreeNodes(TreeNode originalNode, TreeNode rootNode)
    {
        foreach(TreeNode childNode in originalNode.ChildNodes)
        {
            TreeNode newNode = new TreeNode(childNode.Text);
            newNode.Text = childNode.Text;
            rootNode.ChildNodes.Add(newNode);
            IterateTreeNodes(childNode, newNode);
        }
    }
    protected void btnCopyTreeView_Click(object sender, EventArgs e)
    {
        foreach (TreeNode originalNode in TreeView1.Nodes)
        {
            TreeNode newNode = new TreeNode(originalNode.Text);
            newNode.Text = originalNode.Text;
            TreeView2.Nodes.Add(newNode);
            IterateTreeNodes(originalNode, newNode);
        }
    }

#tree-view-control

Lambda exp, Func generic delegate, Action generic delegate, and Predicate generic delegate

Lambda expression, Funct generic delegate, Action generic delegate, and Predicate generic delegate make your delegate code more simple.

Lambda expression helps to build expression tress -> LINQ, BL (Business Language).

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data;
using System.Linq;
using System.Linq.Expressions;

namespace ConsoleApplication2
{
    class Program
    {
        //Lambda expression, Funct generic delegate, Action generic delegate, and Predicate generic delegate make your delegate code more simple
        //Lambda expression helps to build expression tress -> LINQ, BL (Business Language)
        delegate double delCal(int r);
        delegate int delSum(int x, int y);
        static void Main(string[] args)
        {
            //1)
            /**********Lambda expression, Funct generic delegate, Action generic delegate, 
            and Predicate generic delegate make your delegate code more simple************/

            //Simple delegate
            delCal dc = CalArea;
            double Area = dc.Invoke(20);
            //End

            //Anonymous function
            delCal dCal = new delCal(delegate(int r){return 3.14 * r * r;
            }
            );
            double Area2 = dCal.Invoke(20);
            //End

            //Lambda expression -> (input parameters) => expression
            delCal dCalL = r => 3.14 * r * r;
            double Area3 = dCalL.Invoke(20);

            delSum delsum = (x, y) => { x = x + 10; y = y + 10; return x + y; };
            int sum = delsum.Invoke(10, 10);
            //End

            //Lambda + Func => Func is used when we want to pass input and get the out of any type.
            Func delFun = r => 3.14 * r * r;
            double delFunArea = delFun.Invoke(20);
            //End
            
            //Action => It take input but doesn't return output.
            Action oAction = O => Console.WriteLine(O);
            oAction.Invoke("Hello World");
            //End
            
            //Predicate => Used when function should return either True or False value to take further decision or action.
            Predicate oPredicate = O => O.Length > 4;
            bool bl = oPredicate.Invoke("Izhar");
            //End

            //2)
            /**************Lambda expression helps to build expression tress -> LINQ, BL (Business Language)************/

            //Example: (10+15)-(10+5)
            //http://www.codeproject.com/Articles/19154/Understanding-LINQ-C
            BinaryExpression be1 = Expression.MakeBinary(ExpressionType.Add, Expression.Constant(10), Expression.Constant(15));
            BinaryExpression be2 = Expression.MakeBinary(ExpressionType.Add, Expression.Constant(10), Expression.Constant(5));
            BinaryExpression be = Expression.MakeBinary(ExpressionType.Subtract, be1, be2);

            int intResult = Expression.Lambda<Func>(be).Compile()();
            //End
        }

      
        static double CalArea(int r) {
            return 3.14 * r * r;
        }
    }
}

#action-generic-delegate, #and-predicate-generic-delegate, #func-generic-delegate, #lambda-exp

Star Schema

Definition:

The star schema architecture is the simplest data warehouse schema. It is called a star schema because the diagram resembles a star, with points radiating from a center. The center of the star consists of fact table and the points of the star are the dimension tables.

Brief explanation:

In Star Schema, usually the fact tables are in third normal form(3NF) whereas dimensional tables are de-normalized. Despite the fact that the star schema is the simplest architecture, it is most commonly used nowadays and is recommended by Oracle.

Fact Tables

A fact table typically has two types of columns: foreign keys to dimension tables and measures those that contain numeric facts. A fact table can contain fact’s data on detail or aggregated level.

Dimension Tables

A dimension is a structure usually composed of one or more hierarchies that categorizes data. If a dimension hasn’t got a hierarchies and levels it is called flat dimension or list. The primary keys of each of the dimension tables are part of the composite primary key of the fact table. Dimensional attributes help to describe the dimensional value. They are normally descriptive, textual values. Dimension tables are generally small in size then fact table.

Typical fact tables store data about numerical facts like Revenue,  countable facts while dimension tables data about geographic region(markets, cities) , clients, products, times, channels.

The main characteristics of star schema:

  • Simple structure -> easy to understand schema
  • Great query effectives -> small number of tables to join
  • Relatively long time of loading data into dimension tables -> de-normalization, redundancy data caused that size of the table could be large.
  • The most commonly used in the data warehouse implementations -> widely supported by a large number of business intelligence tools

 

Problem:

“Students attend online courses from various geographies. Online courses are authored by teachers. The DW should allow the analysis of the attendance , and the factors that affect the popularity of courses .

You do not need to create SQL statements in this problem. The answer should describe in words a data model for the problem , names of the main tables , description of what they will contain, and relationships. Describe any assumptions you may need to make.”

Solution:

Things to consider are  Attendance of student (can be a measure), Geographies (Location dimension), Time to attend online course (dimension), Teachers (can be a dimension), Courses  (can be a dimension)
Fact table contains :
                                1) Foreign key reference to
                                Location, Time, Teachers, Courses Dimensions
                                2) Fact / Measure : Attendance
Dimension tables: Location, Time, Teachers and Courses

#star-schema

Password Encryption

In this article we will discuss why Password encryption is important and how to do it.

In many web site user authentication is done and this authentication is taken care by using user name and password to verify user details to allow him to perform different operations using the web site. The most import thing here is, if you store the user password in plain text and then validate it when user enters the credential in order to perform different activities then you are basically compromising the user on your web site and also on other web sites as user can use the same password for other web sites as well. This should not be the case. So, what is the best way to handle this problem. The answer to this is ENCRYPTION.

The encryption also should be One-Way encryption. What does one way encryption means? One way encryption means non-reversible (will never decrypt), even by us also.

The best technique to achieve this is to hash the password using Hashing Algorithm.

i.e. Same inputs + same hashing algorithm = same output.

The logic to implement and validate involve below steps:

1) Encrypt the user password using hashing algorithm and then store it.

2) Encrypt the user attempted password for authentication and then compare against the stored password.

Below is the list of few hashing algorithm available:

  • MD5
  • SHA-1
  • SHA-2 (SHA-256, SHA-512)
  • Whirlpool
  • Tiger
  • AES
  • Blowfish

Example using C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string strPass = HashString("Password1");
        }

        public static string HashString(string strPass)
        {
            byte[] b = ASCIIEncoding.ASCII.GetBytes(strPass);
            SHA1 sh = new SHA1CryptoServiceProvider();
            sh.ComputeHash(b);
            byte[] hsh = sh.Hash;
            string pass = "";
            for (int i = 0; i < hsh.Length; i++)
            {
                //change it into 2 hexadecimal digits
                //for each byte
                pass += hsh[i].ToString("x2");
            }
            return pass;
        }
    }
}

Note*: In order to implement Hashing you need add the reference of System.Security dll and import/use System.Security.Cryptography namespace.

#encryption

REVERSE Function in SQL Server

Reverse Function: Reverse function is used to reverse the text provided to the command.

Using reverse function you can not only reverse the content but also along with the CharIndex function you can extract the substring as you are extracting by finding the last index in other programming language.

Example:

Select REVERSE(‘E:\ABC\PQR\Test.txt’) Rev, REVERSE(SUBSTRING(REVERSE(‘E:\ABC\PQR\Test.txt’),0,CHARINDEX(‘\’,REVERSE(‘E:\ABC\PQR\Test.txt’)))) FileName

Output:

 

Reverse

 

#reverse-function

Loop through directory and sub directories to find file and copy using Power Shell script

In this article we will talk about how to search and copy the file using power shell by searching for file recursively inside file system directory.

Resolution:

1) Loop through Main directory for files

2) Loop through each sub directory inside main directory and so on.

3) Compare File Name with file searched inside the directories, if match found then copy the file and break the loop and search for another file.

Below is the example of Power Shell script.

$Source ='D:\SourceFolder'
$Dest = 'D:\DestinationFolder\'

$FilesandFolders = Get-ChildItem -Path $Source -Recurse

ForEach($Item in $FilesandFolders){
              ForEach($FileName In Get-Content D:\FileNames.txt){
                     if($fileName -eq $Item.Name){
                           Copy-Item -Path $Item.FullName -Destination $Dest
                           Break;
                     }
              }
}

Where -Recurse keyword along with Get-ChildItem force to get list recursively for all items.

Get-Content is the command to read the content of the file.

Copy-Item command used to copy the file from one location to another.

 

 

#copy-file-using-power-shell