Developing with
.NET
   Frank La Vigne
   Developer Evangelist
   Microsoft
   @tableteer | FrankLa@Microsoft.com
   www.FranksWorld.com/blog
Not just downloads
• Documentation
• Articles
• Sample Code
• Specialty sites
  • ASP.NET
  • Silverlight.net
  • WindowsClient.net
• And much more!




A Quick Word About MSDN
The Future
Soon, Very Soon.
• Visual Studio 2010
  • Multiple versions with multiple price points
• Expression Blend
Nice to have tools
• F12 Dev Tools
• Fiddler
• Silverlight Spy


Tools of the Trade
Web    Windows      Cloud      Phone     Games       Data



      Write .NET Code in All of These Environments




.NET Everywhere
Win                                          And
WPF               DLR     ASP.NET   WCF     LINQ
         Forms                                        more!




             Base Class Libraries

.NET Framework
  Common Language Runtime

Architecture
 JIT &     Garbage      Security    Exception      Loader &
 NGEN      Collector     Model      Handling        Binder




.NET Architecture
BASE CLASS LIBRARIES
(BCL) IMPROVEMENTS IN .NET
4.X
   Set of public types and APIs
   System.Threading
   System.Threading.Tasks

// Sequential
foreach (var item in sourceCollection)
{
    Process(item);
}

// Parallel
Parallel.ForEach
(sourceCollection, item =>
Process(item));

    Task Parallel Library (TPL)
   Implements the full set of LINQ standard query operators
   Extension methods for the IParallelEnumerable interface
   Additional operators for parallel operations

from n in
names.AsParallel().WithDegreeOfParallelism(ProcessorsT
oUse.Value)
where
      n.Name.Equals(queryInfo.Name,
      StringComparison.InvariantCultureIgnoreCase) &&
      n.State == queryInfo.State &&
      n.Year >= yearStart &&
      n.Year <= yearEnd
        orderby n.Year ascending
        select n;



    Parallel LINQ (PLINQ)
• System.Diagnostics.Contracts
• Code Contracts introduce a way to specify contractual
  information that is not represented by a method or type’s
  signature alone
• Scenarios for using contracts include:
  • Perform static bug finding, which enables some bugs to be found
    without executing the code
  • Create guidance for automated testing tools to enhance test
    coverage
  • Create a standard notation for code behavior, which provides
    more information for documentation



  Design By Contract
• BigInteger
  • Immutable type that represents an arbitrarily large integer whose
    value in theory has no upper or lower bounds
• SortedSet<T>
  • Provides a self-balancing tree that maintains data in sorted order
    after insertions, deletions, and searches




  Data Types
• Memory-Mapped File
  • Used to edit very large files and to create shared memory
    for inter-process communication


• Stream.CopyTo
  • Allows you to copy the contents of one stream into another




I/O
EHANCEMENTS TO
PROGRAMMING LANGUAGES
IN .NET 4.X
• Auto-Implemented Properties
  • Shortened syntax that enables you to quickly specify a property of
    a class without having to write code

• Collection Initializer
  • Shortened syntax that enables you to create a collection and
    populate it with an initial set of values

• Implicit Line Continuation
  • Enables you to continue a statement on the next consecutive line
    without using the underscore character




