Saturday 13 July 2013

Program to Print Password char on Enter Password in Console Application [Masking the Password]

     




  
                                                                                                                                                              Most of the Time developers may face this thing that while receive a password from user through console Application , The password is visible in the window for the user it leads to others knew our password.so this application will tell us that how to get the password in console application as Password char 

Code :



Output for this Program:








Microsoft Sql Server version and the Difference between the versions

Introduction to Sql Server :
    The Abbreviation of SQL is Structured Query Language.It is the standard query language for accessing the Database.Microsoft Sql Server is a Relational Database Server developed by Microsoft.




Microsoft had launched various versions of Sql Server.
  • Sql Server 2000
  • Sql Server 2005
  • Sql Server 2008
  • Sql Server 2008 R2
  • Sql Server 2012
Microsoft Sql Server 2000 is a full-featured relational database management system.That offers variety of administrative tools to ease the burden of administration maintenance and database development.

Administrative tools :
1. Enterprise Manager.
2. Query Analyzer
3. Service Manager
4. Data Transformation service
5. Books Online
6. Sql Profiler

Microsoft Sql Server 2005
New Features available in the 2005 version are ,It has new indexing algorithms, syntax and better recovery system.

1. ETL Tool (SSIS or Business intelligence studio)
2. SQL CLR
3. Reporting Server
4. Analysis service (OLAP and Data Mining)
5. Service Broker and Notification Service
6. Supports XML Data type

Microsoft Sql Server 2008
New Features available in the 2008 version are ,Supports the ADO.Net Entity Framework and the Reporting tools, Replication and  Data Definition will be built around the Entity Data Model.

1. It have better comparison features 
2. Flat Earth and Round Earth are newly introduced data type to represent the Geometric and Geographic         data.
3. Full text search functionality is newly added
4. FILESTREAM new datatype is introduced 
5. Change Tracking

Microsoft Sql Server 2008 R2 
New feature available in version 2008 R2 is Central Management of master data entities and hierarachies.

1. Master data management 
2. Multi server management : A centralized console to manage the multiple sql server versions, including the       services like Reporting,Analysis and Integration.
3. PowerPivot for Excel and sharePoint.
4. StreamInSight, ReportBuilder 3.0, Addins for sharePoint

Microsoft Sql Server 2012
New feature available in version 2012 

1. Native support OLEDB instead of ODBC for native connectivity.

Friday 12 July 2013

Microsoft Change Tracking Sync data from One server to two or more offline - Sql Server Part -1

What is change Tracking in Sql Server ?

Change Tracking is the light weight application, helping the developers to track the data changes takes place in database.Most commonly change track is used to sync the data between the two server applications.

That means synchronization the data from server to the two or more offline store applications.





In Microsoft they release a Change Tracking system in Sql Server 2008 , Which have following features.

1. Efficient and fast
2. Easy to track the data.
3. Minimum disk space
4. Regular clean up of additional table data.

To work with change tracking , we have to  Enable the change Tracking in Database and table .In which we have to track the data .

/* Functions used in change tracking */
CHANGETABLE()   
CHANGE_TRACKING_CURRENT_VERSION()   
CHANGE_TRACKING_MIN_VALID_VERSION()
CHANGE_TRACKING_IS_COLUMN_IN_MASK()   
WITH CHANGE_TRACKING_CONTEXT()

/* Change Tracking database */
Use Master;
Go
Create Database CT
Go

/* Create the Change Tracking Table */
USE CT
CREATE TABLE [SALESTRACKING]
(
SALEID INT PRIMARY KEY,
PRODUCTNAME VARCHAR(40),
MODEL VARCHAR(40)
)

/* INSERT 4 RECORDS */
INSERT INTO [SALESTRACKING] VALUES(1,'LG','AC45')
INSERT INTO [SALESTRACKING] VALUES(2,'SAMSUNG','S453')
INSERT INTO [SALESTRACKING] VALUES(3,'WHIRLPOOL','WL87')
INSERT INTO [SALESTRACKING] VALUES(4,'APPLE','IP342')
GO

