public SyncService(IWebSiteRepository sitesRepository, ISyncStatusRepository syncStatusRepository, CloudStorageAccount storageAccount, string localSitesPath, string localTempPath, IEnumerable<string> directoriesToExclude, IEnumerable<string> sitesToExclude, Func<bool> syncEnabled, IISManager iisManager, ILoggerFactory loggerFactory, LoggerLevel logLevel)
        {
            _sitesRepository = sitesRepository;
            _syncStatusRepository = syncStatusRepository;

            _localSitesPath = localSitesPath;
            _localTempPath = localTempPath;
            _directoriesToExclude = directoriesToExclude;
            _sitesToExclude = sitesToExclude;
            _syncEnabled = syncEnabled;
            _iisManager = iisManager;
            _entries = new Dictionary<string, FileEntry>();
            _siteDeployTimes = new Dictionary<string, DateTime>();
            _logger = loggerFactory.Create(GetType(), logLevel);

            var sitesContainerName = AzureRoleEnvironment.GetConfigurationSettingValue(Constants.WebDeployPackagesBlobContainerKey).ToLowerInvariant();
            _container = storageAccount.CreateCloudBlobClient().GetContainerReference(sitesContainerName);
            _container.CreateIfNotExist();
        }
Beispiel #2
0
        public SyncService(IWebSiteRepository sitesRepository, ISyncStatusRepository syncStatusRepository, CloudStorageAccount storageAccount, string localSitesPath, string localTempPath, IEnumerable <string> directoriesToExclude, IEnumerable <string> sitesToExclude, Func <bool> syncEnabled, IISManager iisManager, ILoggerFactory loggerFactory, LoggerLevel logLevel)
        {
            _sitesRepository      = sitesRepository;
            _syncStatusRepository = syncStatusRepository;

            _localSitesPath       = localSitesPath;
            _localTempPath        = localTempPath;
            _directoriesToExclude = directoriesToExclude;
            _sitesToExclude       = sitesToExclude;
            _syncEnabled          = syncEnabled;
            _iisManager           = iisManager;
            _entries         = new Dictionary <string, FileEntry>();
            _siteDeployTimes = new Dictionary <string, DateTime>();
            _logger          = loggerFactory.Create(GetType(), logLevel);

            var sitesContainerName = AzureRoleEnvironment.GetConfigurationSettingValue(Constants.WebDeployPackagesBlobContainerKey).ToLowerInvariant();

            _container = storageAccount.CreateCloudBlobClient().GetContainerReference(sitesContainerName);
            _container.CreateIfNotExist();
        }
        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_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_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);
        }