Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Professional Visual Studio 2005 (2006) [eng]

.pdf
Скачиваний:
117
Добавлен:
16.08.2013
Размер:
21.9 Mб
Скачать

Chapter 33

Figure 33-8

GhostDoc is an excellent resource for those who find documentation difficult. You can find it at its official web site, www.roland-weigelt.de/ghostdoc.

Testing and Debugging

Many components of Visual Studio 2005 help you to test and debug your solutions, but not surprisingly, you can also find some very good third-party components that can enhance your experience in this area too. The following tools vary in size and functionality, but both will aid you as you test your applications.

Regex Visualizer

Regular expressions can sometimes be hard to decipher and understand, and often the time it hits hardest is when debugging an application that isn’t behaving as you would expect. The Regex Visualizer builds on the capability to create your own visualizers for debugging purposes (which is explained in Chapter 50) by providing a descriptive explanation of a regular expression string and, when used in conjunction with regular expression objects, any matches that met the criteria.

Figure 33-9 demonstrates the visualizer in action with a simple regular expression of (The)*book. The visualizer hooks into the String variable and adds an extra option of how to view the data, with the Matches Details dialog being displayed when it is invoked. The Pattern Desc tab provides an English translation of what the regular expression is trying to match on; in this case, it has determined that the criteria specify looking for zero or more occurrences of The immediately followed by book. To download the visualizer, visit the author’s web site at http://weblogs.asp.net/rosherove/archive/ 2005/11/26/AnnoucingRegexKit10.aspx.

TestDriven.NET

No discussion of third-party tools for Visual Studio would be complete without a mention of TestDriven

.NET. This tool enables you to run a series of unit tests as well as coordinate code coverage testing with a variety of testing frameworks, including NUnit and Visual Studio Team System.

In addition, you can build your own tests with its built-in ad hoc testing framework, and run them as easily as right clicking in the code window and selecting Run Test(s) from the context menu. As you run the tests through their paces, the chosen framework will be invoked, presenting the results in its own way. Get started with TestDriven.NET by visiting the official product web site at www.testdriven.net.

446

Third-Party Extensions

Figure 33-9

Summar y

Dozens of add-ins are available for Visual Studio 2005, but the products highlighted in this chapter describe tools that are either simple but effective, or of a very high quality, enabling you to avoid wading through the murky waters of unknown extensions.

Using third-party add-ins enables you to extend the development experience of Visual Studio 2005 beyond the initial environment setup without having to invest time in creating your own tools. The tools in this chapter cover a wide range of functionality, from assisting you in creating documentation and testing cycles to small helper commands and whole tool suites, such as MZ-Tools. The one thing they do have in common, however, is that they are all excellent additions to a Visual Studio 2005 developer’s toolbox.

447

Star ter Kits

Visual Studio 2005 comes with a wide array of project templates from which you can start building applications. However, each project type does the absolute minimum, creating a blank form, control, or page, leaving the rest up to you. Starter kits take the concept of a project template and add a whole bunch of functionality into the generated output.

Each starter kit shows you best practices for different programming and design concepts, and can be used as a basis for creating your own applications and solutions that share similar features. Perhaps one of the best uses for the official starter kits is to look through the code that is included in the default project generation to see how Microsoft recommends you implement the various techniques, including new programming concepts such as generics, and design elements such as SQL Server database files.

This chapters completes the Automation part of this book by introducing you to each of the four main starter kits that are installed with Visual Studio 2005, describing their purpose and what functionality you can find in them for use with your own applications.

Working with starter kits is easy because they work the same way that normal project templates do and are integrated into the New Project dialog for each language that you can use. Locate the starter kit you want to implement in the New Project dialog, select a name for your instance of it, and click OK to have Visual Studio 2005 process the template and generate all of the required code and data files.

While there is a Starter Kit subcategory within the C#, J#, and Visual Basic project groups, unfortunately not all starter kits will appear in that location. For instance, the Card Game Starter Kit appears only at the root project group for C# and Visual Basic. While it is frustrating that some of the starter kits were implemented incorrectly by Microsoft, there’s no question of the value they provide to developers in getting a handle on different techniques, as explained in this chapter.

Chapter 34

The Card Game Star ter Kit

The Card Game Starter Kit is the most basic kit, covering the use of graphics in Windows Forms applications, using the new settings and resources designers, and introducing programming techniques found in the new 2.0 version of C# and Visual Basic, such as generics.

The default project comes ready to compile and run with the game of Black Jack. It uses a series of forms that contain numerous components such as Button and TextBox controls, which have their properties customized so they appear to be graphically drawn, rather than standard Windows Forms controls (see Figure 34-1).

The form graphics are stored in the resources file that accompanies the project and can be browsed through the Resources page of the Project Designer, while the graphics associated with the player object and card background are saved in separate files, which are then connected to their appropriate component through the Settings page. Keeping the files separate like this shows you how you might best approach building a similar application — with some graphical elements hard-coded into the design, and others easily changed by changing the external image file.

Figure 34-1

450

Starter Kits

In addition to showing you how to use settings and resources, the project builds a set of classes that interact with each other to create a deck of cards, as well as a collection of players. If you were to create your own card game application, you could easily use these classes as a starting point, including the use of generic collections, which are new to .NET 2.0.