Visual Basic
• Dynamic Type
  • Operations that contain expressions of type dynamic are not
    resolved or type ch`ecked by the compiler. The compiler packages
    together information about the operation, and that information is
    later used to evaluate the operation at run time
• Optional and Named Parameters
  • Named arguments enable you to specify an argument for a
    particular parameter by associating the argument with the
    parameter's name rather than with the parameter's position in the
    parameter list.
  • Optional arguments enable you to omit arguments for some
    parameters. Both techniques can be used with methods, indexers,
    constructors, and delegates.

  C#
• You can configure restart manager to autosave documents
  and restart your application after it exits unexpectedly
• Lambda expressions are available in C++
• The new CTaskDialog replaces the standard Windows
  message box and adds functionality to display and gather
  more information




C++
•   IDE support for F#
•   Interactive F# for prototyping code
•   Asynchronous constructs
•   Parallel constructs
•   Immutable data types




F#
Web Client Development
But What About?
I <3 Silverlight!
• Blue Angels Web Site
  • http://blueangels.navy.mil



You Can Use Them Both
Looking Forward
http://buildmypinnedsite.com/




Site Pinning
Web Platform Installer
                                  Ajax Control Toolkit & jQuery

                                           ASP.NET

                                  ADO.NET Entity Framework

                                          SQL Server

                                               IIS


The Microsoft Web Platform combines a rich and powerful web
application framework with a supporting cast of
tools, servers, technologies and applications for
creating, designing, developing and delivering web solutions.


The Microsoft Web Platform
I’m a professional        I <3 Web Apps.        I want to build web
 software developer and    I just need a tool that   sites myself with an
  I build complex, large   makes them easier to        easy to learn tool
  scale web sites with a   configure, customize         and framework
    team of developers        and publish them




Today’s Web Developers
A Free Web Dev Tool
Visual Studio 2010                WebMatrix

                  ASP.NET Core
      Caching           Modules         Globalization
   Web Forms View Engine            Razor View Engine
       Pages             Controls       Master Pages

       Profile             Roles         Membership
   ASP.NET              ASP.NET             ASP.NET
   Web Forms
    Intrinsics           MVC
                        Handlers            Web Pages
                                            Etc.



ASP.NET: A Framework For All
• Ability to set meta tags
• More control over view state
• Added and Updated browser definition files
• ASP.NET Routing
• The ability to persist selected rows in data controls
• More control over rendered HTML in the FormView and
  ListView controls
• Filtering support for data source controls



    ASP.NET 4 Webforms
WHAT IS MVC?
•   Huge investment from Microsoft
•   Alternative to WebForms
•   Modular Architecture
•   MVC 3.0 now available
    • MVC 4 in Developer Preview stage
• Razor Syntax
• MVC 3.0 Tooling Updated
  April 2011


Model-View-Controller
(MVC)
Controller
                    (Input)




       View                     Model
  (Presentation)                (Data)




ASP.NET MVC 101
• What does MVC look like?

                             Controller
  Request       Controller   Retrieves Model
                             “Performs Work”




                             View
   Response       View       Visually represents
                             the model




How MVC Works
WHY SHOULD
WE CARE ABOUT
ASP.NET MVC
IN
PUBLIC SECTOR?
• Users disdain “Ugly” URLs
  • http://answers.usa.gov/system/selfservice.controller?CONFI
    GURATION=1000&PARTITION_ID=1&CMD=VIEW_A
    RTICLE&ARTICLE_ID=11951&USERTYPE=1&LANGU
    AGE=en&COUNTRY=US
    vs
    http://www.whitehouse.gov/briefing-room/speeches-and-
    remarks
• Search Engine Optimization (SEO)
  • Discoverability




More Web Savvy Citizens
• Powerful, patterns-based way to build dynamic websites
• Enables a clean separation of concerns
• Gives you full control over markup for enjoyable, agile
  development.




Developer Productivity
• Enable fast, TDD-friendly development for creating
  sophisticated applications
• Separation of concerns makes for easier testing




Testing
• Uses the latest web standards.
• Full control over markup makes creating
  compliant sites easier




Accessibility
• No ViewState
  • Smaller HTML payload
  • Faster downloads
• HTML5
  • Easy to implement eye catching graphics that leverage GPU
    acceleration with IE9 and IE10




Performance
DEMO
Creating an ASP.NET MVC 3 Project
Razor
@if (You.Understand(Razor)) {
       <div>Hooray!</div>
}
• New, Simplified View Engine
• Write fewer lines of code
• More natural mix code and markup
• Helpers save you time
• Compatible with ASP.NET Web Pages in WebMatrix
  • http://bit.ly/WhatIsWebMatrix




 Razor Syntax
Web Forms            <ul>
  (6 markup transitions):     <% for (int i = 0; i < 10; i++) { %>
                                <li><% =i %></li>
                              <% } %>
                            </ul>


          PHP               <ul>
                              <?php
  (2 markup transitions          for ($i = 0; $i < 10; $i++) {
      & an echo):                   echo("<li>$i</li>");
                                 }
                              ?>
                            </ul>


         Razor              <ul>
                              @for (int i = 0; i < 10; i++) {
  (2 markup transitions):       <li>@i</li>
                              }
                            </ul>




Razor: a Cut Above the Rest
@{
                                var name = “John Doe”;
       Option 1:                <div>
      HTML Block                  Your name: @name
                                </div>
                           }

                           @{
                                var name = “John Doe”;
        Option 2:               <text>
       Text Block                 Your name: @name
                                </text>
                           }

        Option 3:          @{
                                var name = “John Doe”;
   Single line of output        @: Your name: @name
        in markup          }




Easier Code to Markup Transitions
@*
                 <div>
   Option 1:       Hello World
   Markup        </div>
               *@


               @{
                 //var name = "John Doe”;
   Option 2:     //@name
    Code       }


               @*
   Option 3:     @{
                   var name = "John Doe";
    Both           @name
                 }
               *@




Code Comments in Razor
SILVERLIGHT & WPF
DEVELOPMENT
Two Platforms
WPF




              Silverlight




Similar But Different
Two Core      One Common
    Technologies    Language




2 Platforms Powered By XAML
• Markup language derived from XML
• XML serialization of CLR objects
• Markup files have code-behind files
  • Could be C# or VB.NET
• Conceptually similar to ASP.NET
• X stands for Extensible
  • Data Binding
  • Styles
  • Templates


Intro to XAML
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
  <Grid>
    <Button>Click Me!</Button>
  </Grid>
</Window>



     What Does XAML Look Like?
Results
Most Devs Reaction to Blend
Demo
Mobile
For the purposes of this talk, we’ll focus on Silverlight.




1 Platform. 2 Choices.
What is Metro?
METRO IS OUR DESIGN
  ETRO
LANGUAGE. WE CALL IT
METRO BECAUSE IT’S
MODERN AND CLEAN. IT’S
FAST AND IN MOTION. IT’S
ABOUT CONTENT AND
TYPOGRAPHY. AND IT’S
ENTIRELY AUTHENTIC.
Desktop?
• http://frnk.us/8GreatTraitsOfMetroApps
• http://frnk.us/MetroTutorial




Metro Resources
DEMO
Creating a Windows Phone App
Marketplace Sample
•   Creates Entity Model from Database
•   Helpful in creating RESTful Services
•   Exposes Database as Classes/Methods
•   Works with any Database
•   Useful in MVC, Dynamic Data Models




What is the Entity Framework?
Database                 Generated
 First       Existing     Entity Data
            Database        Model




 Model
 First
            Entity Data   Generated
               Model
                          Database



Code-First in EF 4.1
DEMO
 Phone SDK Download
  http://bit.ly/WinPhoneSDKDownload
 Web Matrix
  http://bit.ly/WhatIsWebMatrix
 Azure
  http://bit.ly/FreeAzure90DayTrial
  http://bit.ly/DownloadAzureSDK

 Useful Resources

Intro to .NET for Government Developers

  • 1.
    Developing with .NET Frank La Vigne Developer Evangelist Microsoft @tableteer | [email protected] www.FranksWorld.com/blog
  • 2.
    Not just downloads •Documentation • Articles • Sample Code • Specialty sites • ASP.NET • Silverlight.net • WindowsClient.net • And much more! A Quick Word About MSDN
  • 3.
  • 4.
  • 5.
    • Visual Studio2010 • Multiple versions with multiple price points • Expression Blend Nice to have tools • F12 Dev Tools • Fiddler • Silverlight Spy Tools of the Trade
  • 7.
    Web Windows Cloud Phone Games Data Write .NET Code in All of These Environments .NET Everywhere
  • 8.
    Win And WPF DLR ASP.NET WCF LINQ Forms more! Base Class Libraries .NET Framework Common Language Runtime Architecture JIT & Garbage Security Exception Loader & NGEN Collector Model Handling Binder .NET Architecture
  • 9.
    BASE CLASS LIBRARIES (BCL)IMPROVEMENTS IN .NET 4.X
  • 10.
    Set of public types and APIs  System.Threading  System.Threading.Tasks // Sequential foreach (var item in sourceCollection) { Process(item); } // Parallel Parallel.ForEach (sourceCollection, item => Process(item)); Task Parallel Library (TPL)
  • 11.
    Implements the full set of LINQ standard query operators  Extension methods for the IParallelEnumerable interface  Additional operators for parallel operations from n in names.AsParallel().WithDegreeOfParallelism(ProcessorsT oUse.Value) where n.Name.Equals(queryInfo.Name, StringComparison.InvariantCultureIgnoreCase) && n.State == queryInfo.State && n.Year >= yearStart && n.Year <= yearEnd orderby n.Year ascending select n; Parallel LINQ (PLINQ)
  • 12.
    • System.Diagnostics.Contracts • CodeContracts introduce a way to specify contractual information that is not represented by a method or type’s signature alone • Scenarios for using contracts include: • Perform static bug finding, which enables some bugs to be found without executing the code • Create guidance for automated testing tools to enhance test coverage • Create a standard notation for code behavior, which provides more information for documentation Design By Contract
  • 13.
    • BigInteger • Immutable type that represents an arbitrarily large integer whose value in theory has no upper or lower bounds • SortedSet<T> • Provides a self-balancing tree that maintains data in sorted order after insertions, deletions, and searches Data Types
  • 14.
    • Memory-Mapped File • Used to edit very large files and to create shared memory for inter-process communication • Stream.CopyTo • Allows you to copy the contents of one stream into another I/O
  • 15.
  • 16.
    • Auto-Implemented Properties • Shortened syntax that enables you to quickly specify a property of a class without having to write code • Collection Initializer • Shortened syntax that enables you to create a collection and populate it with an initial set of values • Implicit Line Continuation • Enables you to continue a statement on the next consecutive line without using the underscore character Visual Basic
  • 17.
    • Dynamic Type • Operations that contain expressions of type dynamic are not resolved or type ch`ecked by the compiler. The compiler packages together information about the operation, and that information is later used to evaluate the operation at run time • Optional and Named Parameters • Named arguments enable you to specify an argument for a particular parameter by associating the argument with the parameter's name rather than with the parameter's position in the parameter list. • Optional arguments enable you to omit arguments for some parameters. Both techniques can be used with methods, indexers, constructors, and delegates. C#
  • 18.
    • You canconfigure restart manager to autosave documents and restart your application after it exits unexpectedly • Lambda expressions are available in C++ • The new CTaskDialog replaces the standard Windows message box and adds functionality to display and gather more information C++
  • 19.
    IDE support for F# • Interactive F# for prototyping code • Asynchronous constructs • Parallel constructs • Immutable data types F#
  • 20.
  • 21.
  • 22.
  • 23.
    • Blue AngelsWeb Site • http://blueangels.navy.mil You Can Use Them Both
  • 24.
  • 25.
  • 26.
    Web Platform Installer Ajax Control Toolkit & jQuery ASP.NET ADO.NET Entity Framework SQL Server IIS The Microsoft Web Platform combines a rich and powerful web application framework with a supporting cast of tools, servers, technologies and applications for creating, designing, developing and delivering web solutions. The Microsoft Web Platform
  • 27.
    I’m a professional I <3 Web Apps. I want to build web software developer and I just need a tool that sites myself with an I build complex, large makes them easier to easy to learn tool scale web sites with a configure, customize and framework team of developers and publish them Today’s Web Developers
  • 28.
    A Free WebDev Tool
  • 29.
    Visual Studio 2010 WebMatrix ASP.NET Core Caching Modules Globalization Web Forms View Engine Razor View Engine Pages Controls Master Pages Profile Roles Membership ASP.NET ASP.NET ASP.NET Web Forms Intrinsics MVC Handlers Web Pages Etc. ASP.NET: A Framework For All
  • 30.
    • Ability toset meta tags • More control over view state • Added and Updated browser definition files • ASP.NET Routing • The ability to persist selected rows in data controls • More control over rendered HTML in the FormView and ListView controls • Filtering support for data source controls ASP.NET 4 Webforms
  • 32.
  • 33.
    Huge investment from Microsoft • Alternative to WebForms • Modular Architecture • MVC 3.0 now available • MVC 4 in Developer Preview stage • Razor Syntax • MVC 3.0 Tooling Updated April 2011 Model-View-Controller (MVC)
  • 34.
    Controller (Input) View Model (Presentation) (Data) ASP.NET MVC 101
  • 35.
    • What doesMVC look like? Controller Request Controller Retrieves Model “Performs Work” View Response View Visually represents the model How MVC Works
  • 36.
    WHY SHOULD WE CAREABOUT ASP.NET MVC IN PUBLIC SECTOR?
  • 37.
    • Users disdain“Ugly” URLs • http://answers.usa.gov/system/selfservice.controller?CONFI GURATION=1000&PARTITION_ID=1&CMD=VIEW_A RTICLE&ARTICLE_ID=11951&USERTYPE=1&LANGU AGE=en&COUNTRY=US vs http://www.whitehouse.gov/briefing-room/speeches-and- remarks • Search Engine Optimization (SEO) • Discoverability More Web Savvy Citizens
  • 38.
    • Powerful, patterns-basedway to build dynamic websites • Enables a clean separation of concerns • Gives you full control over markup for enjoyable, agile development. Developer Productivity
  • 39.
    • Enable fast,TDD-friendly development for creating sophisticated applications • Separation of concerns makes for easier testing Testing
  • 40.
    • Uses thelatest web standards. • Full control over markup makes creating compliant sites easier Accessibility
  • 41.
    • No ViewState • Smaller HTML payload • Faster downloads • HTML5 • Easy to implement eye catching graphics that leverage GPU acceleration with IE9 and IE10 Performance
  • 42.
  • 43.
  • 44.
    @if (You.Understand(Razor)) { <div>Hooray!</div> } • New, Simplified View Engine • Write fewer lines of code • More natural mix code and markup • Helpers save you time • Compatible with ASP.NET Web Pages in WebMatrix • http://bit.ly/WhatIsWebMatrix Razor Syntax
  • 45.
    Web Forms <ul> (6 markup transitions): <% for (int i = 0; i < 10; i++) { %> <li><% =i %></li> <% } %> </ul> PHP <ul> <?php (2 markup transitions for ($i = 0; $i < 10; $i++) { & an echo): echo("<li>$i</li>"); } ?> </ul> Razor <ul> @for (int i = 0; i < 10; i++) { (2 markup transitions): <li>@i</li> } </ul> Razor: a Cut Above the Rest
  • 46.
    @{ var name = “John Doe”; Option 1: <div> HTML Block Your name: @name </div> } @{ var name = “John Doe”; Option 2: <text> Text Block Your name: @name </text> } Option 3: @{ var name = “John Doe”; Single line of output @: Your name: @name in markup } Easier Code to Markup Transitions
  • 47.
    @* <div> Option 1: Hello World Markup </div> *@ @{ //var name = "John Doe”; Option 2: //@name Code } @* Option 3: @{ var name = "John Doe"; Both @name } *@ Code Comments in Razor
  • 48.
  • 49.
  • 50.
    WPF Silverlight Similar But Different
  • 51.
    Two Core One Common Technologies Language 2 Platforms Powered By XAML
  • 52.
    • Markup languagederived from XML • XML serialization of CLR objects • Markup files have code-behind files • Could be C# or VB.NET • Conceptually similar to ASP.NET • X stands for Extensible • Data Binding • Styles • Templates Intro to XAML
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
    For the purposesof this talk, we’ll focus on Silverlight. 1 Platform. 2 Choices.
  • 59.
  • 61.
    METRO IS OURDESIGN ETRO LANGUAGE. WE CALL IT METRO BECAUSE IT’S MODERN AND CLEAN. IT’S FAST AND IN MOTION. IT’S ABOUT CONTENT AND TYPOGRAPHY. AND IT’S ENTIRELY AUTHENTIC.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
    Creates Entity Model from Database • Helpful in creating RESTful Services • Exposes Database as Classes/Methods • Works with any Database • Useful in MVC, Dynamic Data Models What is the Entity Framework?
  • 67.
    Database Generated First Existing Entity Data Database Model Model First Entity Data Generated Model Database Code-First in EF 4.1
  • 68.
  • 69.
     Phone SDKDownload http://bit.ly/WinPhoneSDKDownload  Web Matrix http://bit.ly/WhatIsWebMatrix  Azure http://bit.ly/FreeAzure90DayTrial http://bit.ly/DownloadAzureSDK Useful Resources