本文整理汇总了C#中IProgress.Report方法的典型用法代码示例。如果您正苦于以下问题:C# IProgress.Report方法的具体用法?C# IProgress.Report怎么用?C# IProgress.Report使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IProgress
的用法示例。
在下文中一共展示了IProgress.Report方法的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: Run
public async Task Run(IProgress<string> progressOutput, IProgress<string> progressError, IDeploymentAppSettings settings)
{
var processInfo = CreateProcessStartInfo(settings);
await Task.Factory.StartNew(() =>
{
try
{
using (var process = Process.Start(processInfo))
{
if (process == null)
return;
using (var taskReadOutput = Task.Factory.StartNew(state => ReadFromStreamAsync(state, progressOutput), process.StandardOutput))
using (var taskReadError = Task.Factory.StartNew(state => ReadFromStreamAsync(state, progressError), process.StandardError))
{
process.WaitForExit();
Task.WaitAll(new Task[] { taskReadOutput, taskReadError }, 10000);
progressOutput.Report(Environment.NewLine + "Deployer exited : " + DeployerResolution(process.ExitCode));
if(string.IsNullOrWhiteSpace(LogExchange.LogFilePath))
progressOutput.Report("Check log for information.");
else
progressOutput.Report("Check log file at link:[" + LogExchange.LogFilePath + ']');
}
}
}
catch (Exception ex)
{
progressError.Report("Error: " + ex.Message);
}
});
}
示例3: ReadLineAsync
public async Task ReadLineAsync(IProgress<BufferedTextFileReaderArgs> progress = null)
{
Debug.WriteLine("Begin ReadFileAsync: " + Thread.CurrentThread.ManagedThreadId);
var line = "";
var count = 0;
var sb = new StringBuilder();
while ((line = await sr.ReadLineAsync().ConfigureAwait(false)) != null)
{
Debug.WriteLine("After Await ReadFileAsync: " + Thread.CurrentThread.ManagedThreadId);
var l = line;
sb.AppendLine(l);
var lineNo = count++;
if (_processor != null)
{
_processor.ProcessLine(new BufferedTextFileReaderArgs(l, lineNo, false, 0));
}
if (progress != null && sb.Length > 0)
{
progress.Report(new BufferedTextFileReaderArgs(sb.ToString(), lineNo, false, lineNo));
sb.Clear();
}
}
if (_processor != null)
{
_processor.EndTransmission();
}
if (progress != null)
{
progress.Report(new BufferedTextFileReaderArgs(sb.ToString(), -1, true, 100));
}
}
示例4: Generate
public override Chunk Generate(IProgress<string> progress, int chunkX, int chunkY)
{
Reseed(chunkX, chunkY);
progress.Report("Generating chunk.");
var chunk = new Chunk(Width, Height);
var random = new Random();
for (var y = 0; y < chunk.Height; y++)
{
for (var x = 0; x < chunk.Width; x++)
{
if (random.Next(4) == 1)
{
chunk[ChunkLayer.Floor, x, y] = _waterId;
}
else
{
chunk[ChunkLayer.Floor, x, y] = _grassId;
}
}
}
progress.Report("Done generating chunk.");
return chunk;
}
示例5: 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);
}
示例6: Sync
public async Task Sync(IApiClient apiClient,
ServerInfo serverInfo,
IProgress<double> progress,
CancellationToken cancellationToken = default(CancellationToken))
{
_logger.Debug("Beginning media sync process with server Id: {0}", serverInfo.Id);
// First report actions to the server that occurred while offline
await ReportOfflineActions(apiClient, serverInfo, cancellationToken).ConfigureAwait(false);
progress.Report(1);
await SyncData(apiClient, serverInfo, false, cancellationToken).ConfigureAwait(false);
progress.Report(3);
var innerProgress = new DoubleProgress();
innerProgress.RegisterAction(pct =>
{
var totalProgress = pct * .97;
totalProgress += 1;
progress.Report(totalProgress);
});
await GetNewMedia(apiClient, serverInfo, innerProgress, cancellationToken);
progress.Report(100);
// Do the data sync twice so the server knows what was removed from the device
await SyncData(apiClient, serverInfo, true, cancellationToken).ConfigureAwait(false);
}
示例7: Run
public Task Run(IProgress<double> progress, CancellationToken cancellationToken)
{
var items = _libraryManager.RootFolder.RecursiveChildren.ToList();
var boxsets = items.OfType<BoxSet>().ToList();
var numComplete = 0;
foreach (var boxset in boxsets)
{
foreach (var child in boxset.Children.Concat(boxset.GetLinkedChildren()).OfType<ISupportsBoxSetGrouping>())
{
var boxsetIdList = child.BoxSetIdList.ToList();
if (!boxsetIdList.Contains(boxset.Id))
{
boxsetIdList.Add(boxset.Id);
}
child.BoxSetIdList = boxsetIdList;
}
numComplete++;
double percent = numComplete;
percent /= boxsets.Count;
progress.Report(percent * 100);
}
progress.Report(100);
return Task.FromResult(true);
}
示例8: Export
private readonly Encoding encode = Encoding.GetEncoding("UTF-8"); //gb18030
public async Task Export(string fileName, List<Article> urls, IBlogProcess process
, IProgress<DownloadStringTaskAsyncExProgress> progress)
{
await Init(fileName,progress);
articlesList.Clear();
articlesList.AddRange(urls);
if (articlesList.Any())
{
await Build1(process, progress);
}
if (progress != null)
{
progress.Report(new DownloadStringTaskAsyncExProgress
{
ProgressPercentage = 0.5f,
Text = "正在编译。。。"
});
}
BuildTable();
Compile();
if (progress != null)
{
progress.Report(new DownloadStringTaskAsyncExProgress
{
ProgressPercentage = 1f,
Text = "成功导出"
});
}
}
示例9: 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);
}
示例10: FindPaths
private Tuple<List<string>, List<IAnalyzer>> FindPaths(IProgress<Tuple<string, int>> callback)
{
var allPaths = new List<string>();
var usedAnalyzers = new List<IAnalyzer>();
var progress = 0;
var updateAmount = 50/analyzers.Count;
foreach (var analyzer in analyzers)
{
progress += updateAmount;
try
{
IEnumerable<string> paths = null;
if (analyzer.CheckExists())
{
paths = analyzer.FindPaths();
}
if (paths == null || paths.Count() == 0)
{
callback.Report(Tuple.Create(string.Format("No paths for {0}", analyzer.GetType().Name),
progress));
continue;
}
allPaths.AddRange(paths);
usedAnalyzers.Add(analyzer);
callback.Report(Tuple.Create(string.Format("Found paths for {0}", analyzer.GetType().Name), progress));
}
catch (Exception e)
{
callback.Report(Tuple.Create(FormatError(analyzer, e), progress));
Console.WriteLine(e.Message);
}
}
return Tuple.Create(allPaths, usedAnalyzers);
}
示例11: GetRevisionLogAsync
public override Task<RevisionLog> GetRevisionLogAsync(LogOptions options, IProgress<OperationProgress> progress, CancellationToken cancellationToken)
{
Verify.Argument.IsNotNull(options, "options");
if(Repository.IsEmpty)
{
return TaskUtility.TaskFromResult(new RevisionLog(Repository, new Revision[0]));
}
else
{
if(progress != null)
{
progress.Report(new OperationProgress(Resources.StrsFetchingLog.AddEllipsis()));
}
var parameters = options.GetLogParameters();
return Repository.Accessor
.QueryRevisions.InvokeAsync(parameters, progress, cancellationToken)
.ContinueWith(
t =>
{
if(progress != null)
{
progress.Report(OperationProgress.Completed);
}
var revisionData = TaskUtility.UnwrapResult(t);
var revisions = Repository.Revisions.Resolve(revisionData);
var revisionLog = new RevisionLog(Repository, revisions);
return revisionLog;
},
cancellationToken,
TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default);
}
}
示例12: RefreshAllMetadata
public async Task RefreshAllMetadata(MetadataRefreshOptions refreshOptions, IProgress<double> progress, CancellationToken cancellationToken)
{
var items = GetRecursiveChildren().ToList();
var totalItems = items.Count;
var numComplete = 0;
// Refresh songs
foreach (var item in items)
{
cancellationToken.ThrowIfCancellationRequested();
await item.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
numComplete++;
double percent = numComplete;
percent /= totalItems;
progress.Report(percent * 100);
}
// Refresh current item
await RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
progress.Report(100);
}
示例13: FindShortestRouteBetween
public override List<Link> FindShortestRouteBetween(string fromCity, string toCity,
TransportModes mode, IProgress<string> reportProgress)
{
NotifyObservers(fromCity, toCity, mode);
List<City> citiesBetween = FindCitiesBetween(fromCity, toCity);
if (citiesBetween == null || citiesBetween.Count < 1 ||
routes == null || routes.Count < 1)
return null;
if (reportProgress != null) reportProgress.Report("FindCitiesBetween done");
City source = citiesBetween[0];
City target = citiesBetween[citiesBetween.Count - 1];
Dictionary<City, double> dist;
Dictionary<City, City> previous;
List<City> cityNodes = FillListOfNodes(citiesBetween, out dist, out previous);
dist[source] = 0.0;
if (reportProgress != null) reportProgress.Report("FillListOfNodes done");
// the actual algorithm
previous = SearchShortestPath(mode, cityNodes, dist, previous);
if (reportProgress != null) reportProgress.Report("SearchShortestPath done");
// create a list with all cities on the route
List<City> citiesOnRoute = GetCitiesOnRoute(source, target, previous);
if (reportProgress != null) reportProgress.Report("GetCitiesOnRoute done");
// prepare final list if links
List<Link> itinerary = FindPath(citiesOnRoute, mode);
if (reportProgress != null) reportProgress.Report("FindPath done");
return itinerary;
}
示例14: Execute
/// <summary>
/// Returns the task to be executed
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param>
/// <returns>Task.</returns>
public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
{
return Task.Run(() =>
{
// Delete log files more than n days old
var minDateModified = DateTime.UtcNow.AddDays(-(ConfigurationManager.CommonConfiguration.LogFileRetentionDays));
var filesToDelete = new DirectoryInfo(ConfigurationManager.CommonApplicationPaths.LogDirectoryPath).EnumerateFileSystemInfos("*", SearchOption.AllDirectories)
.Where(f => f.LastWriteTimeUtc < minDateModified)
.ToList();
var index = 0;
foreach (var file in filesToDelete)
{
double percent = index;
percent /= filesToDelete.Count;
progress.Report(100 * percent);
cancellationToken.ThrowIfCancellationRequested();
File.Delete(file.FullName);
index++;
}
progress.Report(100);
});
}
示例15: Run
public void Run(IProgress<BuddhabrotReportProgress> progress = null)
{
_stopwatch.Start();
long previousTotalHits = 0;
do
{
MakeOneOrbit();
if ((TotalHits - previousTotalHits * 1d) / HitsMax > 1 / 100d)
{
previousTotalHits = TotalHits;
if (progress != null)
{
progress.Report(new BuddhabrotReportProgress(this, _stopwatch.Elapsed));
}
}
}
while (TotalHits < HitsMax);
Completed = true;
if (progress != null)
{
progress.Report(new BuddhabrotReportProgress(this, _stopwatch.Elapsed, true));
}
}