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);
        }
        public int BackupItem(string tempFolder, System.Xml.XmlWriter writer, ServiceProviderItem item, ResourceGroupInfo group)
        {
            if (item is StatsSite)
            {
                // backup stats site
                StatisticsServer stats = GetStatisticsServer(item.ServiceId);

                // read site info
                StatsSite itemSite = item as StatsSite;
                StatsSite site     = stats.GetSite(itemSite.SiteId);

                XmlSerializer serializer = new XmlSerializer(typeof(StatsSite));
                serializer.Serialize(writer, site);
            }
            return(0);
        }
        public static StatsSite GetSite(int itemId)
        {
            // load meta item
            StatsSite item = (StatsSite)PackageController.GetPackageItem(itemId);

            if (item == null)
            {
                return(null);
            }

            // load item from service
            StatisticsServer stats = new StatisticsServer();

            ServiceProviderProxy.Init(stats, item.ServiceId);
            StatsSite site = stats.GetSite(item.SiteId);

            if (site == null)
            {
                return(null);
            }

            site.Id        = item.Id;
            site.Name      = item.Name;
            site.ServiceId = item.ServiceId;
            site.PackageId = item.PackageId;
            site.SiteId    = item.SiteId;

            // update statistics URL
            if (!String.IsNullOrEmpty(site.StatisticsUrl))
            {
                // load space owner
                UserInfo user = PackageController.GetPackageOwner(item.PackageId);
                if (user != null)
                {
                    UserInfoInternal userInternal = UserController.GetUserInternally(user.UserId);

                    site.StatisticsUrl = Utils.ReplaceStringVariable(site.StatisticsUrl, "username",
                                                                     HttpUtility.UrlEncode(userInternal.Username));
                    site.StatisticsUrl = Utils.ReplaceStringVariable(site.StatisticsUrl, "password",
                                                                     HttpUtility.UrlEncode(userInternal.Password));
                }
            }

            return(site);
        }