Notes on Windows .NET Framework and Tools

climbmoujeanteaSoftware and s/w Development

Dec 13, 2013 (3 years and 7 months ago)

92 views

Page
1

Notes on
Windows .NET Framework

and Tools

Created
07/16/11

Updated 02/08/12
, Updated 02/23/12
, Updated 12/27/12, Updated 07/06/13, Updated 07/30/13
, Updated 08/06/13

Updated 08/22
/13
, Updated 09/03/13
, Updated 09/25/13
, Updated 09/30/13
, Updated 10/0
4
/13
,
Updated 10/28
/13

Introduction

The .NET framework c
ompetes with Java for web applications
.
Contains implementations of the architecture using
Visual Basic and using C#.

The current version is .NET 4.5, which came out in late 2012.


There are two different

designs to the .NET framework: the original

Web
Forms
-
based

design, and the newer MVC
-
based

design (starting with .NET 3).



This document also include
s an overview of the tools used,
specifically

the Visual Studio series.

Resources

T
here are dozens of bo
oks on .NET

and each of its versions
. Based on our focus on C# and the MVC architecture
(since this is similar to Grails and Ruby

on Rails
), we have focused on some of the following books:


“Pro ASP
.NET MVC 4” by Adam Freeman. Ap
ress, January 2013, 756 p
ages. Amazon price $31.64. Rated 4 stars
on Amazon.com.

Available from City of Palo Alto library.


“Visual Studio 2012” by Bruce Johnson. W
rox Press, Novembe
r

2012,
1104 pages
. List price $59.99, Am
azon
price $35.48, used from $31.57
. Rated 5 stars o
n Amazon.com
. Skimmed this in the bookstore, and it looked well
-
written and clear. Quite comprehensive about .NET and Azure in addition to Visual Studio itself.


“Visual Studio 2012 Unleashed” by Mike Snell and Lars Powers. Sams Press, November 2012, 11
45 pages. List
price $49.99.


“Programming ASP.NET MVC 4” by Jess Chadwick, Todd Snyder, and Hrusikesh Panda. O’Reilly Press, October
2012, 471 pages. List price $49.99, Am
azon price $28.56, used from $19.99. Rated 3.4

stars on Amazon.com.
Quite compr
ehensive and well
-
written.

Read this at the Stanford Bookstore
, available online at City of Palo Alto
library
.


“Pro C# 5.0 and the .NET 4.5 Framework (Sixth Edition)” by
Andrew Troelsen
z. Ap
ress, August 2012, 1560 pages.
List price $59.99, Amazon price

$38.98, used from $33.55. Rated 4.5 stars on Amazon.com. Available from the
City of Palo Alto Library.



“ASP.NET MVC 4 in Action: Revised edition of

ASP.NET MVC 2 in Action”
b
y

Jeffrey Palermo,
et. al.

Manning
Press, June
2012,
440

pages. Lis
t price
$49.99. Amazon price $26.23, used from $19.75
.
Rated 2

stars on
Amazon.com.
Available from City of Palo Alto

Library
.


“Beginning ASP.NET 4.5 in C#” by
Matthew MacDonald
.
Apress, 2012.
Rated 4 stars on Amazon.com.
Skimmed
this at the bookstore, however, it didn’t have much material on
using the MVC architecture.


One of the most useful tutorials
is at
http://www.asp.net/mvc/tutorials/mvc
-
4/getting
-
started
-
with
-
aspnet
-
mvc4/intro
-
to
-
aspnet
-
mvc
-
4


Another useful tutorial, because it dealt wi
th a multi
-
table data model is at

http://www.asp.net/mvc/tutorials/getting
-
started
-
with
-
ef
-
using
-
mvc/c
reating
-
an
-
entity
-
framework
-
data
-
model
-
for
-
an
-
asp
-
net
-
mvc
-
application


Also see the following video on creating a web service:

http://www.youtube.com/watch?v=J3_Z6ZHVLho


Page
2

A comparison between .NE
T and Ruby on Rails is present at
http://redlinesoftware.com/blog/2012/01/26/asp
-
dot
-
net
-
mvc
-
vs
-
ruby
-
on
-
rails
-
smackdown
-
results

Tools

We are usin
g
Visual Studio
Express
2012
.


Microsoft provides "Express" editions of its Visual Studio 2010 components Visual Basic, Visual C#, Visual C++,
and Visual Web Developer at no cost.

