Wednesday, October 17, 2012

Asp.net - LINQ Tutorial


ASP.NET LINQ Tutorial
Most applications are data-centric and most of these data repositories are however, relational databases. Over the years designers and developers have designed applications based on object models.
These objects were responsible for connecting to the data access components - called the data access layer (DAL). There are however, two things to consider:
  • All the data needed in an application are not stored in the same source. The source could be a relation database, some business objects, XML file, or on web services.
  • Accessing in-memory object is simpler and less expensive than accessing data from a database or XML file.
  • The data accessed are not used directly, but needs to be sorted, ordered, grouped, altered etc.
So if there is one tool that makes all kinds of data access easy, that allows joining data from such disparate data sources and perform standard data processing operations, in few lines of codes, it would be of great help.
LINQ or Language-Integrated Query is such a tool. LINQ is set of extensions to the .Net Framework 3.5 and its managed languages that sets the query as an object. It defines a common syntax and a programming model to query different types of data using a common language.
The relational operators like Select, Project, Join, Group, Partition, Set operations etc., are implemented in LINQ and the C# and VB compilers in the .Net framework 3.5, which support the LINQ syntax makes it possible to work with a configured data store without resorting to ADO.Net.
For example querying the Customers table in the Northwind database, using LINQ query in C#, the code would be:
var data = from c in dataContext.Customers
where c.Country == "Spain"
select c;
Where:
  • The 'from' keyword logically loops through the contents of the collection.
  • The expression with the 'where' keyword is evaluated for each object in the collection.
  • The 'select' statement selects the evaluated object to add to the list being returned.
  • The 'var' keyword is for variable declaration. Since the exact type of the returned object is not known, it indicates that the information will be inferred dynamically.
LINQ query can be applied to any data-bearing class that inherits from IEnumerable<T>, here T is any data type, for example List<Book>...

Tuesday, October 16, 2012

Android development Tutorial


Summary:  Android is a complete operating environment based upon the Linux® V2.6 kernel. Initially, the deployment target for Android was the mobile-phone arena, including smart phones and lower-cost flip-phone devices. However, Android's full range of computing services and rich functional support have the potential to extend beyond the mobile-phone market. Android can be useful for other platforms and applications. In this article, get an introduction to the Android platform and learn how to code a basic Android application.
 
 
 
Introduction
The BlackBerry and iPhone, which have appealing and high-volume mobile platforms, are addressing opposite ends of a spectrum. The BlackBerry is rock-solid for the enterprise business user. For a consumer device, it's hard to compete with the iPhone for ease of use and the "cool factor." Android, a young and yet-unproven platform, has the potential to play at both ends of the mobile-phone spectrum and perhaps even bridge the gulf between work and play.
Today, many network-based or network-capable appliances run a flavor of the Linux kernel. It's a solid platform: cost-effective to deploy and support and readily accepted as a good design approach for deployment. The UI for such devices is often HTML-based and viewable with a PC or Mac browser. But not every appliance needs to be controlled by a general computing device. Consider a conventional appliance, such as a stove, microwave or bread maker. What if your household appliances were controlled by Android and boasted a color touch screen? With an Android UI on the stove-top, the author might even be able to cook something.
In this article, learn about the Android platform and how it can be used for mobile and nonmobile applications. Install the Android SDK and build a simple application. Download the source code for the example application in this article.
 
A brief history of Android
The Android platform is the product of the Open Handset Alliance, a group of organizations collaborating to build a better mobile phone. The group, led by Google, includes mobile operators, device handset manufacturers, component manufacturers, software solution and platform providers, and marketing companies. From a software development standpoint, Android sits smack in the middle of the open source world.
The first Android-capable handset on the market was the G1 device manufactured by HTC and provisioned on T-Mobile. The device became available after almost a year of speculation, where the only software development tools available were some incrementally improving SDK releases. As the G1 release date neared, the Android team released SDK V1.0 and applications began surfacing for the new platform.
To spur innovation, Google sponsored two rounds of "Android Developer Challenges," where millions of dollars were given to top contest submissions. A few months after the G1, the Android Market was released, allowing users to browse and download applications directly to their phones. Over about 18 months, a new mobile platform entered the public arena.
 
