private void OnTotalConnectionStatsChanged(SyncThingConnectionStats connectionStats)
        {
            var handler = this.TotalConnectionStatsChanged;

            if (handler != null)
            {
                handler(this, new ConnectionStatsChangedEventArgs(connectionStats));
            }
        }
        protected override async Task PollAsync(CancellationToken cancellationToken)
        {
            var connections = await this.apiClient.FetchConnectionsAsync();

            // We can be stopped in the time it takes this to complete
            cancellationToken.ThrowIfCancellationRequested();

            var elapsed = DateTime.UtcNow - this.lastPollCompletion;

            this.lastPollCompletion = DateTime.UtcNow;

            if (this.prevConnections != null)
            {
                // Just do the total for now
                var total     = connections.Total;
                var prevTotal = this.prevConnections.Total;

                if (total.InBytesTotal != prevTotal.InBytesTotal || total.OutBytesTotal != prevTotal.OutBytesTotal)
                {
                    this.haveNotifiedOfNoChange = false;

                    double inBytesPerSecond  = (total.InBytesTotal - prevTotal.InBytesTotal) / elapsed.TotalSeconds;
                    double outBytesPerSecond = (total.OutBytesTotal - prevTotal.OutBytesTotal) / elapsed.TotalSeconds;

                    var totalStats = new SyncThingConnectionStats(total.InBytesTotal, total.OutBytesTotal, inBytesPerSecond, outBytesPerSecond);
                    this.OnTotalConnectionStatsChanged(totalStats);
                }
                else if (!this.haveNotifiedOfNoChange)
                {
                    this.haveNotifiedOfNoChange = true;

                    var totalStats = new SyncThingConnectionStats(total.InBytesTotal, total.OutBytesTotal, 0, 0);
                    this.OnTotalConnectionStatsChanged(totalStats);
                }
            }
            this.prevConnections = connections;
        }
        protected override async Task PollAsync(CancellationToken cancellationToken)
        {
            var connections = await this.apiClient.FetchConnectionsAsync();

            // We can be stopped in the time it takes this to complete
            cancellationToken.ThrowIfCancellationRequested();
            
            var elapsed = DateTime.UtcNow - this.lastPollCompletion;
            this.lastPollCompletion = DateTime.UtcNow;

            if (this.prevConnections != null)
            {
                // Just do the total for now
                var total = connections.Total;
                var prevTotal = this.prevConnections.Total;

                if (total.InBytesTotal != prevTotal.InBytesTotal || total.OutBytesTotal != prevTotal.OutBytesTotal)
                {
                    this.haveNotifiedOfNoChange = false;

                    double inBytesPerSecond = (total.InBytesTotal - prevTotal.InBytesTotal) / elapsed.TotalSeconds;
                    double outBytesPerSecond = (total.OutBytesTotal - prevTotal.OutBytesTotal) / elapsed.TotalSeconds;

                    var totalStats = new SyncThingConnectionStats(total.InBytesTotal, total.OutBytesTotal, inBytesPerSecond, outBytesPerSecond);
                    this.OnTotalConnectionStatsChanged(totalStats);
                }
                else if (!this.haveNotifiedOfNoChange)
                {
                    this.haveNotifiedOfNoChange = true;

                    var totalStats = new SyncThingConnectionStats(total.InBytesTotal, total.OutBytesTotal, 0, 0);
                    this.OnTotalConnectionStatsChanged(totalStats);
                }
            }
            this.prevConnections = connections;
        }
 private void OnTotalConnectionStatsChanged(SyncThingConnectionStats connectionStats)
 {
     var handler = this.TotalConnectionStatsChanged;
     if (handler != null)
         handler(this, new ConnectionStatsChangedEventArgs(connectionStats));
 }
 public ConnectionStatsChangedEventArgs(SyncThingConnectionStats totalConnectionStats)
 {
     this.TotalConnectionStats = totalConnectionStats;
 }
Exemple #6
0
 private void OnTotalConnectionStatsChanged(SyncThingConnectionStats stats)
 {
     this.TotalConnectionStats = stats;
     this.eventDispatcher.Raise(this.TotalConnectionStatsChanged, new ConnectionStatsChangedEventArgs(stats));
 }
 private void OnTotalConnectionStatsChanged(SyncThingConnectionStats stats)
 {
     this.TotalConnectionStats = stats;
     this.eventDispatcher.Raise(this.TotalConnectionStatsChanged, new ConnectionStatsChangedEventArgs(stats));
 }
 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);
     }
 }
 private void OnTotalConnectionStatsChanged(SyncThingConnectionStats connectionStats)
 {
     this.TotalConnectionStatsChanged?.Invoke(this, new ConnectionStatsChangedEventArgs(connectionStats));
 }
 public ConnectionStatsChangedEventArgs(SyncThingConnectionStats totalConnectionStats)
 {
     this.TotalConnectionStats = totalConnectionStats;
 }
Exemple #11
0
 private void OnTotalConnectionStatsChanged(SyncThingConnectionStats connectionStats)
 {
     this.TotalConnectionStatsChanged?.Invoke(this, new ConnectionStatsChangedEventArgs(connectionStats));
 }