The professional copies are $
499

and up.


Final build of Visual Studio 2012

was announced on August 1, 2012 and the official launch event

was held on
September 12, 2012. Some of the features include:



Semantic Colorization
: Improved syntax coloring, various user
-
defined or default colors for C++ syntax
such as macros, enumera
tion
s, typenames, functions etc.



Reference Highlighting
: Selection of a symbol highlights all of the referen
ces to that symbol within scope.



New Solution Explorer
: New solution explorer allows for visualization of class and file hierarchies within
a solution/p
roject. Searching for calls to functions and uses of classes wil
l be supported.



Automatic Display of IntelliSense list
: IntelliSense will automatically be displayed whilst typing code, as
opposed to previous versions where it had to be explicitly invoked t
hrough use of certain operators (i.e. the
scope operator (::)) or shortcut keys (
Ctrl
-
Space

or
Ctrl
-
J
).



Member List Filtering
: IntelliSense uses
fuzzy logic

to determine which functi
ons/variabl
es/types to
display in the list.



Code Snippets
: Code snippets are included in IntelliSense to automatically generate relevant code based
on the user's parameters, cust
om code snippets can be created.


On April 12, 2010, Microsoft released Visual

Studio 2010, codenamed
Dev10
,
[99]

and
.NET Framework 4
.
[100]
[101]

Visual Studio 2010
IDE

has been redesigned which, according to
Microsoft
, clears the UI organization and "reduces
clutter and complexity."
[102]

The new IDE better supports multiple document windows and floating tool
windows,
[102]

while offering better multi
-
monitor support.

The IDE shell has been rewritten using the
Windows
Presentation Foundation

(WPF),
[103]

whereas the internals have been redesigned using
Managed Extensibility
Framework

(MEF) that offers more extensibility points than previous versions of the IDE that enabled add
-
ins to
modify the behavior
of the IDE.


The new
multi
-
paradigm

ML
-
variant
F#

f
orms part of Visual Studio 2010.


Visual Studio
2010 and later include source controls based on Micrsoft
-
specific tools. Visual Studio 2013 and later
provide integration of Git as a source control tool, and facilities to

import/clone/publish to GitHub.

Example Session

You manage the Azure account from the Azure control panel.


Then you create web sites or applications on Azure (in this example, we created grebsir2)


Then you start

up Visual Studio locally.


Create a proje
ct,
and
then when publishing, download th
e publishing profile from Azure. Install this.


Create controllers and Views


Publish the project


Access the project at <profileName>
.azurewebsites.net.

Page
3

Structure of an Application

Each of the files and directorie
s within the default project template serves a specific purpose. We’ll take a look at
each one in turn:

The App_Data Directory

The App_Data directory can be used to store databases, XML files, or any other data that your application needs.
The ASP.NET ru
ntime understands this special directory and will prevent users from accessing files in it directly.
Only your application can read and write to this directory.


The Content Directory

The purpose of the Content directory is to contain any noncode assets
that need to be deployed with your
application. These typically include images and CSS files (stylesheets). By default, the Content directory contains
the default stylesheet used by the project (Site.css) as well as a themes subdirectory that contains imag
es and CSS
for use with jQuery UI.


The Controllers Directory

T
he controller is the coordinator that is responsible for processing input and then deciding which actions should be
performed (such as rendering a view). In ASP.NET MVC, controllers are repre
sented as classes within the
Controllers directory. By default, this directory contains two controllers

the
HomeController

(which handles
requests for your home page) and the
AccountController

(which handles authentication).


The Models Directory

The Mode
ls directory is typically used to contain any classes that represent the core concepts of your application, or
classes that hold data in a format that is specific to a particular view (a
view model
). As your applications get larger,
you may decide that you

wish to move these classes into a separate project, but keeping them in the Models
directory is a good starting point for small projects. The default project contains a single file in this directory

AccountModels.cs. It contains several classes related to

authentication that are used by the default project template.


The Scripts Directory

The Scripts directory is where you can place any JavaScript files used by your application. The default project
template contains quite a lot of files in this directory
, including the popular open
-
source jQuery library and scripts
used for performing client
-
side validation.


The Views Directory

The Views directory contains the templates used to render your user interface. Each of these templates is represented
as a Raz
or view (a .cshtml or .vbhtml file) within a subdirectory named after the controller resp
onsible for rendering
that view
.


