当前位置: 首页>>代码示例>>C#>>正文


C# IProgressReporter类代码示例

本文整理汇总了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;
        }
开发者ID:SLaks,项目名称:Progression,代码行数:31,代码来源:ProgressOperations.cs

示例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();
            }
        }
开发者ID:SyedArifulIslamEmon,项目名称:Billing,代码行数:60,代码来源:StatementGenerator.cs

示例3: ShowProgress

 public void ShowProgress(string title, IProgressReporter progressReporter)
 {
     var progressNotification = new ProgressNotification(title, progressReporter);
     progressNotification.Close += MessageNotification_Close;
     Notifications.Add(progressNotification);
     IsVisible = true;
 }
开发者ID:caesay,项目名称:Hurricane,代码行数:7,代码来源:NotificationManager.cs

示例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);
            }
        }
开发者ID:SLaks,项目名称:Progression,代码行数:41,代码来源:ProgressOperations.cs

示例5: QueueListener

 public QueueListener(IQueueListenerConfiguration config, IQueue queue, IScenarioRunner scenarioRunner, IProgressReporter progressReporter, ITimeProvider timeProvider)
 {
     _config = config;
     _queue = queue;
     _scenarioRunner = scenarioRunner;
     _progressReporter = progressReporter;
     _timeProvider = timeProvider;
 }
开发者ID:AcklenAvenue,项目名称:Pepino,代码行数:8,代码来源:QueueListener.cs

示例6: ComputeDependencies

        public static ReflectionMetadataDependencyInfo ComputeDependencies(IEnumerable<IAssemblyFile> inputAssemblies, IDependencyFilter assemblyFilter, IProgressReporter progressReport)
        {
            var engine = new ReflectionMetadataDependencyInfo(inputAssemblies, assemblyFilter);

            engine.FindDependencies(progressReport);

            return engine;
        }
开发者ID:MetSystem,项目名称:dotnet-apiport,代码行数:8,代码来源:ReflectionMetadataDependencyInfo.cs

示例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;
        }
开发者ID:Amichai,项目名称:Prax,代码行数:9,代码来源:ReferenceSearcher+.cs

示例8: DefaultScenarioRunner

 public DefaultScenarioRunner(IExecutionContextFactory executionContextFactory, ICriterionRunner criterionRunner,
     IProgressReporter progressReporter, IScenarioContextFactory scenarioContextFactory, ILogger logger)
 {
     _executionContextFactory = executionContextFactory;
     _criterionRunner = criterionRunner;
     _progressReporter = progressReporter;
     _scenarioContextFactory = scenarioContextFactory;
     _logger = logger;
 }
开发者ID:AcklenAvenue,项目名称:Pepino,代码行数:9,代码来源:DefaultScenarioRunner.cs

示例9: ProgressNotification

        public ProgressNotification(string title, IProgressReporter progressReporter)
        {
            Title = title;

            _progressReporter = progressReporter;
            progressReporter.ProgressMessageChanged += ProgressReporter_ProgressMessageChanged;
            progressReporter.ProgressChanged += ProgressReporter_ProgressChanged;
            progressReporter.Finished += ProgressReporter_Finished;
        }
开发者ID:caesay,项目名称:Hurricane,代码行数:9,代码来源:ProgressNotification.cs

示例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;
 }
开发者ID:vivmishra,项目名称:dotnet-apiport,代码行数:9,代码来源:ApiPortClient.cs

示例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 };
 }
开发者ID:Dennis-Petrov,项目名称:Cash,代码行数:10,代码来源:TableUpdater.cs

示例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;
        }
开发者ID:AlexGhiondea,项目名称:dotnet-apiport,代码行数:11,代码来源:CciDependencyFinder.cs

示例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;
        }
开发者ID:ravindrapro,项目名称:dotnet-apiport,代码行数:11,代码来源:ReflectionMetadataDependencyFinder.cs

示例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);
            }
        }
开发者ID:MetSystem,项目名称:dotnet-apiport,代码行数:52,代码来源:ReflectionMetadataDependencyInfo.cs

示例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();
            }
        }
开发者ID:imtheman,项目名称:WurmAssistant3,代码行数:52,代码来源:IWurmAssistantService.cs


注:本文中的IProgressReporter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。