Dec 10

This article comes from Scott Mitchell at 4guysfromrolla.com. Its good post which I liked and wanna share with you:

Extension methods allow a developer to tack on her own methods to an existing class in the .NET Framework. For example, imagine that our developer created a method named StripHtml, that strips HTML elements from a string using a regular expression. By associating this method with the System.String class, it could be called as if it was one of the System.String class’s built-in methods:

Dim str As String = "<b>Hello, world!</b>"
Dim strippedString = str.StripHtml()

Creating the Extension Methods with Visual Basic
In order to create the extension methods in Visual Basic we need to first create a Module. For each extension method you want to create, add a method whose first input parameter is of the type that you want to add the extension method to. Moreover, prefix the method with the Extension() attribute.

The following Module named DateTimeHelpers contains two methods: ToRelativeToCurrentTimeString(DateTime) and ToRelativeToCurrentUtcTimeString(DateTime), both of which accept a DateTime instance as their first input parameter. The methods are also marked with the Extension() attribute (which is found in the System.Runtime.CompilerServices namespace). The two methods call the private ToRelativeString method, which returns the appropriate string message based on the difference in time between the two passed-in DateTime values.

Imports System.Runtime.CompilerServices
Imports Microsoft.VisualBasic
 
Namespace Helpers
    Public Module DateTimeHelpers
       <Extension()> _
       Public Function ToRelativeToCurrentTimeString(ByVal dt As DateTime) As String
            Return ToRelativeString(dt, DateTime.Now)
       End Function
 
       <Extension()> _
       Public Function ToRelativeToCurrentUtcTimeString(ByVal dt As DateTime) As String
            Return ToRelativeString(dt, DateTime.UtcNow)
       End Function
 
       Private Function ToRelativeString(ByVal timeInPast As DateTime, ByVal currentTime As DateTime) As String
            If timeInPast.Date <> currentTime.Date Then
                ' timeInPast happend more than a day ago... show the date & time
                Return timeInPast.ToString()
            Else
                ' timeInPast and currentTime happened on the same day...
                Dim secondsApart As Integer = Convert.ToInt32(currentTime.Subtract(timeInPast).TotalSeconds)
 
                ' See if the date dt is within the last hour...
                If secondsApart < 10 Then
                   Return "Seconds ago..."
                ElseIf secondsApart < 60 Then
                   Return "Less than a minute ago..."
                ElseIf secondsApart < 3600 Then
                   Return String.Format("{0:N0} minutes ago...", secondsApart / 60 + 1)
                End If
 
                ' Ok, the date is more than an hour old... show the time
                Return timeInPast.ToShortTimeString()
            End If
       End Function
    End Module
End Namespace

We can now call these extension methods from a DateTime instance. In order to use an extension method, we first need to add an Imports directive to the code file, importing the namespace where the extension methods reside (Helpers). Upon doing that, the extension method is visible in the IntelliSense drop-down list, as the following screen shot illustrates.

read source

Dec 10

Few days ago from Microsoft released ASP.NET 3.5 Extensions CTP Preview. This release brings additional runtime functionality to ASP.NET and .NET 3.5. You can download it here.

Here is what this release includes:

* ASP.NET AJAX Improvements: New ASP.NET AJAX features in the ASP.NET 3.5 Extensions release include better browser history support (back/forward button integration, and server-side history management support), improved AJAX content linking support with permalinks, and additional JavaScript library improvements.

* ASP.NET MVC: This model view controller (MVC) framework for ASP.NET provides a structured model that enables a clear separation of concerns within web applications, and makes it easier to unit test your code and support a TDD workflow. It also helps provide more control over the URLs you publish in your applications, and more control over the HTML that is emitted from them.

* ASP.NET Dynamic Data Support: The ASP.NET 3.5 Extensions release delivers new features that enable faster creation of data driven web sites. It provides a rich scaffolding framework, and will enable rapid data driven site development using both ASP.NET WebForms and ASP.NET MVC.

* ASP.NET Silverlight Support: With the ASP.NET 3.5 Extensions release we’ll deliver support for easily integrating Silverlight within your ASP.NET applications. Included will be new controls that make it easy to integrate Silverlight video/media and interactive content within your sites.

