public WebServerAdministrationBinding InstallWebApp(
            string localDirectory, string applicationInstanceName, uint memMB)
        {
            WebServerAdministrationBinding rv = null;

            try
            {
                ushort applicationPort = 0;

                bool exists = DoesIIsObjectExist(IIsAppPoolObject, applicationInstanceName);
                if (exists)
                {
                    log.Error(Resources.WebServerAdministrationProvider_AppAlreadyExists_Fmt, applicationInstanceName);
                }
                else
                {
                    // NB: must lock to ensure multiple threads don't grab the same port.
                    lock (appcmdLock)
                    {
                        string cmd = String.Format("add apppool /name:{0}", applicationInstanceName);
                        AppCmdResult rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return null;
                        }

                        uint memKB = memMB * 1024;
                        cmd = String.Format(
                            "set apppool {0} /autoStart:true /managedRuntimeVersion:v4.0 /managedPipelineMode:Integrated /recycling.periodicRestart.privateMemory:{1}",
                            applicationInstanceName, memKB);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return null;
                        }

                        applicationPort = Utility.RandomFreePort();
                        cmd = String.Format("add site /name:{0} /bindings:http/*:{1}: /physicalPath:{2}",
                            applicationInstanceName, applicationPort, localDirectory);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return null;
                        }

                        cmd = String.Format("set site {0} /[path='/'].applicationPool:{0}", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return null;
                        }

                        cmd = String.Format("start apppool {0}", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return null;
                        }

                        cmd = String.Format("start site {0}", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return null;
                        }
                    }

                    rv = new WebServerAdministrationBinding { Host = localIPAddress.ToString(), Port = applicationPort };
                }

                firewallService.Open(applicationPort, applicationInstanceName);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }

            return rv;
        }
        public WebServerAdministrationBinding InstallWebApp(
            string localDirectory, string applicationInstanceName, ushort managedRuntimeVersion)
        {
            WebServerAdministrationBinding rv = null;

            if (managedRuntimeVersion != 2 && managedRuntimeVersion != 4)
            {
                throw new ArgumentException(
                    String.Format(Resources.WebServerAdministrationProvider_InvalidManagedRuntimeVersion_Fmt, managedRuntimeVersion), "managedRuntimeVersion");
            }

            try
            {
                ushort applicationPort = 0;

                bool exists = DoesIIsAppPoolExist(applicationInstanceName);
                if (exists)
                {
                    log.Error(Resources.WebServerAdministrationProvider_AppAlreadyExists_Fmt, applicationInstanceName);
                }
                else
                {
                    // NB: must lock to ensure multiple threads don't grab the same port.
                    lock (appcmdLock)
                    {
                        string cmd = String.Format("add apppool /name:{0}", applicationInstanceName);
                        ExecCmdResult rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return null;
                        }

                        cmd = String.Format(
                            "set apppool {0} /autoStart:true /managedRuntimeVersion:v{1}.0 /managedPipelineMode:Integrated /processModel.loadUserProfile:true",
                            applicationInstanceName, managedRuntimeVersion);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return null;
                        }

                        applicationPort = Utility.RandomFreePort();
                        cmd = String.Format("add site /name:{0} /bindings:http/*:{1}: /physicalPath:{2}",
                            applicationInstanceName, applicationPort, localDirectory);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return null;
                        }

                        cmd = String.Format("set site {0} /[path='/'].applicationPool:{0}", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return null;
                        }

                        cmd = String.Format("set config {0} /section:system.webServer/httpLogging /dontLog:True", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return null;
                        }

                        cmd = String.Format("start apppool {0}", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return null;
                        }

                        cmd = String.Format("start site {0}", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return null;
                        }
                    }

                    rv = new WebServerAdministrationBinding { Host = localIPAddress.ToString(), Port = applicationPort };
                }

                firewallService.Open(applicationPort, applicationInstanceName);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }

            return rv;
        }