Global.Asax

The Global.asax file lives in the root of the project structure and contains initialization code that runs when the
app
lication is first started up, such as code that registers routes (which we’ll explore briefly in the next section).


Web.Config

The Web.config file also lives in the root of the application and contains configuration details necessary for
ASP.NET MVC to
run correctly.

Deployment
-
specific Configuration Files

Under web.config are web.debug.config and web.release.config.

The former is a config file in its usual form. The
latter are called “transformation files” and contain instructions for how to change t
he former upon deployment.
Typically these correspond to different deployment targets (i.e, development, production, etc.).


Web.Config Transformation Engine is a simple XML Transformation Engine which takes a source file (your
project’s original web.conf
ig file) and a
transform file (e.g. web.release
.config) and produces an output file
(web.config ready for staging environment).

The
Transform file (e.g. web.release
.config ) needs to have XML
Document Transform namespace registered at the root node as sh
own below:

Page
4


<?
xml

version
="1.0"
?
>


<
configuration

xmlns:xdt
="http://schemas.microsoft.com/XML
-
Document
-
Transform">


</
configuration
>



Some examples of what Transforms can do are:



Replacing a node



Inserting a node



Delete a node



Removing Attributes



Se
tting Attributes


Here is an example:


<
configuration

xmlns:xdt
=
"
http://schemas.microsoft.com/XML
-
Document
-
Transform
"
>


<!
--


In the example below, the "SetAttributes" transform will change the value of


"connectionString" to use "ReleaseSQLServer
" only when the "Match" locator


finds an atrribute "name" that has a value of "MyDB".




<connectionStrings>


<add name="MyDB"


connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated
Security=True"



xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>


</connectionStrings>


--
>


<
system.web
>


<
compilation

xdt:Transform
=
"
RemoveAttributes(debug)
"

/>


<!
--


In the example below, the "Replace" transform will replace the entire


<customErrors> section of your Web.config file.


Note that because there is only one customErrors section under the


<system.web> node, there is no need to use the "xdt:Locator" attribute.




<customErrors defaultRedirect="Generi
cError.htm"


mode="RemoteOnly" xdt:Transform="Replace">


<error statusCode="500" redirect="InternalError.htm"/>


</customErrors>


--
>


</
system.web
>

</
configuration
>

Features of Controllers

Dispatching

This is similar to Spring, wher
e there can be method signatures that indicate request type and processing of request
parameters.


Use

t
he

[HttpPost]

annotation;

otherwise the default is

Get


or any request type.

How Controllers S
end Info to Views

Add content to the
ViewBag.


The
ViewBa
g

is essentially a dictionary

it provides a way to store data that can then be accessed from within a
view.

It uses the dynamic language features of .NET 4 to allow the creation of properties on the fly. For example,
you can assign another property to the

ViewBag

with a single line of code:


public ActionResult Index()

Page
5

{


ViewBag.
Message = "Modify this
to jump
-
start your ASP.NET MVC

application.";



ViewBag.CurrentDate = DateTime.Now;



return View();

}


Here we simply assigned the current date a
nd time to a property on the
ViewBag

called
CurrentDate
. This
property was created on the fly and there was no need to modify a class definition in order to add this property. We
can now access this property from within our view, which is rendered by the c
all to
return View()
.


You can also use ViewData, which is a dictionary.

Working w
ith Databases

.NET supports several types of databases, which are selected through configuration options. Databases provided
with the typical install package:




SQL Express
LocalDB is created specifically for developers.

It is very easy to install and requires no
management, yet it offers the same T
-
SQL language, programming surface and client
-
side providers as the
regular SQL Server Express.


In effect the developers that t
arget SQL Server no longer have to install and
manage a full instance of SQL Server Express on their laptops and other development machines.

Moreover, if the simplicity (and limitations) of LocalDB fit the needs of the target application environment,
dev
elopers can continue using it in production, as LocalDB makes a pre
tty good embedded database too.



SQL Server Compact is a new lightweight database that can be used with both web and desktop
applications. Unlike the full version of SQL Server, SQL Server C
ompact doesn’t require the installation of
any server software in order to run. This means that it is
bin
-
deployable
, meaning that you can use SQL
Server Compact databases merely by adding the appropriate DLLs to your application’s bin folder. The
biggest
advantage of this approach is that you can deploy SQL Server Compact databases to any hosting
provider running .NET 4 without the hosting provider having to install anything.



