Esempio n. 1
0
        private void DoUninstall()
        {
            // enable the line below to debug this installer; disable otherwise
            //MessageBox.Show("Attach the .NET debugger to the 'MSI Debug' msiexec.exe process now for debug. Click OK when ready...", "MSI Debug");

            Trace.TraceInformation("Uninstalling Myrtille.Web");

            try
            {
                // unregister Myrtille.Web from local IIS
                if (IISHelper.IsIISApplicationExists("/Myrtille"))
                {
                    IISHelper.DeleteIISApplication("/Myrtille");
                }

                if (IISHelper.IsIISApplicationPoolExists("MyrtilleAppPool"))
                {
                    IISHelper.DeleteIISApplicationPool("MyrtilleAppPool");
                }

                // retrieve the myrtille self signed certificate
                var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
                store.Open(OpenFlags.ReadWrite);
                var certs = store.Certificates.Find(X509FindType.FindByIssuerName, Environment.MachineName, false);
                if (certs.Count > 0)
                {
                    foreach (var cert in certs)
                    {
                        if (cert.FriendlyName == "Myrtille self-signed certificate")
                        {
                            // unbind it from the default website
                            IISHelper.UnbindCertificate(cert);

                            // remove it
                            store.Remove(cert);

                            // normally, there should be only one myrtille self-signed certificate, but let's check further (just in case)...
                            //break;
                        }
                    }
                }

                store.Close();

                // websockets ports
                int wsPort  = 8181;
                int wssPort = 8431;

                // load config
                var config     = new XmlDocument();
                var configPath = Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "Web.config");
                config.Load(configPath);

                // read settings
                var navigator = config.CreateNavigator();

                var node = XmlTools.GetNode(navigator, "/configuration/appSettings");
                if (node != null)
                {
                    if (!int.TryParse(XmlTools.ReadConfigKey(node, "WebSocketServerPort"), out wsPort))
                    {
                        wsPort = 8181;
                    }

                    if (!int.TryParse(XmlTools.ReadConfigKey(node, "WebSocketServerPortSecured"), out wssPort))
                    {
                        wssPort = 8431;
                    }
                }

                // close ports
                FirewallHelper.CloseFirewallPort(wsPort);
                FirewallHelper.CloseFirewallPort(wssPort);

                Trace.TraceInformation("Uninstalled Myrtille.Web");
            }
            catch (Exception exc)
            {
                Context.LogMessage(exc.InnerException != null ? exc.InnerException.Message : exc.Message);
                Trace.TraceError("Failed to uninstall Myrtille.Web ({0})", exc);
                throw;
            }
        }