Ejemplo n.º 1
0
        public void UpdateState()
        {
            switch (this.FileTransfer.Status)
            {
            case FileTransferStatus.InProgress:
                if (this.FileTransfer.DownloadBytesPerSecond.HasValue)
                {
                    this.ProgressString = String.Format(Resources.FileTransfersTrayView_Downloading_RateKnown,
                                                        FormatUtils.BytesToHuman(this.FileTransfer.BytesTransferred),
                                                        FormatUtils.BytesToHuman(this.FileTransfer.TotalBytes),
                                                        FormatUtils.BytesToHuman(this.FileTransfer.DownloadBytesPerSecond.Value, 1));
                }
                else
                {
                    this.ProgressString = String.Format(Resources.FileTransfersTrayView_Downloading_RateUnknown,
                                                        FormatUtils.BytesToHuman(this.FileTransfer.BytesTransferred),
                                                        FormatUtils.BytesToHuman(this.FileTransfer.TotalBytes));
                }

                this.ProgressPercent = ((float)this.FileTransfer.BytesTransferred / (float)this.FileTransfer.TotalBytes) * 100;
                break;

            case FileTransferStatus.Completed:
                this.ProgressPercent = 100;
                this.ProgressString  = null;
                break;
            }

            this.Error = this.FileTransfer.Error;
        }
Ejemplo n.º 2
0
        private void Update(SyncthingConnectionStats stats)
        {
            var    now      = DateTime.UtcNow;
            double earliest = (now - window - epoch).TotalSeconds;

            this.Update(earliest, this.inboundSeries, stats.InBytesPerSecond);
            this.Update(earliest, this.outboundSeries, stats.OutBytesPerSecond);

            this.xAxis.Minimum = earliest;
            this.xAxis.Maximum = (now - epoch).TotalSeconds;

            // This increases the value to the nearest 1024 boundary
            double maxValue = this.inboundSeries.Points.Concat(this.outboundSeries.Points).Max(x => x.Y);
            double roundedMax;

            if (maxValue > minYValue)
            {
                double factor = Math.Pow(1024, (int)Math.Log(maxValue, 1024));
                roundedMax = Math.Ceiling(maxValue / factor) * factor;
            }
            else
            {
                roundedMax = minYValue;
            }

            // Give the graph a little bit of headroom, otherwise the line gets chopped
            this.yAxis.Maximum = roundedMax * 1.05;
            this.MaxYValue     = FormatUtils.BytesToHuman(roundedMax) + "/s";

            if (this.IsActive)
            {
                this.OxyPlotModel.InvalidatePlot(true);
            }
        }
Ejemplo n.º 3
0
        private void ResetToEmptyGraph()
        {
            var now      = DateTime.UtcNow;
            var earliest = (now - window - epoch).TotalSeconds;
            var latest   = (now - epoch).TotalSeconds;

            // Put points on the far left, so we get a line from them
            this.inboundSeries.Points.Clear();
            this.inboundSeries.Points.Add(new DataPoint(earliest, 0));
            this.inboundSeries.Points.Add(new DataPoint(latest, 0));

            this.outboundSeries.Points.Clear();
            this.outboundSeries.Points.Add(new DataPoint(earliest, 0));
            this.outboundSeries.Points.Add(new DataPoint(latest, 0));

            this.xAxis.Minimum = earliest;
            this.xAxis.Maximum = latest;

            this.yAxis.Maximum = minYValue;
            this.MaxYValue     = FormatUtils.BytesToHuman(minYValue) + "/s";

            if (this.IsActive)
            {
                this.OxyPlotModel.InvalidatePlot(true);
            }
        }
Ejemplo n.º 4
0
 private void UpdateConnectionStats(SyncThingConnectionStats connectionStats)
 {
     if (connectionStats == null)
     {
         this.InConnectionRate  = "0.0B";
         this.OutConnectionRate = "0.0B";
     }
     else
     {
         this.InConnectionRate  = FormatUtils.BytesToHuman(connectionStats.InBytesPerSecond, 1);
         this.OutConnectionRate = FormatUtils.BytesToHuman(connectionStats.OutBytesPerSecond, 1);
     }
 }
Ejemplo n.º 5
0
        public MemoryUsageLogger()
        {
            this.process = Process.GetCurrentProcess();

            this.timer = new Timer()
            {
                AutoReset = true,
                Interval  = pollInterval.TotalMilliseconds,
            };
            this.timer.Elapsed += (o, e) =>
            {
                logger.Debug("Working Set: {0}. Private Memory Size: {1}. GC Total Memory: {2}",
                             FormatUtils.BytesToHuman(this.process.WorkingSet64), FormatUtils.BytesToHuman(this.process.PrivateMemorySize64),
                             FormatUtils.BytesToHuman(GC.GetTotalMemory(true)));
            };
        }
Ejemplo n.º 6
0
        private void UpdateConnectionStats(double?inBytesPerSecond, double?outBytesPerSecond)
        {
            if (inBytesPerSecond == null)
            {
                this.InConnectionRate = null;
            }
            else
            {
                this.InConnectionRate = FormatUtils.BytesToHuman(inBytesPerSecond.Value, 1);
            }

            if (outBytesPerSecond == null)
            {
                this.OutConnectionRate = null;
            }
            else
            {
                this.OutConnectionRate = FormatUtils.BytesToHuman(outBytesPerSecond.Value, 1);
            }
        }
Ejemplo n.º 7
0
        private async Task <bool> TryDownloadToFileAsync(string downloadPath, string url)
        {
            logger.Info("Downloading to {0}", downloadPath);

            // Temp file exists? Either a previous download was aborted, or there's another copy of us running somewhere
            // The difference depends on whether or not it's locked...
            try
            {
                var webClient = new WebClient();

                using (var downloadFileHandle = this.filesystemProvider.Open(downloadPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
                    using (var downloadStream = await webClient.OpenReadTaskAsync(url))
                    {
                        var responseLength = Int64.Parse(webClient.ResponseHeaders["Content-Length"]);
                        var previousDownloadProgressString = String.Empty;

                        var progress = new Progress <CopyToAsyncProgress>(p =>
                        {
                            var downloadProgressString = String.Format("Downloaded {0}/{1} ({2}%)",
                                                                       FormatUtils.BytesToHuman(p.BytesRead), FormatUtils.BytesToHuman(responseLength), (p.BytesRead * 100) / responseLength);
                            if (downloadProgressString != previousDownloadProgressString)
                            {
                                logger.Info(downloadProgressString);
                                previousDownloadProgressString = downloadProgressString;
                            }
                        });

                        await downloadStream.CopyToAsync(downloadFileHandle, progress);
                    }
            }
            catch (IOException e)
            {
                logger.Warn($"Failed to initiate download to temp file {downloadPath}", e);
                return(false);
            }

            return(true);
        }