public override void Install( IDictionary stateSaver) { // 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"); // if the installer is running in repair mode, it will try to re-install Myrtille... which is fine // problem is, it won't uninstall it first... which is not fine because some components can't be installed twice! // thus, prior to any install, try to uninstall first Trace.TraceInformation("Myrtille.Web is being installed, cleaning first"); try { Uninstall(null); } catch (Exception exc) { Trace.TraceInformation("Failed to clean Myrtille.Web ({0})", exc); } base.Install(stateSaver); Trace.TraceInformation("Installing Myrtille.Web"); try { // register Myrtille.Web to local IIS if (!IISHelper.IsIISApplicationPoolExists("MyrtilleAppPool")) { IISHelper.CreateIISApplicationPool("MyrtilleAppPool", "v4.0"); } if (!IISHelper.IsIISApplicationExists("/Myrtille")) { IISHelper.CreateIISApplication("/Myrtille", Path.GetFullPath(Context.Parameters["targetdir"]), "MyrtilleAppPool"); } // create a self signed certificate var cert = CertificateHelper.CreateSelfSignedCertificate(Environment.MachineName, "Myrtille self-signed certificate"); // bind it to the default website IISHelper.BindCertificate(cert); // export it to the targetdir "ssl" folder, for secure websocket communication var certBytes = cert.Export(X509ContentType.Pfx, ""); File.WriteAllBytes(Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "ssl", "PKCS12Cert.pfx"), certBytes); // add write permission to the targetdir "log" folder for MyrtilleAppPool, so that Myrtille.Web can save logs into it PermissionsHelper.AddDirectorySecurity( Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "log"), "IIS AppPool\\MyrtilleAppPool", FileSystemRights.Write, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow); // websockets ports int wsPort; if (!int.TryParse(Context.Parameters["WSPort"], out wsPort)) { wsPort = 8181; } int wssPort; if (!int.TryParse(Context.Parameters["WSSPort"], out wssPort)) { wssPort = 8431; } // load config var config = new XmlDocument(); var configPath = Path.Combine(Path.GetFullPath(Context.Parameters["targetdir"]), "Web.config"); config.Load(configPath); // update settings var navigator = config.CreateNavigator(); var node = XmlTools.GetNode(navigator, "/configuration/appSettings"); if (node != null) { XmlTools.WriteConfigKey(node, "WebSocketServerPort", wsPort.ToString()); XmlTools.WriteConfigKey(node, "WebSocketServerPortSecured", wssPort.ToString()); } // save config config.Save(configPath); // open ports FirewallHelper.OpenFirewallPort(wsPort, "Myrtille Websockets"); FirewallHelper.OpenFirewallPort(wssPort, "Myrtille Websockets Secured"); Trace.TraceInformation("Installed Myrtille.Web"); } catch (Exception exc) { Context.LogMessage(exc.InnerException != null ? exc.InnerException.Message: exc.Message); Trace.TraceError("Failed to install Myrtille.Web ({0})", exc); throw; } }