Case 2: Large Errors

 

Project KT101DeploymentDemo

When you have completed the creation of project KT101DeploymentDemo, it will do the following:

  • Create directory C:\Program Files\KT101 and subdirectory C:\Program Files\KT101\DDT.

  • Transfer five read-write files from the deployment program to subdirectory C:\Program Files\KT101. These files are necessary to perform internal Keeping Track bookkeeping. The files are named Masterfile.dta, KT101Buy_Sold.dta, KT101WeeklyNetWorth.dta, CalendarYear.dta, and CashInPortfolio.dta. The first three files are empty, the fourth file contains four characters (2005), and the fifth file contains nine characters (000000.00).

  • Copy the KT101EntryPoint.exe executable into the PC subdirectory C:\Program Files\KT101.

  • Copy icon Icon1.ico to the desktop. This shortcut will be pathed to the executable KT101EntryPoint.

  • Copy six more executables to C:\Program Files\KT101 that are called by the K101TEntryPoint entry-point program: KT101Startup, KT101Buy_Sold, KT101Plotter, KT101Realphabetize, KT101WeeklyDataPosting, and KT10CopyToFloppy.

To aid in the development of this deployment project, copies of the shortcut icon, the six more executables named above, and five bookkeeping files (*.dta) have all been gathered together in one location in the C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\KT101\Files KT101 Deploy Chap25 subdirectory. This is done for convenience only; the programmer could just as well have dragged and dropped the files from 12 separate locations on his PC.

Creating Bookkeeping Files for This Demo

The five bookkeeping files ” Masterfile.dta, KT101Buy_Sold.dta, KT101WeeklyNetWorth.dta, CalendarYear.dta, and CashInPortfolio.dta ” were all created in WordPad. The first three files are empty, and the last two have one record of data in each. They are all read-write files, and are located in the Files KT101 Deploy Chap25 subdirectory.

Creating Project KT101DeploymentDemo

  1. Open the Visual Studio IDE, and click on File | New . The New Project window shown in Figure 25-1 appears.

    image from book
    Figure 25-1: New Project window

  2. In the Project types list, highlight Windows under Visual C#. In the same list, highlight Setup and Deployment below Other Project Types.

  3. In the Templates area, highlight Setup Project . Then change the name of the project from Setup1 to KT101DeploymentDemo .In the Location box, set the location to C:\Documents and Settings\ Owner\My Documents\Visual Studio 2005\Projects\KT101 . Make sure that the Create directory for solution check box is checked, then click on the OK button.

    The project window should look like Figure 25-2.

    image from book
    Figure 25-2: KT101DeploymentDemo window

  4. Before proceeding any further, open the file My Documents\ Visual Studio 2005\Projects\KT101\Files KT101 Deploy Chap25 , and display it on the main window at the top left of the screen. This subdirectory contains 12 files, all of which will eventually be transferred to this deployment project.

    image from book
    Figure 25-3: Files KT101 Deploy Chap25

Rules for Movement within a Deployment Development Screen

There are subtle rules for moving about the deployment development screen:

  • Whenever the words KT101DeploymentDemo are highlighted in the Solution Explorer (the far-right column on the IDE screen), seven small icons will appear at the top of the Solution Explorer. The six to the left are editors; the seventh is the property pages window.

    The six editors are named File System Editor (the default editor), Registry Editor (not used), File Types Editor (not used), User Interface Editor (briefly used), Custom Actions Editor ( briefly used), and Launch Conditions Editor (not used). The seventh icon, the one to the farthest right, displays the property pages; it is not used in this demonstration.

  • When right-clicked, the top entry in the Solution Explorer, Solution ˜KT101DeploymentDemo (1 project), produces a menu for adding new projects to this solution set. We will add one more project (the program that is the entry point into KT101) to this deployment project.

  • When right-clicked, the second-line entry in the Solution Explorer, KT101DeploymentDemo, produces a menu for adding items (files, folders, etc.) to the existing deployment project. However, we will do all the file and folder adding by using drag and drop techniques, which are easier to do. We will eventually add 12 files to the existing deployment project.

