public EditWebSiteViewModel(WebSite site)
 {
     Name = site.Name;
     Description = site.Description;
     EnableCDNChildApplication = site.EnableCDNChildApplication;
     EnableTestChildApplication = site.EnableTestChildApplication;
 }
        public void Create_new_web_site()
        {
            var site = new WebSite
            {
                Name = "Test Web Site",
                Description = "Description Test Web Site"
            };

            _repository.CreateWebSite(site);

            var id = site.Id.ToString();

            var newsite = _webSiteTable.Query.Where(t => t.RowKey == id).FirstOrDefault();

            Assert.IsNotNull(newsite);
            _webSiteTable.Delete(newsite);
        }
        public ActionResult Create(CreateWebSiteViewModel model)
        {
            if (!ModelState.IsValid)
                return View(model);

            var site = new WebSite
            {
                Name = model.Name,
                Description = model.Description,
                EnableCDNChildApplication = model.EnableCDNChildApplication,
                EnableTestChildApplication = model.EnableTestChildApplication
            };
            _webSiteRepository.CreateWebSite(site);
            if (model.AddStandardBindings)
            {
                var http = new Binding
                {
                    HostName = model.HostName,
                    Port = 80,
                    Protocol = "http",
                    IpAddress = "*",
                    CertificateThumbprint = ""
                };
                var https = new Binding
                {
                    HostName = model.HostName,
                    Port = 443,
                    Protocol = "https",
                    IpAddress = "*",
                    CertificateThumbprint = ""
                };
                _webSiteRepository.AddBindingToWebSite(site.Id, http);
                _webSiteRepository.AddBindingToWebSite(site.Id, https);
            }

            return RedirectToAction("Detail", new {area = ControlPanelAreaRegistration.Name, site.Id});
        }
        private WebSite CreateWebSiteWithBindings(int nbindings)
        {
            var id = Guid.NewGuid();
            var bindings = new List<Binding>();

            var site = new WebSite(id)
            {
                Name = "Test Web Site " + id.ToString(),
                Description = "Description Test Web Site " + id.ToString()
            };

            var binding = new Binding
            {
                Protocol = "http",
                IpAddress = string.Empty,
                Port = 80,
                HostName = "www.test0.com"
            };

            _repository.CreateWebSiteWithBinding(site, binding);
            bindings.Add(binding);

            for (var k = 1; k < nbindings; k++)
            {
                var otherBinding = new Binding
                {
                    Protocol = "http",
                    IpAddress = string.Empty,
                    Port = 80 + k,
                    HostName = string.Format("www.test{0}.com", k)
                };

                _repository.AddBindingToWebSite(site.Id, otherBinding);
                bindings.Add(otherBinding);
            }

            site.Bindings = bindings;

            return site;
        }
        private WebSite SetupWebsiteTest(ServerManager serverManager)
        {
            // Add website to table storage
            var website = new WebSite
            {
                Name = "test",
                Description = "Test website"
            };
            var binding = new Binding { HostName = "test.com", Port = 80, Protocol = "http" };
            _repo.CreateWebSiteWithBinding(website, binding);
            website.Bindings = new[] { binding };

            // Add role website to IIS / wwwroot directory
            serverManager.Sites.Add(RoleWebsiteName, "http", "*:80:test", Path.Combine(_sitePath, "deployment"));
            Directory.CreateDirectory(Path.Combine(_sitePath, RoleWebsiteName.Replace("-", ".").ToLowerInvariant()));
            serverManager.CommitChanges();

            GetBlobContainer().Delete();

            return website;
        }
