/// <summary>
        /// Shows the readonly details.
        /// </summary>
        /// <param name="mediaAccount">The media account.</param>
        private void ShowReadonlyDetails(MediaAccount mediaAccount)
        {
            SetEditMode(false);

            lActionTitle.Text     = mediaAccount.Name.FormatAsHtmlTitle();
            hlInactive.Visible    = !mediaAccount.IsActive;
            hlLastRefresh.Visible = mediaAccount.LastRefreshDateTime.HasValue;
            if (mediaAccount.LastRefreshDateTime.HasValue)
            {
                var refreshTimeSpan = RockDateTime.Now - mediaAccount.LastRefreshDateTime.Value;

                hlLastRefresh.Text = "Last Refreshed: " + refreshTimeSpan.Humanize();
            }

            var mediaAccountComponent = mediaAccount.GetMediaAccountComponent();
            var descriptionList       = new DescriptionList();

            if (mediaAccountComponent != null)
            {
                descriptionList.Add("Type", mediaAccountComponent.EntityType.FriendlyName);
            }

            lDescription.Text = descriptionList.Html;
            lMetricData.Text  = mediaAccountComponent?.GetAccountHtmlSummary(mediaAccount);
        }
Exemplo n.º 2
0
        /// <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}")));
        }