Ejemplo n.º 1
0
        private static bool CreateSiteInIIS(SiteCollection sites, SiteDTO dto)
        {
            try
            {
                var site = sites.CreateElement();
                site.Id = dto.SiteId;
                site.SetAttributeValue("name", dto.SiteName);
                sites.Add(site);

                var app = site.Applications.CreateElement();
                app.SetAttributeValue("path", "/");
                app.SetAttributeValue("applicationPool", dto.PoolName);
                site.Applications.Add(app);

                var vdir = app.VirtualDirectories.CreateElement();
                vdir.SetAttributeValue("path", "/");
                vdir.SetAttributeValue("physicalPath", string.Format(@"{0}\{1}", dto.RootDir, dto.SiteName));
                app.VirtualDirectories.Add(vdir);

                var binding = site.Bindings.CreateElement();
                binding.SetAttributeValue("protocol", "http");
                binding.SetAttributeValue("bindingInformation", string.Format(@":{0}:{1}", dto.Port, dto.SiteName));
                site.Bindings.Add(binding);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Create site {0} failed. Reason: {1}", dto.SiteName, ex.Message);
                return(false);
            }
            return(true);
        }
        public void CreateSiteEx(int siteId, string siteName, string poolName, string dirRoot, string Ip, int Port, string host)
        {
            try
            {
                using (ServerManager serverManager = GetServerManager())
                {
                    string bindingInfo = "";
                    if (Ip == null)
                    {
                        Ip = "*";
                    }
                    bindingInfo += Ip;
                    bindingInfo += ":";
                    bindingInfo += Port;
                    bindingInfo += ":";
                    if (host != null)
                    {
                        bindingInfo += host;
                    }

                    TestUtility.LogTrace(String.Format("#################### Adding Site {0} with App Pool {1} with BindingInfo {2} ####################", siteName, poolName, bindingInfo));

                    SiteCollection sites = serverManager.Sites;
                    Site           site  = sites.CreateElement();
                    site.Id = siteId;
                    site.SetAttributeValue("name", siteName);
                    sites.Add(site);

                    Application app = site.Applications.CreateElement();
                    app.SetAttributeValue("path", "/");
                    app.SetAttributeValue("applicationPool", poolName);
                    site.Applications.Add(app);

                    VirtualDirectory vdir = app.VirtualDirectories.CreateElement();
                    vdir.SetAttributeValue("path", "/");
                    vdir.SetAttributeValue("physicalPath", dirRoot);

                    app.VirtualDirectories.Add(vdir);

                    Binding b = site.Bindings.CreateElement();
                    b.SetAttributeValue("protocol", "http");
                    b.SetAttributeValue("bindingInformation", bindingInfo);

                    site.Bindings.Add(b);

                    serverManager.CommitChanges();
                }
            }
            catch (Exception ex)
            {
                TestUtility.LogInformation(String.Format("#################### Create site {0} failed. Reason: {1} ####################", siteName, ex.Message));
            }
        }
Ejemplo n.º 3
0
        static bool CreateSitesInIIS(SiteCollection sites, string sitePrefix, int siteId, string dirRoot)
        {
            string siteName = sitePrefix + siteId;
            // site gets set to Poolname using the following format. Example: 'Site_POOL10'
            string poolName = POOLPREFIX + sitePrefix + siteId;

            try
            {
                Site site = sites.CreateElement();
                site.Id = siteId;
                site.SetAttributeValue("name", siteName);
                sites.Add(site);

                Application app = site.Applications.CreateElement();
                app.SetAttributeValue("path", "/");
                app.SetAttributeValue("applicationPool", poolName);
                site.Applications.Add(app);

                VirtualDirectory vdir = app.VirtualDirectories.CreateElement();
                vdir.SetAttributeValue("path", "/");
                vdir.SetAttributeValue("physicalPath", dirRoot + @"\" + siteName);

                app.VirtualDirectories.Add(vdir);

                Binding b = site.Bindings.CreateElement();
                b.SetAttributeValue("protocol", "http");
                b.SetAttributeValue("bindingInformation", ":80:" + siteName);
                site.Bindings.Add(b);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Create site {0} failed. Reason: {1}", siteName, ex.Message);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        private static bool CreateSiteInIIS(SiteCollection sites, SiteDTO dto)
        {
            try
            {
                var site = sites.CreateElement();
                site.Id = dto.SiteId;
                site.SetAttributeValue("name", dto.SiteName);
                sites.Add(site);

                var app = site.Applications.CreateElement();
                app.SetAttributeValue("path", "/");
                app.SetAttributeValue("applicationPool", dto.PoolName);
                site.Applications.Add(app);

                var vdir = app.VirtualDirectories.CreateElement();
                vdir.SetAttributeValue("path", "/");
                vdir.SetAttributeValue("physicalPath", string.Format(@"{0}\{1}", dto.RootDir, dto.SiteName));
                app.VirtualDirectories.Add(vdir);

                var binding = site.Bindings.CreateElement();
                binding.SetAttributeValue("protocol", "http");
                binding.SetAttributeValue("bindingInformation", string.Format(@":{0}:{1}", dto.Port, dto.SiteName));
                site.Bindings.Add(binding);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Create site {0} failed. Reason: {1}", dto.SiteName, ex.Message);
                return false;
            }
            return true;
        }