public async Task <CommittedAccountBalance> ExecuteAsync(UserId subscriberId, UserId creatorId, DateTime startTimeInclusive, DateTime endTimeExclusive, CommittedAccountBalance committedAccountBalance) { subscriberId.AssertNotNull("subscriberId"); creatorId.AssertNotNull("creatorId"); committedAccountBalance.AssertNotNull("committedAccountBalance"); var paymentProcessingData = await this.getPaymentProcessingData.ExecuteAsync( subscriberId, creatorId, startTimeInclusive, endTimeExclusive, committedAccountBalance); var results = await this.processPaymentProcessingData.ExecuteAsync(paymentProcessingData); await this.persistPaymentProcessingResults.ExecuteAsync(paymentProcessingData, results); return(results.CommittedAccountBalance); }
public async Task <PaymentProcessingData> ExecuteAsync(UserId subscriberId, UserId creatorId, DateTime startTimeInclusive, DateTime endTimeExclusive, CommittedAccountBalance committedAccountBalance) { using (PaymentsPerformanceLogger.Instance.Log(typeof(GetPaymentProcessingData))) { subscriberId.AssertNotNull("subscriberId"); creatorId.AssertNotNull("creatorId"); committedAccountBalance.AssertNotNull("committedAccountBalance"); IReadOnlyList <SubscriberChannelsSnapshot> subscriberChannelsSnapshots; IReadOnlyList <SubscriberSnapshot> subscriberSnapshots; IReadOnlyList <CalculatedAccountBalanceSnapshot> calculatedAccountBalances; IReadOnlyList <CreatorChannelsSnapshot> creatorChannelsSnapshots; IReadOnlyList <CreatorFreeAccessUsersSnapshot> creatorFreeAccessUsersSnapshots; IReadOnlyList <CreatorPost> creatorPosts; CreatorPercentageOverrideData creatorPercentageOverride; bool updateCache = false; if (this.cachedData != null && subscriberId.Equals(this.cachedData.SubscriberId) && startTimeInclusive >= this.cachedData.StartTimeInclusive && endTimeExclusive <= this.cachedData.EndTimeExclusive) { subscriberChannelsSnapshots = this.cachedData.SubscriberChannelsSnapshots; subscriberSnapshots = this.cachedData.SubscriberSnapshots; calculatedAccountBalances = this.cachedData.CalculatedAccountBalanceSnapshots; } else { updateCache = true; subscriberChannelsSnapshots = await this.getSubscriberChannelsSnapshots.ExecuteAsync(subscriberId, startTimeInclusive, endTimeExclusive); subscriberSnapshots = await this.getSubscriberSnapshots.ExecuteAsync(subscriberId, startTimeInclusive, endTimeExclusive); calculatedAccountBalances = await this.getCalculatedAccountBalances.ExecuteAsync(subscriberId, LedgerAccountType.FifthweekCredit, startTimeInclusive, endTimeExclusive); } if (this.cachedData != null && creatorId.Equals(this.cachedData.CreatorId) && startTimeInclusive >= this.cachedData.StartTimeInclusive && endTimeExclusive <= this.cachedData.EndTimeExclusive) { creatorChannelsSnapshots = this.cachedData.CreatorChannelsSnapshots; creatorFreeAccessUsersSnapshots = this.cachedData.CreatorFreeAccessUsersSnapshots; creatorPosts = this.cachedData.CreatorPosts; creatorPercentageOverride = this.cachedData.CreatorPercentageOverride; } else { updateCache = true; creatorChannelsSnapshots = await this.getCreatorChannelsSnapshots.ExecuteAsync(creatorId, startTimeInclusive, endTimeExclusive); creatorFreeAccessUsersSnapshots = await this.getCreatorFreeAccessUsersSnapshots.ExecuteAsync(creatorId, startTimeInclusive, endTimeExclusive); creatorPosts = await this.GetCreatorPosts(creatorChannelsSnapshots, startTimeInclusive, endTimeExclusive); creatorPercentageOverride = await this.getCreatorPercentageOverride.ExecuteAsync(creatorId, startTimeInclusive); } if (updateCache) { this.cachedData = new CachedData( subscriberId, creatorId, startTimeInclusive, endTimeExclusive, subscriberChannelsSnapshots, subscriberSnapshots, calculatedAccountBalances, creatorChannelsSnapshots, creatorFreeAccessUsersSnapshots, creatorPosts, creatorPercentageOverride); } return(new PaymentProcessingData( subscriberId, creatorId, startTimeInclusive, endTimeExclusive, committedAccountBalance, subscriberChannelsSnapshots, subscriberSnapshots, calculatedAccountBalances, creatorChannelsSnapshots, creatorFreeAccessUsersSnapshots, creatorPosts, creatorPercentageOverride)); } }