Wednesday, October 10, 2012

What is dotNet MVC

When ASP.NET 1.0 was fi rst released in 2002, it was easy to think of ASP.NET and Web Forms as
one and the same thing. ASP.NET has always supported two layers of abstraction, though:
‰ System.Web.UI: The Web Forms layer, comprising server controls, ViewState, and so on
‰ System.Web: The plumbing, which supplies the basic web stack, including modules, handlers,
the HTTP stack, and so on
The mainstream method of developing with ASP.NET included the whole Web Forms stack — taking
advantage of drag-and-drop controls, semi-magical statefulness, and wonderful server controls
while dealing with the complications behind the scenes (an often confusing page life cycle, less than
optimal HTML, and so on).
However, there was always the possibility of getting below all that — responding directly to HTTP
requests, building out web frameworks just the way you wanted them to work, crafting beautiful
HTML — using Handlers, Modules, and other handwritten code. You could do it, but it was painful;
there just wasn’t a built-in pattern that supported any of those things. It wasn’t for lack of patterns
in the broader computer science world, though. By the time ASP.NET MVC was announced in
2007, the MVC pattern was becoming one of the most popular ways of building web frameworks.


The MVC Pattern
 

Model-View-Controller (MVC) has been an important architectural pattern in computer science for
many years. Originally named Thing-Model-View-Editor in 1979, it was later simplifi ed to Model-
View-Controller. It is a powerful and elegant means of separating concerns within an application
(for example, separating data access logic from display logic) and applies itself extremely well to
web applications. Its explicit separation of concerns does add a small amount of extra complexity
to an application’s design, but the extraordinary benefi ts outweigh the extra effort. It has been used
in dozens of frameworks since its introduction. You’ll fi nd MVC in Java and C++, on Mac and on
Windows, and inside literally dozens of frameworks.
The MVC separates the user interface of an application into three main aspects:
‰ The Model: A set of classes that describes the data you’re working with as well as the business
rules for how the data can be changed and manipulated
‰ The View: Defi nes how the application’s user interface (UI) will be displayed
‰ The Controller: A set of classes that handles communication from the user, overall application
fl ow, and application-specifi c logic
 

MVC AS A USER INTERFACE PATTERN
 

Notice that we’re referred to MVC as a pattern for the User Interface. The MVC
pattern presents a solution for handling user interaction, but says nothing about how
you will handle other application concerns like data access, service interactions, etc.
It’s helpful to keep this in mind as you approach MVC: it is a useful pattern, but
likely one of many patterns you will use in developing an application.

a little rememberence about dotNet Extension Methods

Extension methods are defined as static methods but are called by using instance method syntax. Their first parameter specifies which type the method operates on, and the parameter is preceded by the this modifier. Extension methods are only in scope when you explicitly import the namespace into your source code with a using directive.

Sunday, September 30, 2012

Code Snippet

to select a ASP.Net Grid Row by click

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                if(e.Row.RowType == DataControlRowType.DataRow )
                    e.Row.Attributes.Add(
                        "onclick",
                        Page.ClientScript.GetPostBackEventReference(sender as Control, @"Select$" + e.Row.RowIndex.ToString())
                        ) ;
...

Wednesday, September 19, 2012

Windows Azure Platform : AppFabric


The Windows Azure platform represents a radical change in the way applications can be
built and managed. This platform provides an Internet - based cloud computing environment
that anyone can use for hosting applications and storing the associated data. The platform
in general comprises two core services that any cloud - based application can use: compute
(e.g., executing an application) and storage (e.g., storing data on disk).
The compute service enables any application to run in the cloud. In essence, the applications
are deployed in a highly scalable environment where they share computer processor time
available in different virtual machines with Windows Server. These virtual machine
instances are spread around the world in different Microsoft data centers.
The storage service, as its name clearly states, provides simple storage capabilities using
different schemas such as BLOBs (binary objects), queues, or simple tables through a very
easy - to - use REST API based on Http calls. In case an application requires richer querying
capabilities for the storage (e.g., relational databases), an additional service, SQL Azure, is
also provided by Microsoft in this platform.
In both cases, Windows Azure assures the availability and high scalability that any
cloud - based application requires.
AppFabric extends the Windows Azure platform by providing two common building blocks,
the Service Bus and Access Control, to make it easier to extend the reach of any .NET applications in this platform. They currently provide key functionality to support bi - directional
connectivity and federated claims - based access control in any application trying to migrate to
Windows Azure.
The primary feature of the Service Bus is to “ route ” messages from clients through the Windows
Azure cloud to your software running on - premise, bypassing any NAT, fi rewalls, or other network
obstacles that might be in the way. In addition to routing messages, the Service Bus can also help
negotiate direct connections between applications.

The primary feature of Access Control is to provide a claims - based access control mechanism
for applications running on - premises or on the cloud. This makes federated authentication and
authorization much easier to achieve, allowing third - party applications to trust identities provided
by other systems.
Although each of these building blocks is available using open protocols and standards such as
REST, Atom/AtomPub, and SOAP, Microsoft has also provided a SDK that simplifi es the work
for .NET developers by hiding many of the wire protocol complexities that they would otherwise
experience when working with them directly. As part of this SDK, you can take advantage of some
of the new WCF extensions. These include the relay bindings, to talk to the Service Bus, or custom
authorization managers for parsing the security tokens generated by the Access Control.

Tuesday, August 7, 2012

something like Dot Net LINQ in Java : JOOOQ

jOOQ : A peace treaty between SQL and Java

SQL was never meant to be abstracted. To be confined in the narrow boundaries of heavy mappers, hiding the beauty and simplicity of relational data. SQL was never meant to be object-oriented. SQL was never meant to be anything other than... SQL!

It's simple. With the jOOQ DSL, SQL looks almost as if it were natively supported by Java. For instance, get all books published in 2011, ordered by title

create.selectFrom(BOOK)
      .where(PUBLISHED_IN.equal(2011))
      .orderBy(TITLE)
 
jOOQ also supports more complex SQL statements. get all authors' first and last names, and the number of books they've written in German, if they have written more than five books in German in the last three years (from 2011), and sort those authors by last names limiting results to the second and third row, then lock first and last names columns for update
 
http://www.jooq.org/ 

How to add custom unbound property to LINQ2SQL , EF

We encountered this error because we did not map entity property OrganizationName to certain table column in the database. You can check the table mapping by right click the entity User and select “Table Mapping”.
However, I don’t think we can solve the problem by only adding a custom property in the designer. Even we add the Organization table in the Mapping Details and map the OrganizationName property to Organization.Name column, EF still wants us to map the PK of the Organization table to one property in the User entity. But the FK property of User entity is not Entity Key, so the entire mapping still fails. Hope I made it clear to understand.
To workaround, I would recommend you to write some hard code to add a custom property into the User class. Since all the entity classes are partial classes, we can create a new partial User class and add the custom property outside the EDM designer:
==========================================================================
public partial class User
{
public string OrganizationName
{
get
{
if (this.Organization != null)
return this.Organization.Name;
else
return string.Empty;
}
set
{
if (this.Organization != null)
this.Organization.Name = value;
}
}
}
==========================================================================
BTW, I should mention the lazy loading feature of EF4 which is not available in EFv1. That mentions the related entities will not be loaded until we try to access them. If this case, if we turn off the lazy loading feature by (context.ContextOptions.LazyLoadingEnabled = false), we need to add such a filter in the getter/setter of property OrganizationName:
==========================================================================
if (!this.OrganizationReference.IsLoaded)
{
this.OrganizationReference.Load();
}
==========================================================================