* ADO.NET Data Services: In parallel with the ASP.NET Extensions release we will also be releasing the ADO.NET Entity Framework. This provides a modeling framework that enables developers to define a conceptual model of a database schema that closely aligns to a real world view of the information. We will also be shipping a new set of data services (codename “Astoria”) that make it easy to expose REST based API endpoints from within your ASP.NET applications.

read more

Dec 04

Bill Horst continues with those simple examples. After this one here comes the other set. They are perfect to show basic syntax. Here are few more:

DISTINCT
SQL SELECT statements can include the DISTINCT specifier, which causes all duplicate records in the query result to be removed. In a LINQ expression, Distinct is its own individual clause, rather than a specifier on the Select clause. This means that Distinct can appear between any two other clauses. The Distinct clause takes whatever result is returned by the preceding clause (Select, in the case below) and returns a filtered result with duplicates removed. To two code examples below accomplish the same results:

SQL

SELECT DISTINCT Name, Address
FROM CustomerTable

VB

From Contact In CustomerTable _
Select Contact.Name, Contact.Address _
Distinct

ORDER BY
The SQL ORDER BY clause can also be represented in a LINQ expression. A LINQ Order By clause allows for a comma-delimited list of expressions to specify how results should be sorted. Any valid VB expression can be used, so these expressions don’t necessarily have to be the names of field that were selected.

SQL

SELECT * FROM CustomerTable
ORDER BY Phone

VB

From Contact In CustomerTable _
Order By Contact.Phone

ASC/DESC
A SQL ORDER BY clause can also include ASC and DESC keywords, to specify that the sort should be in ascending or descending order, respectively. VB uses Ascending and Descending keywords for the same purpose, with the same syntax. If neither specifier is present, ascending order is the default.

SQL

SELECT * FROM CustomerTable
ORDER BY Phone ASC, Name DESC

VB

From Contact In CustomerTable _
Order By Contact.Phone Ascending, Contact.Name Descending

Here is the original post by Bill Horst

Dec 03

I have severe lack of time so thats the reason to blog about the following posts in one short notice. Few weeks ago I came across Matt Berseth’s blog and made me quite good impression. He blogs frequently and providing quality posts. His last two I liked a lot.

The first one was about how to create image reflections. He describes three practices:

- Browser Specific Client Side Solution
- Cross Browser Client Side Solution
- Cross Browser Server Side Solution

Which one we choose is a matter of what we really want - rendering time or support for all browsers.

Then he wrote about my favourtite IDE - Visual Studio 2008. Matt described how we can use the new ListVew control plus adding DataPager control and extend it with SliderExtender Control from AjaxControlToolkit.

This post is provided with demo and source code for download. Thanks Matt!

Dec 03

This is a series of posts regarding the new language improvements in VB 9. Bill Horst has written the second on which I came across here. As we all know VB LINQ statements enable SQL-like syntax for queries in the VB language. LINQ syntax doesn’t match SQL syntax exactly, so if you are already working with SQL or familiar with SQL queries, you may find yourself wanting to convert an existing SQL query to LINQ.

And here is an example with FROM clause:

A SQL SELECT statement always begins with a SELECT Clause, followed by a FROM Clause. A VB query expression always begins with a From Clause or Aggregate Clause (Aggregate will be discussed later). A basic SQL FROM clause specifies a table over which to query, and similarly, a LINQ From Clause specifies an object over which to query (CustomerTable). This object could represent “In-Memory” data, a SQL data table, or XML information. My examples use the “In-Memory” case, since it allows the simplest code. In addition to this data object, the VB From clause always includes an identifier for the current “row” (Contact), which basically functions as an alias.

SQL

SELECT Contact.CustomerID, Contact.Phone
FROM CustomerTable Contact

LINQ

From Contact In CustomerTable
Select Contact.CustomerID, Contact.Phone

Here is the whole post by Bill Horst.

Nov 27

This afternoon from Microsoft released an updated version of the Silverlight 1.1 Tools Alpha that works with the final release of Visual Studio 2008. You can download it for free here.

