private void OnProgressEvent(ProgressEventArgs eventArgs) { if (ProgressChanged != null) { ProgressChanged.Invoke(this, eventArgs); } }
private void HandleProgressChanged(object sender, ProgressChangedEventArgs e) { if (ProgressChanged != null) { ProgressChanged.Invoke(this, e); } }
/// <summary> /// Report progress /// </summary> /// <param name="value"></param> public virtual void Report(long value) { Items = value; CalculateLinearPrediction(); ProgressChanged?.Invoke(this, new ProgressReporterEventArgs(Progress, Items)); }
protected virtual void OnProgressChanged() { var progressValues = dictionary.Values.ToList(); ProgressChanged?.Invoke(this, progressValues); action?.Invoke(progressValues); }
/// <summary> /// Use this for progress track support /// </summary> /// <param name="url"></param> /// <returns></returns> public async Task <Stream> DownloadDataAsync(string url) { using (var wd = new WebDownload()) { wd.DownloadProgressChanged += (s, e) => { ProgressChanged?.Invoke(this, e); }; return(new MemoryStream(await wd.DownloadDataTaskAsync(Extentions.HandleWeirdFormat(url)))); } }
public override void OnProgressChanged(string deviceAddress, int percent, float speed, float avgSpeed, int currentPart, int partsTotal) { base.OnProgressChanged(deviceAddress, percent, speed, avgSpeed, currentPart, partsTotal); Log.Info("DFUProgress", $"Progress: {percent} % ({currentPart}/{partsTotal})"); ProgressChanged?.Invoke(this, percent); }
protected virtual void OnProgressChanged(object sender, ProgressChangedEventArgs e) { CrossThreadingHelpers.InvokeControl(ProgressBar1, e.ProgressPercentage, (x) => { ProgressBar1.Value = (int)x; ProgressChanged?.Invoke(sender, e); }); }
public void UpdateProgress(int progress) { if (this.progress != progress) { this.progress = progress; ProgressChanged?.Invoke(action, progress); } }
/// <summary> /// Increase DownloadedSize by delta. /// </summary> /// <param name="delta">Delta must be positive.</param> public void Increase(long delta) { Ensure.That(delta).IsGte(0); long old = DownloadedSize; DownloadedSize += delta; ProgressChanged?.Invoke(this, new BaseProgressChangedEventArg(old, DownloadedSize)); }
/// <summary> /// The background downloader worker progress changed event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The event args.</param> private void BackgroundDownloader_ProgressChanged(object sender, ProgressChangedEventArgs e) { downloadedFilesCount = DownloadedFiles.Count; var arr = (object[])e.UserState; DownloaderEventArgs _event = new DownloaderEventArgs((int)arr[0], (int)arr[1], (string)arr[2], (ProgressStatus)arr[3], arr[4]); ProgressChanged?.Invoke(_event); }
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { if (base.CanWrite && ExpectedLength > 0 && (base.Position + buffer.Length) / (ExpectedLength / 100) > percentage) { ProgressChanged?.Invoke(this, new ProgressChangedEventArgs(percentage = (int)((base.Position + buffer.Length) / (ExpectedLength / 100)), null)); } return(base.WriteAsync(buffer, offset, count, cancellationToken));; }
private void OnProgressChanged(long bytesSent) { var args = new CloudStorageProgressArgs { BytesSent = bytesSent }; ProgressChanged?.Invoke(null, args); }
public override ValueTask WriteAsync(ReadOnlyMemory <byte> source, CancellationToken cancellationToken = default) { if (base.CanWrite && ExpectedLength > 0 && (base.Position + source.Length) / (ExpectedLength / 100) > percentage) { ProgressChanged?.Invoke(this, new ProgressChangedEventArgs(percentage = (int)((base.Position + source.Length) / (ExpectedLength / 100)), null)); } return(base.WriteAsync(source, cancellationToken)); }
public void LoadFile(string fileName) { try { _canceled = false; _file = File.OpenText(fileName); _fileLength = new FileInfo(fileName).Length; long fileLength = _file.BaseStream.Length; var doubleFormat = new NumberFormatInfo { CurrencyDecimalSeparator = "." }; var listToReturn = new List <Link>(); string headers; if (!_file.EndOfStream) { headers = _file.ReadLine(); var headersOrder = ParseHeaders(headers); while (!_file.EndOfStream && !_canceled) { string line = _file.ReadLine(); var splitted = line.Split(';'); listToReturn.Add(new Link { //Использовать абсолютные индексы не очень хорошо, лучше объявить константы, //но, т.к. набор заголовков фиксирован, пока можно оставить так date = DateTime.Parse(splitted[headersOrder[0]]), objectA = splitted[headersOrder[1]], typeA = splitted[headersOrder[2]], objectB = splitted[headersOrder[3]], typeB = splitted[headersOrder[4]], direction = (Direction)Enum.Parse(typeof(Direction), splitted[headersOrder[5]], true), color = (Color)ColorConverter.ConvertFromString(splitted[headersOrder[6]]), intensity = int.Parse(splitted[headersOrder[7]]), latitudeA = double.Parse(splitted[headersOrder[8]], doubleFormat), longitudeA = double.Parse(splitted[headersOrder[9]], doubleFormat), latitudeB = double.Parse(splitted[headersOrder[10]], doubleFormat), longitudeB = double.Parse(splitted[headersOrder[11]], doubleFormat) }); ProgressChanged?.Invoke((double)_file.BaseStream.Position / fileLength); } } else { throw new ArgumentException("Файл пуст"); } if (!_canceled) { FileLoaded?.Invoke(listToReturn); } } catch (Exception e) { Error?.Invoke(e.Message); } }
private void Process() { try { if (Info == null) { State = Status.GettingHeaders; GetHeaders(); aop.Post(delegate { DownloadInfoReceived.Raise(this, EventArgs.Empty); }, null); } var append = RemainingRangeStart > 0; var bytesRead = 0; var buffer = new byte[2 * 1024]; State = Status.SendingRequest; using (var response = RequestHelper.CreateRequestGetResponse(Info, RemainingRangeStart, BeforeSendingRequest, AfterGettingResponse)) { State = Status.GettingResponse; using (var responseStream = response.GetResponseStream()) using (var file = FileHelper.CheckFile(FullFileName, append)) { while (allowDownload && (bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0) { State = Status.Downloading; file.Write(buffer, 0, bytesRead); TotalBytesReceived += bytesRead; speedBytesTotal += bytesRead; aop.Post(delegate { ProgressChanged.Raise(this, new ProgressChangedEventArgs(SpeedInBytes, this.Progress, TotalBytesReceived)); }, Progress); } } } if (RemainingRangeStart > Info.Length) { throw new Exception("Total bytes received overflows content length"); } if (TotalBytesReceived == Info.Length) { State = Status.Completed; DownloadCompleted.Raise(this, EventArgs.Empty); } else if (!allowDownload) { State = Status.Paused; } } catch (Exception ex) { State = Status.ErrorOccured; aop.Post(delegate { ErrorOccured.Raise(this, new ErrorEventArgs(ex)); }, null); } }
public CalibrationTool(OptiTrackSystem optiTrack) { this.optiTrack = optiTrack; worker = new BackgroundWorker() { WorkerSupportsCancellation = true }; optiTrackPoints = new List <Vector <double> >(); kukaRobotPoints = new List <Vector <double> >(); calibrationPoints = new List <Vector <double> >(); Transformation transformation = null; worker.DoWork += (s, e) => { Start?.Invoke(); // Move robot to first calibration point and wait //MoveRobotToPoint(robot, calibrationPoints[0], robot.Limits.MaxVelocity.XYZ / 3.0); robot.ForceMoveTo(new RobotVector(calibrationPoints[0], robot.Position.ABC), RobotVector.Zero, 15.0); for (int i = 0; i < calibrationPoints.Count; i++) { // Move robot to next calibration point and wait //MoveRobotToPoint(robot, calibrationPoints[i], robot.Limits.MaxVelocity.XYZ / 3.0); robot.ForceMoveTo(new RobotVector(calibrationPoints[i], robot.Position.ABC), RobotVector.Zero, 4.0); // Add robot XYZ position to list var kukaPoint = robot.Position.XYZ; kukaRobotPoints.Add(kukaPoint); // Gen n samples from optitrack system and add average ball position to the list var optiTrackPoint = optiTrack.GetAveragePosition(samplesPerPoint); optiTrackPoints.Add(optiTrackPoint); // Calculate new transformation int progress = i * 100 / (calibrationPoints.Count - 1); transformation = new Transformation(optiTrackPoints, kukaRobotPoints); ProgressChanged?.Invoke(progress, transformation); } //MoveRobotToPoint(robot, robot.HomePosition.XYZ, robot.Limits.MaxVelocity.XYZ / 3.0); //robot.ForceMoveTo(robot.HomePosition, 6.0); }; worker.RunWorkerCompleted += (s, e) => { if (e.Error != null) { throw e.Error; } else { Completed?.Invoke(transformation); } }; }
public void DoWork() { for (int i = 0; i < 100; i++) { ProgressChanged?.Invoke(this, i); Thread.Sleep(50); } ProgressChanged?.Invoke(this, 100); }
public override void OnProgressChanged(Android.Webkit.WebView view, int newProgress) { //new progress is between 0-100 need to convert to 0-1 double progress = newProgress / 100; Debug.WriteLine($"WebViewChromeClient - Progress Changed! - New Progress: {newProgress}"); ProgressChanged?.Invoke(this, new ProgressEventArgs(progress)); }
protected void ReportProgress(double value) { if (value == 0 || value == 1 || reportWatch.ElapsedMilliseconds > ProgressDelay) { ProgressChanged?.Invoke(this, value); Progress?.Report(value); reportWatch.Restart(); } }
protected void OnStatusChanged(string message, int progress) { ProgressChanged?.Invoke(this, new StatusEventArgs { Message = message, Progress = progress }); }
private void OnProgressChanged(ProgressStatusEventArgs e) { if (IsLoggingProgressAsInfo) { Info(e.Message); } ProgressChanged?.Invoke(this, e); }
protected virtual void OnProgressChanged(string fileName, double progress) { AutomationEventArgs args = new AutomationEventArgs(); args.FileName = fileName; args.Progress = progress; ProgressChanged?.Invoke(args); }
public SynchronousWorkCoordinator(ITypeFinder typeFinder, ISeriesBuilder seriesBuilder, IPublisherProvider publishers, IWorkerContainer workers) : base(typeFinder, publishers, workers) { _seriesBuilder = seriesBuilder; publishers.ProgressChanged += (sender, e) => ProgressChanged?.Invoke(sender, e); publishers.Starting += OnStarting; }
public void UpdateProgress(ProgressAction action, int progress) { if (this.action != action || this.progress != progress) { this.action = action; this.progress = progress; ProgressChanged?.Invoke(action, progress); } }
private static void OnProgressChanged(string fileName, double progress) { ProgressChangedEventArgs args = new ProgressChangedEventArgs(); args.FileName = fileName; args.Progress = progress; ProgressChanged?.Invoke(args); }
private int PerformTemplate(TemplateNode template, XmlDocument xml_doc, ExcelDocument xlsx_doc, int offset) { xlsx_doc.RestartRows(); xlsx_doc.AddRow(); List <string> columns = new List <string>(); var nodes = xml_doc.SelectNodes(template.Path); for (int i = 0; i < nodes.Count; i++) { var node = nodes[i]; var values = template.Apply(node); if (values == null) { continue; } List <string> row = new List <string>(columns.Count); foreach (var value in values) { int index = columns.IndexOf(value.Key); if (index < 0) { index = columns.Count; xlsx_doc.AddColumn(offset + columns.Count); columns.Add(value.Key); } while (row.Count <= index) { row.Add(""); } row[index] = value.Value; } while (row.Count < columns.Count) { row.Add(""); } xlsx_doc.AddRow(offset, row); int progress = (i + 1) * 100 / nodes.Count; if (Progress != progress) { Progress = progress; ProgressChanged?.Invoke(this, EventArgs.Empty); } } for (int i = 0; i < columns.Count; i++) { xlsx_doc[offset + i, 0] = columns[i]; } return(columns.Count); }
private void OnProgressChanged(int current, int total) { if (total > 0) { var p = 100 * current / total; ProgressChangedEventArgs e = new ProgressChangedEventArgs(p, null); ProgressChanged?.Invoke(this, e); } }
/// <summary> /// Kicks off the actual download /// </summary> private async void DownloadWorkerAsync() { try { // Initialize reader/writer using var fs = GetOrUpdateFileStream(); var httpResponse = GetOrCreateWebStream(); // Gets the stream associated with the response. Stream receiveStream = httpResponse.GetResponseStream(); // Better handle resulting file size than blindly using content-length when // a range could result in content-length being a portion of the size. // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range var contentRangeHeader = httpResponse.GetResponseHeader("Content-Range"); if (string.IsNullOrEmpty(contentRangeHeader)) { Size = httpResponse.ContentLength; } else { var sizeHeaderStr = contentRangeHeader.Split("/").LastOrDefault(); if (long.TryParse(sizeHeaderStr, out long parsedSize)) { Size = parsedSize; } } byte[] read = new byte[CHUNK_SIZE]; while (doDownload) { var count = await receiveStream.ReadAsync(read, 0, CHUNK_SIZE); if (count == 0) // End of stream, etc { lastResponse = null; break; } await fs.WriteAsync(read, 0, count); Progress += count; ProgressChanged?.Invoke(this, new EventArgs()); } } catch (Exception ex) // WebException, IOException { Log.WriteLine($"Download failed: {ex.Message}"); failed = true; //throw ex; } finally { StatusChanged?.Invoke(this, new EventArgs()); } }
public void EncryptFile(string inputFile, string outputFile, byte[] key, string mode) { FileStream instream; FileStream outstream; try { double percent = 0.0; long current = 0; long sizeFile = 0; var cipher = new GOST28147Engine(); cipher.Init(true, new KeyParameter(key.ToArray())); IMode chosenMode = ChooseMode(mode, key, cipher); outstream = File.Open(outputFile, FileMode.Create); int chunkSize = 1024 * 1024; using (instream = File.OpenRead(inputFile)) { sizeFile = instream.Length; ProgressChanged?.Invoke(0.0); int byteRead = 0; byte[] input = new byte[chunkSize]; byte[] output = new byte[chunkSize]; while (true) { byteRead = instream.Read(input, 0, chunkSize); if (byteRead == chunkSize) { chosenMode.Process(input, output); outstream.Write(output, 0, chunkSize); } else { byte[] temp = new byte[byteRead]; Array.Copy(input, 0, temp, 0, byteRead); input = temp; input = AddPadding(input.ToArray()); output = new byte[input.Length]; chosenMode.Process(input, output); outstream.Write(output, 0, output.Length); break; } current += byteRead; percent = (double)current / sizeFile; percent *= 100; ProgressChanged?.Invoke(percent); } } } catch (Exception) { throw new Exception("Ошибка!"); } outstream?.Close(); instream?.Close(); }
/// <inheritdoc/> public Task Go(int?percentage, Action <PageProgressOptions> options = null) { var pageProgressOptions = PageProgressOptions.Default; options?.Invoke(pageProgressOptions); ProgressChanged?.Invoke(this, new(percentage, pageProgressOptions) ); return(Task.CompletedTask); }
public Form1() { InitializeComponent(); mCopier = new BackgroundWorker(); aCopier = new BackgroundWorker(); mCopier.DoWork += Copier_DoWork; mCopier.RunWorkerCompleted += Copier_RunWorkerCompleted; mCopier.WorkerSupportsCancellation = true; aCopier.DoWork += Copier_DoAnotherWork; aCopier.RunWorkerCompleted += Copier_RunAnotherWorkerCompleted; aCopier.WorkerSupportsCancellation = true; OnChange += Copier_ProgressChanged; OnError += Copier_Error; ChangeUI(false, copyProgressBar, finalLabel, startCopyButton); ChangeUI(false, pasteProgressBar, finalLabel2, restoreEverythingButton); }
public QuickCrc32(ProgressChanged pc, ProcessFinished pf) { _processFinished = pf; _progressChanged = pc; _bw = new BackgroundWorker {WorkerReportsProgress = true, WorkerSupportsCancellation = true}; _bw.ProgressChanged += BwProgressChanged; _bw.RunWorkerCompleted += BwRunWorkerCompleted; _bw.DoWork += BwDoWork; }
public ResourceProtocol(IChannelManager manager, ProgressChanged progressFunc) { this._manager = manager; this._progressChanged = progressFunc; }
public FfmpegWrapper(string ffpmegPath, ProgressChanged progressChanged, ProcessFinished processFinished) { _ffpmegPath = ffpmegPath; _progressChanged = progressChanged; _processFinished = processFinished; }