private async Task CreateClientAsync() { var auth = await this.preClient.ConnectWithCode(this.AccessToken); this.Client = new MastodonClient(this.appRegistration, auth); this.CurrentUser = (await this.Client.GetCurrentUser()).ToMastodonAccount(); this.PublicStreamingFunctionCounter = new ConnectionFunctionCounter <MastodonStatus>(new PublicTimelineFunction { Client = this.Client, StreamingInstanceUri = this.StreamingUri, }); var homeFunc = new HomeTimelineFunction { Client = this.Client, StreamingInstanceUri = this.StreamingUri, }; this.HomeStreamingFunctionCounter = new ConnectionFunctionCounter <MastodonStatus>(homeFunc); this.NotificationStreamingFunctionCounter = new ConnectionFunctionCompositionCounter <MastodonNotification, MastodonStatus>( new NotificationFunction(this.Client, homeFunc), this.HomeStreamingFunctionCounter ); }
public async Task ReleaseFunctionAsync() { await this.Counter.DecrementAsync(); this.OnFunctionReleased(); this._function.Updated -= this.OnFunctionUpdated; this.Counter = null; this._function = null; this.Auth = null; }
public async Task AllocateFunctionAsync(MastodonAuthentication auth) { this.Auth = auth; this.Counter = this.GetFunctionCounter(auth); this._function = await this.Counter.IncrementAsync(); this.OnFunctionAllocated(); this._function.Updated += this.OnFunctionUpdated; this._function.Deleted += this.OnFunctionDeleted; }
private async Task <bool> CreateClientAsync(OAuthAccessTokenRepository tokenRepo) { Auth auth; if (!string.IsNullOrEmpty(this.AuthorizationCode)) { auth = await this.preClient.ConnectWithCode(this.AuthorizationCode); await tokenRepo.Save(this.InstanceUri, auth.AccessToken); } else { auth = new Auth { AccessToken = this.AccessToken }; } this.Client = new MastodonClient(this.appRegistration, auth); var user = await this.Client.GetCurrentUser(); // 自分のアカウント名が取得できてなかったら失敗とする if (string.IsNullOrEmpty(user?.AccountName)) { return(false); } this.CurrentUser = user.ToMastodonAccount(); this.PublicStreamingFunctionCounter = new ConnectionFunctionCounter <MastodonStatus>(new PublicTimelineFunction { Client = this.Client, StreamingInstanceUri = this.StreamingUri, }); var homeFunc = new HomeTimelineFunction { Client = this.Client, StreamingInstanceUri = this.StreamingUri, }; this.HomeStreamingFunctionCounter = new ConnectionFunctionCounter <MastodonStatus>(homeFunc); this.NotificationStreamingFunctionCounter = new ConnectionFunctionCompositionCounter <MastodonNotification, MastodonStatus>( new NotificationFunction(this.Client, homeFunc), this.HomeStreamingFunctionCounter ); return(true); }