The tools alpha refresh released today has the same feature-set as the Silverlight Tools Alpha add-on which was previously available for Visual Studio 2008 Beta2 (it has simply been updated to work with the final VS 2008 release). This feature-set includes basic Silverlight 1.1 project system support, XAML markup editing and intellisense support, debugging support, Expression Blend project compatibility, and VB and C# code-behind intellisense. You can find quickstart tutorials that detail how to use these features here.

The next public preview of Silverlight will include a ton of new runtime features, as well as a significantly enhanced VS 2008 tooling support. Scott Guthrie will be blogging more details about this shortly.

Nov 19

Today Microsoft shipped Visual Studio 2008 and .NET 3.5. You can download the final release using one of the links below:

* If you are a MSDN subscriber, you can download your copy from the MSDN subscription site (note: some of the builds are just finishing being uploaded now - so check back later during the day if you don’t see it yet).

* If you are a non-MSDN subscriber, you can download a 90-day free trial edition of Visual Studio 2008 Team Suite here. A 90-day trial edition of Visual Studio 2008 Professional (which will be a slightly smaller download) will be available next week. A 90-day free trial edition of Team Foundation Server can also be downloaded here.

*If you want to use the free Visual Studio 2008 Express editions (which are much smaller and totally free), you can download them here.

* If you want to just install the .NET Framework 3.5 runtime, you can download it here.

List of New Features - old version

- VS 2008 Multi-Targeting Support
VS 2008 enables you to build applications that target multiple versions of the .NET Framework. This means you can use VS 2008 to open, edit and build existing .NET 2.0 and ASP.NET 2.0 applications (including ASP.NET 2.0 applications using ASP.NET AJAX 1.0), and continue to deploy these application on .NET 2.0 machines.

- ASP.NET AJAX and JavaScript Support
.NET 3.5 has ASP.NET AJAX built-in (no separate download required). In addition to including all of the features in ASP.NET AJAX 1.0, ASP.NET 3.5 also now includes richer support for UpdatePanels integrating with WebParts, ASP.NET AJAX integration with controls like and , WCF support for JSON, and many other AJAX improvements.

- VS 2008 Web Designer and CSS Support
VS 2008 and Visual Web Developer 2008 Express includes a significantly improved HTML web designer (the same one that ships with Expression Web). This delivers support for split-view editing, nested master pages, and great CSS integration.

- Language Improvements and LINQ
The new VB and C# compilers in VS 2008 deliver significant improvements to the languages. Both add functional programming concepts that enable you to write cleaner, terser, and more expressive code. These features also enable a new programming model we call LINQ (language integrated query) that makes querying and working with data a first-class programming concept with .NET.

- Data Access Improvements with LINQ to SQL
LINQ to SQL is a built-in OR/M (object relational mapper) in .NET 3.5. It enables you to model relational databases using a .NET object model. You can then query the database using LINQ, as well as update/insert/delete data from it. LINQ to SQL fully supports transactions, views, and stored procedures. It also provides an easy way to integrate business logic and validation rules into your data model.

- Browsing the .NET Framework Library Source using Visual Studio

Lots of other improvements

The list above is only a small set of the improvements coming. For client development VS 2008 includes WPF designer and project support. ClickOnce and WPF XBAPs now work with FireFox. WinForms and WPF projects can also now use the ASP.NET Application Services (Membership, Roles, Profile) for roaming user data.

Office development is much richer - including support for integrating with the Office 2007 ribbon, and with Outlook. Visual Studio Tools for Office support is also now built-into Visual Studio (you no longer need to buy a separate product).

New WCF and Workflow projects and designers are now included in VS 2008. Unit testing support is now much faster and included in VS Professional (and no longer just VSTS). Continuous Integration support is now built-in with TFS. AJAX web testing (unit and load) is now supported in the VS Test SKU. And there is much, much more…

Installation Suggestions

People often ask me for suggestions on how best to upgrade from previous betas of Visual Studio 2008. In general I’d recommend uninstalling the Beta2 bits explicitly. As part of this you should uninstall Visual Studio 2008 Beta2, .NET Framework Beta2, as well as the Visual Studio Web Authoring Component (these are all separate installs and need to be uninstalled separately). I then usually recommend rebooting the machine after uninstalling just to make sure everything is clean before you kick off the new install. You can then install the final release of VS 2008 and .NET 3.5 on the machine.

