Пример #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 string AddSite(StatsSite site)
        {
            // generate unique SiteID
            //int iSiteId = site.Name.GetHashCode();
            //if (iSiteId < 0)
            //     iSiteId *= -1;

            //string siteId = iSiteId.ToString();

            // create logs folder if not exists
            //if (!FileUtils.DirectoryExists(site.LogDirectory))
            //    FileUtils.CreateDirectory(site.LogDirectory);

            // add site
            SiteAdmin stAdmin = new SiteAdmin();
            PrepareProxy(stAdmin);

            if (site.Users == null || site.Users.Length == 0)
                throw new Exception("At least one user (site owner) should be specified when creating new statistics site");

            string ownerUsername = site.Users[0].Username.ToLower();
            GenericResult1 result = stAdmin.AddSite(Username, Password,
                site.Users[0].Username, site.Users[0].Password, site.Users[0].FirstName, site.Users[0].LastName,
                ServerId, 0, site.Name, site.LogDirectory, LogFormat, LogWildcard, LogDeleteDays,
                SmarterLogsPath, SmarterLogDeleteMonths, "", "", TimeZoneId);

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

            string siteId = GetSiteId(site.Name);

            int iSiteId = Int32.Parse(siteId);

            // add other users
            UserAdmin usrAdmin = new UserAdmin();
            PrepareProxy(usrAdmin);
            foreach (StatsUser user in site.Users)
            {
                if (user.Username.ToLower() != ownerUsername)
                {
                    // add user
                    GenericResult2 r = usrAdmin.AddUser(Username, Password, iSiteId,
                        user.Username, user.Password, user.FirstName, user.LastName, user.IsAdmin);
                    if (!r.Result)
                        throw new Exception("Error adding site user: " + r.Message);
                }
            }

            return siteId;
        }