Wednesday, 23 November 2016

Factory Dessign Pattern

Step1: Create a console project in visual studio
step2: create a class Dream and replace the class with the following code.

Story:
    //One rich guy has 4 kinds of vehicles, He has an habit riding in dream, He chooses one vehicle among those he own and goes for night ride.

When?

    //When  to go for Factory Design pattern ?
    //Ans:
    // If you want to create an object at run time dynamically based on some flag
    // The creation of object is done when it is required.
    // create object without exposing the creation logic.
    /// <summary>
    /// When to use Factory Pattern
    ///
    /// Subclasses figure out what objects should be created.
    /// Parent class allows later instantiation to subclasses means the creation of object is done when it is required.
    /// The process of objects creation is required to centralize within the application.
    /// class (creator) will not know what classes it will be required to create.
    /// </summary>
    ///


How?

Method1: Implement the above scenario without any factory.


  class BiCycle
    {
        public void RideVehicle()
        {
            Console.WriteLine("Ride Bicycle at 20 kmph");
            describeBicycle();
        }
        public void describeBicycle()
        {
            Console.WriteLine("bicycle has handle and breaks to control speed");
        }
    }
    class Scooter
    {
        public void RideVehicle()
        {
            Console.WriteLine("Ride Bicycle at 80 kmph");
            describeScooter();
        }
        public void describeScooter()
        {
            Console.WriteLine("Scooter has handle , breaks, Gear system to control speed");
        }
    }
    class Car
    {
        public void RideVehicle()
        {
            Console.WriteLine("Ride Bicycle at 100 kmph");
            describeCar();
        }
        public void describeCar()
        {
            Console.WriteLine("Car has Steering , breaks, Gear system to control speed");
        }
    }
    class Helicopter
    {
        public void RideVehicle()
        {
            Console.WriteLine("Ride Bicycle at 150 kmph");
            describeCopter();
        }
        public void describeCopter()
        {
            Console.WriteLine("Copter has Steering , cookpit voice control,GPS , Gear system to control speed");
        }
    }
   
    class Dream
    {
        static void Main()
        {
        
            Console.WriteLine("He is dreeming... and choose a vehicle....");
            string choosenVehicle = Console.ReadLine();
            if (choosenVehicle == "b")
            {
                var b = new BiCycle();
                b.RideVehicle();
            }
            else if (choosenVehicle == "s")
            {
                var s = new Scooter();
                s.RideVehicle();
            }
            else if (choosenVehicle == "c")
            {
                var c = new Car();
                c.RideVehicle();
            }
            else if (choosenVehicle == "h")
            {
                var h = new Helicopter();
                h.RideVehicle();
            }
        }
    }








//Method2: Implement the same with factory pattern



    public interface IVehicle
    {
        void RideVehicle();
    }
    class BiCycle : IVehicle
    {
        public void RideVehicle()
        {
            Console.WriteLine("Ride Bicycle at 20 kmph");
            describeBicycle();
        }
        public void describeBicycle()
        {
            Console.WriteLine("bicycle has handle and breaks to control speed");
        }
    }
    class Scooter : IVehicle
    {
        public void RideVehicle()
        {
            Console.WriteLine("Ride Bicycle at 80 kmph");
            describeScooter();
        }
        public void describeScooter()
        {
            Console.WriteLine("Scooter has handle , breaks, Gear system to control speed");
        }
    }
    class Car : IVehicle
    {
        public void RideVehicle()
        {
            Console.WriteLine("Ride Bicycle at 100 kmph");
            describeCar();
        }
        public void describeCar()
        {
            Console.WriteLine("Car has Steering , breaks, Gear system to control speed");
        }
    }
    class Helicopter : IVehicle
    {
        public void RideVehicle()
        {
            Console.WriteLine("Ride Bicycle at 150 kmph");
            describeCopter();
        }
        public void describeCopter()
        {
            Console.WriteLine("Copter has Steering , cookpit voice control,GPS , Gear system to control speed");
        }
    }
    public class DecideVehicle
    {
        private IVehicle vehicle;
        public IVehicle DreemVehicle(string vName)
        {
            switch (vName)
            {
                case "b":
                    vehicle = new BiCycle();
                    break;
                case "s":
                    vehicle = new Scooter();
                    break;
                case "c":
                    vehicle = new Car();
                    break;
                case "h":
                    vehicle = new Helicopter();
                    break;
                default:
                    vehicle = new Scooter();
                    break;
            }
            return vehicle;
        }
    }
    class Dream
    {
        static void Main()
        {
            DecideVehicle decideVehicle = new DecideVehicle();
            int contine = 0;
            do
            {
                Console.WriteLine("He is dreeming... and choose a vehicle....");
                string choosenVehicle = Console.ReadLine();
                IVehicle vehicle;
                vehicle = decideVehicle.DreemVehicle(choosenVehicle);
                vehicle.RideVehicle();
                Console.WriteLine("Do you want to continue ride press 1 then ?");
                contine = int.Parse(Console.ReadLine());
            } while (contine == 1);
       
        }
    }