Full instances of SQL Server can be used. These can be located on a local syste
m, remote system or on
Azure.

Setting up Connection Strings for databases

Place these into Web.config, as shown here:


<?
xml

version
=
"
1.0
"

encoding
=
"
utf
-
8
"
?>

<!
--


For more information on how to configure your ASP.NET application, please visit


http://go
.microsoft.com/fwlink/?LinkId=169433


--
>

<
configuration
>


<
configSections
>


<!
--

For more information on Entity Framework configuration, visit
http://go.microsoft.com/fwlink/?LinkID=237468
--
>


<
section

name
=
"
entityFramework
"

type
=
"
System.Data.Ent
ity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework,
Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
"

requirePermission
=
"
false
"

/>


</
configSections
>


<
connectionStrings
>


<!
--
add name="DefaultConnection"


connec
tionString="Data Source=(LocalDb)
\
v11.0;Initial Catalog=aspnet
-
MvcApplication1
-
20130712164230;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|
\
aspnet
-
MvcApplication1
-
20130712164230.mdf"


providerName="System.Data.SqlClient"
--
>


<
add

n
ame
=
"
DefaultConnection
"

Page
6


connectionString
=
"
Server=tcp:qer5k4xek0.database.windows.net,1433;Database=rallyon;User
ID=developer@qer5k4xek0;Password=
<password>
;Trusted_Connection=False;Encrypt=True;Connection
Timeout=30;
"


providerName
=
"
System
.Data.SqlClient
"

/>


</
connectionStrings
>


<
appSettings
>


<
add

key
=
"
webpages:Version
"

value
=
"
2.0.0.0
"

/>


<
add

key
=
"
webpages:Enabled
"

value
=
"
false
"

/>


<
add

key
=
"
PreserveLoginUrl
"

value
=
"
true
"

/>


<
add

key
=
"
ClientValidationEnabled
"

value
=
"
true
"

/>


<
add

key
=
"
UnobtrusiveJavaScriptEnabled
"

value
=
"
true
"

/>


</
appSettings
>


In this configuration, we have changed the connection that is used for the default login/membership system. It was
changed from a use of “LocalDB”, over to a SQL datab
ase on Azure.

Data Models and the Entity Framework

EF is like GORM
/Hibnerate
.


You write a set of Model classes, then write one subclass of DbContext that includes a collection of each of the
domain classes.


Here is a typical Model class:


namespace

DN0
2.Models

{


public

enum

ThresholdKind


{


Daily, Weekly, Monthly, Quarterly


}



public

class

ChallengeActivity


{


public

int

ID {
get
;
set
; }


public

int

ChallengeID {
get
;
set
; }


public

int

ActivityID {
get
;
set
; }


public

double

ThresholdValue {
get
;
set
; }


public

ThresholdKind

ThresholdKind {
get
;
set
; }


public

int

NumberThresholds {
get
;
set
; }


public

int

PointsPerThreshold {
get
;
set
; }



public

virtual

Challen
ge

Challenge {
get
;
set
; }


public

virtual

Activity

Activity {
get
;
set
; }


}

}


Here is a DbContext class.
Think of this class as both a DB connection, and a specification of cached state that is
maintained by EF for your application. Here is
an example:


namespace

MvcMovie.DAL

{


public

class

RallyOnContext

:
DbContext


{


public

DbSet
<
Activity
> Activities {
get
;
set
; }


public

DbSet
<
Challenge
> Challenge {
get
;
set
; }


public

DbSet
<
ChallengeActivity
> ChallengeActivit
ies {
get
;
set
; }



protected

override

void

OnModelCreating(
DbModelBuilder

modelBuilder)

Page
7


{


modelBuilder.Conventions.Remove<
PluralizingTableNameConvention
>();


}


}

}

The
P
ersistence
L
ayer

and Query I
nterface

Create a db
Context. This is similar to a wrapper around a connection.


Then use db.<EntityName>.ToList() to fetch all


db.<EntityName>
.
Find(id) to fetch one record.


db.Entry(<object>).State = EntityState.Modified; db.SaveChanges(); to save one record.


There are al
so facilities to build up query strings, using LINQ.

This uses a SQL
-
like syntax in C#. Examples:


var