SELECT * FROM SALESTRACKING

Check the Properties of database about Change Tracking by default it is disabled false

1. Right click the database
2. Select properties
3. Select the change tracking page
4. Now you can see the change tracking status



USE master
GO
ALTER DATABASE CT
SET CHANGE_TRACKING = ON

Now Change tracking is enabled your database .We have addtional two optional parameters (CHANGE_RETENTION,AUTO_CLEANUP). 
CHANGE_RETENTION         : MAINTAIN THE DATA OF HOW MANY DAYS
AUTO_CLEANUP                    : CLEAN THE OLD DATA AUTOMATICALLY IF IT IS ON

USE master
GO
ALTER DATABASE CT 
SET CHANGE_TRACKING = ON (CHANGE_RETENTION = 100 DAYS,AUTO_CLEANUP = ON)
GO

ENABLE THE CHANGE TRACKING FOR TABLE TO TRACK THE DATA
1. Right click the table
2. Select the properties
3. Select the change tracking page
4. Now you can see the change tracking status.


USE CT
GO
ALTER TABLE [dbo].[SALESTRACKING]
ENABLE CHANGE_TRACKING WITH (TRACK_COLUMNS_UPDATED = OFF)

TRACK_COLUMNS_UPDATED: This parameter is used to indicate the columns which are changed by UPDATE operation and also indicates that row has changed. By default, it is OFF. 

Now delete two row and insert one row

DELETE FROM [SALESTRACKING] WHERE SALEID = 1
INSERT INTO [SALESTRACKING] VALUES(8,'LG','AC45')

Now we get the change tracked data by executing the following query

SELECT SYS_CHANGE_VERSION,SYS_CHANGE_OPERATION,SALEID
FROM CHANGETABLE(CHANGES [dbo].[SALESTRACKING],0)AS SI
ORDER BY SYS_CHANGE_VERSION

(OR EXECUTE THIS )

SELECT * FROM CHANGETABLE(CHANGES SALESTRACKING,0)AS SI
ORDER BY SYS_CHANGE_VERSION 



From this article we can learn how to enable the change tracking in Database and tables to track.Above image will show that what kind of change that data goes


Microsoft .Net Framework implementation of Generics in Custom Linked List C#

What is Generics ?

Generics is the Concept of defining a common Template for all kind of data type. It ensure the Type Safety.
Same class or same Algorithm can be derived for all kind of Data Types . generally it is defined  by "T" character.

Feature and Advancement of Generics are , 
1. It increases the Performance of a application.
2. Reusable code.

Let's we see the Generics concepts implemented in Linked List
LinkedList  is a data structure used to store the data in linear manner. LinkedList Node stores the data internally, Node consists of additional information which will have the address of next item which is added to the linked list.

Data's are iterate from head to the tail using the address of next item ,which is present in the current node
Here a,b,c,d,e,f are the data's .

a is stored in address  1000, Point the next data by there address 2000
is stored in address  2000, Point the next data by there address 3000
is stored in address  3000, Point the next data by there address 4000
is stored in address  4000, Point the next data by there address 5000
is stored in address  5000, Point the next data by there address 6000
is stored in address   6000, Point the next data by there address 7000





So Let we create a Common LinkedListNode class which will support all data type.

Now we create a custom Linked list with one method "Add" and iterate the data through foreach 