I hope this is usefull....

Tuesday, 22 November 2016

Cloud Computing

Cloud Computing:

Cloud computing can be referred to as the storing and accessing of data over the internet rather than your computer's hard drive. This means you don't access the data from either your computer's hard drive or over a dedicated computer network (home or office network). Cloud computing means data is stored at a remote place and is synchronized with other web information.

Ex: 

One prominent example of cloud computing is Office 365 which allows users to store, access, edit their MS Office documents online (in browser) without installing the actual program on their device

Cloud provider: One who provides cloud resources to the public over the internet are called as cloud providers.
Ex: Microsoft Azure, Google cloud, Amazon Web services are popular cloud computing platforms.

Microsoft Azure:

Azure can be described as the managed data centers that are used to build, deploy, manage the applications and provide services through a global network.

all cloud resources are categorized into 3.
1. IAAS 2. PAAS 3. SAAS

The following diagram describes these words.





All Services provided by azure are categorised into 3 again:                                                             
1. Compute resources 2. Storage Resources 3. Network Resiurces

    
                                                                                                                       
     




























Git commands to push your code to a git repository



HOW To Push your code to GIT

$ git <navigate to your solution folder in your local system>
$ git init

$ git add .

$ git commit -m "First Commit"

$ git remote add origin <your git https url>

$ git remote -v

$ git push origin master

Visual Studio Short cuts makes my job easier

CTRL+M CTRL+M (that's two key presses!) - collapse/open the current parent region

CTRL+M CTRL+L - Collapse/Open all regions in document recursively (meaning you might get only one line in the document - one big namespace region which is collapsed or you'll see the entire page code uncollapsed

CTRL+M CTRL+O - Collapse all regions not recursively

Prop tab tab     - to create property in the class

[type keyword] +tab   - To generate type

Eg:   class<press Tab>   - It will generate class


while<press Tab>   -to generate while loop
for<press Tab>       - to generate for loop
foreach<press Tab>       - to generate for each loop
do<press Tab>       - to generate do while loop

Ctrl+k+d    --- to align the code in the visual studio

Ctrl+ shift+b   -- to build solution

ctrl+shift+A   -To add any new item(class,interface,web page etc.) in the solution explorer


How to create a region

Select all code to which you want to generate region and then press

ctrl+S+ choose #region or    #region + <press tab>


Code snippets:

ctrl+X and choose which ever you want.




How to run a Csharp file using command line

Step1: Create a csharp project

create a folder MyProject on desktop.

open notepad and copy the bellow code and save as helloworld.cs file in the above folder


using System;
namespace HelloWorld
{
    class Hello
    {
        static void Main()
        {
            Console.WriteLine("Hello India");

            // Keep the console window open in debug mode.
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }
}


step2: Set environment variables for visual studio command line

C:\Program Files (x86)\Microsoft Visual Studio 14.0>cd\

C:\>cd Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools>VsDevCmd.bat

step3: Run the program

 From the Start menu, open the Developer Command Prompt for VS2015

C:\Program Files (x86)\Microsoft Visual Studio 14.0>cd\

C:\>cd Users\Techjini\Desktop\MyProject

C:\Users\Techjini\Desktop\MyProject>csc helloworld.cs
Microsoft (R) Visual C# Compiler version 1.3.1.60616
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Users\Techjini\Desktop\MyProject>helloworld
Hello India

Dependency Injection in C#

Dependency Injection : Injecting all dependent objects