Ejemplo n.º 1
0
        public static WebSite GetWebSite(int siteItemId)
        {
            // load site item
            WebSite siteItem = (WebSite)PackageController.GetPackageItem(siteItemId);
            if (siteItem == null)
                return null;

            // load live site from service
            WebServer web = new WebServer();
            ServiceProviderProxy.Init(web, siteItem.ServiceId);
            WebSite site = web.GetSite(siteItem.SiteId);
            
            // set other properties
            site.Id = siteItem.Id;
            site.Name = siteItem.Name;
            site.ServiceId = siteItem.ServiceId;
            site.PackageId = siteItem.PackageId;

            // load IP address
            site.SiteIPAddressId = siteItem.SiteIPAddressId;
            IPAddressInfo ip = ServerController.GetIPAddress(siteItem.SiteIPAddressId);
            if(ip != null)
                site.SiteIPAddress = ip.ExternalIP;

            // check if site has dedicated IP assigned
            var siteIpAddresses = ServerController.GetItemIPAddresses(siteItemId, IPAddressPool.None);
            foreach (var siteIp in siteIpAddresses)
            {
                var packageIpAddress = ServerController.GetPackageIPAddress(siteIp.AddressID);
                if (packageIpAddress != null && packageIpAddress.ExternalIP == site.SiteIPAddress)
                {
                    site.IsDedicatedIP = true;
                    break;
                }
            }

            // truncate home folder
            site.ContentPath = FilesController.GetVirtualPackagePath(siteItem.PackageId, site.ContentPath);

            //check if Coldfusion is available
            //site.ColdFusionAvailable = siteItem.ColdFusionAvailable;
            
            // set FrontPage account
            site.FrontPageAccount = siteItem.FrontPageAccount;
            if (String.IsNullOrEmpty(site.FrontPageAccount))
                site.FrontPageAccount = GetFrontPageUsername(site.Name);

			// Set Web Deploy publishing account
			site.WebDeployPublishingAccount = siteItem.WebDeployPublishingAccount;
			// Set Web Deploy site publishing enabled
			site.WebDeploySitePublishingEnabled = siteItem.WebDeploySitePublishingEnabled;
			// Set Web Deploy site publishing profile
			site.WebDeploySitePublishingProfile = siteItem.WebDeploySitePublishingProfile;

            return site;
        }
Ejemplo n.º 2
0
        public static WebSite GetWebSite(int siteItemId)
        {
            // load site item
            WebSite siteItem = (WebSite)PackageController.GetPackageItem(siteItemId);
            if (siteItem == null)
                return null;

            // load live site from service
            WebServer web = new WebServer();
            ServiceProviderProxy.Init(web, siteItem.ServiceId);
            WebSite site = web.GetSite(siteItem.SiteId);
            
            // set other properties
            site.Id = siteItem.Id;
            site.Name = siteItem.Name;
            site.ServiceId = siteItem.ServiceId;
            site.PackageId = siteItem.PackageId;

            // load IP address
            site.SiteIPAddressId = siteItem.SiteIPAddressId;
            IPAddressInfo ip = ServerController.GetIPAddress(siteItem.SiteIPAddressId);
            if(ip != null)
                site.SiteIPAddress = ip.ExternalIP;

            // truncate home folder
            site.ContentPath = FilesController.GetVirtualPackagePath(siteItem.PackageId, site.ContentPath);

            //check if Coldfusion is available
            //site.ColdFusionAvailable = siteItem.ColdFusionAvailable;
            
            // set FrontPage account
            site.FrontPageAccount = siteItem.FrontPageAccount;
            if (String.IsNullOrEmpty(site.FrontPageAccount))
                site.FrontPageAccount = GetFrontPageUsername(site.Name);

			#region Restore Web Deploy publishing persistent properties
			// Set Web Deploy publishing account
			site.WebDeployPublishingAccount = siteItem.WebDeployPublishingAccount;
			// Set Web Deploy site publishing enabled
			site.WebDeploySitePublishingEnabled = siteItem.WebDeploySitePublishingEnabled;
			// Set Web Deploy site publishing profile
			site.WebDeploySitePublishingProfile = siteItem.WebDeploySitePublishingProfile;
			#endregion

            return site;
        }
        public static int AddSite(StatsSite item)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
            if (accountCheck < 0) return accountCheck;

            // check package
            int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive);
            if (packageCheck < 0) return packageCheck;

            // check quota
            QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.STATS_SITES);
            if (quota.QuotaExhausted)
                return BusinessErrorCodes.ERROR_STATS_RESOURCE_QUOTA_LIMIT;

            // check if stats resource is available
            int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.Statistics);
            if (serviceId == 0)
                return BusinessErrorCodes.ERROR_STATS_RESOURCE_UNAVAILABLE;

            // check package items
            if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(StatsSite)) != null)
                return BusinessErrorCodes.ERROR_STATS_PACKAGE_ITEM_EXISTS;

            // place log record
            TaskManager.StartTask("STATS_SITE", "ADD", item.Name);

            try
            {
                // load web site
                WebSite siteItem = (WebSite)PackageController.GetPackageItemByName(item.PackageId,
                    item.Name, typeof(WebSite));

                if (siteItem == null)
                    return BusinessErrorCodes.ERROR_WEB_SITE_SERVICE_UNAVAILABLE;

                // get service web site
                WebServer web = new WebServer();
                ServiceProviderProxy.Init(web, siteItem.ServiceId);
                WebSite site = web.GetSite(siteItem.SiteId);

                List<DomainInfo> pointers = WebServerController.GetWebSitePointers(siteItem.Id);
                List<string> aliases = new List<string>();

                foreach(DomainInfo pointer in pointers)
                    aliases.Add(pointer.DomainName);

                StatisticsServer stats = new StatisticsServer();
                ServiceProviderProxy.Init(stats, serviceId);
                string siteNumber = (site.IIs7) ? site[WebSite.IIS7_SITE_ID] : siteItem.SiteId.Replace("/", "");
                string logsCommonFolder = site.LogsPath;
                string logsFolder = Path.Combine(logsCommonFolder, siteNumber);

				// get service settings
				StringDictionary settings = ServerController.GetServiceSettings(serviceId);
				if (Utils.ParseBool(settings["BuildUncLogsPath"], false))
				{
					logsFolder = FilesController.ConvertToUncPath(siteItem.ServiceId, logsFolder);
				}

                item.LogDirectory = logsFolder;
                item.DomainAliases = aliases.ToArray();

                // install statistics
                item.SiteId = stats.AddSite(item);

                // save statistics item
                item.ServiceId = serviceId;
                int itemId = PackageController.AddPackageItem(item);

                TaskManager.ItemId = itemId;

                return itemId;
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }