Вы находитесь на странице: 1из 50

Session 8

Debug, Test and


Deploy Applications

Review

System.IO namespace has classes that facilitate reading


and writing of data to data streams and files.
The BinaryReader and BinaryWriter classes are derived from
System.Object. BinaryReader is the class that is used for
reading binary data. The BinaryWriter class is employed for
writing binary data from a C# variable to a specified stream.
The Stream class is an abstract class from which different
classes such as FileStream and MemoryStream classes are
derived.
The NetworkStream class that resides within the
System.Net.Sockets namespace is used to send and
receive data across the network.
The CryptoStream class is used to link the stream of data
to any cryptography object for the purpose of encrypting the
data.

C# Simplified / Session 8 /

Review Contd

The Directory class contains static methods that help in


handling directories and subdirectories. The File class
contains static methods that help in handling files. It also
helps in the creation of FileStream class.
The FileSystemInfo Class is an abstract class from which the
FileInfo and DirectoryInfo classes are derived. The
TextReader is the abstract base class for the StreamReader
and StringReader classes. The StreamReader reads a
character in a byte stream and converts to the specified
encoding. The StringReader class is used to read data from
an input string.
The TextWriter is the abstract base class for classes that can
be used to write sequential characters. The StreamWriter
class writes characters to a stream in a specified encoding.
The StringWriter class is used to write data to a string.

C# Simplified / Session 8 /

Objectives

Discuss how to debug and


troubleshoot applications
Discuss how to test C# applications
Discuss deployment concepts
Discuss deploying of applications
Explore deployment alternatives
Create a sample application,
package and deploy it
C# Simplified / Session 8 /

Debugging

The process of searching and eliminating


bugs or errors in applications is called
An application
that has been
developed,
tested and
debugged is
ready for
deployment to
C#client
Simplified
machines
/ Session 8 /

Need for debugging

Helps locate and resolve bugs


Reduces time, effort and cost to
maintain the application in the long run

Syntax Errors
Logical/Semantic
Errors
C# Simplified / Session 8 /

Syntax Errors

Wrong syntax of C# statements


Missing braces, semicolons,
spelling mistakes, missing
statements, etc
Identified during compile-time
They can be easily identified and
corrected
C# Simplified / Session 8 /

Logical/Semantic Errors

Infinite loops, reading files that do


not exist, wrong calculations etc
Using objects that do not have values
assigned to them
Identified during execution of the
program
Debugging these is difficult as they
arise only during application run-time
C# Simplified / Session 8 /

Debugging Procedure

Most programming languages and tools provide


debuggers that enable programmers to observe the
run-time behavior of a program, track values of
variables and identify the location of semantic errors.
Visual Studio .NET also provides a debugger that the
programmer can use to debug code written in one of
the .NET supported languages
While using the debugger, a breakpoint can be
inserted in the code to halt its execution at that
particular line.
At this point, the program enters the break mode and
is said to be in a suspended state.
In the break mode, the programmer can check the
values of variables change them if required and also
check other data.

C# Simplified / Session 8 /

Breakpoints

C# Simplified / Session 8 /

Compile and Build


Applications in VS.NET

There are two modes in which


applications can be compiled and built
Debug Mode
Used to repeatedly compile and troubleshoot

an application until it becomes successful


and running.

Release Mode
Used when the application will not be

repeatedly compiled and is ready for release.

C# Simplified / Session 8 /

VS.NET Debugging Tools

Some debugging tools provided by


VS.NET
Locals window
Watch window
QuickWatch dialog box
Immediate window

C# Simplified / Session 8 /

Locals Window

Displays the values


present in the local
variables
Lists only the
variables that are
within the current
scope and tracks
their values
C# Simplified / Session 8 /

Watch Window

Used to evaluate variables,


expressions and track their
values through the program as
the program executes

It can also be used to edit the


value of a variable

The variables that are to be


watched should be provided or
indicated by the developer

Several watch windows can be


simultaneously opened to check
for several expressions or
variables at the same time

