本文整理汇总了C#中IProgressReporter类的典型用法代码示例。如果您正苦于以下问题:C# IProgressReporter类的具体用法?C# IProgressReporter怎么用?C# IProgressReporter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IProgressReporter类属于命名空间,在下文中一共展示了IProgressReporter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComputeHash
///<summary>Calculates a cryptographic hashcode of a stream while reporting progress.</summary>
///<returns>The hash of the data, or null if the user clicked cancel.</returns>
public static byte[] ComputeHash(this HashAlgorithm hasher, Stream stream, IProgressReporter progress)
{
if (hasher == null) throw new ArgumentNullException("hasher");
if (stream == null) throw new ArgumentNullException("stream");
if (progress != null) {
try {
progress.Maximum = stream.Length;
} catch (NotSupportedException) { progress.Progress = null; }
}
progress = progress ?? new EmptyProgressReporter();
long totalCopied = 0;
var buffer = new byte[4096];
while (true) {
var bytesRead = stream.Read(buffer, 0, buffer.Length);
if (progress.Progress != null) progress.Progress = totalCopied;
if (progress.WasCanceled) return null;
totalCopied += bytesRead;
if (bytesRead == 0) break;
hasher.TransformBlock(buffer, 0, bytesRead, null, 0);
}
hasher.TransformFinalBlock(new byte[0], 0, 0);
var retVal = (byte[])hasher.Hash.Clone();
hasher.Initialize();
return retVal;
}
示例2: CreateBills
public static Document CreateBills(ICollection<WordStatementInfo> statements, IProgressReporter progress, bool duplexMode)
{
if (statements == null) throw new ArgumentNullException("statements");
progress = progress ?? new EmptyProgressReporter();
progress.Caption = "Creating document";
Dictionary<StatementKind, Range> sourceRanges = new Dictionary<StatementKind, Range>();
try {
foreach (var kind in statements.Select(s => s.Kind).Distinct()) {
var sd = Word.Documents.Open(
FileName: Path.Combine(WordExport.TemplateFolder, kind.ToString() + ".docx"),
ReadOnly: true,
AddToRecentFiles: false
);
// Fix Word 2013 bug
// http://blogs.msmvps.com/wordmeister/2013/02/22/word2013bug-not-available-for-reading/
sd.ActiveWindow.View.Type = WdViewType.wdPrintView;
sourceRanges.Add(kind, sd.Range());
}
Document doc = Word.Documents.Add();
doc.ShowGrammaticalErrors = doc.ShowSpellingErrors = false;
Range range = doc.Range();
bool firstPage = true;
using (new ClipboardScope()) {
var populator = new StatementPopulator();
progress.Maximum = statements.Count;
int i = 0;
foreach (var info in statements) {
if (progress.WasCanceled) return null;
progress.Progress = i;
progress.Caption = "Creating " + info.Kind.ToString().ToLower(Culture) + " for " + info.Person.VeryFullName;
if (firstPage)
firstPage = false;
else
range.BreakPage(forceOddPage: duplexMode);
sourceRanges[info.Kind].Copy();
range.Paste();
populator.Populate(range, info);
foreach (Shape shape in range.ShapeRange)
populator.Populate(shape.TextFrame.TextRange, info);
i++;
}
}
Word.Activate();
doc.Activate();
return doc;
} finally {
foreach (var sd in sourceRanges.Values) sd.Document.CloseDoc();
}
}
示例3: ShowProgress
public void ShowProgress(string title, IProgressReporter progressReporter)
{
var progressNotification = new ProgressNotification(title, progressReporter);
progressNotification.Close += MessageNotification_Close;
Notifications.Add(progressNotification);
IsVisible = true;
}
示例4: CopyTo
///<summary>Copies one stream to another while reporting progress.</summary>
///<param name="from">The stream to copy from. This stream must be readable.</param>
///<param name="to">The stream to copy to. This stream must be writable.</param>
///<param name="length">The length of the source stream. This parameter is only used to report progress.</param>
///<param name="progress">An IProgressReporter implementation to report the progress of the upload.</param>
///<returns>The number of bytes copied.</returns>
public static long CopyTo(this Stream from, Stream to, long? length, IProgressReporter progress)
{
if (from == null) throw new ArgumentNullException("from");
if (to == null) throw new ArgumentNullException("to");
if (!from.CanRead) throw new ArgumentException("Source stream must be readable", "from");
if (!to.CanWrite) throw new ArgumentException("Destination stream must be writable", "to");
if (progress != null) {
if (length == null) {
try {
length = from.Length;
} catch (NotSupportedException) { progress.Progress = null; }
}
if (length == null)
progress.Progress = null;
else
progress.Maximum = length.Value;
}
progress = progress ?? new EmptyProgressReporter();
long totalCopied = 0;
var buffer = new byte[4096];
while (true) {
var bytesRead = from.Read(buffer, 0, buffer.Length);
if (length != null) progress.Progress = totalCopied;
if (progress.WasCanceled) return -1;
totalCopied += bytesRead;
if (bytesRead == 0) return totalCopied;
to.Write(buffer, 0, bytesRead);
}
}
示例5: QueueListener
public QueueListener(IQueueListenerConfiguration config, IQueue queue, IScenarioRunner scenarioRunner, IProgressReporter progressReporter, ITimeProvider timeProvider)
{
_config = config;
_queue = queue;
_scenarioRunner = scenarioRunner;
_progressReporter = progressReporter;
_timeProvider = timeProvider;
}
示例6: ComputeDependencies
public static ReflectionMetadataDependencyInfo ComputeDependencies(IEnumerable<IAssemblyFile> inputAssemblies, IDependencyFilter assemblyFilter, IProgressReporter progressReport)
{
var engine = new ReflectionMetadataDependencyInfo(inputAssemblies, assemblyFilter);
engine.FindDependencies(progressReport);
return engine;
}
示例7: PerformLookup
///<summary>Finds the best matching labels for a given piece of heuristics.</summary>
public IEnumerable<RecognizedSegment> PerformLookup(HeuristicSet heuristics, IProgressReporter progress = null)
{
if (heuristics.Label != null)
throw new ArgumentException("PerformLookup expects an unidentified segment", "heuristics");
var results = GetMatchesIterator(heuristics, progress).OrderBy(i => i.Certainty);
return results;
}
示例8: DefaultScenarioRunner
public DefaultScenarioRunner(IExecutionContextFactory executionContextFactory, ICriterionRunner criterionRunner,
IProgressReporter progressReporter, IScenarioContextFactory scenarioContextFactory, ILogger logger)
{
_executionContextFactory = executionContextFactory;
_criterionRunner = criterionRunner;
_progressReporter = progressReporter;
_scenarioContextFactory = scenarioContextFactory;
_logger = logger;
}
示例9: ProgressNotification
public ProgressNotification(string title, IProgressReporter progressReporter)
{
Title = title;
_progressReporter = progressReporter;
progressReporter.ProgressMessageChanged += ProgressReporter_ProgressMessageChanged;
progressReporter.ProgressChanged += ProgressReporter_ProgressChanged;
progressReporter.Finished += ProgressReporter_Finished;
}
示例10: ApiPortClient
public ApiPortClient(IApiPortService apiPortService, IProgressReporter progressReport, ITargetMapper targetMapper, IDependencyFinder dependencyFinder, IReportGenerator reportGenerator, IEnumerable<IgnoreAssemblyInfo> assembliesToIgnore)
{
_apiPortService = apiPortService;
_progressReport = progressReport;
_targetMapper = targetMapper;
_dependencyFinder = dependencyFinder;
_reportGenerator = reportGenerator;
_assembliesToIgnore = assembliesToIgnore;
}
示例11: TableUpdater
private TableUpdater(Mode mode, ICashDataReader reader, IEventLink eventLink,
TableMapper mapper, IProgressReporter reporter)
{
_mode = mode;
_reader = reader;
_eventLink = eventLink;
_mapper = mapper;
_reporter = reporter;
_executor = new FbExecutor { Executor = Execute };
}
示例12: FilterValidFiles
private static bool FilterValidFiles(IAssemblyFile file, IProgressReporter _progressReport)
{
if (file.Exists)
{
return true;
}
_progressReport.ReportIssue(string.Format(LocalizedStrings.UnknownFile, file.Name));
return false;
}
示例13: FilterValidFiles
private static bool FilterValidFiles(FileInfo file, IProgressReporter _progressReporter)
{
if (file.Exists)
{
return true;
}
_progressReporter.ReportIssue(string.Format(LocalizedStrings.UnknownFile, file.FullName));
return false;
}
示例14: FindDependencies
private void FindDependencies(IProgressReporter progressReport)
{
_inputAssemblies.AsParallel().ForAll(file =>
{
try
{
foreach (var dependencies in GetDependencies(file))
{
var m = new MemberInfo
{
MemberDocId = dependencies.MemberDocId,
TypeDocId = dependencies.TypeDocId,
DefinedInAssemblyIdentity = dependencies.DefinedInAssemblyIdentity?.ToString()
};
if (m.DefinedInAssemblyIdentity == null && !dependencies.IsPrimitive)
{
throw new InvalidOperationException("All non-primitive types should be defined in an assembly");
}
// Add this memberinfo
var newassembly = new HashSet<AssemblyInfo> { dependencies.CallingAssembly };
var assemblies = _cachedDependencies.AddOrUpdate(m, newassembly, (key, existingSet) =>
{
lock (existingSet)
{
existingSet.Add(dependencies.CallingAssembly);
}
return existingSet;
});
}
}
catch (InvalidPEAssemblyException)
{
// This often indicates a non-PE file
_assembliesWithError.Add(file.Name);
}
catch (BadImageFormatException)
{
// This often indicates a PE file with invalid contents (either because the assembly is protected or corrupted)
_assembliesWithError.Add(file.Name);
}
});
// Clear out unresolved dependencies that were resolved during processing
ICollection<string> collection;
foreach (var assembly in _userAssemblies)
{
_unresolvedAssemblies.TryRemove(assembly.AssemblyIdentity, out collection);
}
}
示例15: GetPackageAsync
public async Task<IStagedPackage> GetPackageAsync(IProgressReporter progressReporter, Version version)
{
progressReporter.SetProgressPercent(0);
progressReporter.SetProgressStatus("Downloading package for version " + version);
var tempFile = stagingLocation.CreateTempFile();
try
{
using (var webclient = new ExtendedWebClient((int)DefaultTimeout.TotalMilliseconds))
{
var tcs = new TaskCompletionSource<bool>();
byte lastPercent = 0;
webclient.DownloadProgressChanged += (sender, args) =>
{
var percent = (byte)(((double)args.BytesReceived / (double)args.TotalBytesToReceive) * 100);
if (percent > lastPercent)
{
lastPercent = percent;
progressReporter.SetProgressPercent(percent);
progressReporter.SetProgressStatus(string.Format("Downloaded {0}/{1}",
args.BytesReceived,
args.TotalBytesToReceive));
}
};
webclient.DownloadFileCompleted += (sender, args) =>
{
if (args.Error != null)
{
progressReporter.SetProgressPercent(100);
progressReporter.SetProgressStatus("download error: " + args.Error.ToString());
tcs.SetException(new ServiceException("Download error", args.Error));
}
else
{
progressReporter.SetProgressStatus("download completed");
tcs.SetResult(true);
}
};
webclient.DownloadFileAsync(
new Uri(string.Format("{0}/Package/{1}", webServiceRootUrl, version.ToString().Replace(".", "-"))),
tempFile.FullName);
await tcs.Task;
return stagingLocation.CreatePackageFromSevenZipByteArray(File.ReadAllBytes(tempFile.FullName), version);
}
}
finally
{
tempFile.Delete();
}
}