Wednesday, February 19, 2014

Start Scripting with PowerShell

Variables

$ is used in PowerShell to create and use variables.
First time in Programming, you can use space in variable.
You can use latters, numbers, spaces and underscores in variables.
Example:
$MyVar = 7
${My Var} = “Test”
You can also give Variable type like string, integer.
Example:
                [String]$MyName = “Ronak”
                [int]$Test = 6
Now if you give $Test = “test” it will give error. Because $Test is fixed for type [int].
You can use variable as multiple types by using runtime type casting.
Example:
                $x = [int] 6  ß This will store 6 as integer in variable x
Now, $x = “Test” ß This will store string into variable x.
You can use all variable types which are available in .NET.
You can also use following commands:
  • New-Variable
  • Set-Variable
  • Get-Variable
  • Clear-Variable
  • Remove-Variable


Quotation Marks

Pay attention! Single quotes and Double quotes performs differently in PowerShell.
Double Quotes resolves all variables.
Single Quotes prevents substitutions.
Example:
$x = 2
"The Value of $x is $x" ß The Value of 2 is 2
'The Value of $x is $x' ß The Value of $x is $x
"The Value of `$x is $x" ß The Value of $x is 2

Back-trick (` sign available below Esc key) is used to prevent individual substitutions.

Getting started with PowerShell


The Purpose of PowerShell
PowerShell allow you to improve the windows management and helps to improve automation.
PowerShell manages real-time commands with large-scale integration.

How to install PowerShell
PowerShell V3 is comes with Windows Management Framework 3.0
PowerShell V3 is compatible with
  • Windows 8
  • Windows Server 2012
  • Windows 7 SP1
  • Windows Server 2008 R2 SP1
  • Windows Server 2008 SP2

Download Windows Management Framework 3.0
Prerequisite: Full .NET Framework 4.0
Windows XP and Windows Server 2003 can run PowerShell V2
TIP: Always run PowerShell as Administrator.

PowerShell Security Goals
By default PowerShell is secured.
It prevents mistakes by unintentional admins and users.
By clicking on scripts it will not execute scripts, so mistakes can be avoided.
.ps1 extension can be used with notepad or any text editor. You can also use PowerShell ISE. We will talk about this later.
We must have to type full path of file to access or execute file. Shorten paths are restricted to prevent mistakes.

Execution Policy
In PowerShell, there are some execution policies defined for security levels.
By default execution policy is Restricted, which does not execute the script.
Command to know your current execution policy:
        GET-ExecutionPolicy
Command to set execution policy:
        SET-ExecutionPolicy <TYPE>
TYPE can be like
  • Restricted
  • Unrestricted
  • AllSigned
  • Remotesigned
  • Bypass
  • Undefined

Windows PowerShell ISE
The Windows PowerShell Integrated Scripting Environment (ISE) is a host application for Windows PowerShell. In Windows PowerShell ISE, you can run commands and write, test, and debug scripts in a single Windows-based graphic user interface with multiline editing, tab completion, syntax coloring, selective execution, context-sensitive help, and support for right-to-left languages. You can use menu items and keyboard shortcuts to perform many of the same tasks that you would perform in the Windows PowerShell console.  For example, when you debug a script in the Windows PowerShell ISE, to set a line breakpoint in a script, right-click the line of code, and then click Toggle Breakpoint.

Feature of PowerShell ISE
  • Multiline editing: To insert a blank line under the current line in the Command pane, press SHIFT+ENTER.
  • Selective execution: To run part of a script, select the text you want to run, and then click the Run Script button. Or, press F5.
  • Context-sensitive help: Type Invoke-Item, and then press F1. The Help file opens to the Help topic for the Invoke-Item cmdlet.

To start Windows PowerShell ISE
  • Click Start, point to All Programs, point to Windows PowerShell V2, and then click Windows PowerShell ISE.
  • In the Windows PowerShell console Cmd.exe, or in the Run box, type, powershell_ise.exe



Sunday, February 16, 2014

C# - Delegates

What is Delegates?
In a simple language, as we use in C and C++, a pointer which points to the functions. In C# there is no pointer, but delegates are working as a pointer to function.
A delegate is a reference type variable that holds the reference to a method. The reference can be changed at run-time.

Use of Delegates
When we want to use functionality of Events and Call-backs at that time delegates comes to the picture.
Delegates are used to pass methods as arguments to other methods. Event handlers are nothing more than methods that are invoked through delegates. You create a custom method, and a class such as a windows control can call your method when a certain event occurs.

Declaration of Delegates
Declaration of delegates determines the methods that can be referenced by the delegate.
All methods which are refers to delegate must have same signature as delegate.


          delegate   <return type>   <delegate-name>    <parameter list>
public    delegate       int            MyDelegate         (string s);

Example
 

using System;

delegate int Calc(int n);
namespace DelegateAppl
{
   class TestDelegate
   {
      static int num = 0;
      public static int AddNum(int p, int q)
      {
         num = p + q;
         return num;
      }

      public static int MultNum(int p, int q)
      {
         num = p * q;
         return num;
      }
      public static int getNum()
      {
         return num;
      }

      static void Main(string[] args)
      {
         //create delegate instances
         Calc c1 = new Calc(AddNum);
         Calc c2 = new Calc(MultNum);
         //calling the methods using the delegate objects
         c1(25,30);
         Console.WriteLine("Value of Num: {0}", getNum());
         c2(5,6);
         Console.WriteLine("Value of Num: {0}", getNum());
         Console.ReadKey();
      }
   }
}


Output:
Value of Num: 55
Value of Num: 30
  



Friday, February 14, 2014

Create Simple Web Service in Visual Studio

STEP 1 : Create a simple Web service

When creating a New Project, under the language of your choice, select "Web" and then change to .NET Framework to your choice and you will get the option to create an ASP.NET WEB Service Application.



I am naming my WEB Service as MyWebService.
 
Now you can see the "Service1.asmx.cs" file and also a "[WebMethod] HelloWorld()" in it.

You can add your methods as I show below.


Service1.asmx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace Myservice
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class Service1 : System.Web.Services.WebService
    {
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
        [WebMethod]
        public string CheckOddandEvenMethods(int a)
        {
            string results;
            if (a % 2 == 0)
            {
                return results = a + "_" + "Is a Even Number";
            }
            else
            {
                return results = a + "_" + "Is a odd Number";
            }
        }
    }

}

After add WebMethods of your choice, you can run your Service.

STEP 2 : Create Client Program

To create client program select NewProject and select "Console Application" in "Windows" Tab.




I am naming my client "ClientAccess".
Now you need to add a Service Reference so that you can access your web service.
To add service reference:
  1. In Solution Explorer, right-click the name of the project that you want to add the service to, and then click Add Service Reference.
    The Add Service Reference dialog box appears.
  2. Click Discover.
    All services in the current solution are added to the Service list. If not available then manually add them by clicking Advance Tab.
  3. In the Service list, expand the node for the service that you want to use and select a service contract.
  4. In the Namespace box, enter the namespace that you want to use for the reference.
  5. Click OK to add the reference to the project.
  6. A service client (proxy) is generated, and metadata describing the service is added to the app.config file.
After adding service reference write program to use service.


Program.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

using ClientAccess.Mytestapp; // Here you need to write namespace Name and its WebReference Name //

namespace ClientAccess
{
    class Program
    {
        static void Main(string[] args)
        {
            // To call Webservice Here
            Service1 Myapp = new Service1();
            string Result = Myapp.CheckOddandEvenMethods(10);
            Console.WriteLine(Result2);
            Console.ReadLine();
        }
    }
} 

Finally Build Project and Run the Project.
Now you can publish your WebApplication in IIS.

For any query regarding this page Comment below.

Tuesday, February 12, 2013

M.Tech/M.S(without GATE)

Some of the reputed colleges in India have their own entrance exams for the admission so friends those who have not appeared for GATE or have not qualified in their GATE exams there a hope for all of you.
Below are some of the well known colleges-

1) IIIT- Hyderabad
2) IIIT - Bangalore
3) IIIT - Delhi 
4) BITS
5) VIT  
6) SRM

All these colleges have limited seats and also the forms for entrance exams are already available so please check out ASAP.

Again I would suggest you all to collect all information about the colleges and then only go for admission in some college,please do not haste!


After B.E?

Hello friends,these are the few last months of your B.E and I hope you all are enjoying them at the fullest.
Well everyone is about to get their Bachelors but at the same time its high time to think about your future too.Some of you want to go for Higher studies, or some for the Job.So for those who want to go for higher studies they have many options for them and that is sort of confusing too.Some of the options available are-

1)M.Tech/M.S(with GATE): Many of you have already appeared for their GATE exams and I do hope you all did great out there.The admissions in all IITs and NITs is based on the GATE exam scores. Keep checking newspapers and keep yourself updated with the information about the colleges.

2)M.Tech/M.S(without GATE): For the students who have appeared for GATE but are not expecting good marks or those who have not appeared for GATE,there is no need to panic.Some of the reputed colleges in India provide M.Tech without considering the GATE scores,the only thing is that they have their own entrance exams which you have to clear and they have their own admission process.Sounds a better option guys!! Please hurry up as the forms for the colleges are already available also also they have limited seats.

3)Masters Abroad: Some of you want to complete their studiea abroad so they have to appear and pass the exams of GRE as well as TOEFL or IELTS. 


Please collect all information about the colleges and then only go for admission in some college,please do not haste!!

Thursday, December 6, 2012

CPD Updated Scheme

Subject: Contributor Personality Development Program
Sub Code: 1990001 

Updated from October 2012

All sections are compulsory. 

Total Marks: 70 

Section A   Marks: 15

Instructions: This section has a scenario. Read carefully before answering the subsequent questions. There are 4 questions in this section. All questions are compulsory. Each question has 3 options, choose ONLY ONE option which you consider the most appropriate option. Read carefully before answering.

Section B  Marks:20

Instructions: There are 10 questions in this section. All questions are compulsory. Each question has 2 statements. Select ONLY ONE statement you feel is closest to your thinking and mark it on the answer sheet given to you.

 Section C   Marks:5

Instructions: This section has 5 questions. All questions are compulsory. Each question has 4 options. Rank in order of your importance / preference from highest to lowest. Choose ONLY ONE option closest to your ranking and mark it on the answer sheet given to you.  

Section D   Marks:30

Instructions: There are 10 questions in this section. All questions are compulsory. Each question has 3 options. Select ONLY ONE option you feel is the most appropriate and mark it on the answer sheet given to you.


 

 

For model question paper : click here

For more detail: gtuhelpdesk.blogspot.com or mail us to gtuhelpdesk@gmail.com

Freemarket.com Marketplace