C# Simplified / Session 8 /

QuickWatch Dialog Box

Used to quickly evaluate a


variable or expression as
well as to modify the value
of the variable

Used to display values for


only one variable at a
time.

Modal in nature

Cannot be used to track


the values of a variable in
the course of execution

C# Simplified / Session 8 /

Immediate Window

Used for checking the value of


a variable, for assigning a
value to a variable as well as
to run a line of code

The name of the variable has


to be prefixed with a question
mark in order to find its value

The value of a variable can be


changed by keying in the
code for the assignment
within the Immediate window,
and pressing Enter.

C# Simplified / Session 8 /

Testing

Any application needs to be tested with


various kinds of data to ensure that it is
fully functional and working
It is the process of inspecting an
application and ensuring that it meets the
specifications for which it was designed
Testing should be done from the point of
view of finding out more and more errors
in an application.
C# Simplified / Session 8 /

Types of Testing
Popular techniques used for testing
include

C# Simplified / Session 8 /

Unit Testing

Isolates the smallest module or unit from


the rest of the application and tests it

Modules are formed as drivers and


stubs.

A driver is a simulation of a calling unit


and a stub is a simulation of a called unit
Consumes time, effort and money but is
highly beneficial
Scrutinizing every unit results in
improving the quality of the application
and chances of errors being discovered
later on are reduced

C# Simplified / Session 8 /

Integration testing

In Integration testing, two or


more units can be merged and
then tested to see if they
function correctly.
There are 3 commonly used
methods for implementing
integration testing:
Top down approach
Bottom-up approach
Umbrella approach
C# Simplified / Session 8 /

Performance Tuning

Performance of an application plays a


major role in terms of client satisfaction
In performance management, one of the
main activities performed is performance
tuning as it helps fine-tune the
application to the needs of the clients
Helps to identify and resolve bottlenecks
that may be leading to the poor
performance of the application
The Performance Tuning cycle involves 4
steps:
Collecting
Analyzing
Configuring
Testing

C# Simplified / Session 8 /

Performance Analysis

Performance Analysis analyzes the performance


of an application for likely problems and ensures that
the software meets or surpasses the design
intentions or expectations.
Microsoft Visual Studio Analyzer is a tool that
works with the .NET framework to assist us in
determining which component is not functioning
properly and conduct performance analysis.
Code profiling tools, such as the Microsoft Source
Profiler, help to understand exactly where a
component or single-process application is spending
its execution time

C# Simplified / Session 8 /

Packaging and Deployment

The term packaging means building


up all the files in the application into
a single file called a Distribution
Unit

The process of distributing a


completed application or component
and installing it on the client
computers is called Deployment.

Before deployment, we need to


decide on what to deploy, where to
deploy and how to deploy.

C# Simplified / Session 8 /

Deployment Tasks

Mandator
y a deployment
Add
project to a
solution
Set properties for
the deployment
project
Add files and other
components

Optional

Specify the location for installing


files on the client machine
Specify settings for the registry
on the clients machine
Specify the user interface that will
be displayed during installation
Specify the actions that need to
be performed during installation
Specify conditions of installation

C# Simplified / Session 8 /

Modes of Packaging

Installer files (using Microsoft Windows Installer)


Shipped along with Windows 2000, Windows ME and

Windows XP as an installation and configuration service


Creates msi files for use with the Windows Installer or
with some other installer

CAB file project


Allow ActiveX controls that are downloaded from a Web

server, to be compressed and packaged into .cab


(Cabinet) files.
These .cab files make distribution or download less time
consuming.

A third method of packaging would be to simply


use the .dll or .exe files as they were built.

C# Simplified / Session 8 /

Deployment Scenarios

Either focus on single machine deployment or


multiple machine deployment
A single machine installation provides a simple
way to deploy and interact with the sample.
The various multiple machine installations
provide the ability to research different scenarios
The requirements for creating and installing
assemblies are relatively minimal, whether we
choose to develop applications with private
assemblies or with strong-named assemblies
Security considerations can also affect how
applications are deployed