The Android platform
With Android's breadth of capabilities, it would be easy to confuse it with a desktop operating system. Android is a layered environment built upon a foundation of the Linux kernel, and it includes rich functions. The UI subsystem includes:
Windows
Views
Widgets for displaying common elements such as edit boxes, lists, and drop-down lists
Android includes an embeddable browser built upon WebKit, the same open source browser engine powering the iPhone's Mobile Safari browser.
Android boasts a healthy array of connectivity options, including WiFi, Bluetooth, and wireless data over a cellular connection (for example, GPRS, EDGE, and 3G). A popular technique in Android applications is to link to Google Maps to display an address directly within an application. Support for location-based services (such as GPS) and accelerometers is also available in the Android software stack, though not all Android devices are equipped with the required hardware. There is also camera support.
Historically, two areas where mobile applications have struggled to keep pace with their desktop counterparts are graphics/media, and data storage methods. Android addresses the graphics challenge with built-in support for 2-D and 3-D graphics, including the OpenGL library. The data-storage burden is eased because the Android platform includes the popular open source SQLite database. Figure 1 shows a simplified view of the Android software layers.
 
Figure 1. Android software layers
The Android software layers
 
 
Application architecture
As mentioned, Android runs atop a Linux kernel. Android applications are written in the Java programming language, and they run within a virtual machine (VM). It's important to note that the VM is not a JVM as you might expect, but is the Dalvik Virtual Machine, an open source technology. Each Android application runs within an instance of the Dalvik VM, which in turn resides within a Linux-kernel managed process, as shown below.
 
Dalvik VM
 
 
An Android application consists of one or more of the following classifications:
Activities
An application that has a visible UI is implemented with an activity. When a user selects an application from the home screen or application launcher, an activity is started.
Services
A service should be used for any application that needs to persist for a long time, such as a network monitor or update-checking application.
Content providers
You can think of content providers as a database server. A content provider's job is to manage access to persisted data, such as a SQLite database. If your application is very simple, you might not necessarily create a content provider. If you're building a larger application, or one that makes data available to multiple activities or applications, a content provider is the means of accessing your data.
Broadcast receivers
An Android application may be launched to process a element of data or respond to an event, such as the receipt of a text message.
An Android application, along with a file called AndroidManifest.xml, is deployed to a device. AndroidManifest.xml contains the necessary configuration information to properly install it to the device. It includes the required class names and types of events the application is able to process, and the required permissions the application needs to run. For example, if an application requires access to the network — to download a file, for example — this permission must be explicitly stated in the manifest file. Many applications may have this specific permission enabled. Such declarative security helps reduce the likelihood that a rogue application can cause damage on your device.
The next section discusses the development environment required to build an Android application.
 
Required tools
The easiest way to start developing Android applications is to download the Android SDK and the Eclipse IDE (see Resources). Android development can take place on Microsoft® Windows®, Mac OS X, or Linux.
This article assumes you are using the Eclipse IDE and the Android Developer Tools plug-in for Eclipse. Android applications are written in the Java language, but compiled and executed in the Dalvik VM (a non-Java virtual machine). Coding in the Java language within Eclipse is very intuitive; Eclipse provides a rich Java environment, including context-sensitive help and code suggestion hints. Once your Java code is compiled cleanly, the Android Developer Tools make sure the application is packaged properly, including the AndroidManifest.xml file.
It's possible to develop Android applications without Eclipse and the Android Developer Tools plug-in, but you would need to know your way around the Android SDK.
The Android SDK is distributed as a ZIP file that unpacks to a directory on your hard drive. Since there have been several SDK updates, it is recommended that you keep your development environment well organized so you can easily switch between SDK installations. The SDK includes:
android.jar
Java archive file containing all of the Android SDK classes necessary to build your application.
documention.html and docs directory
The SDK documentation is provided locally and on the Web. It's largely in the form of JavaDocs, making it easy to navigate the many packages in the SDK. The documentation also includes a high-level Development Guide and links to the broader Android community.
Samples directory
The samples subdirectory contains full source code for a variety of applications, including ApiDemo, which exercises many APIs. The sample application is a great place to explore when starting Android application development.
Tools directory
Contains all of the command-line tools to build Android applications. The most commonly employed and useful tool is the adb utility (Android Debug Bridge).
usb_driver
Directory containing the necessary drivers to connect the development environment to an Android-enabled device, such as the G1 or the Android Dev 1 unlocked development phone. These files are only required for developers using the Windows platform.
Android applications may be run on a real device or on the Android Emulator, which ships with the Android SDK. Figure 3 shows the Android Emulator's home screen.
 
 
 
 
Android Debug Bridge
The adb utility supports several optional command-line arguments that provide powerful features, such as copying files to and from the device. The shell command-line argument lets you connect to the phone itself and issue rudimentary shell commands. Figure 4 shows the adb shell command against a real device connected to a Windows laptop with a USB cable.
 
 
 
 
Within this shell environment, you can:
Display the network configuration that shows multiple network connections. Note the multiple network connections:
lo is the local or loopback connection.
tiwlan0 is the WiFi connection with an address provisioned by a local DHCP server.
Display the contents of the PATH environment variable.
Execute the su command to become the super-user.
Change the directory to /data/app, where user applications are stored.
Do a directory listing where you see a single application. Android application files are actually archive files that are viewable with WinZip or equivalent. The extension is apk.
Issue a ping command to see if Google.com is available.
From this same command-prompt environment, you can also interact with SQLite databases, start programs, and many other system-level tasks. This is fairly remarkable function, considering you're connected to a telephone.
In the next section, you'll create a simple Android application.
 
