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», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

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

Интервал:

Закладка:

Сделать
Figure 1836 Add two references to the project SystemConfigurationInstalland - фото 354

Figure 18-36

Add two references to the project: System.Configuration.Installand System.Windows.Forms(see Figure 18-37).

Figure 1837 Switch to the code view of the RSSReaderInstallercsfile and - фото 355

Figure 18-37

Switch to the code view of the RSSReaderInstaller.csfile and import the following namespaces:

using Microsoft.Win32;

using System.IO;

using System.Diagnostics;

using System.Windows.Forms;

Within the RSSReaderInstallerclass, define the INI_FILEconstant. This constant holds the name of the .inifile that will be used by ActiveSync for installing the CAB file onto the target device.

namespace RSSReaderInstaller {

[RunInstaller(true)]

public partial class RSSReaderInstaller : Installer {

const string INI_FILE = @"setup.ini";

In the constructor of the RSSReaderInstallerclass, wire the AfterInstalland Uninstallevents to their corresponding event handlers:

public RSSReaderInstaller() {

InitializeComponent();

this.AfterInstall += new

InstallEventHandler(RSSReaderInstaller_AfterInstall);

this.AfterUninstall += new

InstallEventHandler(RSSReaderInstaller_AfterUninstall);

}

void RSSReaderInstaller_AfterInstall(object sender, InstallEventArgs e) {

}

void RSSReaderInstaller_AfterUninstall(object sender, InstallEventArgs e) {

}

The AfterInstallevent is fired when the application (CAB file) has been installed onto the user's computer. Similarly, the AfterUninstallevent fires when the application has been uninstalled from the user's computer.

When the application is installed on the user's computer, you use Windows CE Application Manager ( CEAPPMGR.EXE) to install the application onto the user's device.

The Windows CE Application Manager is installed automatically when you install ActiveSync on your computer.

To locate the Windows CE Application Manager, define the following function named GetWindowsCeApplicationManager():

private string GetWindowsCeApplicationManager() {

//---check if the Windows CE Application Manager is installed---

string ceAppPath = KeyExists();

if (ceAppPath == String.Empty) {

MessageBox.Show("Windows CE App Manager not installed",

"Setup", MessageBoxButtons.OK,

MessageBoxIcon.Error);

return String.Empty;

} else return ceAppPath;

}

This function locates the Windows CE Application Manager by checking the registry of the computer using the KeyExists()function, which is defined as follows:

private string KeyExists() {

//---get the path to the Windows CE App Manager from the registry---

RegistryKey key =

Registry.LocalMachine.OpenSubKey(

@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\CEAPPMGR.EXE");

if (key == null) return String.Empty;

else

return key.GetValue(String.Empty, String.Empty).ToString();

}

The location of the Windows CE Application Manager can be obtained via the registry key: " SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\CEAPPMGR.EXE", so querying the value of this key provides the location of this application.

The next function to define is GetIniPath(), which returns the location of the .inifile that is needed by the Windows CE Application Manager:

private string GetIniPath() {

//---get the path of the .ini file---

return "\"" +

Path.Combine(Path.GetDirectoryName(

System.Reflection.Assembly.GetExecutingAssembly().Location),

INI_FILE) + "\"";

}

By default, the .inifile is saved in the same location as the application (you will learn how to accomplish this in the next section). The GetIniPath()function uses reflection to find the location of the custom installer, and then return the path of the .inifile as a string, enclosed by a pair of double quotation marks (the Windows CE Application requires the path of the .ini file to be enclosed by a pair of double quotation marks).

Finally, you can now code the AfterInstallevent handler, like this:

void RSSReaderInstaller_AfterInstall(object sender, InstallEventArgs e) {

//---to be executed when the application is installed---

string ceAppPath = GetWindowsCeApplicationManager();

if (ceAppPath == String.Empty) return;

Process.Start(ceAppPath, GetIniPath());

}

Here, you get the location of the Windows CE Application Manager and then use the Process.Start()method to invoke the Windows CE Application Manager, passing it the path of the .inifile.

Likewise, when the application has been uninstalled, you simply invoke the Windows CE Application Manager and let the user choose the application to remove from the device. This is done in the AfterUninstallevent handler:

void RSSReaderInstaller_AfterUninstall(object sender, InstallEventArgs e) {

//---to be executed when the application is uninstalled---

string ceAppPath = GetWindowsCeApplicationManager();

if (ceAppPath == String.Empty) return;

Process.Start(ceAppPath, String.Empty);

}

The last step in this section is to add the setup.ini file that the Windows CE Application Manager needs to install the application onto the device. Add a text file to the project and name it setup.ini. Populate the file with the following:

[CEAppManager]

Version = 1.0

Component = RSSReader

[RSSReader]

Description = RSSReader Application

Uninstall = RSSReader

CabFiles = RSSReader.cab

For more information about the various components in an .inifile, refer to the documentation at http://msdn.microsoft.com/en-us/library/ms889558.aspx.

To build the project, right-click on RSSReaderInstaller in Solution Explorer and select Build.

Set the SmartDeviceCab1project's properties as shown in the following table.

Property Value
Manufacturer Developer Learning Solutions
ProductName RSS Reader v1.0
Creating a MSI File

You can now create the MSI installer to install the application onto the user's computer and then invoke the custom installer built in the previous section to instruct the Windows CE Application Manager to install the application onto the device.

Using the same solution, add a new Setup Project (see Figure 18-38). Name the project RSSReaderSetup.

Figure 1838 Using the newly created project you can now add the various - фото 356

Figure 18-38

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

Интервал:

Закладка:

Сделать

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

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


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

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

x