Weekplan Software Construction SWC1.2

Semester: 2.sem., fall 2014
Teacher: Henrik Høltzer
Email: heho@easj.dk

Literature/Material:
MSVC#: Microsoft Visual C# 2013 - Step by step, John Sharp, O'Reilly 2013, ISBN: 978-0-7356-8183-5
DS:
Database Solutions - A step-by-step guide to building databases 2Ed , Thomas Connolly & Carolyn Begg, Pearson Education
C#-note: Note by Per Laursen
Exercises: SWC1 Exercise Set
NewBoston: Video tutorial

Weekplan Software Construction SWC1.1 1.sem

NB: The plan is preliminary and will properly be changed during the semester! (Last updated: 18. december 2014 - 3.17pm)

Week Topics Literature/Material Exercises
35 Brush Up
Upgade to Visual Studio 2013 update 3

VS 2013 Update 3

BrushUp
36
Brush Up (cont.),
Inheritance
Polymorphism
Interface

C#-note: p.45-50
MSVC#: Chap. 12, 13

InheritanceDemo



Homework:

Read and do the "exercises" in MSVC#: Chap. 12-13

Exercises: 26, 27

The Bank Job

ISpeak (Philosopher)

C#-Projects:
Company_v1
Company_v2

The Bank Job Steps 1 to 3

Solutions:
Ex 26 (Company_v1Solved)
Ex 27 (Company_v2Solved)


37

Error/Exception
IO/File
Stack ADT (Abstract Data Type)

C#-note: p.51-55
MSVC#: Chap. 6
Exceptions and Exception Handling in C#
MSDN: Basic Serialization
Exercise:
Exceptions-Stack

SerializationTest
ExceptionTextFiles


C#-Projects:
SerializationTest.zip
MyStack.zip
38 Generics
Queue (ADT)
Using Collections

IComparable / IComparer
Equals( ) / GetHashCode( )
Lampda-expressions
MSVC#: Chap. 17 (p. 381-387)
MSVC#
: Chap. 18
MSVC#: Chap. 19 (p. 435-436)
Collections-Overview
An Overview Of System.Collections.Generic
MSDN: IComparable
MSDN: IComparer
MSDN: Guidelines for Overloading Equals()
Video:
What is IEnumerable,IComparable And IComparer Interfaces in C#?

Exercise:
MyGenericStack
CollectionsSort

GenericCollectionsAndDictionarys

C#-Projects:
CollectionSortTest.zip

39 IEnumerable / IEnumerator
More Lamda-expressions
LINQ

MSVC#: Chap. 21 (p. 485-497)
MSDN: Introduction to LINQ
MSDN: 101 LINQ Samples

Exercise:
LinqHotelExercice.zip

C#-Projects:
LinqTest.zip

Solutions:
LinqHotels.zip

40 Database (SQL) DS: Chap. 3 (p. 37-67m)

MSDN: Entity Framework Development Workflows
Channel9-MSDN: Code First to Existing Database
MSDN: Code First to a New Database

Exercise:
SQL (wordPDF)

Solutions:

SQL

Exercise:
Code First - Existing Database
Create your own DB using Visual Studio
(eg a TradeDB with the following tables: Product, Customer, Order and Orderline)
Insert som data.
Watch the video:
Code First to Existing Database

Use ADO.NET Entity Data Model -> Code First From Database to generate your model clases.
Use LINQ to query and manipulate the database.

Code First - New Database
Watch the video:
Code First to a New Database

Create your Model classes in a new project.
Create a class that inherit from DbContext with DbSet properties of your classes.
Verify that your DB is automatic generated and use LINQ to query and manipulate your DB.

 

41 Database (SQL) cont.

MSVC#: Chap. 25, 26
MSDN: How to: Install Sample Databases
(look at: Connecting to a Database file)


Demonstrates how to create a restfull webservice that provides access to our HotelDB
Screencast: WebServiceEntityFrameworkDemo1 (Part1)

