Saturday, March 23, 2013

General Awareness previous question paper for AndharaBank


General Awareness previous question paper for AndharaBank 

1. Who amongst the following does not belong to political party which is normally referred as left front?
(A) Prakash Karat
(B) A. B. Bardhan
(C) D. Raju
(D) T. J. Chandrachoodan
(E) M. Veerappa Moily
Ans (E)
Hint : M.Veerappa Moily is a congress leader.

2. Sujat and Balsara villages were in news recently as breach in main Narmada Canal made them
flooded. Both these villages are in which of the following States?
(A) Maharashtra
(B) Madhya Pradesh
(C) Gujarat
(D) Rajasthan
(E) None of these
Ans : (C)

3. As per the estimates given by the Asian Development Bank (ADB) the Indian Economy will grow at
which of the following rates in 2008 ?
(A) 7%
(B) 7.5%
(C) 8%
(D) 8.5%
(E) None of these
Ans : (C)

4. Which of the following is NOT one of the recommendations of the committee setup on Financial
Sector Reforms under the Chairmanship of Raghuram G.Rajan ?
(1) Give more freedoms to banks to setup branches and ATMS anywhere
(2) Setup an office of financial ombudsmen
(3) All deposits taking institutions should be free from the supervision of the RBI
(A) Only 1
(B) Only 2
(C) Only 3
(D) All 1, 2 & 3
(E) Only 2 & 3
Ans : (A)
5. The Govt. of which of the following States has formed a Fisherman Debt Commission and a
moratorium has been placed on proceedings relating to all debts incurred by poor fisherman from banks
and cooperatives?
(A) West Bengal
(B) Keral
(C) Orissa
(D) Karnataka
(E) None of these
Ans : (B)
6. Federal Reserves is the Central Bank of—
(A) Britain
(B) U.S.A.
(C) Japan
(D) Canada
(E) China
Ans : (B)
7. Which of the following was the issue over which one section of the UPA withdrew its support and
Union Govt. headed by Dr. Man Mohan Singh was required to prove its majority in the Lok Sabha ?
(1) Inflation, which was on a rise consistently for some time
(2) Reservations of Gurjarrs in Govt. jobs
(3) Nuclear deal with USA
(A) Only 1
(B) Only 2
(C) Only 3
(D) Both 1 & 2
(E) Only 2 & 3
Ans : (C)
8. As a gesture to promote denuclearization and also to end nuclear arms programme the cooling tower
of a nuclear complex situated in "Youngbyon" was demolished recently. This nuclear complex is in which
of the following countries?
(A) South Korea
(B) Iran
(C) China
(D) North Korea
(E) None of these
Ans : (D)
9. The Reserve Bank of India (RBI) keeps on modifying various rates / ratios to keep the flow of liquidity
in the market in a balanced situation. Which of the following rates/ratios/indexes is NOT directly
controlled by the RBI?
(A) Cash Reserve Ratio (CRR)
(B) Bank Rate
(C) Repo Rate
(D) Reserve Repo Rate
(E) Wholesale Price Index (WPI)
Ans : (E)
10. China has signed an agreement with which of the following countries, which will help both the
parties to make the East China Sea "a sea of peace, co-operation and friendship”?
(A) North Korea
(B) South Korea
(C) Japan
(D) Russia
(E) All of these
Ans : (C)
11. The former President of which of the following countries has taken over as the Prime Minister ofthe
nation in May 2008 ?
(A) Venezuela
(B) Russia
(C) Uganda
(D) Tanzania
(E) None of these
Ans : (B)
12. Which of the following companies of Indian origin has been placed amongst the World's seven Best
Firms in Financial Sector ?
(A) IDBI Bank
(B) HDFC Bank
(C) Bajaj Capitals
(D) ICICI Bank
(E) None of these
Ans : (B)
13. Michel Sleiman has taken over as the president of—
(A) Lebanon
(B) Cuba
(C) Yemen
(D) Zambia
(E) Turkey
Ans : (A)
14. Which of the following is/are true about the "Pradhan Mantri Adarsh Gram Yojana" to be launched
in the near future ?
(1) This scheme is to develop those villages where SC/ST population is in prominence
(2) About 70,000 villages are identified for the same
(3) A special fund of Rs.7,000 Crore is setup for the scheme
(A) Only 1
(B) only 2
(C) Only 3
(D) All 1, 2 & 3
(E) None of these
Ans : (A)
15. Which of the following countries had decided to come out of the membership of OPEC ?
(A) Iran
(B) Indonesia
(C) Kuwait
(D) Saudi Arabia
(E) None of these
Ans : (B)
16. Many Banks have adopted / launched "Core Banking Solution (CBS)" .Core Banking Solution is—
(A) a marketing strategy adopted by the Banks
(B) a new type of ATM useful for rural population
(C) a delivery channel for quick and fast delivery
(D) a new product launched to help senior citizens only as they are not able to visit branches / ATMs
frequently
(E) None of these
Ans : (C)
17. As per the figures released recently, the rate of growth of agriculture during 2007-08 has been at the
level of approximately—
(A) 2.5 %
(B) 3 %
(C) 4.5 %
(D) 5 %
(E) 6.33 %
Ans : (C)
18. The import of which of the following has raised the Current Account Deficit of India by about 77 %?
(A) Oil
(B) Gas
(C) Sugar
(D) Foodgrain
(E) None of these
Ans : (A)
19. The National e-Governance plan was launched by the Govt. of India in the year 2006 with which of
the following intentions/objectives?
(1) To provide qualitative service of Govt. business to the citizens of India
(2) To promote IT sector in India so that trained IT personnel do not go out of the country for jobs
(3) To keep a vigil on the business transaction of Indian population to avoid illegal transactions
(A) Only 1
(B) Only 2
(C) Only 3
(D) All 1, 2 & 3
(E) None of these
Ans : (A)
20. As per the figure released recently what was the per capita income at Current Price in the year 2007-08 in India? About—
(A) Rs. 20,000/-(B) Rs. 25,000/-(C) Rs. 23,000/-(D) Rs. 33,000/-(E) Rs. 48,000/-Ans : (D)
21. Ana Ivanovic won the "French Open Women's Singles" of Lawn Tennis after defeating—
(A) Katrina Srebtnik
(B) Dinara Safina
(C) Virginia Ruano Pascual
(D) Victoria Azarenka
(E) None of these
Ans : (B)
22. The World Environment Day is celebrated on which of the following days?
(A) 5th October
(B) 5th August
(C) 5th July
(D) 5th June
(E) None of these
Ans : (D)
23. Who amongst the following is included in the list of "Biggest Brains in Business"?
(A) L. N. Mittal
(B) Anil Ambani
(C) Kumar Mangalam Birla
(D) Mukesh Ambani
(E) Ratan Tata
Ans : (A)
24. Which of the following cannot be called as a value Added service offered by a Bank?
(A) Special accounts for poor sections of the society
(B) Accident insurance cover
(C) Instant Credits of Outstation Cheques
(D) Free cheque book
(E) All are value Added services
Ans : (D)
25. Which of the following is the total amount Government of India has earmarked for Agriculture Debt
Waiver and Debt Relief Scheme 2008?
(A) Rs.10,000 Crore
(B) Rs.25,000 Crore
(C) Rs.45,000 Crore
(D) Rs.72,000 Crore
(E) Rs.83,000 Crore
Ans : (D)
26. Which of the following States of India was recognized as the Best e- Governed State in 2007 ?
(A) Jammu & Kashmir
(B) Tamil Nadu
(C) Madhya Pradesh
(D) Goa
(E) Delhi
Ans : (E)
27. Daiichi Sanyo which has taken a major stake in India's Pharma company Ranbaxy is a firm based in—
(A) China
(B) South Korea
(C) North Korea
(D) Japan
(E) USA
Ans : (D)
28. Which of the following airlines became the first Indian Based Airlines to operate flight to China?
(A) Indian
(B) Air India
(C) Kingfisher
(D) Jet Airways
(E) None of these
Ans : (D)
29. Which of the following meets / summit was organized in Damascus in March 2008 ?
(A) Arab League Summit
(B) G-8 Summit
(C) G-15 Summit
(D) Meeting of trade Minister of WTO members
(E) None of these
Ans : (A)
30. India recently signed a Bilateral Investment Promotion Agreement (BIPA) with which of the following
countries ?
(A) China
(B) Bangladesh
(C) Nepal
(D) Bhutan
(E) Myanmar
Ans : (E)
31. Opening the Saving Bank Account of a minor girl will be called as which of the following in Banking
terminology ?
(A) Retail Banking
(B) Merchant Banking
(C) Institutional Banking
(D) Social Banking
(E) Corporate Banking
Ans : (A)
32. Which of the following terms NOT used in Banking Sector?
(A) SLR
(B) NPA
(C) Credit Rating
(D) Fixed
(E) PURA
Ans : (E)
33. Banking Sector will fall under which of the following sectors?
(A) Agriculture Sector
(B) Service Sector
(C) Manufacturing
(D) Industrial Sector
(E) None of these
Ans : (B)
34. An account in which trading of shares in their electronic form is done is known as—
(A) Demat Account
(B) NRI Account
(C) NRIO Account
(D) Current Account
(E) None of these
Ans : (A)
35. Which of the following is NOT a measure of the Risk Management in Banks ?
(A) CRR
(B) RTGS
(C) SLR
(D) Deposit Insurance
(E) All are the measures of risk management
Ans : (B)
36. The foreign Direct Investment this year in India reached to the level of about US $ 3.74 billion. In
comparison to last years investment the increase is About _______
(A) 50 %
(B) 100%
(C) 125 %
(D) 200 %
(E) 250 %
Ans : (C)
37. The duration of which of the following Policies / Schemes is from 2004–2009 ?
(A) Foreign Trade Policy
(B) 11th Five Year Plan
(C) 10th Five Year Plan
(D) National Rural Guarantee Act
(E) None of these
Ans : (A)
38. Which of the following test is conducted to know if a sportsman has taken any performance
enhancing drugs ?
(A) EEG
(B) Narco Test
(C) ELISA Test
(D) Mind mapping
(E) DOPE tEST
Ans : (E)
39. Who amongst the following is the recipient of the IIFA Awards 2008 as Best Actress?
(A) Shamita Shetty
(B) Rani Mukherjee
(C) Priyanka Chopra
(D) Konkana Sen
(E) Kareena Kapoor
Ans : (E)
40. Who amongst the following is the author of the book "Toward a Hunger Free World" ?
(A) A. P. J. Abdul Kalam
(B) Ashok Lahiri
(C) Amartya Sen
(D) M. S. Swaminathan
(E) None of these
Ans : (D)
41. Which of the following awards is given in the field of cinema?
(A) Kalidas Samman
(B) Dronacharya Award
(C) Arjun Award
(D) Kalinga Award
(E) Dada Sahab Phalke Award
Ans : (E)
42. Sudan recently cut its ralations with which of the following countries following an attack on
Khartoum by a Darfur Rebel Group ?
(A) Chad
(B) Uganda
(C) Libya
(D) Lebanon
(E) None of these
Ans : (A)
43. Who amongst the following is the Chairperson of the Children's Film Society?
(A) Kareena Kapoor
(B) Jaya Bachchan
(C) Shabana Azmi
(D) Sridevi
(E) None of these
Ans : (E)
Hint : Nafisa Ali
44. Which of the following is the abbreviated name of an autonomous organization under Ministry of
Rural Development ?
(A) NIMI
(B) IGNOU
(C) CAPART
(D) NPCIL
(E) ICRP
Ans : (C)
45. World's largest oil reserves (about 2/3rd) are located in—
(A) Russia
(B) Middle East
(C) Africa
(D) Europe
(E) Canada
Ans : (B)
46. Who amongst the following is the author of "Animal People" which was adjudged as the Best Book
of the Year?
(A) V.S.Naipaul
(B) Indra Sinha
(C) William Darlymple
(D) Bill Clinton
(E) John Banville
Ans : (B)
47. What is India's rating in the "Doing Business Report" prepared by the World Bank ?
(A) 55th
(B) 80th
(C) 100th
(D) 120th
(E) None of these
Ans : (D)
Hint : According to 2008 India's rating in the "Doing Business Report" prepared by the World Bank was
120th but to 2009 India's rating in the "Doing Business Report" prepared by the World Bank is 122nd
position.
48. Which of the following term related with the game of Cricket ?
(A) Grand Slam
(B) Half Nelson
(C) Ashes
(D) Screen
(E) Love
Ans : (C)
49. The Russian President visited China in May 2008 and signed a deal for the security of which of the
following?
(A) Global Energy
(B) China Sea
(C) Intellectual Property Rights of the Chinese Scientists
(D) Nuclear installation in China
(E) None of these
Ans : (D)
50. Which of the following Programmes / Schemes of the Govt. of India is NOT directly related with
agriculture activities ?
(A) Drought Prone Areas Programmes (DPAP)
(B) Promotion of Integrated Pest Management (IPM)
(C) Integrated Westlands Development Programme (IWDP)
(D) ANNAPURNA
(E) Desert Development Programme (DDP)
Ans : (D)

