[longomatch] Fix exception when the nodes list is empty



commit 8c84c98316c5e9b67f58b88c10e7743242ebf285
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Wed Dec 3 00:31:42 2014 +0100

    Fix exception when the nodes list is empty

 LongoMatch.Core/Stats/TimerStats.cs |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)
---
diff --git a/LongoMatch.Core/Stats/TimerStats.cs b/LongoMatch.Core/Stats/TimerStats.cs
index 27efa2a..a2157de 100644
--- a/LongoMatch.Core/Stats/TimerStats.cs
+++ b/LongoMatch.Core/Stats/TimerStats.cs
@@ -73,12 +73,20 @@ namespace LongoMatch.Core.Stats
                        set;
                }
 
-               public void Update () {
+               public void Update ()
+               {
                        Count = timer.Nodes.Count;
-                       TotalDuration = new Time (timer.Nodes.Sum (n => n.Duration.MSeconds));
-                       AverageDuration = new Time ((int) timer.Nodes.Average (n => n.Duration.MSeconds));
-                       MinDuration = timer.Nodes.Min (n => n.Duration);
-                       MaxDuration = timer.Nodes.Max (n => n.Duration);
+                       if (Count > 0) {
+                               TotalDuration = new Time (timer.Nodes.Sum (n => n.Duration.MSeconds));
+                               AverageDuration = new Time ((int)timer.Nodes.Average (n => 
n.Duration.MSeconds));
+                               MinDuration = timer.Nodes.Min (n => n.Duration);
+                               MaxDuration = timer.Nodes.Max (n => n.Duration);
+                       } else {
+                               TotalDuration = new Time (0);
+                               AverageDuration = new Time (0);
+                               MinDuration = new Time (0);
+                               MaxDuration = new Time (0);
+                       }
                }
        }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]