Wei-Meng Lee - C# 2008 Programmer's Reference

Здесь есть возможность читать онлайн «Wei-Meng Lee - C# 2008 Programmer's Reference» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: Indianapolis, Год выпуска: 2009, ISBN: 2009, Издательство: Wiley Publishing, Inc., Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

C# 2008 Programmer's Reference: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «C# 2008 Programmer's Reference»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

C# 2008 Programmers Reference provides a concise and thorough reference on all aspects of the language. Each chapter contains detailed code samples that provide a quick and easy way to understand the key concepts covered.

C# 2008 Programmer's Reference — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «C# 2008 Programmer's Reference», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

By default, the application checks for updates every time before it starts.

When the user closes and then relaunches the PhotoViewer application, he gets a prompt, as shown in Figure 16-25.

Figure 1625 The user can click OK to download the updated application or - фото 280

Figure 16-25

The user can click OK to download the updated application, or click Skip if he doesn't want to update the application now. The updated application will look like Figure 16-26.

Figure 1626 Programmatically Updating the Application Instead of the - фото 281

Figure 16-26

Programmatically Updating the Application

Instead of the application checking for updates before it starts, it would be a good idea for users to be able to choose when they want to check for updates. For that, add a new button to the form, as shown in Figure 16-27.

Figure 1627 Import the following namespace using - фото 282

Figure 16-27

Import the following namespace:

using System.Deployment.Application;

Code the Update button like this:

private void btnUpdate_Click(object sender, EventArgs e) {

//---check if the application is deployed by ClickOnce---

if (ApplicationDeployment.IsNetworkDeployed) {

//---Get an instance of the deployment---

ApplicationDeployment deployment =

ApplicationDeployment.CurrentDeployment;

//---if there is any update---

if (deployment.CheckForUpdate()) {

DialogResult response =

MessageBox.Show(("A new version of the " +

"application is available. " +

"Do you want to update application?"),

("Application Updates"), MessageBoxButtons.YesNo);

//---if user wants to update---

if (response == DialogResult.Yes) {

Cursor.Current = Cursors.WaitCursor;

//---update the application---

deployment.Update();

//---prompt the user to restart---

MessageBox.Show("Update completed. You need to restart" +

" the application.", ("Update Completed"),

MessageBoxButtons.OK, MessageBoxIcon.Information);

//---restart the application---

Application.Restart();

}

} else {

//---application is up-to-date---

MessageBox.Show(("Application is up-to-date."), "Update",

MessageBoxButtons.OK, MessageBoxIcon.Information);

}

} else {

//---application is not installed using ClickOnce---

MessageBox.Show(("Application is not installed " +

"using ClickOnce"), ("Updates not available"),

MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}

You first check to see if the application is deployed using ClickOnce. This can be done by using the IsNetworkDeployedproperty from the ApplicationDeploymentstatic class. If the application is indeed deployed using ClickOnce, you proceed to obtain an instance of the deployment using the currentDeploymentproperty of the ApplicationDeploymentclass. Using this instance of the deployment, you call the CheckForUpdate()method to check whether there is a newer version of the application available from the publishing server. If there is, you prompt the user by asking if he wants to update the application. If he does, you update the application, using the Update() method. After that, you force the user to restart the application, using the Restart()method.

To test the update, first run an instance of the PhotoViewer application by launching it from the Start menu. Next, republish the application in Visual Studio 2008. Click the Update button to see if an update is available. You should see the prompt shown in Figure 16-28. Click Yes, and the application will be updated.

Figure 1628 Rolling Back Once an application is updated the user has a - фото 283

Figure 16-28

Rolling Back

Once an application is updated, the user has a choice to roll it back to its previous version. To do so, go to the Control Panel and run the Add or Remove Programs application. Locate the application (in this case, PhotoViewer) and click on the Change/Remove button. You have two choices — restore the application to its previous state or remove the application from the computer (see Figure 16-29).

Figure 1629 An application can be rolled back only to its previous version - фото 284

Figure 16-29

An application can be rolled back only to its previous version. If it's been updated several times, it only rolls back to the version preceding the last update.

Under the Hood: Application and Deployment Manifests

When you use the Publish Wizard to publish your application using ClickOnce, Visual Studio 2008 publishes your application to the URL that you have indicated. For example, if you specified http://localhost/PhotoViwer/ as the publishing directory and your web publishing directory is C:\Inetpub\wwwroot\, then the virtual directory PhotoViewer will be mapped to the local path C:\Inetpub\wwwroot\PhotoViewer\.

Two types of files will be created under the C:\Inetpub\wwwroot\PhotoViewer directory:

□ Application Manifest

□ Deployment Manifest

The next two sections take a closer look at these two types of files.

Application Manifest

When you publish your application, three files and a folder are created in the publishing directory (see Figure 16-30):

Application Files— Folder containing the deployment files.

A publish.htmweb page— This contains instructions on how to install the application.

Application manifestPhotoViewer.application. This is the file that is referenced by the publish.htm file. An application manifest is an XML file that contains detailed information about the current application as well as its version number. Chapter 15 has more about application manifests.

setup.exe— A setup application that installs the application onto the target computer.

Figure 1630 The Application Files folder contains the various versions of - фото 285

Figure 16-30

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «C# 2008 Programmer's Reference»

Представляем Вашему вниманию похожие книги на «C# 2008 Programmer's Reference» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «C# 2008 Programmer's Reference»

Обсуждение, отзывы о книге «C# 2008 Programmer's Reference» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x