Demonstrates how to use the webservice from a client application (console)
Screencast: WebServiceEntityFrameworkDemo2 (Part2)

Demonstrates how to create a database view and how to provide the view by using a webservice controller.
Screencast: WebServiceView (Part3)

Exercise:
Webservice - soap

Webservice - rest
In this exercise you have to create a restfull webservice to the HotelDB, then fetch
the data from the HotelDB by using the service - and print the result in the console.

Start createing a new Console project (HotelWebserviceRest) and follow
the steps in the book (MSVC#: Chap. 26 p. 723 -> ).

Notice:
When using the DbContext API for Code First you have to add:
base.Configuration.ProxyCreationEnabled = false in the DbContext-class

public class MyClass : DbContext
{
public MyClass(){base.Configuration.ProxyCreationEnabled = false;} }
see: https://stackoverflow.com/questions/3372895/datacontractserializer

Hint to the client-site:

const string ServerUrl = "http://localhost:50000";

HttpClientHandler handler = new HttpClientHandler();
handler.UseDefaultCredentials = true;

using (var client = new HttpClient(handler))
{
client.BaseAddress = new Uri(ServerUrl);
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
try
{

var response = client.GetAsync("api/Hotels").Result;

if (response.IsSuccessStatusCode)
{
IEnumerable<Hotel> hotelData = response.Content.ReadAsAsync<IEnumerable<Hotel>>().Result;
foreach (var hotel in hotelData)
{
Console.WriteLine(hotel);
}

}


Notice:
When using Web API Client library (HttpClient) it can be nessesary to change the DefaultCredentials

HttpClientHandler handler = new HttpClientHandler();  
handler.UseDefaultCredentials = true;  
HttpClient client = new HttpClient(handler);
see: http://social.msdn.microsoft.com/forums/windowsapps



Windows Store App:

Read and follow the steps in MSVC#: Chap. 25, 26 to build a full Windows Store App

C#-Projects:
WebserviceTest.zip (Code demonstrated in the class)

 

Sample Database: AdventureWorks

42 Autumn holidays  
43
Web API 2 (Cont.)

Advanced Stuff:
In ASP.NET Web API, a controller is a class that handles HTTP requests. The public methods of the controller are called action methods or simply actions. When the Web API framework receives a request, it routes the request to an action. For more information read:
Routing in ASP.NET Web API
Routing and Action Selection
Create a REST API with Attribute Routing in Web API 2

Web API: Mixing Traditional & Verb-Based Routing ***
MVC web API with more then one Get method



(It's about - Rest isn't just CRUD actions, and how to invoke the non-CRUD actions)

Other interresting links:
RESTful HTTP in practice


MSVC#
: Chap. 23-24

C#-Projects:
WSRestHotels.zip (code demonstrated in class)
HotelDbtest2.mdf (zip-fil)

 

44.1 Git/GitHub

Git and Software control:

Videos:
Fundamentals of Softvare Control (video - lynda.com)
Introduction to Git using VS tools from Microsoft
Git Branching and Merging Strategies

MSDN: Use Visual Studio with Git

Slides: IntroGit (PowerPoint)


Book:

Git Pro, Scott Chacon, Ben Straub, Apress, 2ed 2014
1.1 About Version Control
1.3 Git Basics
2.2 Recording Changes to the Repository
3.1 Branches in a Nutshell
3.2 Basic Branching and Merging
6.1 Account Setup and Configuration

Downloads
GIT: http://git-scm.com/
GIT-Extensions: http://sourceforge.net/projects/gitextensions/

Kdiff3: http://sourceforge.net/projects/kdiff3/?source=typ_redirect

Code Scool - Try Git (Online training):
https://try.github.io/levels/1/challenges/1

Exercise:
GitHub


44.2 Unit Test

Unit Test (MSTest in Visual Studio)

Videos:
Channel 9:
Improving quality with unit tests and fakes
Channel 9: Unit testing your metro style apps built using XAML

Introducing the Unit Test Generator for Visual Studio 2012 and Visual Studio 2013: http://www.youtube.com/watch?v=GD2xxRSwgkI

MSDN: Unit Test Basics
MSDN: How to: Create a Unit Test Project
MSDN: Using Code Coverage to Determine How Much Code is being Tested


Downloads:
Unit Test Generator (a plug-in for Visual Studio)


Slides:
Unit testing (PowerPoint)

 

Exercise:
UnitTest

C#-Projects:

Car UnitTest
(code demonstrated in class)
45 Bindings
MVVM Design Pattern etc.

Architecture
XAML-links
Controls by function (Windows Store apps using C# and XAML)

MSDN: Commands, RelayCommands and EventToCommand
EventToCommand is now built into Windows 8.1!

Other Interesting XAML-links (about ListView and GridView)
Quickstart: adding ListView and GridView controls (XAML)
How to group items in a list or grid (XAML)
Data Templating overview (DataTemplate, ItemTemplate)

Designing Your XAML UI with Blend Jump Start:
01 | XAML Development in Visual Studio 2013, Part 1
02 | XAML Development in Visual Studio 2013, Part 2
03 | XAML Design and Styling in Blend, Part 1 (Especially from 33min ->)
04 | XAML Design and Styling in Blend, Part 2
05 | Building Windows Store Apps with Blend
(Especially from 11min ->)
06 | Developer Candy


Calling a Web API From a .NET Client in ASP.NET Web API 2 (C#)

C#-Projects:
WSRestHotels.zip (ver. 2 - HotelApp/HotelWS)


Exercise:

Make a front-end (windows store app) to your Hotel webservice, so you can do the CRUD and non-CRUD operations on the HotelDB (eg. display hotel/room information, create new guest and bookings, display current bookings on a selected hotel ....).

Use ICommand/RelayCommand - not code-behind event-handling. (look at the new EventTriggerBehavior/InvokeCommandAction)

Use GridView/ListView (ItemSource, ItemTemplate) and DataTemplates

Notice:
If you have used "Windows Authentification" to your back-end Webservice - you will get an 401 error when trying to get access from win 8.1 store app. Create a new web-service with "No Authentification" (or find out - how to change by configuration?)

For saving an object in the DB, you must use PostAsync( ) and convert the c#-object to a Json-object:

string postBody = JsonConvert.SerializeObject(hotel);
var response = client.PostAsync("api/Hotels",new StringContent(postBody, Encoding.UTF8, "application/json")).Result;

But you have to install the NuGet Package: Json.Net first.

OR use PostAsJsonAsync see: Calling a Web API From a .NET Client in ASP.NET Web API 2 (C#)

If You want to insert a new hotel:

1) In the DB - change the primary key to be auto generated (set column Hotel_No to identity)
2) In class Hotel - change the Annotation for Hotel_No to:

[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Hotel_No { get; set; }


Hint:
Install the NuGet Package: MVVM Helpers for Windows 8.1 Store app
Include e.g setting the focus to a TextBox control see: http://www.julmar.com/blog/programming/managing-focus-with-mvvm-in-windows-store-apps/

46
Task, Thread, Asynchron
MSDN: Asynchronous Programming with Async and Await
CodeProject: Asynchronous Programming in C# 5.0 using async and await

Don't Block on Async Code

Slides: ProcessesAndThreads (PowerPoint)
Slides: AsynchronousProgramming (PowerPoint)
C#-Projects:
WSRestHotels.zip (ver. 3 - HotelApp/HotelWS)

C#-Projects:
GuiExampleAsyncAwait
SimpleBrowserAsync

47-51 Exam Project
Hand-in: 18. december
Presentation: 19. december
   
52-2 Exam preparation    
3 Exam: 15-16 january Curriculum