Wednesday, March 20, 2013

Microsoft .Net Framework


What is Microsoft.NET platform?

Microsoft .NET is a software development platform based on virtual machine based architecture. Dot net is designed from the scratch to support programming language independent application development. The entire .NET programs are independent of any particular operating system and physical hardware machine. They can run on any physical machine, running any operating system that contains the implementation of .NET Framework. The core component of the .NET framework is its Common Language Runtime (CLR), which provides the abstraction of execution environment (Physical machine and Operating System) and manages the overall execution of any of the .NET based program.

With dot NET, Microsoft introduces a completely new architecture for Windows applications (WinForm), Data Access (ADO.NET), Web Applications (ASP.NET), Windows components (Assemblies), Distributed Applications (.NET remoting), and above all the XML based Web Services. The famous figure for the representation of dot net is presented below:

What is the .NET framework?

The .NET framework is a collection of all the tools and utilities required to execute the .NET managed applications on a particular platform. The MS.NET framework includes the standard compilers (C#, VB.NET, J#, C++.NET, Jscript.NET), various utilities like (caspol, ngen, installutil, tlbimp, sn, asmreg, ildasm, etc), runtime environment (CLR), garbage collector, security manager, thread manager, assembly loader, just in time compilers, and the standard framework or base class libraries. It is important to realize that while the implementation of .Net applications is platform independent; the implementation of .NET framework is platform specific. In fact, it is this particular specific implementation of the .NET framework that makes the managed .NET applications platform independent. 


Static vs Instance in C#.net



-The variables, methods & constructors defined under a class are known as "Members" of a class, where the members of a class are categorized into 2 types:
    -Instance Members (Non-Static)
    -Static Members

-The members under the class which requires the object of that class for initialization or execution are known as Instance or Not-Static members.

-The members under the class which doesn't require the object of that class for initialization or execution are known as Static members.

Instance Variables Vs Static Variables:

-An Instance Variable gets initialized when the object of the class is created where as a static variable is initialized when the execution of the class starts.
-If you want to declare an static variable it can be done either by using the static modifier or variables declared under a static block is also static.
int x = 100; // Instance
static int y = 200; // Static
static void Main()
{
  int z = 300; // Static
}

-The minimum and maximum no. of execution for an instance variable is 0 or n, where as in case of a static variable it is 1 and only 1.

Note: Use an instance variable if u want the changes made by one object not to be reflected to the other, use static variable if u want to reflect the changes made by one to the other.

-We refer to instance members of a class using the object of the class where as we refer to the static members of a class using the Class Name.
-------------------------------------------------------------------------------------
Static Vs Instance Methods:
-A method declared with the help of a "static" modifier is a static method and the rest are instance.

-A static method is invoked with the name of its class. eg: WriteLine is a static method under the class Console which is referred as Console.WriteLine.

-A non-static member of a class cannot be referred from a static block direclty, but still if u want to refer this can be done with the object of the class.

Note: While defining static method never refer to the non-static members with out the object of class
-------------------------------------------------------------------------------------
Static Vs Instance Constructors:

-As we were aware constructors are responsible in initializing the variables of the class, for instance variables instance constructors and for static variables static constructors were used.

-An static constructor is called only once in the life cycle of a class i.e. when the execution of the class starts, where as instance constructors are called each time u create the object of class.

-The first block of code which executes under a class is Static Constructor.

Note: If u want to perform any action once the execution of the class starts write it under the static constructor, in the same way any actions which should be performed when ever the object is created write them under instance constructor.

-Static constructors cannot be parameterized, it can be done only for instance contructors.
-------------------------------------------------------------------------------------
class Customer
{
 double bal;
 static int count = 0;
 Customer(int Custid)
 {
  count++;
  bal = <load from db>
 }

Remoting in C#.net


Application Architecture:

-Every application may contain 3 different parts in it like:
1. UI Part
2. Logic Part (BL + DL)
3. DataSource Part

-Organizations as per their requirement adopts diff architecture's for execution of their applications those are:

1. Single Tier Architecture: in this model all the 3 parts (UI + Logic + DB) will reside on the same machine to execute, so as the DB is also present on every machine changes made on 1 machine will not be reflected to the other.

2. 2-Tier  Architecture: in this model the (UI+Logic) sits on all the client machines, moving the DB to a centralized location, so all the clients connect with the same DB Server to store & access data. In this model changes made on 1 machine reflects to the other.

3. 3-Tier or N-Tier Architecture: in this model all the 3 parts will sit on 3 diff. machines to execute. On the client machine what we have is only light weight client (UI) which will connect with the logic part residing on server machine that will in turn connect with the DB Server. Maintainance of the software becomes easier in this model when there were more no. of client accessing the application.
-------------------------------------------------------------------------------------
-To develop a 3-Tier application in desktop model we have various distributed technologies like:

   -RPC (Remote Procedure Call)
   -CORBA (Common Object Request Broker Architecture)
   -RMI (Remote Method Invocation (Java))
   -DCom (Distributed Component Object Model)
   -Remoting (.Net Languages)
-------------------------------------------------------------------------------------
Remoting:
-It was a technology from Microsoft for developing distributed applications replacing traditional DCOM available under COM.

-All the distributed technologies speak about the same i.e. consuming of libraries present on remote machines.

-In .Net libraries were implemented as Assemblies, where we can consume an assembly residing on local machine by adding its reference. We can now consume Assemblies residing on remote machines also using Remoting.
-------------------------------------------------------------------------------------
Developing a Remoting Application:
-To develop a Remoting Application first we need to understand various things regarding the process of communication, those are:

1. How does both the parties (client and server) exchange information between each other ?

Ans: To exchange information between both the parties they make use of a process known as Serialization and Deserialization.

-As applications represent the data in High Level (Object Format) which are not free flowable, needs to be converted into Low Level (Binary or Text) and then transferred to the other system where on the target machine Low Level data has to be converted back into High Level.

-Serialization is a process of converting high level data to low level and De-Serialization is in opposite of serialization that converts low level data to high level.

-To perform serialization & deserialization remoting provides Formatter Classes, those are:
-Binary Formatters
  -TCPServerChannel
  -TCPClientChannel
-Soap Formatters
  -HttpServerChannel
  -HttpClientChannel
-Binary Formatters are used for binary serialization and deserialization & Soap Formatters are used for text serialization and deserialization.

Note: traditional DCOM supports only binary.
-------------------------------------------------------------------------------------
2. Marshalling and UnMarshalling:
-After serializing the data which has to be sent to the target machine it packages the data into packets this is what we call as marshalling, at this time it associates the IP Address of the target machine where the information has to be sent.

UnMarshalling is in opposite to Marshalling which opens the packets of data for de-serializing.
-------------------------------------------------------------------------------------
-Every system in a network is identified by using a unique id known as IPAddress.
-It is a 4 part numeric value where each part will be ranging between 0-255.
eg: 0-255.0-255.0-255.0-255
-We can mask IP Address of a system by specifying an alias name to it known as HostName. Systems under a network will be configured as following:
 IPAddress HostName
192.168.26.0      (nit0)
192.168.26.1      (nit1)
......
192.168.26.24   (nit24)
-------------------------------------------------------------------------------------
3. Activation Models:
-In execution of remoting application clients needs  object of remote class to invoke methods under it.

-Activation Models decide where does the remote class object resides in execution of the app.

-Remoting supports 2 different activation models:
-Server Activated Objects (SAO)
-Client Activated Objects (CAO)

-In SAO model object of remote class resides on server Machine and a reference of this object is maintained on the client machine using which clients can invoke the methods of remote class.

-In CAO model the object of remote class resides on client machine using which clients can invoke the methods of remote class.

Server Activated Objects:
-In SAO model we were again provided with 2 types like singleton and singlecall.

SingleTon:
-In this case when ever a first request comes from a client an object of remote class gets created and it's reference is given to the client, from then every new request comming from a new client, server provides the reference of same object which is already created, so changes made by 1 client gets reflected to the other.

-Used in the development of application like public chat, cricket scores, share prices etc.,

SingleCall:
-In this mode when ever a request comes from a client 1 object of remote class gets created and it's reference is given to client, once the request is served immediately object gets destroyed with out allowing him to make any other requests on that object, for a new request a new object gets created again and destroyed.

-Used in the development of single request app like "Railway PNR Status Enquiry", "ATM Machines", "Examination Results".

Note: this is very highly secured model used in app development.

Client Activated Objects:
-In this case when ever the first request from a client an object of remote class is created and provided using which the client can make any no. of requests. Here a seperate object will be given for each client so changes made by 1 client will never reflect to the other.

-Used in the development of applications that requires multiple requests for a single client.
eg: "Traditional ATM Machines", where we can perform multiple transactions once we insert the card.
-------------------------------------------------------------------------------------
4. Server:
-When we want to develop an application to be consumed from remote machines we require some one to take the request from clients. To take a request from client we use server softwares, which works on the principles request and response.

-We can install multiple server softwares on a machine, but each server should be running on a seperate logical address known as port.

-In process of developing a remoting application it is our responsibility to develop a server that takes requests of clients to the RemoteClass, because a class is not capable of taking the request.

-The server which we are going to develop has to be running on a unique port of the OS. By default every machine has port's ranging between 0-65535 in which 0-1023 were OS reserved ports, rest can be used by any app.

-After developing a Remote Server every Remote Class on the machine has to be registered under the Server with an alias name, so that clients can send their request to required class.
-------------------------------------------------------------------------------------
5. Remote Interface:

-In remoting the methods what we want to define under Remote Class, that are accessible to clients should be first declared under an interface & then implemented in remote class which was a rule.

-The same interface will also be provided to clients that acts as a Proxy to Remote Class on client machine, which will be used in 2 ways:
   1. Using it clients can recongnize methods of               remote class.
   2. Using it we can hold reference of remote class         on client machines.
-------------------------------------------------------------------------------------
Execution of a Remoting Application:

1. Client sends a request to server.
2. Server creates object of Remote Class.
3. Sends reference of that object to client which         has to be captured under interface variable.
4. After capturing, the variable gets converted into      reference pointing to the object on Server.
5. Now UI can invoke methods on the reference.
6. Methods gets executed on server machine as the     reference points to object on server.
-------------------------------------------------------------------------------------
-To develop a Remoting Application we require the following:
1. Interface (Class Library)
2. Remote Class (Class Library)
3. Remote Server (Windows Service)
4. Client (UI) (Windows or Console Application)
-------------------------------------------------------------------------------------
Developing an Interface:
-Open a new project of type class library & name it as InterfaceProject.

-Delete the Class1.cs file under project and add a Interface to the project naming it IRemoteApp.cs, and write the following code:

public interface IRemoteApp
{
   string Get_Sname(int sno);
   decimal Get_Bal(int cid);
   string SayHello();
}

-Now open solution explorer and build the project which generates an assembly.

   Project Name: InterfaceProject
   Interface Name: IRemoteApp.cs
   Assembly Name: InterfaceProject.dll
-------------------------------------------------------------------------------------
Developing a Remote Class:
-The RemoteClass needs to be inherited from the predefined class MarshalByRefObject & implement all the methods that were declared under interface.

-Open a new project of type class library and name it as ClassProject, rename the class Class1.cs as ClsRemoteApp.cs using Solution Explorer.

-Add reference of InterfaceProject.dll we have created previously & write the following code:

using InterfaceProject;
using System.Data.SqlClient;
public class ClsRemoteApp : MarshalByRefObject, IRemoteApp
{
 SqlConnection con;
 SqlCommand cmd;
 int x = 0;
 public ClsRemoteApp()
 {
  con = new SqlConnection(
    "User Id=Sa;Password=123;Database=CSharp7");
  cmd = new SqlCommand();
  cmd.Connection = con;
 }
 public string Get_Sname(int sno)
 {
  string name = "";
  try
  {
   cmd.CommandText = "Select Sname From Students Where Sno=" + sno;
   con.Open();
   name = cmd.ExecuteScalar().ToString();
  }
  catch (Exception ex)
  { ex = null; }
  finally
  { con.Close(); }
  return name;
 }
 public decimal Get_Bal(int cid)
 {
  decimal bal = 0;
  try
  {
   cmd.CommandText = "Select Balance From Customer Where Custid=" + cid;
   con.Open();
   bal = Convert.ToDecimal(cmd.ExecuteScalar());
  }
  catch (Exception ex)
  { ex = null; }
  finally
  { con.Close(); }
  return bal;
 }
 public string SayHello()
 {
  x += 1;
  return "Hello: " + x;
 }
 public string Demo()
 {
  return "Not accessible to remote clients";
 }
}

-Now open solution explorer and build the project to generate an assembly.

   Project Name: ClassProject
   Remote Class: ClsRemoteApp.cs
   Assembly Name: ClassProject.dll
-------------------------------------------------------------------------------------
Process to develop a RemoteServer:

-If you want to develop a remote server that should be started along with OS, develop it as an windows service.

-A Windows Service is an application which runs in the background process with out any knowledge to end users.

-Windows Services will be under control of OS and gets started when OS is started & stopped when we shutdown the system.

-DataBase's & Web Servers will be implemented as Windows Services only. Every system by default has no. of services installed on it.

-You can view the Services that are present on a machine making use of Service Control Manager window as following:
Start -> Settings -> Control Panel -> Administrative Tools -> Services

-Every service will have 4 attributes, those are:
1. Display Name: It is the name for identification.
2. Description: It is a brief information about the service (Optional).
3. StartupType: It decides how a service gets started on the machine, which can be set with 3 options:
   i) Automatic: Service gets started by OS.
  ii) Manual: Service needs to be started by users or some other applications.
 iii) Disabled: Service cannot be started by any one      from any where.