Everything that you add to this deployment project (other folders or single files) exists here in virtual form only ” they are merely copies of files that exist elsewhere. Copies of the necessary files are placed in the executable file only when the programmer begins the build process.

Setting the Application Folder Name

The Application Folder is the folder that will eventually be placed in the receiving PC s Program Files directory by the deployment that is being created in this chapter. The creator of the application suite builds the deployment and sends the output of the deployment, a file named KT101DeploymentDemo.msi in this case, to the users who want to install the application suite on their PCs. When the deployment creator (programmer) has done everything right in the building of the deployment file, he will choose Build | Build Solution from the main menu to create the deployment executable. Next , all attention shifts to that executable, which will be located in KT101DeploymentDemo\ KT101DeploymentDemo\debug. If the msi executable places all the files in their proper places on the PC and registers the application with the PC s registry, then it s time to celebrate!

Place the File System Editor in the center of the screen if it is not there. This editor can be retrieved by clicking on KT101DeploymentDemo in the Solution Explorer (this action sets the icons for the editors at the top of the Solution Explorer). Click on the second icon from the left, File System Editor, to bring the editor into the center of the screen.

With the File System Editor showing in the center of the IDE (the editor has two columns of data ” File System on Target Machine on the left and Name on the right), proceed as follows :

  1. Highlight Application Folder in the left column to place its properties in the leftmost column of the IDE (the Properties column). Change the Always Create property from False to True by highlighting Always Create in the left column of the Properties window, clicking on the down arrow that appears in the right column of the Properties window, and picking True .

  2. Highlight the Default Location property to produce this long name in the right column:

     [ProgramFilesFolder][Manufacturer]\[ProductName] 

    The names Program Files Folder, Manufacturer, and Product Name are all taken from another page in this deployment scheme. To find these names , make sure that the KT101DeploymentDemo entry in the Solution Explorer is highlighted. Then a list of the project s properties will appear in the Properties listing. The formal name for Program Files Folder is always Program Files ” it is never changed. You can choose any name you want for Manufacturer and Product Name. But the easy way to set the default location on the PC where this project will end up is to click on the entry, erase all of it, and type in C:\Program Files\KT101 .

  3. During the installation program execution (performed by the user at his PC), the user may be offered the opportunity to change this location in the Program Files.

IMPORTANT  

If you do not want to allow the user to change the location of the project in Program Files, then do the following:

With KT101DeploymentDemo highlighted in the Solution Explorer, click on the User Interface Editor icon at the top of the Solution Explorer window (which replaces the File System Editor in the center of the IDE). Delete the Installation Folder entry at this time (the first time it appears, after Install, Start, and Welcome). To do this, right-click on the Installation Folder entry and click on Delete . Now, the user will never be given the opportunity to change the location of the files/folders being deployed.

Since we do not want the user to change this path , perform the above and delete the Installation Folder entry in Install.

Adding a Subdirectory to C:\Program Files\KT101

We need to add a subdirectory named DDT to the top-level directory (the Application folder). Follow these steps:

  1. Make sure that the File System Editor is in the center of the IDE, and highlight Application Folder in the left column.

  2. Right-click on Application Folder to produce a context menu and click on Add , then Folder . A subfolder will appear below the Application Folder entry. Change this subfolder name to DDT . This subdirectory will be used by the suite of programs after deployment.

  3. Right-click on DDT to produce another context menu. Click on Properties Window to place its properties in the far-left properties list, and change the Always Create property from False to True . If you fail to do this, the DDT subdirectory will not be created during deployment.

Adding an Additional Project to This Deployment Solution Set

To add an additional project ” in this case, the entry point project into KT101 ” follow these steps:

  1. Move to the Solution Explorer on the right side of the IDE main window and right-click on the Solution ˜KT101Deployment Demo (1 Project) entry in the Solution Explorer. Choose Add from the context menu, then pick Existing Project . The Add Existing Project window appears, as shown in Figure 25-4. (You must navigate to C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\KT101 to view this list in the Add Existing Project window.)

    image from book
    Figure 25-4: Add Existing Project window

  2. Highlight KT101EntryPoint , and then click on the Open button at the lower right of the window to display the lower- tier list of files in the project. Double-click on the KT101EntryPoint folder in this new list to reveal three lower-tier folders and the KT101EntryPoint.csproj file. Double-click on the KT101EntryPoint. csproj file to transfer this project to the deployment project. When this project has been added to the deployment project, the right side of the main window in the IDE will look like Figure 25-5.

    image from book
    Figure 25-5: All projects aboard