Once installed, I usually recommend explicitly running the Tools->Import and Export Settings menu option, choosing the “Reset Settings” option, and then re-pick your preferred profile. This helps ensure that older settings from the Beta2 release are no longer around (and sometimes seems to help with performance).

Note that VS 2008 runs side-by-side with VS 2005 - so it is totally fine to have both on the same machine (you will not have any problems with them on the same box).

Silverlight Tools and VS Web Deployment Project Add-Ins

Two popular add-ins to Visual Studio are not yet available to download for the final VS 2008 release. These are the Silverlight 1.1 Tools Alpha for Visual Studio and the Web Deployment Project add-in for Visual Studio. Our hope is to post updates to both of them to work with the final VS 2008 release in the next two weeks. If you are doing Silverlight 1.1 development using VS 2008 Beta2 you’ll want to stick with with VS 2008 Beta2 until this updated Silverlight Tools Add-In is available.

Read Scott Gu

Nov 17

Today I came across this blog article by Fredrik Normen in which he describes how to list and save data in new MVC Framework.

Here is his part of his post:

When building application today (X)HTML-based web interfaced is often used as the front-end choice today. Several companies used Microsoft SharePoint or other web-based portals solutions as intranet; we have several public applications which are web based. Enterprise applications continue to adopt web-based user interfaces, and this will unlikely change in the near future. A web-based user interface can today target almost any platform, and the deployment of web-based application is much easier than a desktop application that needs to be installed on every client. It’s easier to brand a web application than a desktop application like a Windows Form. A web based application will not take up to much resource on the client’s computer. But there are some challenges also.

The Request-Response paradigm can complicate interactions that would be simple in traditional UI. For example if we have a Windows application we can simply hold the state, HTTP is a stateless protocol which will complicate state management. A web applications user interface today can also be complex, often produced by tools like DreamWeaver and “probably” FrontPage ;) The applications also often use client-side JavaScript. Some content can be hard to be edited by a .Net developer. But for a designer and of course some developers it’s easy to change the user interface, and often a web applications user interface will be changed. This requires a clean separation of presentation from business logic.
With the ASP.Net MVC Framework we will have separation of concerns. We separate the presentation from the business logic. The MVC is an abbreviation of Model View Controller, where the Controller objects accept user input and invoke business logic to create and update model objects. The Model object has the responsibility to provide the data to display; the model is a contract between controller and view. The View objects are responsible to display the Model, as provided by the controller that invokes it. By using the ASP.Net MVC Framework we will have more control over the HTML (a cleaner HTML page), we will have a controller separated from the View. By having this separation developers can create controllers and use unit-testing or TDD without knowing anything about how the model should be presented. The designer of the User Interface doesn’t need to know about the controller, only what data that should be displayed and sent back during a POST. The three parts in the MVC pattern, the View, Controller and Model can be implemented by three different developers and designer at the same. TDD can be applied when creating the Controllers and also the Model, this because of the separations and the possibility to create mock objects. The MVC Framework works against interface so we have interfaces for everything so we can easy create our mocks and test our controllers without needing to know about the View. We can also mock the Model.

read original

Nov 13

Today Scott Guthrie released first post from a series of post describing the new .NET model - MVC(Model View Controller).
It provides a structured model that enforces a clear separation of concerns within applications, and makes it easier to unit test your code and support a TDD workflow. It also helps provide more control over the URLs you publish in your applications, and can optionally provide more control over the HTML that is emitted from them.

In his post he shows how easily a simple E-Commerce application is build. The sample project is availabe in the new Visual Studio 2008 Project Templates.

Great plus for developers is that when created the solution includes also a unit test project!

You can use any unit testing framework (including NUnit, MBUnit, MSTest, XUnit, and others) with the ASP.NET MVC Framework. VS 2008 Professional now includes built-in testing project support for MSTest (previously in VS 2005 this required a Visual Studio Team System SKU), and our default ASP.NET MVC project template automatically creates one of these projects when you use VS 2008.

