Esempio n. 1
0
        public UserDetail Update(User user)
        {
            if (user.Id != this.Id)
            {
                throw new ArgumentException(nameof(user.Id));
            }

            const string RemoteUrlBase = "https://twitter.com/";

            var batch = new BatchPropertyChanges();

            batch.Set(ref this._createdAt, user.CreatedAt, nameof(this.CreatedAt));
            batch.Set(ref this._followersCount, user.FollowersCount, nameof(this.FollowersCount));
            batch.Set(ref this._followingCount, user.FriendsCount, nameof(this.FollowersCount));
            batch.Set(ref this._location, user.Location, nameof(this.Location));
            batch.Set(ref this._name, user.Name, nameof(this.Name));
            batch.Set(ref this._profileBannerUrl, user.ProfileBannerUrl, nameof(this.ProfileBannerUrl));
            batch.Set(ref this._isProtected, user.IsProtected, nameof(this.IsProtected));
            batch.Set(ref this._statusCount, user.StatusesCount, nameof(this.StatusesCount));
            batch.Set(ref this._remoteUrl, RemoteUrlBase + user.ScreenName, nameof(this.RemoteUrl));
            batch.Set(ref this._isSuspended, user.IsSuspended ?? false, nameof(this.IsSuspended));

            if (batch.Set(ref this._userName, user.ScreenName, nameof(this.UserName)) || this._fullName == null)
            {
                var longUserName = user.ScreenName + "@twitter.com";
                batch.Set(ref this._fullName, longUserName, nameof(this.FullName));
            }

            if (batch.Set(ref this._description, user.Description ?? string.Empty, nameof(this.Description)))
            {
                batch.Set(ref this._descriptionEntities, null, nameof(this.DescriptionEntities));
                this._descriptionEntitiesTokenBuilder = new TwitterTextTokenBuilder(this.Description, user.Entities?.Description);
            }

            if (batch.Set(ref this._url, user.Url ?? string.Empty, nameof(this.Url)))
            {
                batch.Set(ref this._urlEntities, null, nameof(this.UrlEntities));
                this._urlEntitiesTokenBuilder = new TwitterTextTokenBuilder(this.Url, user.Entities?.Url);
            }

            this.UpdatedAt = DateTime.Now;

            batch.Execute(this.RaisePropertyChanged);

            return(this);
        }
Esempio n. 2
0
        public AccountDetail Update(Account account)
        {
            var batch = new BatchPropertyChanges();

            batch.Set(ref this._followersCount, account.FollowersCount, nameof(this.FollowersCount));
            batch.Set(ref this._followingsCount, account.FollowingCount, nameof(this.FollowingsCount));
            //batch.Set(ref this._language, account.Language, nameof(this.Language));
            //batch.Set(ref this._location, account.Location, nameof(this.Location));
            batch.Set(ref this._name, account.DisplayName, nameof(this.Name));
            batch.Set(ref this._profileBannerUrl, account.Header, nameof(this.ProfileBannerUrl));
            batch.Set(ref this._profileImageUrl, account.Avatar, nameof(this.ProfileImageUrl));
            batch.Set(ref this._isProtected, account.IsLocked, nameof(this.IsProtected));
            batch.Set(ref this._statusCount, account.StatusesCount, nameof(this.StatusesCount));
            batch.Set(ref this._remoteUrl, account.Url, nameof(this.RemoteUrl));

            if (batch.Set(ref this._userName, account.Acct, nameof(this.UserName)) || this._fullName == null)
            {
                var longUserName = string.Equals(account.UserName, account.Acct)
                    ? account.Acct + "@" + this.Instance.Host
                    : account.Acct;

                batch.Set(ref this._fullName, longUserName, nameof(this.FullName));
            }

            if (batch.Set(ref this._description, account.Note, nameof(this.Description)))
            {
                var entities = new[] { new PlainTextEntity(this.Description) };
                batch.Set(ref this._descriptionEntities, entities, nameof(this.DescriptionEntities));
            }

            if (batch.Set(ref this._url, account.Url, nameof(this.Url)))
            {
                var entities = new[] { new PlainTextEntity(this.Url) };
                batch.Set(ref this._urlEntities, entities, nameof(this.UrlEntities));
            }

            this.UpdatedAt = DateTime.Now;

            batch.Execute(this.RaisePropertyChanged);

            return(this);
        }