Sunday, September 1, 2013

JQUERY

JQuery is a library based on JavaScript.
It is scripting language (mainly for client side).
HTML only supports the web pages which are static. For dynamic operations we cannot do by using Html.
To perform dynamic operation we use scripting language.

Things we have to know before learning JQuery.
·        HTML.
·        CSS
·        JAVASCRIPT

Important JavaScript functions are
document.getElementById(“”)
document.getElementByName(“”)
document.getElementByTagName(“”)
document.getElementByClassName(“”)

What is JQUERY?
Jquery is a light weight cross browser JavaScript library. It is collection of pre- defined functions.
Jquery is the most popular JavaScript library in use today.
It is collection of write less Do More library.
It is released in Jan 2006 at Bar Camp NYC by John Resign.
Bar camp is an international network of user generated conferences primarily focused around technology and the Web.
Jquery greatly simplifies JavaScript Programming.
Jquery is free open source software. Jquery is designed to keep the things easy, simple and reusable.
Jquery syntax is designed to make it easier to navigate a document. Select DOM Element, create animations, handle events and develop Ajax applications.


The official Jquery statement is
“JQUERY is a fast and concise JavaScript library that simplifies html document traversing, event handling, and animating and Ajax interactions for rapid web development.”
Features of Jquery
·        DOM element selection functions
·        Event Handling
·        DOM transversal & Modifications
·        CSS Manipulations
·        Effects and Animations
·        Ajax Interactions
·        Cross Browser Support.

If we want an event to work on your page we should call it inside the
$(document).ready ()
Everything inside it will be loaded as soon as DOM is loaded and before the page contents are loaded.
To do this we register a ready event for the document as following.
$(document).ready (function () {
//do something when Dom is ready.
});



$(document).ready ()
Query’s document.ready () method gets called as soon as DOM is ready (means browser has parsed the HTML and built the DOM tree). It is cross browser compatible means behave equally on all browsers.

 If your web page has large images, it will not wait for loading of images completely. Hence it may called before page Load () method. We can have multiple document.ready () methods on a web page .







·         Best for onetime initialization.
·         Called as soon as DOM is ready; may called slightly before than pageLoad().
·         Cross browser compatible.
·         Unable to re-attach the functionality to elements/controls of the page affected by partial postbacks.

Page_load
pageLoad() method gets called when images and all associated resources of the page have been fully loaded.
Suppose your web page has large size images then until all the images are not fully loaded on the page, pageLoad() method will not called. pageLoad() method is not browser compatible. We can have only one page Load () method on a web page.
Not best for onetime initialization if used with UpdatePanel.
Not Cross browser compatible.
Best to re-attach the functionality to elements/controls of the page affected by partial postbacks with UpdatePanel.

Introducing Update Panel Partial Post Back with page Load () and $(document).ready ().
Since we know, in asp.net update panel gets partially postback to the server. Hence If you are using $(document).ready() and pageLoad() methods on the page, it is mandatory to know the difference between both the methods.
pageLoad() methods is called each and every partial postback of update panel but $(document).ready() is not called each and every partial postback of update panel. $(document).ready() is called only one time (during first time of page loading). Hence code written in $(document).ready() method will not be initialized each and every partial postback.

An ASP.NET AJAX alternative to $(document).ready()

If you are using AJAX on your asp.net web page then you can use Application.add_init() method in place of $(document).ready() for one time initialization



Note that to call Application.add_init, we need to place it after the ScriptManager. This is required because the ScriptManager injects its reference to MicrosoftAjax.js at that location. Attempting to reference the Sys object before Script Maanager will throw a javascript error "sys is undefined".

1.     Useful for one time initialization if only ASP.NET AJAX is available.
2.     More work required to wire the event up.

3.     "sys is undefined" javascript error may occurs if you are not careful.


MVC Working with AJAX, JQUERY

File->New->Project



Select Project Template as
Internet Application