We’ll also be shipping project template downloads for NUnit, MBUnit and other unit test frameworks as well, so if you prefer to use those instead you’ll also have an easy one click way to create your application and have a test project immediately ready to use with it.

Understanding the Folder Structure of a Project

The default directory structure of an ASP.NET MVC Application has 3 top-level directories:

* /Controllers
* /Models
* /Views

As you can probably guess, we recommend putting your Controller classes underneath the /Controllers directory, your data model classes underneath your /Models directory, and your view templates underneath your /Views directory.

While the ASP.NET MVC framework doesn’t force you to always use this structure, the default project templates use this pattern and we recommend it as an easy way to structure your application. Unless you have a good reason to use an alternative file layout, I’d recommend using this default pattern.

Mapping URLs to Controller Classes

In most web frameworks (ASP, PHP, JSP, ASP.NET WebForms, etc), incoming URLs typically map to template files stored on disk. For example, a “/Products.aspx” or “/Products.php” URL typically has an underlying Products.aspx or Products.php template file on disk that handles processing it. When a http request for a web application comes into the web server, the web framework runs code specified by the template file on disk, and this code then owns handling the processing of the request. Often this code uses the HTML markup within the Products.aspx or Products.php file to help with generating the response sent back to the client.

MVC frameworks typically map URLs to server code in a different way. Instead of mapping URLs to template files on disk, they instead map URLs directly to classes. These classes are called “Controllers” and they own processing incoming requests, handling user input and interactions, and executing appropriate application and data logic based on them. A Controller class will then typically call a separate “View” component that owns generating the actual HTML output for the request.

Also here are his conclusion words:
Summary

This first blog post is a pretty long one, but hopefully helps provide a reasonably broad look at how all the different components of the new ASP.NET MVC Framework fit together, and how you can build a common real world scenario with it. The first public preview of the ASP.NET MVC bits will be available in a few weeks, and you’ll be able to use them to do all of the steps I outlined above.

While many of the concepts inherent to MVC (in particular the idea of separation of concerns) are probably new to a lot of people reading this, hopefully this blog post has also show how the ASP.NET MVC implementation we’ve been working on fits pretty cleanly into the existing ASP.NET, .NET, and Visual Studio feature-set. You can use .ASPX, .ASCX and .MASTER files and ASP.NET AJAX to create your ASP.NET MVC Views. Non-UI features in ASP.NET today like Forms Authentication, Windows Authentication, Membership, Roles, Url Authorization, Caching, Session State, Profiles, Health Monitoring, Configuration, Compilation, Localization, and HttpModules/HttpHandlers all fully support the MVC model.

If you don’t like the MVC model or don’t find it natural to your style of development, you definitely don’t have to use it. It is a totally optional offering - and does not replace the existing WebForms Page Controller model. Both WebForms and MVC will be fully supported and enhanced going forward. You can even build a single application and have parts of it written using WebForms and parts written using an MVC approach if you want.

Read the whole article

Nov 05

Today, during the keynote address at Microsoft TechEd Developers 2007, S. “Soma” Somasegar, corporate vice president of the Developer Division at Microsoft Corp., announced that Microsoft will release Visual Studio 2008 and the .NET Framework 3.5 by the end of November 2007. Visual Studio 2008 and the .NET Framework 3.5 enable developers at all levels to rapidly create connected applications that offer compelling user experiences for Windows Vista, Windows Server 2008, the 2007 Microsoft Office system, mobile devices and the Web. Soma also unveiled plans to open new opportunities for Visual Studio partners, as well as to deliver new tools and resources for developers, including a first Community Technology Preview (CTP) of the Microsoft Sync Framework and new capabilities for Popfly Explorer.

“The highly social and visual nature of the Web has fundamentally changed what users expect from all applications they interact with, regardless of whether it’s on a customer-facing Web site or Windows rich client application, or a desktop business application built using Microsoft Office,” said Somasegar. “Traditionally, organizations have been hard pressed to deliver the richer, more connected applications and services they need to boost productivity, drive revenue and stay ahead of the competition. With Visual Studio 2008 and the .NET Framework 3.5, it is easy for developers to use the skills they already have to build compelling applications that take advantage of the latest platforms.”

press release