コード例 #1
0
ファイル: SmarterStats.cs プロジェクト: pasamsin/SolidCP
        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);
                    }
                }
            }
        }