IMPORTANT  

This is the one case where drag and drop won t work (to add this new project to the original KT101DeploymentDemo project).

In case you are wondering why we went to such heroic lengths to transfer the complete KT101EntryPoint project to this deployment project but ignored the other six executable projects in the KT101 suite, this is the reason: As a result of this deployment, a shortcut icon must be created to point to this project, KT101EntryPoint, to bring the suite into the PC initially. The pointing process requires that the complete KT101EntryPoint project be placed inside the deployment project. The other six executables will be copied to the installation folder as simple executables.

Note the new project that has been added, KT101EntryPoint, goes to the top of the Solution Explorer, pushing down the original project, KT101DeploymentDemo. The top line in the Solution Explorer now shows two projects in this suite.

Adding 12 Files to This Deployment Project

The 12 files listed in Files KT101 Deploy Chap25 will be added to the deployment project ( not to the solution set).

Make sure that the File System Editor occupies the center of the screen. It is time to drag and drop the 12 files/folders. When Application Folder is highlighted in the leftmost column of the File System Editor, the only item that appears in the rightmost column is the DDT entry, a subdirectory that you added earlier.

Drag and drop each of the 12 items from the Files KT101 listing into the rightmost column of the File System Editor, under DDT.

The only entry that has not been entered in the KT101DeploymentDemo is the Primary output from KT101EntryPoint. We will do that now.

Converting an Executable to Project Output Form

Project KT101EntryPoint has been included in this deployment project as the second project and must be executed automatically every time the user clicks on the KT101 shortcut on the desktop. KT101EntryPoint must be placed into the deployment project in the Project Output form so this can happen.

  1. Right-click on the KT101DeploymentDemo entry near the top of the Solution Explorer list. Click on Add , and then on Project Out put . The Add Project Output Group window appears.

    image from book
    Figure 25-6: Add Project Output Group window

  2. If you had not transferred the KT101EntryPoint project to this deployment project earlier, the Project entry list at the top of the Add Project Output Group window would be empty. To create the KT101EntryPoint Project Output, double-click on the Primary output entry (the first entry) in the list of six possible choices in this window. This action places the entry Primary Output from KT101EntryPoint into the list of elements in Solution Explorer. After this is accomplished, the right side of the deployment project main window in the IDE should look like Figure 25-7.

    image from book
    Figure 25-7: All outputs aboard

Creating a Shortcut Icon and Pathing It to KT101EntryPoint

It takes a special action within the deployment project to prepare KT101EntryPoint for execution when the desktop shortcut icon is clicked by the user.

  1. Highlight KT101DeploymentDemo on the Solution Explorer (to bring up the six editor icons at the top of the Solution Explorer), and click on the Custom Actions Editor to bring the editor into the middle of the screen.

  2. Right-click on the Custom Actions entry (just above the word Install) in the editor. A context menu named Add Custom Action appears. Click on Add Custom Action to open the Select Item in Project window.

  3. Double-click on the Application Folder entry in the new window list to bring it to the top of the window.

    image from book
    Figure 25-8: Select Item in Project window

  4. Double-click on the Primary output from KT101EntryPoint entry (which may be mostly hidden at the right edge of the list). The main window will look like the following figure:

    image from book
    Figure 25-9: Special action

    At this point we have created the primary output of KT101EntryPoint, but we have not created the path between the desktop and this output. Now it is time to set the shortcut icon.

  5. Return to the File System Editor and highlight the entry User s Desktop in the left column of the editor. Right-click on the blank column to the right of the User s Desktop column. If you click on the left column, this next context menu will not appear. This seems like a foolish instruction (right-click on the blank column to the right), but it is the only way to create the icon. In the context menu that appears, click on Create New Shortcut to open the Select Item in Project window.

  6. Double-click on Application Folder , then double-click on the Icon1.ico file in the list of items in the Application Folder. The Select Item in Project window disappears, and in the rightmost column of the File System Editor (in the center of the IDE) the words Shortcut to Icon1.ico appear. This is the default name given to the shortcut in this deployment. Highlight the name and change it to KT101 .

  7. Right-click on KT101 and choose Properties Window from the context menu to open the icon s Properties window. Click on the Icon property to display the down arrow in the right column, and click on the down arrow. Click on Browse to find an icon. The Icon window appears.

    image from book
    Figure 25-10: Icon window

  8. Click on the Browse button near the top of the window. The Select Item in Project window reappears. Double-click on Application Folder ; the Icon1.ico file that you placed there earlier should be shown in the list. Highlight Icon1.ico and click on the OK button at the bottom of the window. A second Icon window appears, as shown in Figure 25-11.

    image from book
    Figure 25-11: Icon window

  9. Double-click on the yellow KT icon to set it into the deployment project. The window closes .