4. LogOnAs (Account): Indicates the account type under which the service runs, can be set with 3 options:
   i) User: runs under a particular user account.
  ii) Local System: runs under all users of the local system.
 iii) Network Service: runs under remote users   account also.

Note: While developing a windows service it is our responsibility to set all the 4 attributes we discussed above.
-------------------------------------------------------------------------------------
How to develop a Windows Service ?
-If we want to develop a windows service we can make use of "Windows Service" Project template under VS.

-If we want to choose Windows Service Project template, under New Project Window expand the Language node i.e Visual C# in the LHS panel and select the option Windows which displays Windows Service template on RHS panel.

-Every Windows Service Class is a sub class of pre-defined class ServiceBase present under System.ServiceProcess namespace.

-In a Windows Service code has to be written under few overridden methods like OnStart, OnStop, OnPause etc., which were declared as virtual under parent class ServiceBase.

-The code under OnStart executes when service is started & OnStop executes before the service is getting stopped.

-After defining code in the service class we need to set the 4 attributes discussed previously, for this, under the project we were given "Add Installer" option to set all the 4 attributes.

-Once we build the project it will generate an exe assembly that should be installed on a machine by using "installutil" tool. Once the service is installed we can view this under Services Windows of OS.
-------------------------------------------------------------------------------------
Developing Remote Server:
-Open a New Project of type Windows Service and name it as RemoteServer.