C# Simplified / Session 8 /

Deployment Alternatives

There are various approaches to


deploy an application in .NET.
XCOPY Command
Windows Installer 2.0
Code Download

C# Simplified / Session 8 /

XCOPY Command

A DOS command that can be used to copy


the application to the appropriate directory
Easiest way to install an application.
Un-installing the application can be done
by deleting the directory structure of the
application.
Installs private and strong-named
assemblies only
C# Simplified / Session 8 /

Options of XCopy command


Option
/p

Description
Prompts us to confirm whether
we want to create each

destination file.
/q
messages.

Suppresses display of XCOPY

/e
they are

Copies all subdirectories, even if


empty.

/s
Copies directories and
subdirectories,
unless they
are
empty. If we omit this
option, XCOPY works within
C# Simplified / Session
a single directory.

8 /

Windows Installer 2.0

Windows Installer 2.0 can install, repair, or remove


Microsoft .NET Framework assemblies in the Global
Assembly Cache and in private directories
A Visual Studio .NET setup project can be used to
build a .msi file, which acts as a database that stores
all instructions and data required for installation and
un-installation.
Enforces installation rules that help to prevent
conflicts with shared resources between existing
applications.
It allows a Rollback of unsuccessful installations,
repairs, or removals of assemblies.

C# Simplified / Session 8 /

Code Download

When an application is to be
distributed over the Internet or
through a corporate intranet, the code
can be downloaded to a computer and
the application can be executed
This method is efficient for distributing
Compressed .CAB files and windows
form controls.
C# Simplified / Session 8 /

Deploying a simple
application

1. Create a console based application using the code given below