The Final Connection

Everything has been determined in the icon area except what the target will be when the user clicks on the desktop icon.

  1. To set this, return to the File System Editor and click on User s Desktop . This causes the shortcut name KT101 to appear in the right column.

  2. Highlight KT101 to bring its properties into the Properties window. Scroll down to the Target property, highlight it, and click on the three dots in the right column (Browse). The Select Item in Project window opens to display all items within the Application Folder.

  3. Highlight Primary output from KT101EntryPoint (Active) (which is located at the far right edge of the window). Then click on the OK button to make the connection between the desktop icon and the executable KT101EntryPoint in the Application Folder.

Now that this desktop shortcut is set up, it will initiate the executable KT101EntryPoint every time it is clicked.

Compiling the Deployment Project

At the main IDE menu, pick Build | Build Solution . Later, at the bottom of the screen, the message Build Successful will appear. There is no need to run the output of the deployment project at this time. If you want to look at the KT101DeploymentDemo.msi executable (the deployment program output), you will find it at My Documents\Visual Studio 2005\KT101\KT101DeploymentDemo\Debug. The *.msi output is about 445 K in size .

Save All and exit the C# compiler.

Executing the Deployment Project

Warning  

This is a full-fledged installation program and is subject to the same restrictions as any other installation program you may receive with commercial software. You cannot run this program if it has been run earlier on this PC unless you remove previous installations . So, before you attempt to execute this msi program, you must go to the Control Panel, choose Add or Remove Programs, find the KT101DeploymentDemo project, and remove it. The worst thing you can do is navigate to Program Files and KT101, then simply delete the KT101 folder. If you do this, the remove mechanism in Control Panel will never work!

If all parts of KT101 are removed from your PC, then navigate to My Documents\Visual Studio 2005\Projects\KT101\KT101Deploy mentDemo\Debug and execute KT101DeploymentDemo.msi . Good luck! If all goes well, the C:\Program Files\KT101DeploymentDemo subdirectory should look like Figure 25-12.

image from book
Figure 25-12: KT101 files listing

To send a copy of the KT101 suite to a friend, place the msi file KT101DeploymentDemo on a CD. On this same CD add the Microsoft file dotnetfx.exe (22.4 meg in size). This is a self-extracting file that must be placed on the friend s PC ” this is the giant cookie that C# uses to execute its programs on a PC. The dotnetfx.exe file can be downloaded from a link at www.wordware.com/unlockingcsharp. All Windows XP operating system sales after mid-2005 should have this cookie included in the package.

This completes the description of a deployment project. This project writes to the PC registry and installs all files necessary for the complete solution set. Therefore, the only way to remove this solution set is by using the formal methods in Control Panel | Add or Remove Programs.

Note  

There is a third financial suite in the companion files named TISourceCode that contains exactly the same executables as KT (Keeping Track). This suite is provided for users who want to track financial data with two programs on one PC. TI is exactly the same as KT, but the letters KT in the original suite are replaced with TI. (In case you re wondering, TI stands for TIAA-CREF, and is used by the author to track his retirement funds in TIAA-CREF.)

 


Unlocking Microsoft C# V 2.0 Programming Secrets
Unlocking Microsoft C# V 2.0 Programming Secrets (Wordware Applications Library)
ISBN: 1556220979
EAN: 2147483647
Year: 2005
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net