-Add reference of 3 assemblies to the project:
1. System.Runtime.Remoting.dll (.net)
2. ClassProject.dll (browse)
3. InterfaceProject.dll (browse)

-Write the following code in Code View:

using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

Under OnStart Method:
TcpServerChannel chan = new         TcpServerChannel(5000);
ChannelServices.RegisterChannel(chan, true);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(ClassProject.ClsRemoteApp), "XXX", WellKnownObjectMode.Singleton);

-Now go to design view of the project, right click on it & select Add Installer which adds 2 components ServiceInstaller1 & ServiceProcessInstaller1 using which we need to set the 4 attributes of service.

-Under serviceInstaller1 Properties set following:
1. DisplayName: Remote Server
2. Description: Takes request from remote clients
3. StartupType: Automatic.

-Under serviceProcessInstaller1 Properties set the following:
1. Account: Local System

-Now open Solution Explorer and build the Project which creates an assembly RemoteServer.exe.

Installing the service on your machine:
-To Install the service on a machine we were given with a command line utility "installutil", which has to be used as following:
installutil <service exe name>
Note: To un-install a service which is installed use as following:
installutil -u <service exe name>

-Open VS Command Prompt and go into the location where RemoteServer.exe is present and write the following:

C:\CSharp6\RemoteServer\RemoteServer\bin\Debug>installutil RemoteServer.exe

-Now we can find our service under Service Window, right click on it & select start which will start the server.

-To check server running or not open VS Command Prompt and use the following statement: "netstat -a"
-------------------------------------------------------------------------------------
-Under Server App we have done the following:

Step 1: Create an object of TcpServerChannel or HttpServerChannel by passing port no as argument to the constructor.

System.Runtime.Remoting.Channels.Tcp
TcpServerChannel(int port)

System.Runtime.Remoting.Channels.Http
HttpServerChannel(int port)

Step 2: Register the Channel under OS using RegisterChannel static method of ChannelServices class.

System.Runtime.Remoting.Channels
   ChannelServices.RegisterChannel(Channel chan, bool security)
   true - secured;   false - unsecured

Step 3: Register the Remote Class under Remote Server with an alias name using the static method RegisterWellKnownServiceType of the class RemotingConfiguration.

System.Runtime.Remoting
RemotingConfiguration.RegisterWellKnownServiceType(Type type, string alias, Mode mode)

Note: Mode can be SingleTon or SingleCall
-------------------------------------------------------------------------------------
Developing the Client(UI): under client application we perform following activities:

Step 1: Create object of appropriate client channel class which doesn't require any port no.

Step 2: Register the channel under OS.

Step 3: Send request from Client to Remote Server requesting for reference of Remote Class using the static method GetObject of Activator class present under System.Runtime.Remoting namespace.

Activator.GetObject(Type type, string url) -> Object

URL: Uniform Resource Locator
<protocol>://<host name>:<port>/<request for>
eg: http://www.yahoo.com:80/index.htm
tcp://<server name>:5000/XXX

Step 4: Server takes request & provides reference of RemoteClass to client in object format as return type of GetObject method is object.
eg: Object obj = Activator.GetObject(<type>, <url>);

Step 5: Now client needs to convert reference of Remote Class present in object format to Interface format.
eg: IRemoteApp ira = (IRemoteApp)obj;

Step 6: Now using the reference we can invoke methods of Remote Class thats executes on server machine only.
-------------------------------------------------------------------------------------
Developing Client Application (UI):
-Open a new project of type windows & name it as RemoteClient.

-Add Reference of 3 assemblies to the project
1. System.Runtime.Remoting.dll (.net)
2. System.Configuration.dll (.net)
3. InterfaceProject.dll (Browse)

-Add an "Application Configuration File" under the project using "Add New Item" window and write the following in it:

<configuration>
 <appSettings>
  <add key ="URL" value ="tcp://server:5000/XXX"/>
 </appSettings>
</configuration>

-Write the following code under form:

using InterfaceProject;
using System.Configuration;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
-------------------------------------------------------------------------------------
Class Declarations:
   IRemoteApp ira;
-------------------------------------------------------------------------------------
Under Form Load:
string url =                                                                           ConfigurationManager.AppSettings.Get("URL");
TcpClientChannel chan = new TcpClientChannel();
ChannelServices.RegisterChannel(chan, true);
Object obj = Activator.GetObject(
typeof(IRemoteApp), url);
ira = (IRemoteApp) obj;
-------------------------------------------------------------------------------------
Under Call SayHello Button:
button1.Text = ira.SayHello();
-------------------------------------------------------------------------------------
Under Call Get_Sname Button:
button2.Text =                                                                       ira.Get_Sname(int.Parse(textBox1.Text));
-------------------------------------------------------------------------------------
Under Call Get_Bal Button:
button3.Text = ira.Get_Bal(int.Parse(textBox2.Text)).ToString();
-------------------------------------------------------------------------------------
Execution of the Application:
-As our Remote Server is a windows service it gets started automatically when ever OS is started.

-Now run the Remote Client application we have developed & test it. Once it was working perfectly prepare a set-up for the application which includes RemoteClient.exe, ConfigFile & InterfaceProject.dll which can be carried & installed on any systems in the network.

-To run the client application on a machine, first open the config file, edit the "URL" and then start the application.
-------------------------------------------------------------------------------------
Singleton Vs SingleCall:
-Right now Remote Class is registered under Remote Server in Singleton mode, in this mode when ever the first request comes from first client an object of RemoteClass is created and it's reference is provided to the client. From then for any new request comming from a new client server provides reference of same object that is already created, so all clients share same object because of this changes made by a client gets reflected to  other clients.

-To change the mode of our app from Singleton to SingleCall follow the below process:

  i) Open visual studio command prompt, go into the location where RemoteServer.exe was present &
