Ejemplo n.º 1
0
        private Site GetConfigureSite(IProgram app)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            if (app.Addresses == null || app.Addresses.Length == 0)
            {
                throw new ArgumentException("Must have at least one address", nameof(app));
            }

            var physicalPath = GetAppPath(app);

            var site = manager.Sites.CreateElement();

            site.Id   = app.Id;
            site.Name = app.Name.ToString();                           // id?

            site.ServerAutoStart = true;                               // Start the server automatically
            site.LogFile.Enabled = false;                              // Disable site logging

            var siteApp = site.Applications.CreateElement();           // Create a site app

            siteApp.Path = "/";                                        // Site the root path
            siteApp.ApplicationPoolName = GetApplicationPoolName(app); // Site the pool name

            site.Applications.Add(siteApp);

            // Create a virtual directory
            var virtualDirectory = siteApp.VirtualDirectories.CreateElement();

            virtualDirectory.Path         = "/";
            virtualDirectory.PhysicalPath = physicalPath.ToString();

            siteApp.VirtualDirectories.Add(virtualDirectory);

            /*
             * {
             * addresses: [ "http://carbon.com:8080" ],
             * }
             */

            foreach (var address in app.Addresses)
            {
                var b = new IISBinding(Listener.Parse(address));

                log.Info("configuring binding:" + b.ToString());

                var binding = site.Bindings.CreateElement();

                binding.Protocol           = b.Protocol;
                binding.BindingInformation = b.ToString();

                site.Bindings.Add(binding);

                var firewallRuleName = "app" + app.Id;

                if (!firewall.Exists(firewallRuleName, (ushort)b.Port))
                {
                    log.Info("- opening firewall port:" + b.Port);

                    firewall.Open(firewallRuleName, (ushort)b.Port);
                }
            }

            return(site);
        }