The Screensaver Star ter Kit

The Screensaver Starter Kit goes an extra step beyond the project based on a card game. It teaches you how to harness the GDI+ engine to draw various graphical and textual objects onscreen, as well as consume RSS feeds from the web and process XML using the System.XML namespace.

When the project is compiled and started in its default configuration, it will invoke the screensaver with an empty RSS feed and a series of default images (as shown in Figure 34-2). However, the project shows you how to take advantage of command-line arguments with the /c parameter, invoking an options form that can be used to customize the directory for background images as well as the location for an RSS feed to consume.

Figure 34-2

451

Chapter 34

The code uses the OnPaint and OnPaintBackground events to draw the graphics on the screensaver form, harnessing the power of the GDI+ engine for the different components. Using these events means that every component needs to be manually painted, but it also provides you with total control over what appears.

In addition to the graphics-based coding blocks illustrated throughout the project, the Screensaver Starter Kit also shows you how to use the WebClient class to connect to and download information (an RSS feed) from the Internet. It uses WebClient in conjunction with XmlTextReader and XmlNode objects to extract the information from the RSS feed into a human-readable form and presents it on the screensaver form.

The Movie Collection Star ter Kit

With the Movie Collection Starter Kit, you can see how data binding works, with the project building a single form that connects to a database file to store a collection of movie DVDs. The standard kit only allows you to enter the information manually and view your existing data, but is still a useful project because it demonstrates how easy it is to implement a project using a SQL Server database file without having to resort to using an instance of SQL Server.

The main form is actually empty and hosts two user controls, each of which contains its own set of user interface components and business logic. This implementation illustrates how you can achieve easy customization of the user interface for your own projects, with many of the components obtaining their appearance from a resources file of images (see Figure 34-3).

Figure 34-3

452

Starter Kits

However, the primary purpose of this starter kit is to show you how to connect different components to a database, and the code fully documents this process so you can reuse the techniques of populating data-bound controls at runtime in your own applications.

A web-enabled version of the Movie Collection Starter Kit is available for download. This version implements the online search capabilities of the application and introduces additional techniques for connecting to web services and consuming the information they expose in a Windows Forms environment. To download the latest version of the starter kit, refer to the documentation that comes with the kit in Visual Studio 2005.

The Personal Web Site Star ter Kit

The Personal Web Site Starter Kit introduces you to a wide array of web-specific functionality. The accompanying documentation walks you through the process of setting up the security and basic user configuration for a user-based site.

A number of the new components available in ASP.NET 2.0 are covered with this starter kit, including the ability to create master pages that can then be used to contain details pages and control their appearance. Figure 34-4 shows the default configuration of the project as it appears in Internet Explorer. The top part of the page is part of the master page, while the rest is defined in a details page that inherits the style and structure of the master.

Figure 34-4

453

Chapter 34

The kit also illustrates how to implement user management for a site (with functionality being activated and deactivated based on which user is logged in), and includes a number of common functions found in a personal site, such as photo albums and common links.

Creating Your Own Star ter Kit

Creating your own starter kit is actually quite easy. Because starter kits are basically just project templates with pre-generated code, all you need to do is follow the same steps you would follow if you were creating a project template, including the additional form design, components and properties, and all underlying code.

You can include as many files as you require, including documentation like the official starter kits. You can even have Visual Studio automatically open the files you want to display. Chapter 25 has a complete discussion about creating your own project templates for use as a starting point. Once you have created your project and tested it to ensure that it will build without error, you should export it as a project template.

To open files automatically, edit the .vstemplate file for the project template and locate the ProjectItem node that corresponds to each file you want to display to developers using the starter kit, and add an OpenInEditor attribute with a value of true. You can also use the OpenOrder attribute to specify the order in which the files should be opened, as shown in the following example:

<ProjectItem OpenInEditor=”true” OpenOrder=”10”>MyForm.vb</ProjectItem>

<ProjectItem OpenInEditor=”true” OpenOrder=”20”>ReadMe.html</ProjectItem>

Using these official starter kits in conjunction with the walkthrough for creating project templates in Chapter 25 as a basis, you will be able to create good, strongly built starter kits of your own, which can be used as a basis for starting complex projects with a set of corporate standards-compliant classes and objects such as user controls and forms. Even solo developers should benefit from the ability to create starter kits in this fashion.

Summar y

The Automation part of this book has shown you many techniques that can be used through the Visual Studio 2005 IDE to minimize the amount of work you need to perform for a variety of tasks that were previously difficult to implement, including assembly signing, creating your own add-ins, item and project templates, and strongly typing DataSets and creating macros to minimize repetition. Section VII continues with this theme, demonstrating additional ways to save time in Visual Studio 2005.

454

Part VII

Other Time Savers

Chapter 35: Workspace Control

Chapter 36: Find and Replace

Chapter 37: Server Explorer

Chapter 38: Visual Database Tools

Chapter 39: Regular Expressions

Chapter 40: Tips, Hacks, and Tweaks

Chapter 41: Creating Web Applications

Chapter 42: Additional Web Techniques

Chapter 43: Building Device Applications

Chapter 44: Advanced Device Application Programming