uninstall it using installutil tool as following:
C:\CSharp6\RemoteServer\RemoteServer\bin\Debug > installutil -u RemoteServer.exe

 ii) Now open RemoteServer project in VS & under it change the mode from Singleton to SingleCall with in the 3rd statement of OnStart method and rebuild the project.

iii) Re-install RemoteServer from VS Command Prompt again.
C:\CSharp6\RemoteServer\RemoteServer\bin\Debug > installutil RemoteServer.exe

 iv) Open the service's window and start the server for first time.
-------------------------------------------------------------------------------------


Tuesday, March 19, 2013

Method Overriding in C#.net


Method Overriding in C#.net with example

LoadParent:
public void Test() -> 1
public virtual void Test(int x)

LoadChild:
public void Test(string s) -> 3
public override void Test(int x) -> 4
public void PTest(int x) -> 2

-After Overriding a method under the Child Class can we also consume the parent's method from the Child ?

Ans: Yes this can be done in 2 ways:
   1. Create the object of the parent under the child class and then call the virtual method of the Parent.
   -To test this re-write the following code under the Main method of the class LoadChild.
            LoadParent P = new LoadParent();
            P.Test(10);   //Calls Parent Method
            LoadChild c = new LoadChild();
            c.Test(10);   //Calls Child Method

Note: If the object of the child class was assigned to the parents variable and then if we invoke the overridden method, parent object also will invoke child methods only, as it has given the permission for the child to override the method it will give the preference to child methods.

-To test this re-write the following code under the Main method of the class LoadChild.
            LoadChild c = new LoadChild();
            LoadParent p = c;
            p.Test(10);   //Calls Child Method
            c.Test(10);   //Calls Child Method

   2. Using the base keyword also we can call the virtual methods of the parent from the child class.
Note: using the base keyword is not allowed from static blocks like Main.

-To test this do the following:
   i) Add a new method under the child class LoadChild as PTest which will internally call the virtual method of the parent.
  public void PTest(int x)
{
    base.Test(x);
}
   ii) Now from the Main method of the child class LoadChild u can call all the methods by using the object of the child class only as following:
LoadChild c = new LoadChild();
c.Test();              //Calls Parent Method
  c.PTest(10);       //Calls Parent Method
c.Test("Hello");  //Calls Child Method
c.Test(10);         //Calls Child Method

Linq in C#.net with example


Linq in C#.net with example:

1. Creates a class DataContext referring to the DB under which the table was present. The class will have your dbml file name as a prefix:
eg: CSharp7DataContext

2. Creates a seperate class referring to each table or view that is placed on OR-Designer. The name of class will be same as table or view name.
eg: Students Or Customer Or Employee

3. Defines properties under table class where each property refers to each column of the table.

4. Provides methods using which we can perform CRUD operations.

Note: to view all the above goto, solution explorer & expand the .dbml file node which dispays a file desinger.cs, under it we can find all the above.
-------------------------------------------------------------------------------------
Customer:
   Custid(PK) Int
   Cname Varchar  
   City Varchar
   Balance Money
-------------------------------------------------------------------------------------
Under Form Load:
CSharp7DataContext dc = new CSharp7DataContext();
dataGridView1.DataSource = dc.GetTable<Customer>();

Note: GetTable is a generic method which will returns the table we requested for.
-------------------------------------------------------------------------------------
Performing DML Operations thru Linq:
-If we want to perform any DML operations using Linq we adopt the following process:

-Steps For Inserting:
1. Create the object of class (Table) into which we want to insert a record where each object is a record.
2. Referring to properties of the object assign vals, as we are aware a property is a column.
3. Call InsertOnSubmit method on DataContext object referring to records (Customers) of table that adds record under table in a pending state.
4. Call SubmitChanges method on DataContext object for commiting the changes to DB server.

-Steps for Updating:
1. Identify the Record that has to be Updated by calling SingleOrDefault method on DataContext object referring to the records (Customers).
2. Re-assign values to properties so that old values gets changed to new values.
3. Call SubmitChanges method.

-Steps for Deleting:
1. Identify the Record that has to be deleted same as in update.
2. Call DeleteOnSubmit method on DataContext object referring to the records (Customers) that deletes the record from table in a pending state.
3. Call SubmitChanges method.
-------------------------------------------------------------------------------------
         Code in first form
-------------------------------------------------------------------------------------
Declarations:
  CSharp7DataContext dc;
-------------------------------------------------------------------------------------
private void LoadData()
{
  dc = new CSharp7DataContext();
  dgView.DataSource = dc.GetTable<Customer>();
}
-------------------------------------------------------------------------------------
Under Form Load:
  LoadData();
-------------------------------------------------------------------------------------
Under Insert Button:
  Form3 f = new Form3(); //Form3 is second form
  f.button1.Text = "Insert";
  f.ShowDialog();
  LoadData(); //Re-loads the data after insert
-------------------------------------------------------------------------------------
Under Update Button:
if (dgView.SelectedRows.Count > 0)
{
 Form3 f = new Form3(); //Form3 is second form
 f.textBox1.Text = dgView.SelectedRows[0].Cells [0].Value.ToString();
 f.textBox2.Text = dgView.SelectedRows[0].Cells [1].Value.ToString();
 f.textBox3.Text = dgView.SelectedRows[0].Cells [2].Value.ToString();
 f.textBox4.Text = dgView.SelectedRows[0].Cells [3].Value.ToString();
 f.textBox1.ReadOnly = true;
 f.button1.Text = "Update";
 f.ShowDialog();
 LoadData(); //Re-loads the data after update
}
else
 MessageBox.Show("Select a record to update");  
-------------------------------------------------------------------------------------
Under Delete Button:
if (dgView.SelectedRows.Count > 0)
{
 if (MessageBox.Show(
     "Do you wish to delete the record?",                               "Confirmation", MessageBoxButtons.YesNo,                  MessageBoxIcon.Question)                              ==DialogResult.Yes)
 {
  int custid = Convert.ToInt32(
                 dgView.SelectedRows[0].Cells[0].Value);
  Customer obj = dc.Customers.SingleOrDefault(
C => C.Custid == custid);
  dc.Customers.DeleteOnSubmit(obj);
  dc.SubmitChanges();
  LoadData(); //Re-loads the data after delete
 }
}
else
  MessageBox.Show("Select a record to delete");  
-------------------------------------------------------------------------------------
Under Close Button:
  this.Close();
-------------------------------------------------------------------------------------
        Code in second form
-------------------------------------------------------------------------------------
Under Save Button:
CSharp7DataContext dc = new CSharp7DataContext();
if (button1.Text == "Insert")
{
  Customer obj = new Customer();
  obj.Custid = int.Parse(textBox1.Text);
  obj.Cname = textBox2.Text;
  obj.City = textBox3.Text;
  obj.Balance = decimal.Parse(textBox4.Text);
  dc.Customers.InsertOnSubmit(obj);
  dc.SubmitChanges();                
}
else
{
  Customer obj = dc.Customers.SingleOrDefault(
             C => C.Custid == int.Parse(textBox1.Text));
  obj.Cname = textBox2.Text;
  obj.City = textBox3.Text;
  obj.Balance = decimal.Parse(textBox4.Text);
  dc.SubmitChanges();
}
-------------------------------------------------------------------------------------
Under Close Button:
  this.Close();
-------------------------------------------------------------------------------------
Calling Stored Procedures thru Linq:
-If we want to call any SP of Sql Server DB using Linq we need to first drag & drop the SP on RHS panel of OR-designer, so that it get's converted into a method under DataContext class with same name of the procedure.

-If the SP has any params they will be defined for the method also, where input params of procedure becomes input params to method & output params of procedure becomes ref params to the method.

e.g.:
-If the below procedure was dropped on RHS panel of OR-designer:
  Create Procedure Add(@x int, @y int, @z int output)

-The method gets created as following:
  public int Add(int? x, int? y, ref int? z)

-If the SP contains Insert or Update or Delete or has any output params in such cases the return type of method will be int, where as if the SP has any select stmts in it that returns tables as result then the return type of method will be a ResultSet (Collection of Tables).

-Now we can call the method by creating object of DataContext class & pass required values for the method.
-------------------------------------------------------------------------------------
Declarations:
CSharp7DataContext dc;
-------------------------------------------------------------------------------------
Under Form Load:
dc = new CSharp7DataContext();
-------------------------------------------------------------------------------------
Under Execute Button:
string sname = null; decimal? afees = null;
dc.Get_SDetails(int.Parse(textBox1.Text),
ref sname, ref afees);
textBox2.Text = sname;
textBox3.Text = afees.ToString();
-------------------------------------------------------------------------------------
Under Close:
 this.Close();
-------------------------------------------------------------------------------------
Filtering the data using Linq:
-If we want to filter the data using Linq, we can use the "Linq To Sql" query stmt's, same as we used for quering on collections.

var tab = from <alias> in <table> [<Clauses>] select <alias> | new { <list of columns> }

Note: Clauses can be where, group by, having & order by.
-------------------------------------------------------------------------------------
Declarations:
 CSharp7DataContext dc;
-------------------------------------------------------------------------------------
Under Form Load:
 dc = new CSharp7DataContext();
 dgView.DataSource = from C in dc.Customers select C;                  
-------------------------------------------------------------------------------------
Under ComboBox SelectedIndexChanged:
if (comboBox1.Text != "All")
 dgView.DataSource = from C in dc.Customers                        where C.City == comboBox1.Text select C;
else
 dgView.DataSource = from C in dc.Customers select C;
-------------------------------------------------------------------------------------
Under Balance Asc Button:
 dgView.DataSource = from C in dc.Customers orderby C.Balance select C;
-------------------------------------------------------------------------------------
Under Balance Desc Button:
 dgView.DataSource = from C in dc.Customers orderby C.Balance descending select C;
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------



Class Declarations:
   CSharp7DataContext dc;
-------------------------------------------------------------------------------------
Under Form Load:
   dc = new CSharp7DataContext();
   var tab = from E in dc.Emps select E;
   dataGridView1.DataSource = tab;
-------------------------------------------------------------------------------------
Under ComboBox SelectedIndexChanged:
var tab = from E in dc.Emps select E;
if (comboBox1.Text != "All")
   tab = from E in dc.Emps where E.Job == comboBox1.Text select E;         dataGridView1.DataSource = tab;
-------------------------------------------------------------------------------------
Under Button1:
var tab = from E in dc.Emps orderby E.Salary select E;
dataGridView1.DataSource = tab;
-------------------------------------------------------------------------------------
Under Button2:
var tab = from E in dc.Emps orderby E.Salary descending select E;
dataGridView1.DataSource = tab;
-------------------------------------------------------------------------------------
Non-Ansi Join:
Select E.Empno, E.Ename, E.Job, E.Sal, E.Hiredate, D.Deptno, D.Dname, D.Loc From Emp E, Dept D Where E.Deptno=D.Deptno

Ansi Join:
Select E.Empno, E.Ename, E.Job, E.Sal, E.Hiredate, D.Deptno, D.Dname, D.Loc From Emp E Inner Join Dept D On E.Deptno=D.Deptno

Linq Join:
from E in dc.Emps join D in dc.Depts on E.Deptno equals D.Deptno select new {E.Empno, E.Ename, E.Job, E.Sal, E.Hiredate, D.Deptno, D.Dname, D.Loc };






Extension Methods in C#.net


Extension Methods: 
-It is one of the best approach to extend the functionality of a class other than inheritance.

-Using this approach u can add new methods under an existing class even if u don't have permission to make changes on the class or the source code of the class is not available.

-After adding new methods to a class using the extension methods approach we can access those methods with the object of the class to which the methods were added, where as in inheritance they can be accessed only with the object of the child class.

-To define extension methods follow the below guidelines:
   i) Extension methods need to be defined only under a static class.
  ii) As they were being defined under a static class they must be declared as static but after linking with a class they will be considered as instance methods but not static for the class.
 iii) The first parameter of an extension method should be the name of the class to which the method belongs which will not be considered while calling.
  iv) If u want any parameters to an extension method we can pass them while defining but only from the second parameter.
   v) You can define any no of extension methods under a single static class linking with any no of classes.

Exceptions and Exception Handling in C#.net


Exceptions & Exception Handling:

-Generally under every program we will be comming across errors which are of 2 types:
     -Compile Time Errors
     -Run Time Errors

-A compile time error occurs due to the syntactical mistake that occurs in a program, these are not considered to be dangerous.

-A runtime error also known as an Exception occurs under a program while the execution of the program is taking place this can be due to various reasons like wrong implementation of logic, invalid input supplied to the program etc., these errors are considered to be dangerous because when they occur under the program the program terminates abnormally with out executing the next lines of code.

-What happens when an exception or runtime error occurs under a program ?
Ans: When ever an exception occurs in a program on a certain line, the execution of the program stops immediately on the line with out executing the next lines of code as well as displays an error msg related with the error.

-What is an Exception as a programmer ?
Ans: As a programmer every exception is a class which is defined under the system namaspace. The parent class for all these exeception classes is "Exception".

-How can we stop the abnormal termination that occurs when an exception occurs ?
Ans: To stop the abnormal termination that occurs when an exception occurs we are provided with an approach known as "Exception Handling", which allows u to stop the abnormal termination as well as can be used to display user friendly error msgs to the end users.

-How to perform Exception Handling within a program ?
Ans: To perform Exception Handling we were provided with 2 blocks of code known as "try..catch" blocks, which has to be used as following:

try
{
 -Stmts which will cause the exception
 -Stmts which are related with the exception and   should not execute when exception occurs
}
catch (<exception> <var>)
{
 -Stmts which should execute only when the   exception occurs
}
-----<multiple catch blocks>.....

Constructors in C#.net


-What is the role of the "new" operator in the creation of an object ?

Ans: When u use the "new" operator for creating the object of the class it will internally perform the following:
   -Reads the Classes
   -Calls the Constructors
   -Allocates the memory required for the object

-What is meant by reading the class ?
Ans: Reading the class in the sense it will recongnize each and every member which was defined under the class.

-What is a Constructor ?
Ans: a constructor is a special method available under every class which is responsible for initializing the variables of the class.

-The Name of the constructor method is always same as the class name.

-A constructor is a non value returning method.

-Every class should contain a constructor in it if it has to execute.

-What happens if a constructor is not defined in a class ?
Ans: as a constructor is mandatory for the execution of a class if it was not defined under the class by the programmer while getting compiled the compiler takes the responsibility to define the constructor under that class, so that the class can execute.

-Can we define a constructor explicitly under the class ?
Ans: we can also define a constructor under the class as following:
[<modifiers>] <Name> ( [<param list>] )
{
<Stmts>;
}
-------------------------------------------------------------------------------------
-Constructors of 2 types:
-Default Constructors
-Parameterized Constructors

-Default or Zero Arguments Constructors does not take any parameters, this can be defined either by a programmer or by the compiler.

-Parameterized Construtors can take parameters, this can be defined only by the programmers.

Note: Compiler defines a constructor under the class only if there is no constructor available under the class.

-If a class contains a parameterized constructor in it while creating the object of that class u need to send the values to the parameters.

-To check this do the following changes in the previous program:

1. Make the constructor as parameterized:
        ConDemo(int x)
        {
            Console.WriteLine("Constructor: " + x);
        }

2. Now under the Main the object creation of the class should be as following:
       ConDemo cd1 = new ConDemo(1);
       ConDemo cd2 = new ConDemo(2);
-------------------------------------------------------------------------------------
-Under a class we can have variables declared with in the class as well as with in the blocks like methods or constructors.

-A variable declared under the class is a Class Variable and accessible thru out the class, where as variables declared under a block are block variables and accessible only with in the block.

-If a class and block variable are declared with the same name, with in the block the preference goes to block variables only, in such cases to refer to the class variables from that blocks use the "this" keyword.

-"this" is used for referring to the members of a class like variables or methods.

-To test this change the constructor code in the previous program as following:
Params(int x , int y)  
        {
                this.x = x;
                      this.y = y;
        }


Assemblies in C#.Net


Assemblies:

-When ever a project is compiled it generates an output file known as Assembly. The name of an assembly will be same as project name from which it was created.

-Assemblies were known as units of deployment because once the application development is done what we install on client machines is assemblies only.

-An assembly file can have an extension of either exe or dll.
exe: executable dll: dynamic link library

-Exe assemblies are in-process components which were capable of running on their own as well as provide the support for others to execute. When we use project templates like Windows Forms, WCF, Console Applications & Windows Services they generate an exe assembly when compiled.

-Dll assemblies are out-process components which were not capable of running on their own they can only support others to execute. Project templates like Class & Control Library will generate an dll assembly when compiled.

-Assemblies are of 2 types:
-Private Assemblies
-Shared Assemblies

