示例#1
0
        public virtual void UpdateSite(StatsSite site)
        {
            // update site
            SiteAdmin stAdmin = new SiteAdmin();
            PrepareProxy(stAdmin);

            int siteId = Int32.Parse(site.SiteId);

            // get original site
            SiteInfoResult siteResult = stAdmin.GetSite(Username, Password, siteId);
            if (siteResult.Site == null)
                return;

            SiteInfo origSite = siteResult.Site;

            // update site with only required properties
            GenericResult1 result = stAdmin.UpdateSite(Username, Password, siteId, site.Name, origSite.LogDirectory,
                origSite.LogFormat, origSite.LogWildcard, origSite.LogDaysBeforeDelete,
                origSite.SmarterLogDirectory, origSite.SmarterLogMonthsBeforeDelete, origSite.ExportPath, origSite.ExportPathURL,
                origSite.TimeZoneID);

            if (!result.Result)
                throw new Exception("Error updating statistics site: " + result.Message);

            // update site users
            UserAdmin usrAdmin = new UserAdmin();
            PrepareProxy(usrAdmin);

            // get original users
            if (site.Users != null)
            {
                List<string> origUsers = new List<string>();
                List<string> newUsers = new List<string>();
                string ownerUsername = null;
                UserInfoResultArray usrResult = usrAdmin.GetUsers(Username, Password, siteId);
                foreach (UserInfo user in usrResult.user)
                {
                    // add to original users
                    origUsers.Add(user.UserName.ToLower());

                    // remember owner (he can't be deleted)
                    if (user.IsSiteOwner)
                        ownerUsername = user.UserName.ToLower();
                }

                // add, update users
                foreach (StatsUser user in site.Users)
                {
                    if (!origUsers.Contains(user.Username.ToLower()))
                    {
                        // add user
                        GenericResult2 r = usrAdmin.AddUser(Username, Password, siteId,
                            user.Username, user.Password, user.FirstName, user.LastName, user.IsAdmin);
                        if (!r.Result)
                            throw new Exception("Error adding site user: "******"Error updating site user: " + r.Message);
                    }

                    // add to new users list
                    newUsers.Add(user.Username.ToLower());
                }

                // delete users
                foreach (string username in origUsers)
                {
                    if (!newUsers.Contains(username) && username != ownerUsername)
                    {
                        // delete user
                        GenericResult2 r = usrAdmin.DeleteUser(Username, Password, siteId, username);
                    }
                }
            }
        }
示例#2
0
        public virtual StatsSite GetSite(string siteId)
        {
            SiteAdmin stAdmin = new SiteAdmin();
            PrepareProxy(stAdmin);

            int sid = Int32.Parse(siteId);
            SiteInfoResult result = stAdmin.GetSite(Username, Password, sid);
            if (result.Site == null)
                return null;

            StatsSite site = new StatsSite();
            site.Name = result.Site.DomainName;
            site.ExportPath = result.Site.ExportPath;
            site.ExportPathUrl = result.Site.ExportPathURL;
            site.LogDirectory = result.Site.LogDirectory;
            site.TimeZoneId = TimeZoneId;
            site.Status = result.Site.SiteStatus;

			// process stats URL
			string url = null;
			if (!String.IsNullOrEmpty(StatisticsUrl))
			{
				url = StringUtils.ReplaceStringVariable(StatisticsUrl, "domain_name", site.Name);
				url = StringUtils.ReplaceStringVariable(url, "site_id", siteId);
			}

            // get site users
            UserAdmin usrAdmin = new UserAdmin();
            PrepareProxy(usrAdmin);

            UserInfoResultArray usrResult = usrAdmin.GetUsers(Username, Password, sid);
            if (usrResult.user != null)
            {
                site.Users = new StatsUser[usrResult.user.Length];
                for (int i = 0; i < site.Users.Length; i++)
                {
                    site.Users[i] = new StatsUser();
                    site.Users[i].Username = usrResult.user[i].UserName;
                    site.Users[i].Password = usrResult.user[i].Password;
                    site.Users[i].FirstName = usrResult.user[i].FirstName;
                    site.Users[i].LastName = usrResult.user[i].LastName;
                    site.Users[i].IsAdmin = usrResult.user[i].IsAdmin;
                    site.Users[i].IsOwner = usrResult.user[i].IsSiteOwner;
                }

				if (site.Users.Length > 0 && !String.IsNullOrEmpty(url))
				{
					url = StringUtils.ReplaceStringVariable(url, "username", site.Users[0].Username);
					url = StringUtils.ReplaceStringVariable(url, "password", site.Users[0].Password);
				}
            }

			site.StatisticsUrl = url;

            return site;
        }