Ejemplo n.º 1
0
        public int RestoreItem(string tempFolder, System.Xml.XmlNode itemNode, int itemId, Type itemType, string itemName, int packageId, int serviceId, ResourceGroupInfo group)
        {
            if (itemType == typeof(StatsSite))
            {
                StatisticsServer stats = GetStatisticsServer(serviceId);

                // extract meta item
                XmlSerializer serializer = new XmlSerializer(typeof(StatsSite));
                StatsSite     site       = (StatsSite)serializer.Deserialize(
                    new XmlNodeReader(itemNode.SelectSingleNode("StatsSite")));

                // create site if required
                if (stats.GetSite(site.SiteId) == null)
                {
                    stats.AddSite(site);
                }

                // add meta-item if required
                if (PackageController.GetPackageItemByName(packageId, itemName, typeof(StatsSite)) == null)
                {
                    site.PackageId = packageId;
                    site.ServiceId = serviceId;
                    PackageController.AddPackageItem(site);
                }
            }

            return(0);
        }
Ejemplo n.º 2
0
        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();
            }
        }