Private Assemblies:
-By default every assembly is private, if reference of these assemblies was added to any project, a copy of the assembly is created and given to the project, so each project maintains a private copy of the assembly.
-------------------------------------------------------------------------------------
Creating a Private Assembly:
-Open a new project of type "Class Library" & name it as "PAssembly", which will by default come with a class as Class1.
Note: a class library is a collection of types like  classes, interfaces, structures etc., but cannot be executed, can only be consumed as they were dll's.

-Now under the class write following code:
   public string SayHello()
   {
      return "Hello from private assembly";
   }

-To compile the project open Solution Explorer, right click on the project and select "Build" which will generate an assembly as PAssembly.dll.

Note: we can find path of the assembly which was created in the output window present at bottom of the studio after build.

Consuming the Private Assembly:
-Open a new project of type Windows, name it as "TestPAssembly", place a button on Form & set the text as "Call SayHello of PAssembly".

-Now add the reference of PAssembly.dll from its physical location & write the following code under click of button:

PAssembly.Class1 obj = new PAssembly.Class1();
MessageBox.Show(obj.SayHello());

-Run the project to test it, then go and verify under bin/debug folder of current project where we can find a copy of PAssembly.dll as it was private.

Note: the advantage of a private assembly is faster execution as it was in the local folder, where as the draw back was multiple copies gets created when multiple projects add's the reference to consume it.
------------------------------------------------------------------------------------
Shared Assemblies:
-An assembly which sits under the GAC (Global Assembly Cache) to provide resources for multiple applications was known as shared assembly.

-If an assembly was shared multiple copies will not be created even if being consumed by multiple projects, only a single copy under GAC serves all the projects.

-GAC was a special folder under the OS:
             <drive>:\Windows\assembly   <- GAC Folder

-Note: all the BCL were Shared dll Assemblies, so we can find them under GAC.
-------------------------------------------------------------------------------------
-What assemblies can be copied into GAC ?
Ans: we can copy only strong named assemblies in to GAC.

-What is a Strong Named Assembly ?
Ans: an assembly which has 3 attributes Name, Version & PublicKeyToken value were known as Strong Named Assemblies.

1. Name: it was the name of an assembly used for identification. Every assembly by default has name. eg: PAssembly

2. Version: every software has versions to it, for discriminating changes that has been made from time to time. As an assembly is also a software component it will maintain versions, when ever the assembly is created it has a default version for it i.e. 1.0.0.0, which can be changed when required.

3. Public Key Token: as GAC contains multiple assemblies in it, to identify each assembly it will maintain a key value for the assembly known as public key token, which should be generated by us & associate with an assembly to make it Strong Named.

-How to generate a Public Key Token ?
Ans: to generate a Public Key Token value we were provided with a tool, Strong Name Utility, which is a command line tool that should be used from VS command prompt as following:
sn -k <file name>
eg: sn -k Key.snk
-The above stmt generates a key value & writes it into the file "Key.snk".
Note: use either sn or snk extension for key files.
-------------------------------------------------------------------------------------
Creating a Shared Assembly:

Step 1: Generate a key file. Open VS command prompt, go into your folder and generate a key file as following:
C:\CSharp6> sn -k key.snk

Step 2: Create a project & associate the key file to it before compilation so that the assembly which is generated will be Strong Named.

-Open a new project of type Class Library & name it as "SAssembly".

-Under the class Class1 write following code:
public string SayHello()
{
   return "Hello from shared assembly 1.0.0.0";
}

-To associate the key file we have generated with project, open project properties window, select Signing tab on LHS, which displays a CheckBox as "Sign the Assembly" select it, in the ComboBox below select browse, select the key.snk file from its physical location which adds the file under solution explorer, then compile the project using "Build" option that will generate SAssembly.dll which is Strong Named.

Step 3: Copying the Assembly into GAC.
-To copy the assembly into GAC .Net provides an utility known as "gacutil" which is a command line tool that has to be used as following:
gacutil -i | -u <assembly name>
-i Install
-u Uninstall
-Open VS command prompt, go into the location where SAssembly.dll was present and write the following:

C:\CSharp6\SAssembly\SAssembly\bin\Debug> gacutil -i SAssembly.dll

Step 4: Testing the Shared Assembly:
-Open a new project of type Windows & name it as "TestSAssembly", place a button on form & set the text as "Call SayHello of SAssembly 1.0.0.0".

-Add reference of SAssembly.dll from its physical location & write following code under button click:

SAssembly.Class1 obj = new SAssembly.Class1();
MessageBox.Show(obj.SayHello());

-Run the project, test it and verify under bin/debug folder of current project where we will not find any copy of SAssembly.dll as it was shared.

Note: when a shared assembly is used in multiple applications there will not be multiple copies of the assembly, where as it's not faster when compared with private assembly.
-------------------------------------------------------------------------------------
Assembly Attributes:
-An assembly is associated with a set of attributes that describes about general info of an assembly like Title, Company, Description, Version etc.

-These attributes will be under AssemblyInfo.cs file of each project. To view them expand properties node under the project in Solution Explorer where we find AssemblyInfo.cs file.
Note: we can change values of any attribute as per our requirements.

-In bottom of the file we find an attribute version which is a combination of 4 values:
-Major Version
-Minor Version
-Build Number
-Revision
-The default version of every assembly is 1.0.0.0, to change version no. we follow the below guidelines:

-Change revision no when modifications were made to existing members of types in an assembly.
-Change build no when new members were added to existing types in an assembly.
-Change minor version when modifications were made to existing types in an assembly.
-Change major version when new types were added in an assembly.

Checking the process of changing version no's:

-Open SAssembly project we created previously & change the code under SayHello method as below:

   return "Hello from new shared assembly 1.0.0.1";

-Now open AssemblyInfo.cs file and change the AssemblyVersion & AssemblyFileVersion attributes to 1.0.0.1.

-Re-build the project and add the new version of SAssembly also into GAC using gacutil tool.

Note: GAC allows placing of multiple versions of an assembly in it & provides different app using different versions of the assembly to execute correctly using their required version.

-Now open the GAC folder where we find 2 versions of SAssembly i.e. 1.0.0.0 & 1.0.0.1

-After placing multiple versions of an assembly under GAC we can develop applications in such a way where a different application uses a different version of the assembly and still execute correctly what we call as side by side execution which was not possible under tradition COM technologies.

-To test this open a new project of type Windows and name it as TestSAssemblyNew, place a button on the form and set the text as "Call SayHello of SAssembly 1.0.0.1".

-Add reference of 1.0.0.1 version of SAssembly from its physical location and write the following code under button click:

SAssembly.Class1 obj = new SAssembly.Class1();
MessageBox.Show(obj.SayHello());

To check side by side execution of projects run the exe files of TestSAssembly & TestSAssemblyNew projects at the same time, where each project will use it's required version of SAssembly & execute, as following:
-------------------------------------------------------------------------------------
Multi-Module Assemblies (2.0):
.netmodule

Imports System
Namespace MyVBNSP
 Public Class VBTest
  Public Function VBMethod() As String
   Return "Hello from Visual Basic"
  End Function
 End Class
End Namespace

using System;
namespace MyCSNSP
{
 public class CSharpTest
 {
  public string CSMethod()
  {
   return "Hello from C Sharp";
  }
 }
}

Compiling Sub-Modules:
vbc /target:module <vb file name>
csc /target:module <cs file name>

Compiling Main-Module:
vbc [/target:library] /addmodule:<list of sub modules> <vb file name>

csc [/target:library] /addmodule:<list of sub modules> <cs file name>
Making VBTest as a Sub-Module:
C:\CSharp6> vbc /target:module VBTest.vb

Making CShartTest as a Main-Module:
C:\CSharp6> csc /target:library /addmodule:VBTest.netmodule CSharpTest.cs

Consuming Multi-Module assembly:
-Open a new project of type windows and name it as TestMulti, place 2 buttons on the form and set the text as "Call CS Test" & "Call VB Test".
-Add reference of the CSharpTest.dll what we generated above from its physical location .

Under Call CS Test Button:
MyCSNSP.CSharpTest obj = new MyCSNSP.CSharpTest();
MessageBox.Show(obj.CSMethod());

Under Call VB Test Button:
MyVBNSP.VBTest obj = new MyVBNSP.VBTest();
MessageBox.Show(obj.VBMethod());
-------------------------------------------------------------------------------------
Globalization & Localization using Satellite Assemblies

