Exemplo n.º 1
0
        public void GetNetValues(int duration)
        {
            using (var db = new ArgonDB()) {
                var time = new DateTime(DateTime.Now.AddSeconds(-duration).Ticks.NextSecond());
                var data = db.NetworkTraffic
                           .OrderByDescending(x => x.Time)
                           .Take(30000)
                           .Where(x => x.Time > time.Ticks)
                           .GroupBy(x => x.Time)
                           .Select(y => new
                {
                    Time = y.Select(z => z.Time).First(),
                    Sent = y.Sum(z => z.Sent),
                    Recv = y.Sum(z => z.Recv)
                }).ToList();

                for (int i = 0; i < duration; i++)
                {
                    var _time = time.AddSeconds(i);
                    var val   = data.Where(x => x.Time == _time.Ticks).FirstOrDefault();
                    if (val != null)
                    {
                        SentValues.Add(new DateTimePoint(_time, val.Sent));
                        RecvValues.Add(new DateTimePoint(_time, val.Recv));
                    }
                    else
                    {
                        SentValues.Add(new DateTimePoint(_time, 0));
                        RecvValues.Add(new DateTimePoint(_time, 0));
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void Run(object sender, EventArgs e)
        {
            Task.Run(() =>
            {
                var NetGraphValues  = GetLast2NetValues();
                var ProcGraphValues = GetLast2ProcValues();
                bool IsScrolling, AtStart, AtEnd, IsActive, IsExpanded;
                IsScrolling = AtStart = AtEnd = IsActive = IsExpanded = false;

                Dispatcher.BeginInvoke(new Action(() =>
                {
                    IsActive    = mainWindow.IsVisible && mainWindow.MainTabControl.SelectedIndex == 0;
                    IsScrolling = ScrollChart.IsMouseCaptureWithin;
                    AtStart     = ScrollChart.ScrollHorizontalTo > DateTime.Now.AddSeconds(-10).Ticks;
                    AtEnd       = ScrollChart.ScrollHorizontalFrom < DateTime.Now.AddSeconds(-duration).Ticks;
                    IsExpanded  = DataGridExpander.IsExpanded;
                })).Wait();

                Dispatcher.BeginInvoke(new Action(() =>
                {
                    SentValues.RemoveAt(SentValues.Count - 1);
                    RecvValues.RemoveAt(RecvValues.Count - 1);
                    ProcLoadValues.RemoveAt(ProcLoadValues.Count - 1);
                    SentValues.RemoveAt(0);
                    RecvValues.RemoveAt(0);
                    ProcLoadValues.RemoveAt(0);
                    SentValues.Add(NetGraphValues[0]);
                    RecvValues.Add(NetGraphValues[1]);
                    SentValues.Add(NetGraphValues[2]);
                    RecvValues.Add(NetGraphValues[3]);
                    ProcLoadValues.AddRange(ProcGraphValues);

                    if (!IsScrolling)
                    {
                        if (AtStart)
                        {
                            ScrollChart.ScrollHorizontalFrom = From = DateTime.Now.AddSeconds(-61).Ticks;
                            ScrollChart.ScrollHorizontalTo   = To = DateTime.Now.AddSeconds(-1).Ticks;
                        }
                        else if (AtEnd)
                        {
                            ScrollChart.ScrollHorizontalFrom = From = DateTime.Now.AddSeconds(-duration).Ticks;
                            ScrollChart.ScrollHorizontalTo   = To = DateTime.Now.AddSeconds(-duration + 60).Ticks;
                        }
                    }
                }));

                Task.Run(() =>
                {
                    if (IsActive && IsExpanded && !IsScrolling && (AtEnd || AtStart))
                    {
                        UpdateDataGrid();
                    }
                });
            });
        }