本文整理汇总了C#中ActionableProgress类的典型用法代码示例。如果您正苦于以下问题:C# ActionableProgress类的具体用法?C# ActionableProgress怎么用?C# ActionableProgress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ActionableProgress类属于命名空间,在下文中一共展示了ActionableProgress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
{
var users = _userManager.Users
.DistinctBy(ChannelDownloadScheduledTask.GetUserDistinctValue)
.Select(i => i.Id.ToString("N"))
.ToList();
var numComplete = 0;
foreach (var user in users)
{
double percentPerUser = 1;
percentPerUser /= users.Count;
var startingPercent = numComplete * percentPerUser * 100;
var innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(p => progress.Report(startingPercent + (percentPerUser * p)));
await DownloadContent(user, cancellationToken, innerProgress).ConfigureAwait(false);
numComplete++;
double percent = numComplete;
percent /= users.Count;
progress.Report(percent * 100);
}
progress.Report(100);
}
示例2: Execute
public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
{
CleanChannelContent(cancellationToken);
var users = _userManager.Users.Select(i => i.Id.ToString("N")).ToList();
var numComplete = 0;
foreach (var user in users)
{
double percentPerUser = 1;
percentPerUser /= users.Count;
var startingPercent = numComplete * percentPerUser * 100;
var innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(p => progress.Report(startingPercent + (.8 * p)));
await DownloadContent(user, cancellationToken, innerProgress).ConfigureAwait(false);
numComplete++;
double percent = numComplete;
percent /= users.Count;
progress.Report(percent * 100);
}
progress.Report(100);
}
示例3: Sync
public async Task Sync(IServerSyncProvider provider,
ISyncDataProvider dataProvider,
SyncTarget target,
IProgress<double> progress,
CancellationToken cancellationToken)
{
var serverId = _appHost.SystemId;
var serverName = _appHost.FriendlyName;
await SyncData(provider, dataProvider, serverId, target, cancellationToken).ConfigureAwait(false);
progress.Report(3);
var innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(pct =>
{
var totalProgress = pct * .97;
totalProgress += 1;
progress.Report(totalProgress);
});
await GetNewMedia(provider, dataProvider, target, serverId, serverName, innerProgress, cancellationToken);
// Do the data sync twice so the server knows what was removed from the device
await SyncData(provider, dataProvider, serverId, target, cancellationToken).ConfigureAwait(false);
progress.Report(100);
}
示例4: GetFFMpegInfo
public async Task<FFMpegInfo> GetFFMpegInfo(IProgress<double> progress)
{
var versionedDirectoryPath = Path.Combine(GetMediaToolsPath(true), FFMpegDownloadInfo.Version);
var info = new FFMpegInfo
{
ProbePath = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFProbeFilename),
Path = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFMpegFilename),
Version = FFMpegDownloadInfo.Version
};
Directory.CreateDirectory(versionedDirectoryPath);
var tasks = new List<Task>();
double ffmpegPercent = 0;
double fontPercent = 0;
var syncLock = new object();
if (!File.Exists(info.ProbePath) || !File.Exists(info.Path))
{
var ffmpegProgress = new ActionableProgress<double>();
ffmpegProgress.RegisterAction(p =>
{
ffmpegPercent = p;
lock (syncLock)
{
progress.Report((ffmpegPercent / 2) + (fontPercent / 2));
}
});
tasks.Add(DownloadFFMpeg(info, ffmpegProgress));
}
else
{
ffmpegPercent = 100;
progress.Report(50);
}
var fontProgress = new ActionableProgress<double>();
fontProgress.RegisterAction(p =>
{
fontPercent = p;
lock (syncLock)
{
progress.Report((ffmpegPercent / 2) + (fontPercent / 2));
}
});
tasks.Add(DownloadFonts(versionedDirectoryPath, fontProgress));
await Task.WhenAll(tasks).ConfigureAwait(false);
return info;
}
示例5: Run
/// <summary>
/// Runs the specified progress.
/// </summary>
/// <param name="progress">The progress.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
{
var allItems = _libraryManager.RootFolder.GetRecursiveChildren();
var allSongs = allItems.OfType<Audio>().ToList();
var innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(pct => progress.Report(pct * .8));
var allArtists = await GetAllArtists(allSongs, cancellationToken, innerProgress).ConfigureAwait(false);
progress.Report(80);
var numComplete = 0;
var userLibraries = _userManager.Users
.Select(i => new Tuple<Guid, List<IHasArtist>>(i.Id, i.RootFolder.GetRecursiveChildren(i).OfType<IHasArtist>().ToList()))
.ToList();
var numArtists = allArtists.Count;
foreach (var artist in allArtists)
{
cancellationToken.ThrowIfCancellationRequested();
// Only do this for artists accessed by name. Folder-based artists use ArtistInfoFromSongsProvider
if (artist.IsAccessedByName && !artist.LockedFields.Contains(MetadataFields.Genres))
{
// Avoid implicitly captured closure
var artist1 = artist;
artist.Genres = allSongs.Where(i => i.HasArtist(artist1.Name))
.SelectMany(i => i.Genres)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
}
// Populate counts of items
//SetItemCounts(artist, null, allItems.OfType<IHasArtist>());
foreach (var lib in userLibraries)
{
SetItemCounts(artist, lib.Item1, lib.Item2);
}
numComplete++;
double percent = numComplete;
percent /= numArtists;
percent *= 20;
progress.Report(80 + percent);
}
progress.Report(100);
}
示例6: Run
/// <summary>
/// Runs the specified progress.
/// </summary>
/// <param name="progress">The progress.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
{
var allItems = _libraryManager.RootFolder.RecursiveChildren.ToList();
var allArtists = await GetAllArtists(allItems).ConfigureAwait(false);
progress.Report(10);
var allMusicArtists = allItems.OfType<MusicArtist>().ToList();
var allSongs = allItems.OfType<Audio>().ToList();
var numComplete = 0;
foreach (var artist in allArtists)
{
var musicArtist = FindMusicArtist(artist, allMusicArtists);
if (musicArtist != null)
{
artist.Images = new Dictionary<ImageType, string>(musicArtist.Images);
artist.BackdropImagePaths = musicArtist.BackdropImagePaths.ToList();
artist.ScreenshotImagePaths = musicArtist.ScreenshotImagePaths.ToList();
artist.SetProviderId(MetadataProviders.Musicbrainz, musicArtist.GetProviderId(MetadataProviders.Musicbrainz));
artist.Genres = musicArtist.Genres.ToList();
}
else
{
// Avoid implicitly captured closure
var artist1 = artist;
artist.Genres = allSongs.Where(i => i.HasArtist(artist1.Name))
.SelectMany(i => i.Genres)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
}
numComplete++;
double percent = numComplete;
percent /= allArtists.Length;
percent *= 5;
progress.Report(10 + percent);
}
var innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(pct => progress.Report(15 + pct * .85));
await _libraryManager.ValidateArtists(cancellationToken, innerProgress).ConfigureAwait(false);
}
示例7: DownloadContent
private async Task DownloadContent(string user, CancellationToken cancellationToken, IProgress<double> progress)
{
var channels = await _channelManager.GetChannelsInternal(new ChannelQuery
{
UserId = user
}, cancellationToken);
var numComplete = 0;
var numItems = channels.Items.Length;
foreach (var channel in channels.Items)
{
var channelId = channel.Id.ToString("N");
var features = _channelManager.GetChannelFeatures(channelId);
const int currentRefreshLevel = 1;
var maxRefreshLevel = features.AutoRefreshLevels ?? 0;
if (maxRefreshLevel > 0)
{
var innerProgress = new ActionableProgress<double>();
var startingNumberComplete = numComplete;
innerProgress.RegisterAction(p =>
{
double innerPercent = startingNumberComplete;
innerPercent += (p / 100);
innerPercent /= numItems;
progress.Report(innerPercent * 100);
});
try
{
await GetAllItems(user, channelId, null, currentRefreshLevel, maxRefreshLevel, innerProgress, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.ErrorException("Error getting channel content", ex);
}
}
numComplete++;
double percent = numComplete;
percent /= numItems;
progress.Report(percent * 100);
}
progress.Report(100);
}
示例8: Execute
public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
{
var innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(p => progress.Report(.95 * p));
await UpdateToLatestSchema(cancellationToken, innerProgress).ConfigureAwait(false);
innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(p => progress.Report(95 + (.05 * p)));
//await CleanDeadItems(cancellationToken, innerProgress).ConfigureAwait(false);
progress.Report(100);
}
示例9: ValidatePeople
/// <summary>
/// Validates the people.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param>
/// <returns>Task.</returns>
public async Task ValidatePeople(CancellationToken cancellationToken, IProgress<double> progress)
{
var innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(pct => progress.Report(pct * .15));
// Run prescan tasks
await RunPrescanTasks(innerProgress, cancellationToken).ConfigureAwait(false);
progress.Report(15);
var people = _libraryManager.RootFolder.GetRecursiveChildren()
.SelectMany(c => c.People)
.DistinctBy(p => p.Name, StringComparer.OrdinalIgnoreCase)
.ToList();
var numComplete = 0;
foreach (var person in people)
{
cancellationToken.ThrowIfCancellationRequested();
try
{
var item = _libraryManager.GetPerson(person.Name);
await item.RefreshMetadata(cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.ErrorException("Error validating IBN entry {0}", ex, person.Name);
}
// Update progress
numComplete++;
double percent = numComplete;
percent /= people.Count;
progress.Report(15 + 85 * percent);
}
progress.Report(100);
_logger.Info("People validation complete");
// Bad practice, i know. But we keep a lot in memory, unfortunately.
GC.Collect(2, GCCollectionMode.Forced, true);
GC.Collect(2, GCCollectionMode.Forced, true);
}
示例10: Run
/// <summary>
/// Runs the specified progress.
/// </summary>
/// <param name="progress">The progress.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
{
var allItems = _libraryManager.RootFolder.GetRecursiveChildren();
var allSongs = allItems.OfType<Audio>().ToList();
var innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(pct => progress.Report(pct * .8));
var allArtists = await GetAllArtists(allSongs, cancellationToken, innerProgress).ConfigureAwait(false);
progress.Report(80);
var numComplete = 0;
var numArtists = allArtists.Count;
foreach (var artist in allArtists)
{
cancellationToken.ThrowIfCancellationRequested();
// Only do this for artists accessed by name. Folder-based artists get it from the normal refresh
if (artist.IsAccessedByName && !artist.LockedFields.Contains(MetadataFields.Genres))
{
// Avoid implicitly captured closure
var artist1 = artist;
artist.Genres = allSongs.Where(i => i.HasArtist(artist1.Name))
.SelectMany(i => i.Genres)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
}
numComplete++;
double percent = numComplete;
percent /= numArtists;
percent *= 20;
progress.Report(80 + percent);
}
progress.Report(100);
}
示例11: Run
/// <summary>
/// Runs the specified progress.
/// </summary>
/// <param name="progress">The progress.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
{
if (!_config.Configuration.EnableInternetProviders && !_config.Configuration.EnableTmdbUpdates)
{
progress.Report(100);
return;
}
var innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(pct => progress.Report(pct * .8));
await Run(innerProgress, false, cancellationToken).ConfigureAwait(false);
progress.Report(80);
//innerProgress = new ActionableProgress<double>();
//innerProgress.RegisterAction(pct => progress.Report(80 + pct * .2));
//await Run(innerProgress, true, cancellationToken).ConfigureAwait(false);
progress.Report(100);
}
示例12: Sync
public async Task Sync(IEnumerable<IServerSyncProvider> providers, IProgress<double> progress, CancellationToken cancellationToken)
{
var targets = providers
.SelectMany(i => i.GetAllSyncTargets().Select(t => new Tuple<IServerSyncProvider, SyncTarget>(i, t)))
.ToList();
var numComplete = 0;
double startingPercent = 0;
double percentPerItem = 1;
if (targets.Count > 0)
{
percentPerItem /= targets.Count;
}
foreach (var target in targets)
{
cancellationToken.ThrowIfCancellationRequested();
var currentPercent = startingPercent;
var innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(pct =>
{
var totalProgress = pct * percentPerItem;
totalProgress += currentPercent;
progress.Report(totalProgress);
});
var dataProvider = _syncManager.GetDataProvider(target.Item1, target.Item2);
await new MediaSync(_logger, _syncManager, _appHost, _fileSystem, _config)
.Sync(target.Item1, dataProvider, target.Item2, innerProgress, cancellationToken)
.ConfigureAwait(false);
numComplete++;
startingPercent = numComplete;
startingPercent /= targets.Count;
startingPercent *= 100;
progress.Report(startingPercent);
}
}
示例13: Run
/// <summary>
/// Runs the specified progress.
/// </summary>
/// <param name="progress">The progress.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
{
var allItems = _libraryManager.RootFolder.RecursiveChildren.ToList();
var allArtists = await GetAllArtists(allItems).ConfigureAwait(false);
progress.Report(10);
var allMusicArtists = allItems.OfType<MusicArtist>().ToList();
var numComplete = 0;
foreach (var artist in allArtists)
{
var musicArtist = FindMusicArtist(artist, allMusicArtists);
if (musicArtist != null)
{
artist.Images = new Dictionary<ImageType, string>(musicArtist.Images);
artist.BackdropImagePaths = musicArtist.BackdropImagePaths.ToList();
artist.ScreenshotImagePaths = musicArtist.ScreenshotImagePaths.ToList();
artist.SetProviderId(MetadataProviders.Musicbrainz, musicArtist.GetProviderId(MetadataProviders.Musicbrainz));
}
numComplete++;
double percent = numComplete;
percent /= allArtists.Length;
percent *= 5;
progress.Report(10 + percent);
}
var innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(pct => progress.Report(15 + pct * .85));
await _libraryManager.ValidateArtists(cancellationToken, innerProgress).ConfigureAwait(false);
}
示例14: RefreshMetadataRecursive
private async Task RefreshMetadataRecursive(MetadataRefreshOptions refreshOptions, bool recursive, IProgress<double> progress, CancellationToken cancellationToken)
{
var children = ActualChildren.ToList();
var percentages = new Dictionary<Guid, double>(children.Count);
var numComplete = 0;
var count = children.Count;
foreach (var child in children)
{
cancellationToken.ThrowIfCancellationRequested();
if (child.IsFolder)
{
var innerProgress = new ActionableProgress<double>();
// Avoid implicitly captured closure
var currentChild = child;
innerProgress.RegisterAction(p =>
{
lock (percentages)
{
percentages[currentChild.Id] = p / 100;
var innerPercent = percentages.Values.Sum();
innerPercent /= count;
innerPercent *= 100;
progress.Report(innerPercent);
}
});
await RefreshChildMetadata(child, refreshOptions, recursive, innerProgress, cancellationToken)
.ConfigureAwait(false);
}
else
{
await RefreshChildMetadata(child, refreshOptions, false, new Progress<double>(), cancellationToken)
.ConfigureAwait(false);
}
numComplete++;
double percent = numComplete;
percent /= count;
percent *= 100;
progress.Report(percent);
}
progress.Report(100);
}
示例15: DownloadContent
private async Task DownloadContent(string user,
CancellationToken cancellationToken,
IProgress<double> progress)
{
var innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(p => progress.Report(0 + (.8 * p)));
await DownloadAllChannelContent(user, cancellationToken, innerProgress).ConfigureAwait(false);
progress.Report(80);
innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(p => progress.Report(80 + (.2 * p)));
await DownloadLatestChannelContent(user, cancellationToken, progress).ConfigureAwait(false);
progress.Report(100);
}