Coding a basic application
This section provides a whirlwind tour of building an Android application. The example application is about as simple as you can imagine: a modified "Hello Android" application. You'll add a minor modification to make the screen background color all white so you can use the phone as a flashlight. Not very original, but it will be useful as an example. Download the full source code.
To create an application in Eclipse, select File > New > Android project, which starts the New Android Project wizard.
 
 
 
 
Next, you create a simple application with a single activity, along with a UI layout stored in main.xml. The layout contains a text element you're going to modify to say Android FlashLight. The simple layout is shown below.
 
Listing 1. Flashlight layout
 
<?xml version="1.0" encoding="utf-8"?>
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/all_white">
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" android:textColor="@color/all_black" 
   android:gravity="center_horizontal"/>
</LinearLayout>
 
Create a couple of color resources in strings.xml.
 
Listing 2. Color in strings.xml
 
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Android FlashLight</string>
    <string name="app_name">FlashLight</string>
    <color name="all_white">#FFFFFF</color>
    <color name="all_black">#000000</color>
</resources>
 
The main screen layout has a background color defined as all_white. In the strings.xml file, you see that all_white is defined as an RGB triplet value of #FFFFFF, or all white.
The layout contains a single TextView, which is really just a piece of static text; it is not editable. The text is set to be black and is centered horizontally with the gravity attribute.
The application has a Java source file called FlashLight.java, as shown below.
 
Listing 3. Flashlight.java
 
package com.msi.flashlight;
import android.app.Activity;
import android.os.Bundle;
public class FlashLight extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}
 
The code is boiler-plate directly from the New Project wizard:
It is part of a Java package called com.msi.flashlight.
It has two imports:
One for the activity class
One for the bundle class
When this activity is initiated, the onCreate method is invoked, passing in a savedInstanceState. Don't be concerned with this bundle for our purposes; it is used when an activity is suspended and then resumed.
The onCreate method is an override of the activity class method of the same name. It calls the super class's onCreate method.
A call to setContentView() associates the UI layout defined in the file main.xml. Anything in main.xml and strings.xml gets automatically mapped to constants defined in the R.java source file. Never edit this file directly, as it is changed upon every build.
Running the application presents a white screen with black text.
 
 
 
 
The AndroidManifest.xml file setup for the FlashLight application is shown below.
 
Listing 4. AndroidManifest.xml for FlashLight
 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.msi.flashlight"
      android:versionCode="1"
      android:versionName="1.0.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".FlashLight"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
 
This file was created automatically by the Android Developer Tools plug-in for Eclipse. You didn't have to do anything.
Of course, the application is not terribly magnificent. But it could come in handy if you want to do some reading without disturbing your sleeping spouse, or if you need to find your way to the fuse box in the basement during a power outage.


Read More Tutorial on Developersfaq.com

Sunday, October 14, 2012

Elaborate different types of assemblies?


Elaborate different types of assemblies?

 
In .NET there are basically three different types of assemblies as follows.
1.Private assemblies:-A private assembly is normally used by a single application and is stored in the application's directory.
2.Public/shared assemblies:- A shared assembly is normally stored in the global assembly cache which is a repository of assemblies maintained by the .NET runtime.
3.satellite assemblies:-Satellite assemblies are often used to deploy language-specific resources for an application. These language-specific assemblies work in side-by-side execution because the application has a separate product ID for each language and installs satellite assemblies in a language-specific subdirectory for each language.

Read More Articles/Tutorials

What is an assembly in .NET Framework


An assembly is the primary building block of a .NET Framework application. It is a collection of functionality that is built, versioned, and deployed as a single implementation unit (as one or more files). All managed types and resources are marked either as accessible only within their implementation unit or as accessible by code outside that unit.
 
Assemblies are self-describing by means of their manifest, which is an integral part of every assembly.
 
The manifest: Establishes the assembly identity (in the form of a text name), version, culture, and digital signature (if the assembly is to be shared across applications).
Defines what files (by name and file hash) make up the assembly implementation.
Specifies the types and resources that make up the assembly, including which are exported from the assembly.
 
Itemizes the compile-time dependencies on other assemblies.
 
Specifies the set of permissions required for the assembly to run properly.
 
This information is used at run time to resolve references, enforce version binding policy, and validate the integrity of loaded assemblies. The runtime can determine and locate the assembly for any running object, since every type is loaded in the context of an assembly. Assemblies are also the unit at which code access security permissions are applied. The identity evidence for each assembly is considered separately when determining what permissions to grant the code it contains.
 