movies =
from

m
in

db.Movies


select

m;



if

(!
String
.IsNullOrEmpty(searchString))

{


movies = movies.Where(s => s.Title.
Contains(searchString));


}

Database Tools within Visual Studio

Click on the
Database Explorer tab at the bottom of the right
-
hand window:



Within this tool, we can view DB structure and content, much like the tools for MySQL.


Note that if you hav
e configured the database to use Azure, unless is configured to accept requests from your local
system, you will not be able to connect to or view the database.

Page
8

Using Schema Migrations

This is a key feature of the framework, and is similar to that provided

in Rails. Each migration is a file that contains
a set of directives to migrate “up” or “down”.


There is a table in the database called “__MigrationHistory” that indicates what migrations have been applied. This
way the deployment process knows what on
es to apply.

That table is hidden, but you can fetch from or alter if it you
type in the full tablename with underscores in a SQL statement through the SQL console.


You
use the Package Manager
Console to issue migration directives, including one to creat
e a migration (perhaps by
diffing the current model and the existing schema), and one to update the database. There were similar commands
in the Liquibase plugin for Grails.


Run the

e
nable
-
m
igrations


command in Package Manager
Console
.

Run the “
add
-
m
ig
ration

<name>


command
in Package Manager Console.


This will generate the migration automatically, based on comparing the new and deployed schema. You may need
to review the file before running it.


Run the “
update
-
database
” command in Package Manager Co
nsole.

How

to C
ustomize a View

Here we are discussing the
view rendering engine that is provided with .NET MVC, which is

called Razor.


The organization of views within a .NET MVC application is that there is a directory called “Views”, and within
that is
“Shared” directory (contains layouts that are used as the master layout for many views), and “Entity
-
class
specific” directory, which includes a list, detail, edit, create, etc. view for that entity class.


There are also view partials.


To create a link,
use

a helper such as:

@
Html.ActionLink(
"your logo here"
,
"Index"
,
"Home"
)


At the top, the layout contains CSS and script imports.

The Site.css file contains the styles for the application, and
the script element includes the jQuery library

(currently at

version 1.8.2)
, which we can use to add rich client
interactivity to the page.


To change the application title, we can simply replace the contents of the
<h1>

element with a string of our
choosing (in this case, let’s use “My Guest Book”).



There are s
everal other interesting things in this file.

The Log On link that you see in the default application is
rendered through a
partial view
.

We’ll be looking at partial views later, but they essentially provide a way to re
-
use
portions of HTML across multip
le pages.

Summary of C
apabilities of the Rendering Engine (Razor)

Fetch values from the ViewBag

Include other files

(@RenderBody, @RenderSection, @Render.Script)

Include from the packages of supporting libraries (i.e., the jQuery library)

Iteration (@for
)

Conditional Logic (@if)


The main files are located in the views folder, along with the supporting files in the packages folder.


There is a concept of “sections” and “partial views”, but these need further explanation.


There are also facilities to genera
te drop
-
down selectors.

Page
9

Helpers

These all seem to start with “Html”.


There are several variants on ActionLink.


@
Html.ActionLink(
"your logo here"
,
"Index"
,
"Home",
null,

new { @class = "btn"}
)


Within a form, you might use:


@
using

(Html.BeginForm()) {



<form contents>

}


@
Html.LabelFor(model => model.Name)


@
Html.EditorFor(model => model.Name)

@
Html.ValidationMessageFor(model => model.Name)


@
Html.DropDownListFor(model => model.TeamworkType,
new



SelectList
(
Enum
.GetValues(
typeof
(DN02.Models.
Teamwo
rkType
))))


Using jQuery in the View

See
http://www.codeproject.com/Articles/344292/ASP
-
NET
-
MVC3
-
Razor
-
With
-
jQuery
-
For
-
Beginners


Although it is n
ot a direct part of MVC, jQuery is a very useful JavaScript library that can enable you to enhance
your user interface.

The first useful thing you will be able to do is

easily find HTML elements in DOM tree. This is
a standard use of jQuery selectors
.


j
Query selector

Description

$("table")

Find all table nodes in the HTML

$("#Name")

Find elements in the HTML with ID
Name

$(".required")

Find all elements in the HTML that have CSS class "
required
"

$("table a.delete")

In any table, find all
A

tags tha
t have CSS class "
delete
"

$("table tr:odd")