Exemple #3
0
        public WebServerAdministrationBinding InstallWebApp(string localDirectory, string applicationInstanceName)
        {
            WebServerAdministrationBinding rv = null;

            try
            {
                ushort applicationPort = 0;

                bool exists = DoesIIsAppPoolExist(applicationInstanceName);
                if (exists)
                {
                    log.Error(Resources.WebServerAdministrationProvider_AppAlreadyExists_Fmt, applicationInstanceName);
                }
                else
                {
                    // NB: must lock to ensure multiple threads don't grab the same port.
                    lock (appcmdLock)
                    {
                        string       cmd  = String.Format("add apppool /name:{0}", applicationInstanceName);
                        AppCmdResult rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        cmd = String.Format(
                            "set apppool {0} /autoStart:true /managedRuntimeVersion:v4.0 /managedPipelineMode:Integrated",
                            applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        applicationPort = Utility.RandomFreePort();
                        cmd             = String.Format("add site /name:{0} /bindings:http/*:{1}: /physicalPath:{2}",
                                                        applicationInstanceName, applicationPort, localDirectory);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        cmd  = String.Format("set site {0} /[path='/'].applicationPool:{0}", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        cmd  = String.Format("start apppool {0}", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        cmd  = String.Format("start site {0}", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }
                    }

                    rv = new WebServerAdministrationBinding {
                        Host = localIPAddress.ToString(), Port = applicationPort
                    };
                }

                firewallService.Open(applicationPort, applicationInstanceName);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }

            return(rv);
        }
        public WebServerAdministrationBinding InstallWebApp(string localDirectory, string applicationInstanceName)
        {
            WebServerAdministrationBinding rv = null;

            try
            {
                lock (serverManagerLock)
                {
                    using (var manager = new ServerManager())
                    {
                        ApplicationPool cloudFoundryPool = GetApplicationPool(manager, applicationInstanceName);
                        if (null == cloudFoundryPool)
                        {
                            cloudFoundryPool = manager.ApplicationPools.Add(applicationInstanceName);
                        }

                        ushort applicationPort = FindNextAvailablePort();

                        firewallService.Open(applicationPort, applicationInstanceName);

                        /*
                         * NB: for now, listen on all local IPs, a specific port, and any domain.
                         * TODO: should we limit by host header here?
                         * TODO: use local IP here?
                         */
                        manager.Sites.Add(applicationInstanceName, "http", "*:" + applicationPort.ToString() + ":", localDirectory);

                        manager.Sites[applicationInstanceName].Applications[0].ApplicationPoolName = applicationInstanceName;

                        cloudFoundryPool.ManagedRuntimeVersion = "v4.0";

                        manager.CommitChanges();

                        rv = new WebServerAdministrationBinding() { Host = localIPAddress.ToString(), Port = applicationPort };
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }

            return rv;
        }
Exemple #5
0
        public WebServerAdministrationBinding InstallWebApp(
            string localDirectory, string applicationInstanceName, ushort managedRuntimeVersion)
        {
            WebServerAdministrationBinding rv = null;

            if (managedRuntimeVersion != 2 && managedRuntimeVersion != 4)
            {
                throw new ArgumentException(
                          String.Format(Resources.WebServerAdministrationProvider_InvalidManagedRuntimeVersion_Fmt, managedRuntimeVersion), "managedRuntimeVersion");
            }

            try
            {
                ushort applicationPort = 0;

                bool exists = DoesIIsAppPoolExist(applicationInstanceName);
                if (exists)
                {
                    log.Error(Resources.WebServerAdministrationProvider_AppAlreadyExists_Fmt, applicationInstanceName);
                }
                else
                {
                    // NB: must lock to ensure multiple threads don't grab the same port.
                    lock (appcmdLock)
                    {
                        string        cmd  = String.Format("add apppool /name:{0}", applicationInstanceName);
                        ExecCmdResult rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        cmd = String.Format(
                            "set apppool {0} /autoStart:true /managedRuntimeVersion:v{1}.0 /managedPipelineMode:Integrated /processModel.loadUserProfile:true",
                            applicationInstanceName, managedRuntimeVersion);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        applicationPort = Utility.RandomFreePort();
                        cmd             = String.Format("add site /name:{0} /bindings:http/*:{1}: /physicalPath:{2}",
                                                        applicationInstanceName, applicationPort, localDirectory);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        cmd  = String.Format("set site {0} /[path='/'].applicationPool:{0}", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        cmd  = String.Format("set config {0} /section:system.webServer/httpLogging /dontLog:True", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        cmd  = String.Format("start apppool {0}", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }

                        cmd  = String.Format("start site {0}", applicationInstanceName);
                        rslt = ExecAppcmd(cmd, 5, twoSeconds);
                        if (false == rslt.Success)
                        {
                            return(null);
                        }
                    }

                    rv = new WebServerAdministrationBinding {
                        Host = localIPAddress.ToString(), Port = applicationPort
                    };
                }

                firewallService.Open(applicationPort, applicationInstanceName);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }

            return(rv);
        }