public Task PopulateStateAsync( PackageQueryContext context, PackageConsistencyState state, IProgressReporter progressReporter) { return(Task.CompletedTask); }
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(); } }
public PythonAnalyzerSession(IServiceManager services, IProgressReporter progress, AsyncManualResetEvent analysisCompleteEvent, Action <Task> startNextSession, CancellationToken analyzerCancellationToken, IDependencyChainWalker <AnalysisModuleKey, PythonAnalyzerEntry> walker, int version, PythonAnalyzerEntry entry) { _services = services; _analysisCompleteEvent = analysisCompleteEvent; _startNextSession = startNextSession; _analyzerCancellationToken = analyzerCancellationToken; Version = version; AffectedEntriesCount = walker?.AffectedValues.Count ?? 1; _walker = walker; _entry = entry; _state = State.NotStarted; _diagnosticsService = _services.GetService <IDiagnosticsService>(); _analyzer = _services.GetService <IPythonAnalyzer>(); _log = _services.GetService <ILogger>(); _telemetry = _services.GetService <ITelemetryService>(); _progress = progress; }
public static Task <PreparedFolder> Load(string rootPath, IProgressReporter reporter) { if (string.IsNullOrEmpty(rootPath)) { throw new ArgumentNullException("rootPath"); } if (!Directory.Exists(rootPath)) { throw new DirectoryNotFoundException(rootPath); } return(Task.Factory.StartNew(() => { var reader = new PreparedRootFolderReader(); bool report = reporter != null; if (report) { reporter.Start("read prepared folders"); reader.ProgressChanged += (_, e) => { reporter.Report(e.Percent, e.Status); }; } var root = reader.Read(rootPath); if (report) { reporter.Complete("prepared folders loaded"); } return root; })); }
/// <summary> /// Saves the underlying project. /// </summary> /// <param name = "reporter">The progress reporter to use for logging</param> public override void Save(IProgressReporter reporter) { if (Project != null) { Project.Save(reporter); } }
/// <summary> /// Saves the solution file. /// </summary> /// <param name = "reporter">The progress reporter to use for logging.</param> public override void Save(IProgressReporter reporter) { reporter.ProgressVisible = true; for (int i = 0; i < Nodes.Count; i++) { reporter.Report("Saving {0}.", Nodes[i].Name); Nodes[i].Save(reporter); //progressReporter.ProgressPercentage = (int)(((double)Nodes.Count / (double)i) * 100); } reporter.Report("Writing solution file."); using (var writer = new StreamWriter(FilePath.FullPath)) { using (var solutionWriter = new SolutionWriter(writer)) { solutionWriter.WriteSolution(this); } } reporter.Report("Writing solution settings."); Settings.Save(FilePath.ChangeExtension(".litesettings").FullPath); reporter.Report("Finished saving solution."); reporter.ProgressVisible = false; HasUnsavedData = false; }
public void WriteDataPacket(IDataPacket dataPacket, IProgressReporter progressReporter, ref long handledBytes, long totalBytes) { // TODO: refactor to use ProgressDataReader using (IDataReader dataReader = new FragmentedDataReader(dataPacket, _dataReaderPool)) { // Write data fragment while (dataReader.State == DataReaderState.Ready) { long bytesRemaining = (dataReader.Length - dataReader.Position); int bytesRead = dataReader.Read(_buffer, 0, (int)Math.Min(_buffer.Length, bytesRemaining)); dataReader.Position += bytesRead; _outputStream.Write(_buffer, 0, bytesRead); _bytesWritten += bytesRead; if (progressReporter != null) { handledBytes += bytesRead; if (progressReporter.CancellationPending) { return; } progressReporter.ReportProgress(totalBytes == 0 ? 0 : (int)((handledBytes * 100) / totalBytes)); } } } }
public SystemValidationsProcessor(IPowershellCommandRunner commandRunner, IList <ISystemValidation> validations, IList <IOutputWriter> outputWriters, IProgressReporter progressReporter) { this._commandRunner = commandRunner; this._validations = validations; this._outputWriters = outputWriters; this._progressReporter = progressReporter; }
public void ShowProgress(string title, IProgressReporter progressReporter) { var progressNotification = new ProgressNotification(title, progressReporter); progressNotification.Close += MessageNotification_Close; Notifications.Add(progressNotification); IsVisible = true; }
public void OnExecute_Should_Create_Generator( IConsoleOutput console, IAutoRestOptions options, IProcessLauncher processLauncher, IProgressReporter progressReporter, IAutoRestCodeGeneratorFactory factory, IOpenApiDocumentFactory documentFactory, string swaggerFile) { new AutoRestCommand( console, options, processLauncher, progressReporter, factory, documentFactory) { SwaggerFile = swaggerFile } .OnExecute(); Mock.Get(factory) .Verify( c => c.Create( swaggerFile, "GeneratedCode", options, processLauncher, documentFactory)); }
public PythonAnalyzerSession(IServiceContainer services, IProgressReporter progress, Action <Task> startNextSession, CancellationToken analyzerCancellationToken, IDependencyChainWalker <AnalysisModuleKey, PythonAnalyzerEntry> walker, int version, PythonAnalyzerEntry entry, bool forceGC = false) { _services = services; _startNextSession = startNextSession; _analyzerCancellationToken = analyzerCancellationToken; Version = version; AffectedEntriesCount = walker?.AffectedValues.Count ?? 1; _walker = walker; _entry = entry; _state = State.NotStarted; _forceGC = forceGC; _diagnosticsService = _services.GetService <IDiagnosticsService>(); _platformService = _services.GetService <IOSPlatform>(); _analyzer = _services.GetService <IPythonAnalyzer>(); _log = _services.GetService <ILogger>(); _moduleDatabaseService = _services.GetService <IModuleDatabaseService>(); _progress = progress; var interpreter = _services.GetService <IPythonInterpreter>(); _modulesPathResolver = interpreter.ModuleResolution.CurrentPathResolver; _typeshedPathResolver = interpreter.TypeshedResolution.CurrentPathResolver; }
public void OnExecuteAsync_Should_NotThrow( IConsoleOutput console, IAutoRestOptions options, IProcessLauncher processLauncher, IProgressReporter progressReporter, IAutoRestCodeGeneratorFactory factory, ICodeGenerator generator, IOpenApiDocumentFactory documentFactory, string outputFile, string code) { var sut = new AutoRestCommand( console, options, processLauncher, progressReporter, factory, documentFactory) { OutputFile = outputFile }; Mock.Get(generator).Setup(c => c.GenerateCode(progressReporter)).Returns(code); new Func <int>(sut.OnExecute).Should().NotThrow(); }
/// <summary>Disconnects from the current operation and calls its End() method</summary> /// <remarks> /// This unsubscribes the queue from the current operation's events, calls End() /// on the operation and, if the operation didn't have an exception to report, /// counts up the accumulated progress of th e queue. /// </remarks> private void endCurrentOperation() { Thread.MemoryBarrier(); OperationType operation = this.children[this.currentOperationIndex].Transaction; // Disconnect from the operation's events operation.AsyncEnded -= this.asyncOperationEndedDelegate; IProgressReporter progressReporter = operation as IProgressReporter; if (progressReporter != null) { progressReporter.AsyncProgressChanged -= this.asyncOperationProgressChangedDelegate; } try { operation.Join(); // Add the operations weight to the total amount of completed weight in the queue this.completedWeight += this.children[this.currentOperationIndex].Weight; // Trigger another progress update OnAsyncProgressChanged(this.completedWeight / this.totalWeight); } catch (Exception exception) { this.exception = exception; } }
/// <inheritdoc /> public override void Save(IProgressReporter reporter) { foreach (var node in Nodes) { node.Save(reporter); } }
// Compile() is called by a background Thread in ProgressForm so be carful void ICompilableHelp.Compile(IProgressReporter progressReporter) //Called by Progress form { try { HxComp hxsCompiler = new HxComp(); hxsCompiler.Initialize(); CompMsg compMsg = new CompMsg(progressReporter, this.logFile); compMsg.Log("Date: " + DateTime.Today.ToShortDateString() + ", " + DateTime.Today.ToShortTimeString()); compMsg.Log("Log file: " + logFile); compMsg.Log("Project file: " + projectFile); compMsg.Log(""); int cookie = hxsCompiler.AdviseCompilerMessageCallback(compMsg); // Compile // hxsCompiler.Compile(projectFile, hxsDir, outputFile, 0); hxsCompiler.UnadviseCompilerMessageCallback(cookie); //Done - Break link with compMsg Obj compMsg.SaveLog(); hxsCompiler = null; //Show the log file if errors if (compMsg.ErrorCount > 0) //If nore Warnings { SafeShowCompileError(); } } catch (Exception ex) { throw ex; } }
private static void VerifyFileHash(IProgressReporter progressReporter, IFile file, int bufferSize, IReadOnlyCollection <byte> expectedNcaHash, CancellationToken cancellationToken, out bool hashValid) { if (file.GetSize(out var fileSize) != Result.Success) { fileSize = 0; } var sha256 = SHA256.Create(); var ncaStream = file.AsStream(); var buffer = new byte[bufferSize]; decimal totalRead = 0; int read; while ((read = ncaStream.Read(buffer, 0, buffer.Length)) > 0) { cancellationToken.ThrowIfCancellationRequested(); sha256.TransformBlock(buffer, 0, read, null, 0); totalRead += read; progressReporter.SetPercentage(fileSize == 0 ? 0.0 : (double)(totalRead / fileSize)); } sha256.TransformFinalBlock(Array.Empty <byte>(), 0, 0); var currentNcaHash = sha256.Hash !; hashValid = IsHashEqual(currentNcaHash, expectedNcaHash); }
public Processor( IProgressReporter progress, JsonSerializer serialiser, IConfigurationRepository configRepository, IDataProcessor processor, IInputFactory inputFactory) { if (serialiser == null) { throw new ArgumentNullException(nameof(serialiser)); } if (progress == null) { throw new ArgumentNullException(nameof(progress)); } if (configRepository == null) { throw new ArgumentNullException(nameof(configRepository)); } if (processor == null) { throw new ArgumentNullException(nameof(processor)); } this.serialiser = serialiser; this.configRepository = configRepository; this.processor = processor; this.inputFactory = inputFactory; this.progress = progress; }
public IMaxTree <ElementType> BuildMaxTree(ElementType[] element_array, IComparer <ElementType> element_value_comparer, ITopologyElement topology, int real_element_count, IProgressReporter reporter) { this.d_element_array = element_array; this.element_value_comparer = element_value_comparer; this.element_index_comparer = new ComparerArrayIndex <ElementType>(element_value_comparer, element_array); this.d_topology = topology; this.d_reporter = reporter; this.d_done = 0; this.d_elements_to_queued = new bool[d_element_array.Length]; this.d_neigbor_element_array = new int[d_topology.MaximumConnectivity]; this.d_fringe = new PriorityQueueC5 <int>(element_index_comparer); this.d_component_stack = new Stack <Tuple <ElementType, IList <int>, IList <MaxTreeNode <ElementType> > > >(); d_fringe.Enqueue(0); d_elements_to_queued[0] = true; // Build tree while (d_fringe.Count != 0) { Process(d_fringe.PeekLast()); } Tuple <ElementType, IList <int>, IList <MaxTreeNode <ElementType> > > component = d_component_stack.Pop(); MaxTreeNode <ElementType> bottom_level_node = new MaxTreeNode <ElementType>(component.Item1, component.Item2, component.Item3, element_value_comparer); return(new MaxTree <ElementType>(bottom_level_node, d_element_array.Length, real_element_count, element_value_comparer)); }
/// <summary> /// Runs the updating process. /// </summary> public void RunUpdate() { try { _progressReporter = GetProgressReporter(); } catch (Exception ex) { Popup.ShowPopup(SystemIcons.Error, "Error while initializing the graphical user interface.", ex, PopupButtons.Ok); return; } ThreadPool.QueueUserWorkItem(arg => RunUpdateAsync()); try { _progressReporter.Initialize(); } catch (Exception ex) { _progressReporter.InitializingFail(ex); _progressReporter.Terminate(); } }
public void Run(IProgressReporter progressReporter, CancellationToken cancellationToken) { try { if (_url == null || _filePath == null) { throw new InvalidOperationException($"{nameof(Setup)} should be called first."); } progressReporter.SetText(LocalizationManager.Instance.Current.Keys.Status_DownloadingFile.SafeFormat(Path.GetFileName(_filePath))); _logger.LogInformation(LocalizationManager.Instance.Current.Keys.Log_DownloadingFileFromUrl.SafeFormat(_filePath, _url)); _httpDownloader.DownloadFileAsync(_url, _filePath, cancellationToken).Wait(cancellationToken); _logger.LogInformation(LocalizationManager.Instance.Current.Keys.Log_FileSuccessfullyDownloaded.SafeFormat(_filePath)); } catch (OperationCanceledException) { _logger.LogWarning(LocalizationManager.Instance.Current.Keys.Log_DownloadFileCanceled); try { File.Delete(_filePath !); } catch { // ignored } } catch (Exception ex) { _logger.LogError(ex, LocalizationManager.Instance.Current.Keys.Log_FailedToDownloadFileFromUrl.SafeFormat(_filePath, _url, ex.Message)); } }
public void OnExecuteAsync_Should_NotThrow( IConsoleOutput console, IProgressReporter progressReporter, IOpenApiDocumentFactory openApiDocumentFactory, INSwagOptions options, INSwagCodeGeneratorFactory codeGeneratorFactory, ICodeGenerator generator, string outputFile, string code) { var sut = new NSwagCommand( console, progressReporter, openApiDocumentFactory, options, codeGeneratorFactory); sut.OutputFile = outputFile; Mock.Get(generator) .Setup(c => c.GenerateCode(progressReporter)) .Returns(code); new Func <int>(sut.OnExecute).Should().NotThrow(); }
public async Task <string> GetLatestVersionAsync(IProgressReporter progressReporter, string buildCode) { HttpClient client = new HttpClient(); client.Timeout = DefaultTimeout; progressReporter.SetProgressPercent(null); progressReporter.SetProgressStatus("Obtaining latest version for build " + buildCode); var response = await client.GetAsync(string.Format("{0}/LatestBuildNumber/{1}", webServiceRootUrl, buildCode)); if (response.IsSuccessStatusCode) { using (var stream = await response.Content.ReadAsStreamAsync()) { var versionString = serializer.Deserialize <string>(new JsonTextReader(new StreamReader(stream))); progressReporter.SetProgressStatus("Latest version for build " + buildCode + " is: " + (versionString ?? "None")); return(versionString); } } else { throw new ServiceException(string.Format("Server returned {0} : {1}", response.StatusCode, response.ReasonPhrase)); } }
private void ReportProgress(IProgressReporter reporter) { if (!Dispatcher.CheckAccess()) // CheckAccess returns true if you're on the dispatcher thread { Dispatcher.Invoke(new ProgressReporterInvoker(ReportProgress), reporter); return; } foreach (var report in reporter.GetReports()) { var i = findIndexFor(report.Category); if (report.Max > 0 && report.Max != report.Current) { ProgressGroups[i].Category.Text = report.Category; ProgressGroups[i].Category.Visibility = Visibility.Visible; ProgressGroups[i].ProgressBar.Maximum = report.Max; ProgressGroups[i].ProgressBar.Value = report.Current; ProgressGroups[i].ProgressBar.Visibility = Visibility.Visible; ProgressGroups[i].ProgressBarText.Text = $"{report.Current}/{report.Max}"; ProgressGroups[i].ProgressBarText.Visibility = Visibility.Visible; } if (report.Max == report.Current) { ProgressGroups[i].Category.Text = ""; ProgressGroups[i].Category.Visibility = Visibility.Collapsed; ProgressGroups[i].ProgressBar.Visibility = Visibility.Collapsed; ProgressGroups[i].ProgressBarText.Visibility = Visibility.Collapsed; } } }
public Unpacker(IProgressReporter reporter) { this.reporter = reporter; this.report = reporter != null; AppExitingHandler.AppExiting += onAppExiting; }
public async Task <bool> Mux(Project project, IProgressReporter reporter) { var tTpl = new Texplate.Texplate(); using (tTpl.EnterContext(this)) using (tTpl.EnterContext(project)) { var tXmlDir = project.XmlTempDir; var tClipDescFile = tXmlDir.PickFile(ClipDescFile); using (var tClipDescWriter = tClipDescFile.CreateText()) { var tRenderer = this[ClipDesc]; tClipDescWriter.Write(tRenderer.Render(tTpl)); } var tProjDefFile = tXmlDir.PickFile(ProjDefFile); using (tTpl.EnterContext(new ClipDescFileContext(tClipDescFile))) using (var tProjDefWriter = tProjDefFile.CreateText()) { var tRenderer = this[ProjDef]; tProjDefWriter.Write(tRenderer.Render(tTpl)); } MuxEnqueueStruct tMuxTaskDef = new MuxEnqueueStruct(tProjDefFile.FullName, project.ClipCount); var tMuxTask = muxService.Enqueue(tMuxTaskDef); return(await Task.Run(() => WaitMuxTask(tMuxTask, reporter))); } }
private bool WaitMuxTask(Guid muxTaskId, IProgressReporter reporter) { const float Amount = 1.0f; reporter.Amount = Amount; for (;;) { if (reporter.IsCanceled) { muxService.Cancel(muxTaskId); } var tInfo = muxService.GetRequestInfo(muxTaskId); var tStatus = tInfo.Status; reporter.Progress = tInfo.TotalProgress >= 0 ? tInfo.TotalProgress : 0; if (tStatus.HasFlag(MuxRequestStatus.EndFlag)) { var tIsOk = tStatus.HasFlag(MuxRequestStatus.Processed); tIsOk &= tInfo.LastMuxStatusCode == MuxCommon.MuxStatusCode.MUX_SN_S_DONE; if (tIsOk) { reporter.Progress = Amount; } muxService.Confirm(muxTaskId); reporter.OnTaskEnd(); return(tIsOk); } Thread.Sleep(1000); } }
private static IFileSystemFactory Create( IProgressReporter progressReporter = null) { return(new FileSystemFactory( progressReporter ?? new FakeProgressReporter() )); }
private void PerformSystemChecks(IList <ISystemValidation> validations, IProgressReporter progressReporter, ICmdlet cmdlet, TextSummaryOutputWriter summaryWriter, PsObjectsOutputWriter psObjectsWriter) { PowerShellCommandRunner commandRunner = null; try { commandRunner = new PowerShellCommandRunner(this.ComputerNameValue.Value, this.Credential); } catch { this.WriteWarning( $"Establishing management service connection with host '{this.ComputerNameValue.Value}' as {this.UserName} didn't work." + Environment.NewLine + $"Ensure {this.UserName} has administrative rights and that the process is running with administrative permissions." + Environment.NewLine + $"You can also use -SkipSystemChecks switch to skip system requirements checks."); throw; } var outputWriters = new List <IOutputWriter> { summaryWriter, psObjectsWriter }; SystemValidationsProcessor systemChecksProcessor = new SystemValidationsProcessor(commandRunner, validations, outputWriters, progressReporter); systemChecksProcessor.Run(); }
///<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); } }
/// <summary> /// Gets the reference reader based on the reference relative path. /// NOTE: this uses a constructor that passes in the reference /// </summary> /// <param name="zReference">The reference to get the reader for</param> /// <param name="zProgressReporter">ProgressReporter for the Reader to use</param> /// <returns>Reference reader (defaults to CSV)</returns> public static ReferenceReader GetReader(ProjectLayoutReference zReference, IProgressReporter zProgressReporter) { if (zReference == null) { return(null); } ReferenceReader zReferenceReader = null; if (zReference.RelativePath.StartsWith(GoogleSpreadsheetReference.GOOGLE_REFERENCE + GoogleSpreadsheetReference.GOOGLE_REFERENCE_SPLIT_CHAR)) { zReferenceReader = new GoogleReferenceReader(zReference); } if (zReference.RelativePath.StartsWith(ExcelSpreadsheetReference.EXCEL_REFERENCE + ExcelSpreadsheetReference.EXCEL_REFERENCE_SPLIT_CHAR)) { zReferenceReader = new ExcelReferenceReader(zReference); } if (null == zReferenceReader) { zReferenceReader = new CSVReferenceReader(zReference); } zReferenceReader.ProgressReporter = zProgressReporter; return(zReferenceReader.Initialize()); }
///<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; }
/// <summary> /// Gets the reference reader based on the type /// </summary> /// <param name="eReferenceType">The type of reference to get the reader for</param> /// <param name="zProgressReporter">ProgressReporter for the Reader to use</param> /// <returns>Reference reader (defaults to null)</returns> public static ReferenceReader GetDefineReader(ReferenceType eReferenceType, IProgressReporter zProgressReporter) { ReferenceReader zReferenceReader = null; switch (eReferenceType) { case ReferenceType.CSV: zReferenceReader = new CSVReferenceReader(); break; case ReferenceType.Google: zReferenceReader = new GoogleReferenceReader(); break; case ReferenceType.Excel: zReferenceReader = new ExcelReferenceReader(); break; } if (zReferenceReader != null) { zReferenceReader.ProgressReporter = zProgressReporter; } return(zReferenceReader.Initialize()); }
/// <summary> /// Saves the file to the current file path. /// </summary> public virtual void Save(IProgressReporter progressReporter) { if (string.IsNullOrEmpty(FilePath.FullPath)) { throw new NotSupportedException("File path must be specified."); } if (HasUnsavedData) { using (var fileStream = File.Create(FilePath.FullPath)) { if (CurrentDocumentContent != null) { CurrentDocumentContent.Save(fileStream); _contents = null; } else { fileStream.Write(_contents, 0, _contents.Length); } fileStream.Flush(); } HasUnsavedData = false; } }
private static void CalculateDeltaInternal(string sourcePath, string targetPath, string deltaPath, string signaturePath, int chunkSize, FilePatchProgress progressReporter = null) { using (var signatureStream = new FileStream(signaturePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) { using (var basisStream = new FileStream(sourcePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { SignatureBuilder sb = new SignatureBuilder { ChunkSize = (short)chunkSize }; sb.Build(basisStream, new SignatureWriter(signatureStream)); } signatureStream.Position = 0L; using (var newFileStream = new FileStream(targetPath, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var deltaStream = new FileStream(deltaPath, FileMode.Create, FileAccess.Write, FileShare.Read)) { IProgressReporter reporter = progressReporter; if (reporter == null) { reporter = new NullProgressReporter(); } new DeltaBuilder().BuildDelta(newFileStream, new SignatureReader(signatureStream, reporter), new AggregateCopyOperationsDecorator(new BinaryDeltaWriter(deltaStream))); } } }
public QueueListener(IQueueListenerConfiguration config, IQueue queue, IScenarioRunner scenarioRunner, IProgressReporter progressReporter, ITimeProvider timeProvider) { _config = config; _queue = queue; _scenarioRunner = scenarioRunner; _progressReporter = progressReporter; _timeProvider = timeProvider; }
public static ReflectionMetadataDependencyInfo ComputeDependencies(IEnumerable<IAssemblyFile> inputAssemblies, IDependencyFilter assemblyFilter, IProgressReporter progressReport) { var engine = new ReflectionMetadataDependencyInfo(inputAssemblies, assemblyFilter); engine.FindDependencies(progressReport); return engine; }
///<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; }
public PatchCommand() { options = new OptionSet(); options.Positional("basis-file", "The file that the delta was created for.", v => basisFilePath = v); options.Positional("delta-file", "The delta to apply to the basis file", v => deltaFilePath = v); options.Positional("new-file", "The file to write the result to.", v => newFilePath = v); options.Add("progress", "Whether progress should be written to stdout", v => progressReporter = new ConsoleProgressReporter()); options.Add("skip-verification", "Skip checking whether the basis file is the same as the file used to produce the signature that created the delta.", v => skipHashCheck = true); }
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; }
public ProgressNotification(string title, IProgressReporter progressReporter) { Title = title; _progressReporter = progressReporter; progressReporter.ProgressMessageChanged += ProgressReporter_ProgressMessageChanged; progressReporter.ProgressChanged += ProgressReporter_ProgressChanged; progressReporter.Finished += ProgressReporter_Finished; }
public DefaultScenarioRunner(IExecutionContextFactory executionContextFactory, ICriterionRunner criterionRunner, IProgressReporter progressReporter, IScenarioContextFactory scenarioContextFactory, ILogger logger) { _executionContextFactory = executionContextFactory; _criterionRunner = criterionRunner; _progressReporter = progressReporter; _scenarioContextFactory = scenarioContextFactory; _logger = logger; }
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 }; }
private static bool FilterValidFiles(IAssemblyFile file, IProgressReporter _progressReport) { if (file.Exists) { return true; } _progressReport.ReportIssue(string.Format(LocalizedStrings.UnknownFile, file.Name)); return false; }
private static bool FilterValidFiles(FileInfo file, IProgressReporter _progressReporter) { if (file.Exists) { return true; } _progressReporter.ReportIssue(string.Format(LocalizedStrings.UnknownFile, file.FullName)); return false; }
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); } }
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(); } }
public ApiPortVsAnalyzer( ApiPortClient client, OptionsViewModel optionsViewModel, OutputWindowWriter outputWindow, IReportViewer viewer, IProgressReporter reporter) { _client = client; _optionsViewModel = optionsViewModel; _outputWindow = outputWindow; _viewer = viewer; _reporter = reporter; }
public CompMsg(IProgressReporter progressReporter, String logFile) { this.progressReporter = progressReporter; Abort = false; cError = 0; cFatal = 0; cWarn = 0; cInfo = 0; if (File.Exists(logFile)) File.Delete(logFile); writer = new StreamWriter(logFile, true, System.Text.Encoding.UTF8); }
private static DotNetCatalog GetData(IProgressReporter progressReporter) { using (var progressTask = progressReporter.StartTask("Loading catalog")) { try { return Data.LoadCatalog(); } catch (Exception) { progressTask.Abort(); throw; } } }
/// <inheritdoc /> public override void Load(IProgressReporter reporter) { try { foreach (var node in Nodes) node.Load(reporter); _isLoaded = true; OnLoadComplete(new SolutionNodeLoadEventArgs()); } catch (Exception ex) { _isLoaded = true; OnLoadComplete(new SolutionNodeLoadEventArgs(ex)); } }
/// <summary> /// Loads the underlying project. /// </summary> /// <param name = "reporter">The progress reporter to use for logging</param> public override void Load(IProgressReporter reporter) { foreach (var node in Nodes) node.Load(reporter); try { Project = Project.OpenProject(FilePath.FullPath); OnLoadComplete(new SolutionNodeLoadEventArgs()); } catch (Exception ex) { OnLoadComplete(new SolutionNodeLoadEventArgs(ex)); } }
public IDependencyInfo FindDependencies(IEnumerable<IAssemblyFile> inputAssemblies, IProgressReporter _progressReport) { var inputAssemblyPaths = inputAssemblies.Where(f => FilterValidFiles(f, _progressReport)).Select(i => i.Name).ToList(); using (var task = _progressReport.StartTask(LocalizedStrings.DetectingAssemblyReferences, inputAssemblyPaths.Count)) { try { return DependencyFinderEngine.ComputeDependencies(inputAssemblyPaths, task); } catch (Exception) { task.Abort(); throw; } } }
public IDependencyInfo FindDependencies(IEnumerable<FileInfo> inputAssemblies, IProgressReporter _progressReporter) { var inputAssemblyPaths = inputAssemblies.Where(f => FilterValidFiles(f, _progressReporter)).Select(i => i.FullName).ToList(); using (var task = _progressReporter.StartTask(LocalizedStrings.DetectingAssemblyReferences, inputAssemblyPaths.Count)) { try { return ReflectionMetadataDependencyInfo.ComputeDependencies(inputAssemblyPaths, _progressReporter); } catch (Exception e) { task.Abort(); throw e; } } }
public IDependencyInfo FindDependencies(IEnumerable<IAssemblyFile> files, IProgressReporter _progressReporter) { var inputAssemblyPaths = files.Where(f => FilterValidFiles(f, _progressReporter)).ToList(); using (var task = _progressReporter.StartTask(LocalizedStrings.DetectingAssemblyReferences)) { try { return ReflectionMetadataDependencyInfo.ComputeDependencies(files, _assemblyFilter, _progressReporter); } catch (Exception) { task.Abort(); throw; } } }
public static Document CreateMailing(ICollection<WordStatementInfo> statements, string templateName, IProgressReporter progress) { if (statements == null) throw new ArgumentNullException("statements"); if (templateName == null) throw new ArgumentNullException("templateName"); var templatePath = Path.Combine(WordExport.MailingTemplateFolder, templateName); if (!File.Exists(templatePath)) throw new ArgumentException("Template does not exist", "templateName", new FileNotFoundException("Template does not exist", templatePath)); progress = progress ?? new EmptyProgressReporter(); progress.Caption = "Creating " + Path.GetFileNameWithoutExtension(templateName); Document sourceDoc = null; try { sourceDoc = Word.Documents.Open(FileName: templatePath, ReadOnly: true, AddToRecentFiles: false); Document doc = Word.Documents.Add(); doc.ShowGrammaticalErrors = doc.ShowSpellingErrors = false; ; object subjectProp = sourceDoc.BuiltInDocumentProperties.GetType().InvokeMember("Item", BindingFlags.Default | BindingFlags.GetProperty, null, sourceDoc.BuiltInDocumentProperties, new object[] { WdBuiltInProperty.wdPropertySubject }, CultureInfo.InvariantCulture); var type = (string)subjectProp.GetType().InvokeMember("Value", BindingFlags.Default | BindingFlags.GetProperty, null, subjectProp, new object[0], CultureInfo.InvariantCulture).ToString(); switch (type.ToUpperInvariant()) { case "MASS": CreateMassMailing(statements, sourceDoc, doc, progress); break; case "PERSONALIZED": CreatePersonalizedMailing(statements, sourceDoc, doc, progress); break; default: throw new ArgumentException("Unknown document type: " + type + ". Please set the Subject field of " + templateName + " to either Mass or Personalized.", "templateName"); } Word.Activate(); doc.Activate(); return doc; } finally { Word.ScreenUpdating = true; if (sourceDoc != null) sourceDoc.CloseDoc(); } }
public IEnumerable<RecognizedSegment> Recognize(Stream document, IProgressReporter progress) { var imageData = new ImageData(document); var boards = imageData.DefineIteratedBoards(); var heuristics = boards.Segment().ToList(); progress.Maximum = heuristics.Count * 1000; foreach (var segment in heuristics) { var whitespaceResults = trainingData.PerformWhitespaceLookup(segment, progress.ScaledChildOperation(500)).LastOrDefault(r => r.Certainty > 10); if (whitespaceResults != null && whitespaceResults.Text == "AllLabels") { var match = trainingData.PerformLookup(segment, progress.ScaledChildOperation(500)).LastOrDefault(r => r.Certainty > 10); if (match != null) yield return match; } else progress.Progress += 500; //Add the progress that would have been used by the character recognition } }
public void WriteFirmware(Firmware fw, IProgressReporter rep) { SendAndWait("WRITE", "OK", rep); SendAndWait(new string(new[] { (char) 2, (char) fw.Version.Major, (char) fw.Version.Minor }), "OK", rep); for(var i = 0; i < fw.Chunks.Count; i++) { var kvp = fw.Chunks.ElementAt(i); var addr = kvp.Key; var data = new byte[kvp.Value.Length + 5]; data[0] = 0; data[1] = (byte) ((addr >> 0) & 0xff); data[2] = (byte) ((addr >> 8) & 0xff); data[3] = (byte) ((addr >> 16) & 0xff); data[4] = (byte) ((addr >> 24) & 0xff); Array.Copy(kvp.Value, 0, data, 5, kvp.Value.Length); Write(data); Wait("OK", rep); rep.Progress((float) (i + 1) / (float) fw.Chunks.Count); } Write(3); Wait("OK", rep); }
///<summary>Downloads the update and extracts its files to a temporary directory.</summary> ///<param name="existingFiles">The path to the existing files that should be updated. /// Any files in this directory that match files in the update will not be re-downloaded.</param> ///<param name="organizationId">The organization ID to match organization-specific directories (see <see cref="OrganizationDirectoryPattern"/>).</param> ///<param name="ui">An optional IProgressReporter implementation to report the progress of the download.</param> ///<returns>The path to the extracted files.</returns> public string DownloadFiles(string existingFiles, string organizationId, IProgressReporter ui) { if (!Directory.Exists(existingFiles)) throw new DirectoryNotFoundException(existingFiles + " does not exist"); ui = ui ?? new EmptyProgressReporter(); ui.CanCancel = true; var path = Path.GetTempFileName(); File.Delete(path); Directory.CreateDirectory(path); try { var newFiles = Files // Extract files from this organization to the root .Select(f => organizationId == null ? f : f.StripPrefix(OrganizationPrefix + organizationId + "\\")) // Skip other organization directories .Where(f => !OrganizationDirectoryPattern.IsMatch(f.RelativePath)) .Where(f => !f.Matches(existingFiles)) .ToList(); ui.Maximum = newFiles.Sum(f => f.Length); foreach (var file in newFiles) { ui.Caption = "Downloading " + file.RelativePath; file.DownloadFile(path, ui.ChildOperation()); if (ui.WasCanceled) { Directory.Delete(path, true); return null; } } } catch (Exception ex) { Directory.Delete(path, true); if (ui.WasCanceled) return null; //If it was canceled, we'll get a CryptoException because the CryptoStream was closed throw new UpdateErrorException(ex); } return path; }
static void CreateMassMailing(ICollection<WordStatementInfo> statements, Document sourceDoc, Document doc, IProgressReporter progress) { using (new ClipboardScope()) { sourceDoc.Range().Copy(); int pageSize = sourceDoc.ContentControls.Count; var people = statements.Select(s => s.Person).Distinct().OrderBy(p => p.LastName).ToArray(); int pageCount = (int)Math.Ceiling(people.Length / (float)pageSize); progress.Maximum = pageCount; var range = doc.Range(); for (int i = 0; i < pageCount; i++) { if (progress.WasCanceled) return; progress.Progress = i; range.Collapse(WdCollapseDirection.wdCollapseEnd); range.Paste(); } new MassMailingGenerator(people).Populate(doc.Range()); } }
public async Task<Version> GetLatestVersionAsync(IProgressReporter progressReporter) { HttpClient client = new HttpClient(); client.Timeout = DefaultTimeout; progressReporter.SetProgressPercent(null); progressReporter.SetProgressStatus("Obtaining latest version"); var response = await client.GetAsync(string.Format("{0}/LatestVersion", webServiceRootUrl)); if (response.IsSuccessStatusCode) { using (var stream = await response.Content.ReadAsStreamAsync()) { var versionString = serializer.Deserialize<string>(new JsonTextReader(new StreamReader(stream))); progressReporter.SetProgressStatus("Latest version is: " + versionString); return new Version(versionString); } } else { throw new ServiceException(string.Format("Server returned {0} : {1}", response.StatusCode, response.ReasonPhrase)); } }