Find all odd rows in the table

Once you find elements with jQuery selectors, you can hide them, change their color, attributes (classes, values,
inner text), add some event handlers to them (click, double cli
ck), e
tc.


Another example would be to add a DatePicker to the page. In many programs, a date
is entered as plain text
.
Instead of plain text input, we

will attach a jQuery
DatePicker

to this field so the user can select a date from the
calendar popup. In

order to integrate the jQuery
DatePicker
, we

will put the following custom script in the edit
view:


@section PageScripts{


<link href=
"/Content/themes/base/jquery.ui.all.css"

rel=
"stylesheet"

type=
"text/css"

/>


<script src=
"/Scripts/jquery
-
ui
-
1.8.
11.js"

type=
"text/javascript"
>
</
script
>


<
script

type
="text/javascript">


$(document).ready(function () {


$(
"input#DoB"
).datepicker();


});


</script>

}


This custom script will include all necessary JavaScript and CSS files

(jQuery UI) and put
DatePicker

on the input
element with an ID
DoB
.

Page
10

Using Bundles

These are like the resource combinations that are generated by the Asset Pipeline in Ruby on Rails.


A b
undle is defined in BundleConfig.cs within the App_Start directory.

Here are some examples:



public

static

void

RegisterBundles(
BundleCollection

bundles)


{


bundles.Add(
new

ScriptBundle
(
"~/bundles/jquery"
).Include(


"~/Scripts/jquery
-
{version}.js"
));



bundles.Ad
d(
new

ScriptBundle
(
"~/bundles/jqueryui"
).Include(


"~/Scripts/jquery
-
ui
-
{version}.js"
));



bundles.Add(
new

ScriptBundle
(
"~/bundles/jqueryval"
).Include(


"~/Scripts/jquery.unobtrusive*"
,



"~/Scripts/jquery.validate*"
));

}


Using Filters

This is like Filters in a Grails project. They are defined in FilterConfig.cs within the App_Start directory.

Using AJAX Requests

The framework supports this.

Use the Ajax request methods within

jQuery on the client side, and use partial views
on the server to render the results.


ASP.NET MVC also offers native JSON result support in the form of the JsonResult action result, which accepts a
model object and serializes it into the JSON format.

Usi
ng Services and Dependency Injection

There are several different IoC containers out there, and the one with best reviews is
Ninject
. It is extremely simple
to use, contained within a single DLL, and configured with a fluent
-
like syntax (e.g., when registe
ring the various
type mappings and object instances).

Build, Test, and Deploy

This section discusses the .NET support for writing test
s
, running tests, and automation of tests as part of
deployment.


The approaches described here
make use of the MSBuild co
mponent of the Visual Studio suite, plus
the
Te
am Foundation Server (TFS), which runs locally or on a cloud
-
based server.

Writing Tests

What test framework is used?

VisualStudio.TestTools.


This offers a set of “assert” checks that are similar to JUnit.

S
ource Control Tools

The primary tool is
TFVC
, which

is a centralized version control system.


While it works well for small teams with small code bases, TFVC is capable of scaling to support very large
codebases (millions of files per branch with server w
orkspaces) and it handles large binary files well. TFVC
provides very granular permission control, allowing teams to restrict access down to a file level if needed. Since all
contributions are checked in to the central server, it is very easy to audit chan
ges and identify exactly which user
committed a given code change.


Page
11

In addition, Git support is offered by a p
lug
-
in available for Visual Studio 2012 since Jan
uary 2013.

See
http://blogs.msdn.com/b/visualstudioalm/archive/2013/01/30/getting
-
started
-
with
-
git
-
in
-
visual
-
studio
-
and
-
team
-
foundation
-
service.aspx


In Visual Studio 2013, Git is provided out of the b
ox.

Continuous Builds

and Automation

The Team Foundation Server is used for
build/
deployment.

Most Hudson/Jenkins.

Deployment Container

The .NET deployment container is IIS (Internet Information Server), which corresponds to a hybrid of Apache and
Tomcat.

Deploying to Azure

Windows
Azure is t
he Microsoft cloud.

This is most similar to Heroku, because it provides a container for a
runtime, and automated setup of one or more databases.


See our document “Notes on Windows Azure”.


There are tools to deploy t
o Azure within Visual Studio 2012.

Caching

Caching enables you to store data in memory for rapid access.