示例#6
0
        private void UpdateApplications(WebSite site, ServerManager serverManager, string siteName, string sitePath, ApplicationPool appPool)
        {
            var iisSites = serverManager.Sites;
            var adminSite = iisSites[AzureRoleEnvironment.RoleWebsiteName()];

            var testApplication = adminSite.Applications.FirstOrDefault(
                app => app.Path.EndsWith("/test/" + siteName, StringComparison.OrdinalIgnoreCase));
            var cdnApplication = adminSite.Applications.FirstOrDefault(
                app => app.Path.EndsWith("/cdn/" + siteName, StringComparison.OrdinalIgnoreCase));

            if (site.EnableTestChildApplication)
            {
                if (testApplication == null)
                {
                    _logger.InfoFormat("Adding Test application for site '{0}'", siteName);
                    testApplication = adminSite.Applications.Add("/test/" + siteName, sitePath);
                    testApplication.ApplicationPoolName = appPool.Name;
                }
            }
            else
            {
                if (testApplication != null)
                {
                    _logger.InfoFormat("Removing Test application for site '{0}'", siteName);
                    adminSite.Applications.Remove(testApplication);
                }
            }

            if (site.EnableCDNChildApplication)
            {
                if (cdnApplication == null)
                {
                    _logger.InfoFormat("Adding CDN application for site '{0}'", siteName);
                    cdnApplication = adminSite.Applications.Add("/cdn/" + siteName, Path.Combine(sitePath, "cdn"));
                    cdnApplication.ApplicationPoolName = appPool.Name;
                }
            }
            else
            {
                if (cdnApplication != null)
                {
                    _logger.InfoFormat("Removing CDN application for site '{0}'", siteName);
                    adminSite.Applications.Remove(cdnApplication);
                }
            }
        }
 public void CreateWebSite(WebSite webSite)
 {
     _webSiteTable.Add(webSite.ToRow());
 }
        public void CreateWebSiteWithBinding(WebSite webSite, Binding binding)
        {
            binding.WebSiteId = webSite.Id;

            _webSiteTable.Add(webSite.ToRow());
            _bindingTable.Add(binding.ToRow());
        }
 public void AddBindingToWebSite(WebSite webSite, Binding binding)
 {
     binding.WebSiteId = webSite.Id;
     _bindingTable.Add(binding.ToRow());
 }
 public void UpdateWebSite(WebSite webSite)
 {
     _webSiteTable.AddOrUpdate(webSite.ToRow());
 }
        public void Update_sites_adding_bindings()
        {
            var contosoWebSite = new WebSite
            {
                Name = ContosoWebSiteName,
                Bindings = new List<Binding>
                {
                    new Binding
                    {
                        Protocol = "http",
                        IpAddress = "10.0.0.1",
                        Port = 8081,
                        HostName = "contoso.com"
                    }
                }
            };

            var factory = new AzureStorageFactory(CloudStorageAccount.DevelopmentStorageAccount);
            var iisManager = new IISManager(LocalSitesPath, TempSitesPath, new SyncStatusRepository(factory), new ConsoleFactory(), LoggerLevel.Debug);
            var sites = new List<WebSite> {contosoWebSite};

            iisManager.UpdateSites(sites, _excludedSites);

            var contoso = RetrieveWebSite(ContosoWebSiteName);

            Assert.IsNotNull(contoso);
            Assert.AreEqual(contosoWebSite.Name, contoso.Name);
            Assert.AreEqual(contosoWebSite.Bindings.Count(), contoso.Bindings.Count);

            // Add a new binding (https)
            var contosoBindings = contosoWebSite.Bindings.ToList();
            contosoBindings.Add(new Binding
                {
                    Protocol = "https",
                    IpAddress = "10.0.0.1",
                    Port = 8443,
                    CertificateThumbprint = "12345"
                }
            );
            contosoWebSite.Bindings = contosoBindings;

            iisManager.UpdateSites(sites, _excludedSites);

            // Asserts
            Assert.AreEqual(sites.Count, RetrieveWebSites().Count() - _excludedSites.Count);

            contoso = RetrieveWebSite(ContosoWebSiteName);

            Assert.IsNotNull(contoso);
            Assert.AreEqual(contosoWebSite.Name, contoso.Name);
            Assert.AreEqual(2, contoso.Bindings.Count);

            Assert.AreEqual(contosoWebSite.Bindings.First().HostName, contoso.Bindings.First().Host);
            Assert.AreEqual(contosoWebSite.Bindings.First().Protocol, contoso.Bindings.First().Protocol);
            Assert.AreEqual(contosoWebSite.Bindings.First().IpAddress, contoso.Bindings.First().EndPoint.Address.ToString());
            Assert.AreEqual(contosoWebSite.Bindings.First().Port, contoso.Bindings.First().EndPoint.Port);
            Assert.IsNull(contoso.Bindings.First().CertificateHash);

            Assert.IsTrue(string.IsNullOrEmpty(contoso.Bindings.Last().Host));
            Assert.AreEqual(contosoWebSite.Bindings.Last().Protocol, contoso.Bindings.Last().Protocol);
            Assert.AreEqual(contosoWebSite.Bindings.Last().IpAddress, contoso.Bindings.Last().EndPoint.Address.ToString());
            Assert.AreEqual(contosoWebSite.Bindings.Last().Port, contoso.Bindings.Last().EndPoint.Port);
            // todo: Figure out why these don't work!
            //Assert.AreEqual(StoreName.My.ToString().ToUpperInvariant(), contoso.Bindings.Last().CertificateStoreName.ToUpperInvariant());
            //Assert.IsNotNull(contoso.Bindings.Last().CertificateHash);
        }
        public void Update_sites_removing_site()
        {
            var contosoWebSite = new WebSite
            {
                Name = ContosoWebSiteName,
                Bindings = new List<Binding>
                {
                    new Binding
                    {
                        Protocol = "http",
                        IpAddress = "127.0.0.1",
                        Port = 8081,
                        HostName = "contoso.com"
                    }
                }
            };

            var fabrikamWebSite = new WebSite
            {
                Name = FabrikamWebSiteName,
                Bindings = new List<Binding>
                {
                    new Binding
                    {
                        Protocol = "https",
                        IpAddress = "127.0.0.1",
                        Port = 8443,
                        CertificateThumbprint = "12345"
                    }
                }
            };

            var factory = new AzureStorageFactory(CloudStorageAccount.DevelopmentStorageAccount);
            var iisManager = new IISManager(LocalSitesPath, TempSitesPath, new SyncStatusRepository(factory), new ConsoleFactory(), LoggerLevel.Debug);
            var sites = new List<WebSite> {contosoWebSite, fabrikamWebSite};

            iisManager.UpdateSites(sites, _excludedSites);

            Assert.AreEqual(2, RetrieveWebSites().Count() - _excludedSites.Count);

            sites.RemoveAt(0);
            iisManager.UpdateSites(sites, _excludedSites);

            // Asserts
            Assert.AreEqual(1, RetrieveWebSites().Count() - _excludedSites.Count);

            Site contoso = RetrieveWebSite(ContosoWebSiteName);
            Site fabrikam = RetrieveWebSite(FabrikamWebSiteName);

            Assert.IsNull(contoso);
            Assert.IsNotNull(fabrikam);
        }
        public void Update_sites_removing_bindings()
        {
            var fabrikamWebSite = new WebSite
            {
                Name = FabrikamWebSiteName,
                Bindings = new List<Binding>
                {
                    new Binding
                    {
                        Protocol = "https",
                        IpAddress = "127.0.0.1",
                        Port = 8443,
                        CertificateThumbprint = "12345"
                    },
                    new Binding
                    {
                        Protocol = "http",
                        IpAddress = "127.0.0.1",
                        Port = 8082
                    }
                }
            };

            var factory = new AzureStorageFactory(CloudStorageAccount.DevelopmentStorageAccount);
            var iisManager = new IISManager(LocalSitesPath, TempSitesPath, new SyncStatusRepository(factory), new ConsoleFactory(), LoggerLevel.Debug);
            var sites = new List<WebSite> {fabrikamWebSite};

            iisManager.UpdateSites(sites, _excludedSites);

            var fabrikam = RetrieveWebSite(FabrikamWebSiteName);

            Assert.IsNotNull(fabrikam);
            Assert.AreEqual(fabrikamWebSite.Name, fabrikam.Name);
            Assert.AreEqual(2, fabrikam.Bindings.Count);

            var fabrikamBindings = fabrikamWebSite.Bindings.ToList();
            fabrikamBindings.RemoveAt(1);
            fabrikamWebSite.Bindings = fabrikamBindings;

            iisManager.UpdateSites(sites, _excludedSites);

            // Asserts
            Assert.AreEqual(sites.Count(), RetrieveWebSites().Count() - _excludedSites.Count);

            fabrikam = RetrieveWebSite(FabrikamWebSiteName);

            Assert.IsNotNull(fabrikam);
            Assert.AreEqual(fabrikamWebSite.Name, fabrikam.Name);
            Assert.AreEqual(1, fabrikam.Bindings.Count);

            Assert.IsTrue(string.IsNullOrEmpty(fabrikam.Bindings.First().Host));
            Assert.AreEqual(fabrikamWebSite.Bindings.First().Protocol, fabrikam.Bindings.First().Protocol);
            Assert.AreEqual(fabrikamWebSite.Bindings.First().IpAddress, fabrikam.Bindings.First().EndPoint.Address.ToString());
            Assert.AreEqual(fabrikamWebSite.Bindings.First().Port, fabrikam.Bindings.First().EndPoint.Port);
            // todo: Figure out why these don't work!
            //Assert.AreEqual(StoreName.My.ToString().ToUpperInvariant(), fabrikam.Bindings.First().CertificateStoreName.ToUpperInvariant());
            //Assert.IsNotNull(fabrikam.Bindings.First().CertificateHash);
        }