class Program
    {
    
    
        public static void Main(string[] args)
        {
            LinkedList<int> list1=new LinkedList<int>();
            list1.Add(2);
            list1.Add(4);
            list1.Add(5);
            foreach(int j in list1)
                Console.WriteLine("Number {0}",j);
        
            LinkedList<string> list2=new LinkedList<string>();
            list2.Add("C#");
            list2.Add("Java");
            list2.Add("Sql");
            foreach(string k in list2)
                Console.WriteLine("String {0} ",k);
                    
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }

output




We see the implementation of Generics in LinkedListNode . Node consists of Value which will store the data and Prev , Next store the address of Previous and Next Value.

      public class LinkedListNode<T>
    {
        private T _value;
        public T Value
        {
            get {return _value;}
        }
      
        private LinkedListNode<T> _next;
        public LinkedListNode
<T> Next
        {
            get{return _next;}
            internal set{_next = value;}
        }
      
        private LinkedListNode
<T> _prev;
        public LinkedListNode<T> Prev
        {          
            get{return _prev;}
            internal set{_prev = value;}
        }
      
        public LinkedListNode(T value)
        {
            this._value = value;  
        }              
    }
   
Now the LinkedList will store the LinkedListNode on addition of each value.This class is implemented simply actually it can be implemented by adding more methods and properties. like Remove,Exists,Length etc.

   public class LinkedList
<T>:IEnumerable<T>
    {
        private LinkedListNode
<T> _first;
        public LinkedListNode<T> First
        {
            get {return _first;}
        }
      
        private LinkedListNode
<T> _last;
        public LinkedListNode<T> Last
        {          
            get {return _last;}
        }
      
        public void Add(T value)
        {
            LinkedListNode
<T> node=new LinkedListNode<T>(value);
            if(_first==null)
            {
                _first = node;  /* Now assign the value to first node */
                _last = _first;
            }
            else
            {
                _last.Next = node;
                _last=node;
            }
        }
      
        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
      
        public IEnumerator GetEnumerator
<T>()
        {
            LinkedListNode
<T> cur=_first;
            while(cur!=null)
            {
                yield return cur.Value;
                cur = cur.Next;
            }
        }
    }
     From this article we can see the basic information of custom implementation of Generic LinkedList .

Thursday 11 July 2013

Microsoft .Net Framework internal implementation Binary Search in List (Collection) - Data structure

                 In Dotnet framework System.Collections is a namespace where we can find the collection class like Stack, Queue, LinkedList ,List etc.Now in this article we are going to see the real implementation of List inside the framework and explanation of how we are using the List in our code.

                          It is designed to be fast for internal implementations, It contains lot of useful operation such as Binary Search,Sort etc.The methods on List are not virtual and so cannot be overridden.Let we see the How to code List and get the data from that collection. In List  T refers to the datatype of the collection , so because of this declaration boxing and unboxing are avoided in storing and retrieve the data from collection. We can store any type . Each type have individual object.




Output : 




Now let we see the implementation of Binary Search in List class internally in framework. This algorithm is used to find the Element exist in List and return the index of that element.

Binary Search is actually implemented in Array , It is called from List for check the item exists.

Code for Binary Search Tree :









From this article we can see the Algorthim BinarySearch used for search the item exist in List

Wednesday 10 July 2013

Microsoft internel implementation of Stack C# - Data Structure and Algorithm



What is the usage of Data structures in programming?        
      Data structures are used to store the Data in formatted manner and process the data in algorithm way

         Data structure used by an algorithm can greatly affect the algorithm's performance, it is important that there exists a rigorous method by which to compare the efficiency of various data structures. What we, as developers utilizing a data structure, are primarily interested in is how the data structures performance changes as the amount of data stored increases. That is, for each new element stored by the data structure, how are the running times of the data structure's operations effected?

Now Let we take the Example of Stack 

        Stack which follows the LIFO algorithm , LIFO means the data which is inserted last can be taken first from the collection. Real time example is Place the CD's in CD Pouch and take it back .

Stack have 2 Operations Push (insert the data into the stack), Pop (remove and returns the last item from stack)






In C# Stack Example :

using System.Collections;

class Program
    {     
        public static void Main(string[] args)
        {                 
            Stack sample=new Stack();
            sample.Push("Rajesh");
            sample.Push("Suresh");     
            string name=sample.Pop().ToString();
            Console.WriteLine(name);
            Console.Read();
        }

    }

Output : Suresh 


In this stack one dis-advantage is we have to cast the value from object to our type. It is not a Generic Stack.

Let we see how Microsoft implemented this class in .Net FrameWork, Now we see the internals of this class detailed. Not all the Stuff. we can see the Methods  Push,Pop, Contains,Clear and make the stack to iterate the values in foreach. by Implement the Enumertor.


From the below screenshot we can see that custom stack have few 4 methods and one property




calling part of custom stack, In the following code I am inserting a few objects to the stack and remove an object from the top of the stack.  Always objects are removed from Top of the stack.





Output of the Above code



From the output you can see that name "Ramu" is removed and return from the top of the stack,Values are returning in the Format of LIFO Raju is last inserted but it is printed first.then Suresh, Rajesh.

Code for the User Defined Stack : Which follows the LIFO Algorithm


namespace Custom
{



using System;
using System.Collections;

    class Stack:IEnumerable
    {

        private object[] _array;

        private int _size;

        private int _version;

        private const int _defaultCapacity = 10;

        public class StackEnumerator:IEnumerator
        {
            private Stack _stack;
            private int _index;
            private int _version;
            private object _curelement;

            public StackEnumerator(Stack stack)
            {
                this._stack = stack;
                this._version = this._stack._version;
                this._index = -2;
                this._curelement = null;
            }

            public virtual object Current
            {
                get 
                {

                    if (this._index == -2)
                    {
                       throw new InvalidOperationException("Enum not started");
                    }
                    if (this._index == -1)
                    {
                        throw new InvalidOperationException("Enum ended");
                    }

                    return this._curelement;
                
                }
            }

            public virtual bool MoveNext()
            {
                bool flag;
                if (this._index == -2)
                {
                    this._index = this._stack._size;
                    flag = (--this._index >= 0);
                    if (flag)
                    {
                        this._curelement = this._stack._array[this._index];
                    }
                    return flag;
                }
                if (this._index == -1)
                {
                    return false;
                }
                flag = (--this._index >= 0);
                if (flag)
                {
                    this._curelement = this._stack._array[this._index];
                }
                else
                {
                    this._curelement = null;
                }
                return flag;
            }

            public virtual void Reset()
            {
                this._index = -2;
                this._curelement = null;
            }
        }

        public virtual int Count
        {
            get { return this._size; }
        }

        public Stack()
        {
            this._array = new object[_defaultCapacity];
            this._size = 0;
            this._version = 0;
         }
        

        public Stack(ICollection col):this((col==null)? 32 : col.Count)
        {
            if (col == null)
                throw new ArgumentNullException("col");

            IEnumerator enumerator = col.GetEnumerator();
            while (enumerator.MoveNext())
            {
                this.Push(enumerator.Current);
            }
        }

        public Stack(int capacity)
        {
            if (capacity < 0)
            {
                throw new ArgumentNullException("capacity is less than Zero");
            }

            if(capacity>10)
            {
               this. _array = new object[capacity];
            }
            else
            {
                this._array = new object[_defaultCapacity];
            }
            this._size = 0;
            this._version = 0;
        }

        public virtual void Clear()
        {
            Array.Clear(this._array, 0this._size);
            this._size = 0;
            this._version++;
        }

        public virtual bool Contains(object obj)
        {
            int size = this._size;
            while (size-- > 0)
            {
                if (obj == null)
                {
                    if (this._array[size] == null)
                    {
                        return true;
                    }
                }
                else
                {
                    if (this._array[size].Equals(obj))
                        return true;
                }
            }
            return false;
        }

        public virtual void Push(object obj)
        {
            if (this._size == this._array.Length)
            {
                Array.Resize(ref this._array, 2 * this._array.Length);
            }
            this._array[this._size++] = obj;
            this._version++;
        }

        public virtual object Pop()
        {
            if (this._size == 0)
            {
                throw new InvalidOperationException("there is no element to remove from stack");

            }
            this._version++;
            object result = this._array[--this._size];
            this._array[this._size] = null;
            return result;
        }

        public IEnumerator GetEnumerator()
        {
            return new StackEnumerator(this);
        }

    }

}



From this article we can learn the Stack implementation and usage of algorithm in that.