/// <summary> /// Handles the Click event of the btnSyncWithProvider control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnSyncWithProvider_Click(object sender, EventArgs e) { var mediaAccountId = hfMediaAccountId.ValueAsInt(); Task.Run(async() => { await MediaAccountService.SyncMediaInAccountAsync(mediaAccountId); await MediaAccountService.SyncAnalyticsInAccountAsync(mediaAccountId); }); mdSyncMessage.Show("Synchronization with provider started and will continue in the background.", ModalAlertType.Information); }
/// <summary> /// Processes one account and return the result of the operation. /// </summary> /// <param name="mediaAccount">The media account.</param> /// <param name="limitFullSync"><c>true</c> if a full-sync should only be performed once per day.</param> /// <returns>The result of the operation.</returns> private async Task <OperationResult> ProcessOneAccount(MediaAccount mediaAccount, bool limitFullSync) { var sw = System.Diagnostics.Stopwatch.StartNew(); var errors = new List <string>(); if (mediaAccount.GetMediaAccountComponent() == null) { return(new OperationResult($"Skipped account {mediaAccount.Name}.", new[] { $"{mediaAccount.Name}: Media Account component was not found." })); } // Determine if this is a full sync or a partial refresh. var currentDateTime = RockDateTime.Now; var lastFullSync = mediaAccount.LastRefreshDateTime; var haveSyncedToday = lastFullSync.HasValue && lastFullSync.Value.Date == currentDateTime.Date; var refreshOnly = limitFullSync && haveSyncedToday; if (refreshOnly) { // Quick refresh media and folders only. var result = await MediaAccountService.RefreshMediaInAccountAsync(mediaAccount.Id); errors.AddRange(result.Errors); } else { // First sync all the media and folders. var result = await MediaAccountService.SyncMediaInAccountAsync(mediaAccount.Id); errors.AddRange(result.Errors); // Next sync all the analytics. result = await MediaAccountService.SyncAnalyticsInAccountAsync(mediaAccount.Id); errors.AddRange(result.Errors); } sw.Stop(); var seconds = ( int )sw.Elapsed.TotalSeconds; var message = $"{( refreshOnly ? "Refreshed" : "Synchronized" )} account {mediaAccount.Name} in {seconds}s."; // Since we will be aggregating errors include the // account name if there were any errors. return(new OperationResult(message, errors.Select(a => $"{mediaAccount.Name}: {a}"))); }