When the data is accessed again, applications can get
the data from the cache instead of retrieving it from the original source.

This can improve per
formance and
scalability.

In addition, caching makes data available when the data source is temporarily unavailable.


The .NET Framework provides caching functionality that you can use to improve the performance and scalability of
both Windows client and
server applications, including ASP.NET.


Note


In the .NET Framework

3.5 and earlier versions, ASP.NET provided an in
-
memory cache implementation in the
System.Web.Caching

namespace. In previous versions of the .NET Framework, caching was available only in the
System.Web

namespace and therefore required a dependency on ASP.NET classes. In the .NET Framework

4, the
System.Runtime.Caching

namespace contains APIs that are designed

for both Web and non
-
Web applications.

Using Web Services

To build a web client, add a Service Reference.


This takes a URL to a WSDL file.

Questions and Open Issues

None at present

Appendix A: Learning Programs Created

DN
01

Example

program that manage
s a list of
activities, a list of challenges, and a list of challengeActivities that joins to
the other two entities. Based heavily on the two tutorials mentioned above under “Resources”.


[DONE] Define the
d
ata model (there must be usages of the string,
int, date,
double
, and bool datatypes)

Page
12

[DONE] Create a subclass of DbContext

[DONE] Create the controllers. This will also create the views

[DONE] Add a navigation menu at the top

[DONE] Add an enumerated field to one of the entities, and adjust the views

to use it.

[DONE] A
dd at least one non
-
CRUD

use of the EF, such as su
pporting criteria
-
based queries

[DONE] Customize the header and footer, adding images and
CSS

rules.

[DONE] Add a background image

DN
02

Example program that a
dds use of jQuery

and Twitte
r Bootstrap, along with
other capabil
ities of Razor’s view
rendering to the DN01 program.


[DONE
] Specify library on asset list

[DONE] Add the ChallengeMember and ChallengeTeam data entities

[DONE
] Use a
Twitter Bootstrap

button on each page

[
DONE] Use a T
witter Bootstrap

date picker on challenge editor

[in
-
progress] User/Account management

DN
03

Example program that add
s use of Ajax processing and Backbone.js


[in
-
progress] Specify library on asset list

Appendix B: Specific capabilities, and tricks for usi
ng Visual Studio

What other IDE’s call an “Application”, Visual Studio calls a “Solution”. A Project, therefore, is a collection of
Soluti
o
ns. Currently, though, our examples

have a separate project for each solution.


You can have only one project open
at a time.


You can re
-
format portions of code in the editor windows.


You can connect to databases,
both local ones and ones located

on the Azure server.

To add an existing item to a project
, including from another project

In Solution Explorer, select a t
arget project.


On the
Project

menu, select
Add Existing Item
.


In the
Add Existing Item

dialog box, locate and select the project item you want to add.

Note

Some it
ems related to XML Web Services and ASP.NET Web applications are located in a virtual directory
on the Web server.

Click the
Add

button to add the item to your project.

Sync files

You can switch between logical or physical folders in the solution by clic
king the "Show all files" icon (2nd top left
icon in the solution pane). When not activated, you are viewing logical folders in the solution, drag and drop simply
re arrange files virtually. When activated, you are viewing physical folders, drag and drop m
oves files on disk, using
the source controller.


When in the “Show all files” mode those files or directories which are not in your project can be added using
ContextMenu
-
> Include In Project.

Page
13

Using Visual Studio Tools for Git

Installed this on 10/07/13


Integrates with Visual Studio projects to automatically track changes to your active solution. Shows file status in
Solution Explorer, and uses context menus to issue source control commands like Commit, Compare, and Undo.


Upon create of a repo, the tool

also sets up a .gitignore file for you.


Then you use the Team Explorer tab on the right side window.

When pushing to remote, use the HTTPS protocol,
as shown below:



Appendix C: Specific capabilities, and tricks for using C#

It is just like Java, exc
ept that method names begin with a capital letter
.


For example, string.toLowerCase() is string.ToLowerCase()


In fact, the class String, which is now a “primitive”, is called “string” in order to match “int”.


You need to declare polymorphic methods as “v
irtual”.


Only the version of C# contained in .NET 4.5 or later has Enumerations.

Or maybe that is, “only the version of the
EntityFramework contained in 4.5 or later has support for persistence of Enumeration values”.


Annotations are given within square

brackets.