/// <summary> /// Requests that an account synchronize all the analytics data in Rock /// with the data on the provider. /// </summary> /// <param name="mediaAccountId">The media account identifier to be synchronized.</param> /// <param name="cancellationToken">The cancellation token that can be used to abort the operation.</param> /// <returns>A <see cref="SyncOperationResult"/> object with the result of the operation.</returns> public static async Task <SyncOperationResult> SyncAnalyticsInAccountAsync(int mediaAccountId, CancellationToken cancellationToken = default) { using (var rockContext = new RockContext()) { var mediaAccount = new MediaAccountService(rockContext).GetNoTracking(mediaAccountId); if (mediaAccount == null) { return(new SyncOperationResult(new[] { "Media Account was not found." })); } var component = mediaAccount.GetMediaAccountComponent(); if (component == null) { return(new SyncOperationResult(new[] { "Media Account component was not found." })); } var result = await EnqueueOperationAsync(mediaAccountId, () => { return(component.SyncAnalyticsAsync(mediaAccount, cancellationToken)); }, cancellationToken); return(result); } }
/// <summary> /// Requests that an account synchronize the data in Rock with all of /// the media content stored on the provider. /// </summary> /// <param name="mediaAccountId">The media account identifier to be synchronized.</param> /// <param name="cancellationToken">The cancellation token that can be used to abort the operation.</param> /// <returns>A <see cref="SyncOperationResult"/> object with the result of the operation.</returns> public static async Task <SyncOperationResult> SyncMediaInAccountAsync(int mediaAccountId, CancellationToken cancellationToken = default) { using (var rockContext = new RockContext()) { var mediaAccount = new MediaAccountService(rockContext).Get(mediaAccountId); if (mediaAccount == null) { return(new SyncOperationResult(new[] { "Media Account was not found." })); } var component = mediaAccount.GetMediaAccountComponent(); if (component == null) { return(new SyncOperationResult(new[] { "Media Account component was not found." })); } // Set time to just before we start. Better to have a small // amount of overlap than miss data. var refreshDateTime = RockDateTime.Now; var result = await EnqueueOperationAsync(mediaAccountId, () => { return(component.SyncMediaAsync(mediaAccount, cancellationToken)); }, cancellationToken); if (result.IsSuccess) { mediaAccount.LastRefreshDateTime = refreshDateTime; rockContext.SaveChanges(); } return(result); } }