using System;
using System.Collections;
namespace CalculateArea
{
class Area
{
private int areaVal;
public void AreaCal(int radius)
{
areaVal = (22/7)* radius*radius;
}
public void AreaCal(int length, int breadth)
{
areaVal = length*breadth;
}

C# Simplified / Session 8 /

Deploying a simple
application Contd

public void AreaCal(int length, int breadth, int height)


{
areaVal = length*breadth*height;
}
[STAThread]
static void Main(string[] args)
{
int radius = 0;
int len = 0;
int breadth = 0;
int height = 0;
Area newArea = new Area();
Console.WriteLine ("Enter radius");
radius = Int32.Parse(Console.ReadLine());
newArea.AreaCal(radius);

C# Simplified / Session 8 /

Deploying a simple
application-Contd
Console.WriteLine ("Area with radius
provided is {0}",newArea.areaVal);
Console.WriteLine("\nEnter length");
len = Int32.Parse(Console.ReadLine());
Console.WriteLine("\nEnter breadth");
breadth = Int32.Parse(Console.ReadLine());
Console.WriteLine("\nEnter height");
height = Int32.Parse(Console.ReadLine());
newArea.AreaCal (len,breadth,height);
Console.WriteLine ("Area with length, breadth
and height provided is {0}",newArea.areaVal);
newArea.AreaCal(len,breadth);
Console.WriteLine ("Area with length and
breadth provided is {0}",newArea.areaVal);
Console.ReadLine();
}
}
C# Simplified / Session
}

8 /

Deploying a simple
applicationContd
2. Create
a new deployment project by selecting File New
Project.
3. Select Setup and Deployment Projects from the Project
Types list and
select Setup Project from the list of Templates provided

C# Simplified / Session 8 /

Deploying a simple
applicationContd
Change the project name to AreaSetup and select the
application Folder node of the File System Editor

C# Simplified / Session 8 /

Deploying a simple
applicationContd
5. Select Action -> Add -> File
6. Select the .exe file CalculateArea.exe

C# Simplified / Session 8 /

Deploying a simple
applicationContd
7. select the .exe file just added and Click Action Create
shortcut to [ApplicationName].Exe option. Notice that a
Shortcut to the application CalculateArea.exe is added

C# Simplified / Session 8 /

Deploying a simple
applicationContd
8. Drag and drop this shortcut file to the Users
Desktop folder on the left hand pane of the editor.
This adds the file to the Users Desktop folder

C# Simplified / Session 8 /

Deploying a simple
applicationContd

9. Select the .exe file from the Application Folder in the File
System Editor. Select Action Create shortcut to
CalculateArea.exe and create another shortcut to the
application.
10. Follow the procedure mentioned in Step 9 to add this new
shortcut to the Users Program Menu folder.
11. Click on View Editor Launch Conditions

C# Simplified / Session 8 /

Deploying a simple
applicationContd
12. Select Requirements on Target Machine node and click on
Action Add File Launch Condition
13. Rename the Search for File1 node to Search for Internet
Explorer and Right Click on Search for Internet Explorer to
invoke the Properties Window. Set the FileName property to
Iexplore.exe.
14. Set the Folder property to [ProgramFilesFolder], Depth
property to 2, MinVersion property to 5.0 and Property
property to IEFILEXISTS

C# Simplified / Session 8 /

Deploying a simple
applicationContd

C# Simplified / Session 8 /

Deploying a simple
applicationContd
15. Select the Condition1 node and open its Properties window.
Set its Condition property to IEFILEXISTS <> . Set the
Message property to Internet Explorer 5.0 or higher version
not found

C# Simplified / Session 8 /

Deploying a simple
applicationContd
16. Select the deployment project and on the View menu, click
Property Pages
17. Select Windows Installer Bootstrapper option from the
Bootstrapper drop down options

C# Simplified / Session 8 /

Deploying a simple
applicationContd
18. Select AreaSetup in the Solution Explorer and select
Build Build AreaSetup from the menu

As a result of all the steps executed, the start up


project is created and is ready for distribution and
installation in any system.
Setup.exe is one of the files that is included in the
files that are added to the Debug folder of the
deployment project and it acts as an entry point
for the installation process
C# Simplified / Session 8 /

Installing the Application

Start Windows Explorer and browse to the folder


containing the setup project. This would be in the Debug
folder of the AreaSetup folder on the system.
From the Edit Menu select Select All option.
Copy these files into another directory of the same
computer or any other target computer where the
application is to be installed.
In the Target machine, at the location where the files are
copied, click on the Setup.exe file.
Windows Installer will start the Application Setup Wizard.
Follow the directions provided by the Windows Installer.
Once the installation is complete, locate the shortcut,
Shortcut to CalculateArea.exe on the Desktop.
Double-click the shortcut to open the application

C# Simplified / Session 8 /

Installing the Application

C# Simplified / Session 8 /

Output of CalculateArea.exe

C# Simplified / Session 8 /

Summary

The process of searching and eliminating each error or bug is


called debugging.
The Visual Studio.NET environment provides means to create,
compile and build application solutions. There are two modes
in which applications can be built:
Debug mode
Release mode
The Locals window displays the values present in the local
variables.
The Watch window is used to evaluate variables and
expressions and track their values through the program.
The QuickWatch dialog box can be used to quickly evaluate a
variable or expression.
The Immediate window can be used for checking the value of
a variable, for assigning a value to a variable as well as to run
a line of code.
Testing large applications can be done using techniques such
C# Simplified / Session 8 /
as unit testing and integration testing.

Summary Contd

Performance tuning helps fine-tune the application to the


needs of the clients, identifies and resolves bottlenecks
Performance Analysis analyzes the performance of an
application for likely problems and ensures that the software
meets or surpasses the design intentions or expectations.
Microsoft Visual Studio Analyzer is a tool that works with
the .NET framework to assist us in determining which
component is not functioning properly.
The term packaging means building up all the files in the
application into a single file called a Distribution Unit. And the
process of distributing a completed application or component
and installing it on the client computers is called Deployment.
Deployment in VS.NET is based on Microsoft Windows Installer
technology
XCOPY, Windows Installer 2.0 and Code download are various
approaches to deploy an application in .NET.

C# Simplified / Session 8 /

Вам также может понравиться