And Click on Ok Button
And Go App Data (Right Click on it and select add existing item and add any database.



and add any database with extension.mdf

Now, go to model right click on it and select add->new item.

And select ADO.NET ENTITY DATA MODEL







 Now Model is created. Build the solution.
Now go to controller Right click on it and select Add.
Add->Controller





And click on Add Button.

And go to Index.cs.html and modify the code as below





And go to Layout.cs.html and paste the following code from bottom to top and write the following code.



Run, and see the output



And click on Details





Saturday, August 24, 2013

WCF


WCF

Before learning wcf we need to know

Distributed Programing
Communication between multiple server apps or services in the network.
Must be capable to run behind Firewall.
Some share common protocol but not a common platform.

When communication between different platforms than
Heterogeneous Access-àUniversal Access
Performance->Low
Security->Low



When communication between same platform
Heterogeneous Access-àIt is access only through .Net to .Net
Performance->High
Security->High

.Net support for developing Distributed Program
All the distributed technologies speak about the same i.e. consuming of libraries present on remote machines.

We have three concepts
1 Remoting                   
2 Web Services
3 WCF

.NET Remoting
It provides proprietary type of communication.
.NET to .NET

Remoting offers distributed programming between two dot net applications
It is fixed architecture where different customization is provided for development.

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 R emoting.

Architecture





P1 makes a request to a component called Proxy.


Now proxy will take the request with the help of formatter to convert this local call to remote calls. After converting the channel will take & transfer to the remote destination.






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 flow able, 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.


-Serializationis 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.

Advantages
Any distributed programming developed with remoting libraries will get
Good Performance
Good Security

Drawbacks:
Heterogeneous Environment is not possible with remoting Marsh

2 Web Services
It follows open standards XML Web services.
Firewall Friendly.
.Net to Non .Net Distributed App can be developed.
It is an application which is design as collection of services and can take Http Request process it and gives response as Http Response.
Web Service will only have one formatter that is SOAP
Channel->Http


Architecture



WCF

Unified framework for rapidly building service oriented apps. It is the new way of easily exposing the components.


Architecture



===========================================================

Rules for Developing WCF Service

1       Creating a .Net Component which is compatible to WCF(WCF Runtime Enabled)
To do this WCF provides different classes in the form of attributes, so that we can attach them to our component content. All the libraries and WCF runtime is provided in
System.ServiceModel.dll
System.ServiceModel Namespace
Note: the above .dll is only for the WCF Framework which contains libraries and WCF Runtime.
WCF Recommends interface pattern of development for its service & highly recommended even for normal component development.
Eg:
      [Service Contract]
      Interface IDemo
{
                  //
}
Here [Service Contract] attributes tells us it is a WCF Enabled Component.
Here we are using [Service Contract] attribute because to make .Net Component Distributed.

 [Operation Contract]

To specify methods of service Contract in Service Consumption.
A good service should not have more than 12 [Operation Contract] attributes
We should have at least one [Operation Contract]

2       Every service requires hosting so that it can manage the operating system and other environment related issues.

WCF provides rich hosting options so that user can plan service where good management capabilities
WCF provides the following hosting options

Self-Hosting
Windows Service Hosting
IIS Hosting
Windows Activation Services Hosting [WAS]

3       Endpoints for accessing the service

In WCF Service is exposed to client using end points. Every Client understands as well as communicates with WCF service using Endpoints only

1 Address
 Here we specify the location where our service is available. WCF Follows industry standard addressing pattern, so while writing address instead of .Net style of addressing we have to write W3 style of addressing.

2 Binding
Binding defines how to communicate with service. It includes the Formatter, Channel and other information with just the binding name that we specify.
            For Eg:
Basic Http Binding means SOAP formatter of communication using http channel
            BasicTcpBinding means Binary formatter of communication using Tcp Channel.

3 Contract
This is .Net Type that we provide for client for Request and Response.
Contract -àInterface
WCF will take that interface and give to client.

What is End Point?
It is structure defined with Address+Binding+Contract so that user can communicate with service using this end point information.

Here we are telling that this service should be exposed to client by using those end points

                      

Saturday, August 17, 2013

MVC Controller

MVC Controller

A controller is responsible for controlling the way that a user interacts with an MVC application.
                
A controller determines what response to send back to a user when a user makes a browser request.

·         It is Just a class that implements IController

·         Use the View Method to display the View.

·         Public methods are the action methods

Explanation: In MVC, we write the code in service oriented pattern. Anything you write as service oriented, every method you write in controller should be public, globally accessed because we will have multiple layers.


·         Apply [NonAction] attribute to turn this off
Explanation:
[NonAction]
Public void Add ()
This method will be public to your project, but not accessible to other project.



·         Invoking via routing mechanisms(**********)
Explanation: MVC says we will have friendly Uri
Uri—uniform resource identifier
Today it is not URL, today they are URI



What is routing:
Is the process where requested URL is mapped to MVC Controller method resulting in the simple URL’S to invoke methods
Aspx request—handler->aspx engine
Webserveràhandleràextensions
Webserver are based on handler and handlers are based on extensions
Routing will do the mapping to webserver understandable format.

How mapping is performed
Based on routing instructions that the developers provide .
In every mvc project ,that we create by default following route instructions is added
Note: By default one route instruction is added.

Where is the route mapping code written?

The route mapping code is written in the “global.asax” file.


Why Routing Instructions
Because mvc works with routing, so we have one routing instruction by default.
Local hostà routing
Is the mediator between webserver handler and URL

For example, consider the following URL:  /Job/Details/3
• This URL is parsed into three parts like this:
Controller = Job Controller
Action = Details & Id = 3
The default route includes default values for all three segments. The default Controller is Home Controller,
The default Action is Index,
And the default Id is an empty string.

Controllers
Core Action Functionality

What are the different types of results in MVC?

In MVC, we will not have the return types as string, int, etc.

Actions methods should return an Action Result
• ViewResult if you want to show a View
• ContentResult directly returning content
• RedirectResult to redirect to a new URL
• RedirectToRouteResult redirect to route
• EmptyResult null object pattern
• JsonResult returning a Json
JavaScriptResult - script that can be executed on the client

--------------------------------------------------------------------------------------------------------
1.    FileContentResult - Returns a file to the client
2.    FileStreamResult - Returns a file to the client, which is provided by a Stream
3.    FilePathResult - Returns a file to the client


Routing

MVC gives you great control over how URLs are mapped to your controllers. It gives you the ability to define your URLs in a human readable SEO (Search Engine Optimization) friendly fashion, to remap old URLs to new functionality and side-by-side utilize classic ASP.NET sites inside of MVC3. It also results in hiding what kind of page user is calling and what environment we are working in. Most of the new websites are following this and it is important to understand that routing is not URL rewriting as routing will have customization's and many attachments towards request/response.

When we create any type of MVC application by default GLOBAL.ASAX file is created becoz ASP.NET implements MVC using this global application class mainly. Routes defined in the Global.asax.cs file of our MVC3 web application/site. In this global.asax file most important element relative to our work is RegisterRoutes method. By default, there is only one route defined in the RegisterRoutes method that looks like the line below.




Custom MVC Routes

 In a ASP.NET site for a magazine, you might have a URL that looks like www.internet.com/ViewArticle.aspx?id=123. This URL passes the ID number of the article to view, but the URL itself doesn't describe the content in any human readable way

 If the URL instead was www.internet.com/MVC_Routing/123 a human-or a web crawler-could read that and know that the article is about MVC_ Routing
Defination of Routing :
It is a program or process which is responsible to map the given URL to a controller and its action method.
Explanation: Is the process where user will type the URL which will be converted to handlers and there will be the mediator who will take this Uri and map to the server.
Now product ID for what(tv,mobile,etc)
In mvc we can define as
Initially routing was provided in MVC today available in entire .Net.
This was introduced because of the way ASP.NET MVC works rather, than being handled by a page handler each request needs to be routed to a specific action method of a specific controller Class.

Routing provides "clean" URLs
URL is mapped to a route handler
Extra level of indirection
Handlers can be changed without impacting URL
URL can be changed without impacting handler

URL Example Example http://www.mysite.com/Home/ProductList 



Note




Catch-all route
Put this route last
It will match any URL which has not matched any other route


============================

Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...