The self-describing nature of assemblies also helps makes zero-impact install and XCOPY deployment feasible.

What is AmbientTalk about?


What is AmbientTalk about?

Ambient-Oriented programming is a paradigm geared towards mobile computing. Mobile hardware (such as cell phones) is mostly equipped with wireless networking, allowing it to collaborate with nearby devices in its environment. However, because wireless network links are volatile (basically: when devices move out of wireless range, the connection drops), network failures occur much more frequently than in traditional networks. The basic assumption of the Ambient-Oriented Programming paradigm is that languages should incorporate network failures at the heart of their programming model, and not treat them as “exceptions”.
Our own experimental language, AmbientTalk, differs from most traditional languages because:
  • It employs a purely event-driven concurrency framework, founded on actors.
  • It abandons the RPC abstraction in favor of asynchronous, non-blockingmessage passing. Because the system automatically buffers such messages while the receiver of the message is disconnected, the programmer can make abstraction from temporary network failures by default.
  • It has built-in programming language constructs for objects to discover one another in the local ad hoc network. Peer-to-peer service discovery is built into the language.
  • It features a dynamic OO kernel language built upon the principles of prototype-based programming (based on Scheme, Self and Smalltalk). The kernel language supports reflection using mirrors, which provide access to an extensive metaobject protocol, making the language extensible from within itself.
  • The language syntax derives primarily from the ‘curly brace’ family of languages, but it mixes in the keyworded messaging syntax from Smalltalk as well. This, together with AmbientTalk’s lightweight block syntax, enables you to easily build your own control structures. Like many other dynamic and functional languages, AmbientTalk embraces the use of blocks to express higher-order, functional patterns.
  • The current implementation of AmbientTalk embraces the JVM as a platform. It’s easy for AmbientTalk programs to use Java libraries, and it’s easy for Java objects to use !AmbientTalk as an embedded scripting language. This interaction is safe: even when AmbientTalk objects are “exposed” to the JVM, JVM threads cannot violate the concurrency constraints of AmbientTalk’s actor model.
Check out the introduction to AmbientTalk for a hands-on example showing you the benefits in actual code. Alternatively, glance at the key expressionsin the language to get a 60-second overview of the language’s design and intents.
The screencast below shows how to implement a simple echo server for mobile ad hoc networks. It introduces AmbientTalk’s support for peer-to-peer service discovery, asynchronous messages, futures and how remote object references are resilient to network failures by default:

AmbientTalk is not our only research artifact. We have ported the ideas of Ambient-oriented Programming to Scheme, leading to the iSchemelanguage. There is also CRIME, a data-driven programming language which explores the logic programming paradigm to tackle similar coordination issues in mobile ad hoc networks.

What is Difference between Web Farm and Web Garden?


Web Farm
This is the case where you have only one web server and multiple clients requesting for resources from the same server. But when there are is huge amount of incoming traffic for your web sites, one standalone server is not sufficient to process the request. You may need to use multiple servers to host the application and divide the traffic among them. This is called “Web Farm”. So when you are hosting your single web site on multiple web servers over load balancer is called “Web Farm”.
Web Garden

Before starting web garden we have to understand what is Worker Process and Application Pool

  1. Worker Process
  2.  Application Pool

Worker Process:  Worker Process (w3wp.exe) runs the ASP.Net application in IIS. This process is responsible to manage all the request and response that are coming from client system.  All the ASP.Net functionality runs under the scope of worker process.  When a request comes to the server from a client worker process is responsible to generate the request and response. In a single word we can say worker process is the heart of ASP.NET Web Application which runs on IIS.

Application Pool: Application pool is the container of worker process.  Application pools is used to separate sets of IIS worker processes that share the same configuration.  Application pools enables a better security, reliability, and availability for any web application.  The worker process serves as the process boundary that separates each application pool so that when one worker process or application is having an issue or recycles, other applications or worker processes are not affected. This makes sure that a particular web application doesn’t not impact other web application as they are configured into different application pools.
Application Pool with multiple worker process is called “Web Garden”.


ASP.NET Control State vs View State


Control State (or ControlState) was introduced with ASP.NET 2.0 as an alternative to View State (or ViewState) as a method for preserving the state of a control.
Control State is designed only to  store a control’s essential data (like a dropdown list’s selected item) that needs to be available on a page postback. Unlike View State, Control State cannot be disabled.  to enable the control to function even when view state has been disabled. ASP.NET   stores the control state in for pages in the same hidden element which stores the view state. So if all you wish to do is preserve the control’s basic state over postbacks you can disable View State and Control State will handle all the preserving of state and reduce the page load.