1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Configuration.Install;
5using System.EnterpriseServices;
6using System.Diagnostics;
7using System.IO;
8using System.Runtime.InteropServices;
9
10namespace DTS.ArcGIS.Server.SOE.LineUtils
11{
12 [ComVisible(false)]
13 [RunInstaller(true)]
14 public partial class SOEInstaller : Installer
15 {
16 public SOEInstaller()
17 {
18 InitializeComponent();
19 }
20
21 public override void Install(System.Collections.IDictionary stateSaver)
22 {
23 try
24 {
25 string appID = null;
26 string typeLib = null;
27 // Get the location of the current assembly
28 string assembly = GetType().Assembly.Location;
29 // Install the application
30 RegistrationHelper regHelper = new RegistrationHelper();
31 regHelper.InstallAssembly(assembly, ref appID, ref typeLib, InstallationFlags.FindOrCreateTargetApplication);
32 // Save the state - you will need this for the uninstall
33 stateSaver.Add("AppID", appID);
34 stateSaver.Add("Assembly", assembly);
35 }
36 catch (Exception ex)
37 {
38#if DEBUG
39 Debug.WriteLine(ex);
40#endif
41 StreamWriter writer = File.AppendText("InstallError.log");
42 writer.WriteLine("Uninstall Error: {0}", ex.Message);
43 // If the installer catches the exception it will display
44 // an error message. Show a friendly error message
45 throw new ApplicationException("Error installing the middle tier", ex);
46 }
47 }
48
49
50 public override void Uninstall(System.Collections.IDictionary savedState)
51 {
52 try
53 {
54 // Get the state created when the app was installed
55 string appID = (string)savedState["AppID"];
56 string assembly = (string)savedState["Assembly"];
57 // Uninstall the application
58 RegistrationHelper regHelper = new RegistrationHelper();
59 regHelper.UninstallAssembly(assembly, appID);
60 }
61 catch (Exception ex)
62 {
63 // Don't allow unhandled exceptions during uninstall
64#if DEBUG
65 Debug.WriteLine(ex);
66#endif
67 StreamWriter sw = File.AppendText("InstallError.log");
68 sw.WriteLine("Uninstall Error: {0}", ex.Message);
69 }
70 }
71
72 }
73}