MyRes.resx:
Name Value
L1 User Name
L2 Password
B1 Login
B2 Logout
-------------------------------------------------------------------------------------
MyRes.hi-IN.resx:
Name Value
L1 उपयोगकर्ता नाम
L2 पासवर्ड
B1 साइन इन
B2 साइन आउट
-------------------------------------------------------------------------------------
MyRes.te-IN.resx:
Name Value
L1 యూజర్‌పేరు
L2 పాస్‌‌వర్డు
B1 సైన్ ఇన్
B2 సైన్ ఔట్
-------------------------------------------------------------------------------------
System.Globalization
CultureInfo(string cultureflag)

System.Resources
ResourceManager(string basename,
Assembly assembly)

-In place of Assembly we need to give the current executing assembly information to get that use the Method GetExecutingAssembly() under Assembly class of System.Reflection namespace.
-------------------------------------------------------------------------------------
using System.Reflection;
using System.Resources;
using System.Globalization;
-------------------------------------------------------------------------------------
Declarations:
  CultureInfo ci;
  ResourceManager rm;
-------------------------------------------------------------------------------------
under Form Load:
rm = new ResourceManager("MultiLang.MyRes", Assembly.GetExecutingAssembly());
-------------------------------------------------------------------------------------
private void GetValues()
{
 label1.Text = rm.GetString("L1", ci);
 label2.Text = rm.GetString("L2", ci);
 button1.Text = rm.GetString("B1", ci);
 button2.Text = rm.GetString("B2", ci);
}
-------------------------------------------------------------------------------------
Under English Link Label:
  ci = new CultureInfo("en-US");
  GetValues();
-------------------------------------------------------------------------------------
Under Hindi Link Label:
  ci = new CultureInfo("hi-IN");
  GetValues();
-------------------------------------------------------------------------------------
Under Telugu Link Label:
  ci = new CultureInfo("te-IN");
  GetValues();
-------------------------------------------------------------------------------------
Note: now go and verify under the debug folder of the current project where we find a seperate folder created for each resource file (except english) & in the folder we find the satellite assembly which got created.
-------------------------------------------------------------------------------------
-An Assembly internally contains following things in it:
-Manifest Info
-Type Metadata
-IL Code
-Resource Info

Manifest Info: it contains info about the attributes that are associated with an assembly like Title,  Description, Company, Version etc.,

Type Metadata: it contains info about all the types under assembly like Namespaces, Classes, their members (only signature), Structures, Interfaces etc. It describes only about contents of assembly, so an assembly can be called as self describing unit of execution which describes about it self to the execution environment with the help of its metadata.

Note: when we add reference to an assembly VS will read the information of assembly from its type metadata only using reflection.

-Reflection is an approach of dynamically recongnizing the contents of an assembly.

IL Code: this was the language instructions we have defined using .net lang's which can be understood only by the CLR and required only while execution of application.

Resource Info: this is going to contain the info which was associated with the resource files which was only optional.
-------------------------------------------------------------------------------------
 COM: Component Object Model
-It's a specification prescribed by Microsoft which advices never build a software as monolithic unit(single), in spite it suggests building of software by dividing into smaller components (libraries) & then integrate as a software that gives below features:
   i) Software maintanance becomes easier.
  ii) Re-usability of components under multiple app is possible.
 iii) Language Independency.

-Inspite of the features it has, it suffers from few criticisms also:
   i) Platform dependency where COM works only on       windows.
  ii) COM components (dll or exe) has to be first              registered under OS registry to consume on a           machine.
 iii) Versioning problem or dll Hell.

Note: COM components were nothing but libraries similar to assemblies in .Net.

-To overcome the problems with COM components, in .Net Microsoft replaced them with Assemblies which are Platform Independent, doesn't require any OS registration and also solves versioning problem's.
-------------------------------------------------------------------------------------
COM Interoperability:
-After replacing COM libraries with .Net assemblies Microsoft has given a flexibility to the industry i.e. consuming of COM libraries under .Net application development and .Net assemblies under COM app development known as COM Interoperability.

-A COM component can be consumed under a .Net application by converting it into RCW (Runtime Callable Wrapper) which exposes COM interfaces as .Net interfaces to .Net applications.

-CCW (COM Callable Wrapper) is opposite of RCW that exposes .Net interfaces as COM interfaces to a COM applications.
-------------------------------------------------------------------------------------
Developing a COM Component:

-COM Components can be developed using various languages like classical VB, C++ & VCPP.

-To develop a COM Component in Classical VB goto Start Menu -> Programs -> Microsoft Visual Studio 6.0 -> Microsoft Visual Basic 6.0 -> click on it which shows "New Project" window -> select ActiveX Dll (Class Library in .Net) project template -> click on open which displays the code window.

-Goto View Menu -> select "Project Explorer" which launches the explorer on RHS -> right click on the node Project1 -> select properties which opens a window -> under that change the "Project Name" as CSharp11 -> click Ok.

-Now right click on Class1 node -> select properties -> change the name as "Test".

-Now in code window write the following:
   Public Function SayHello() As String
      SayHello = "Hello from COM"
   End Function

Note: classical VB lang doesn't support return stmt so the value which has to be returned should be assigned to name of the function which will return the value.

-Go to File Menu -> select Save Project ->  specify a location to save the project.
eg: C:\CSharp11\VB

-Go to File Menu -> select Make 'CSharp11.dll', which will compile, generate a dll and registers it under windows registry because COM Components were not functional unless they were registered under windows registry.

-Close the Studio.
-------------------------------------------------------------------------------------
Registering Com components under OS registry:
-We can also manually register com components under windows registry, using following command from command prompt:
syntax: regsvr32 <name of com dll>
eg: C:\CSharp6\VB> regsvr32 CSharp6.dll

Note: we don't require it right now because VS has already registered our component.
-------------------------------------------------------------------------------------
Consuming COM Components from .Net App's:
-If we want to consume a COM Component from .Net Applications first it should be converted into RCW which can be done in 2 ways:
-Using Visual Studio.Net
-Using tlbimp utility
-------------------------------------------------------------------------------------
Using Visual Studio.Net:
-Open a new .Net project of type Windows & name it is as TestCom1, place a button on the form & set Text as "Call SayHello of COM".

-Now open "Add Reference" window, select COM tab & under it we can find our Component CSharp6 we have created, select it and write the following code under click of button:

CSharp6.TestClass obj = new CSharp6.TestClass();
MessageBox.Show(obj.SayHello());

-Run the project, test it & then go into debug folder of current project where we  can find the RCW created by VS as "Interop.CSharp6.dll".

-The above process is simple & easy but the RCW created here is private which maintains multiple copies if used under multiple projects.
-------------------------------------------------------------------------------------
Using tlbimp Utility:
-VS is capable of generating RCW of type private only where as tlbimp is capable of generating both private & shared RCW's.

-To create an RCW Or CCW we were provided with 2 command line utilities:
1. tlbimp (Type Library Importer): for converting a COM component into RCW

2. tlbexp (Type Library Exporter): for converting a .net assembly into CCW

-These were command line utilities which should be used from VS Command Prompt as following:

tlbimp <name of com dll> /out: <name of .net dll> [/keyfile: <name of key file>]

Creating a Private RCW:
C:\CSharp6\VB> tlbimp CSharp6.dll /out:ComToNetP.dll

Creating a Shared RCW:
Step 1: Generate a key file
C:\CSharp6\VB> sn -k Key.snk

Step 2: Convert to Shared RCW
C:\CSharp6\VB> tlbimp CSharp6.dll /out:ComToNetS.dll /keyfile: Key.snk

Step 3: Add the RCW to GAC
C:\CSharp6\VB> gacutil -i ComToNetS.dll
-------------------------------------------------------------------------------------
-Now add to more buttons on our previous project TestCom1 with the same Text, add the reference of both the RCW's we have created (ComToNetP.dll & ComToNetS.dll) from their physical location, then write the following code under them:

Under Second Button:
ComToNetP.TestClass obj = new ComToNetP.TestClass();
MessageBox.Show(obj.SayHello());

Under Third Button:
ComToNetS.TestClass obj = new ComToNetS.TestClass();
MessageBox.Show(obj.SayHello());
-------------------------------------------------------------------------------------
tlbexp is a tool that converts a .Net assembly into CCW, this is opposite to tlbimp.

tlbexp <name of .net dll> /out:<name of com dll>

Note: after creating CCW it cannot be used directly under any system as it was a COM component, it first requires registration on windows OS which has to be done using regsvr32 stmt we discussed above.

amazon

Sukanya Samriddhi Account - SBI

SUKANYA SAMRIDDHI Account information by SBI SUKANYA SAMRIDDHI ACCOUNT : FACILITY AVAILABLE AT ALL BRANCHES OF SBI Sukanya Samriddhi ...