Exemple #1
0
        private void UpdateRecords()
        {
            var records = new Dictionary <string, StatisticsRecord>();
            UpdateRecordsState state = new UpdateRecordsState();
            int serverCount          = _controller.GetCurrentConfiguration().configs.Count;

            state.counter = serverCount;
            bool isPing = Config.Ping;

            for (int i = 0; i < serverCount; i++)
            {
                try
                {
                    var        server = _controller.GetCurrentConfiguration().configs[i];
                    var        id     = server.Identifier();
                    List <int> inboundSpeedRecords  = null;
                    List <int> outboundSpeedRecords = null;
                    List <int> latencyRecords       = null;
                    _inboundSpeedRecords.TryGetValue(id, out inboundSpeedRecords);
                    _outboundSpeedRecords.TryGetValue(id, out outboundSpeedRecords);
                    _latencyRecords.TryGetValue(id, out latencyRecords);
                    StatisticsRecord record = new StatisticsRecord(id, inboundSpeedRecords, outboundSpeedRecords, latencyRecords);
                    /* duplicate server identifier */
                    if (records.ContainsKey(id))
                    {
                        records[id] = record;
                    }
                    else
                    {
                        records.Add(id, record);
                    }
                    if (isPing)
                    {
                        // FIXME: on ping completed, every thing could be asynchrously changed.
                        // focus on: Config/ RawStatistics
                        MyPing ping = new MyPing(server, Repeat);
                        ping.Completed += ping_Completed;
                        ping.Start(new PingState {
                            state = state, record = record
                        });
                    }
                    else if (!record.IsEmptyData())
                    {
                        AppendRecord(id, record);
                    }
                }
                catch (Exception e)
                {
                    Logging.Debug("config changed asynchrously, just ignore this server");
                }
            }

            if (!isPing)
            {
                Save();
                FilterRawStatistics();
            }
        }
Exemple #2
0
        private void UpdateRecords()
        {
            var records = new Dictionary <string, StatisticsRecord>();
            UpdateRecordsState state = new UpdateRecordsState();

            state.counter = _controller.GetCurrentConfiguration().configs.Count;
            foreach (var server in _controller.GetCurrentConfiguration().configs)
            {
                var        id = server.Identifier();
                List <int> inboundSpeedRecords  = null;
                List <int> outboundSpeedRecords = null;
                List <int> latencyRecords       = null;
                _inboundSpeedRecords.TryGetValue(id, out inboundSpeedRecords);
                _outboundSpeedRecords.TryGetValue(id, out outboundSpeedRecords);
                _latencyRecords.TryGetValue(id, out latencyRecords);
                StatisticsRecord record = new StatisticsRecord(id, inboundSpeedRecords, outboundSpeedRecords, latencyRecords);
                /* duplicate server identifier */
                if (records.ContainsKey(id))
                {
                    records[id] = record;
                }
                else
                {
                    records.Add(id, record);
                }
                if (Config.Ping)
                {
                    MyPing ping = new MyPing(server, Repeat);
                    ping.Completed += ping_Completed;
                    ping.Start(new PingState {
                        state = state, record = record
                    });
                }
                else if (!record.IsEmptyData())
                {
                    AppendRecord(id, record);
                }
            }

            if (!Config.Ping)
            {
                Save();
                FilterRawStatistics();
            }
        }
Exemple #3
0
        private void ping_Completed(object sender, MyPing.CompletedEventArgs e)
        {
            PingState          pingState = (PingState)e.UserState;
            UpdateRecordsState state     = pingState.state;
            Server             server    = e.Server;
            StatisticsRecord   record    = pingState.record;

            record.SetResponse(e.RoundtripTime);
            if (!record.IsEmptyData())
            {
                AppendRecord(server.Identifier(), record);
            }
            Logging.Debug($"Ping {server.FriendlyName()} {e.RoundtripTime.Count} times, {(100 - record.PackageLoss * 100)}% packages loss, min {record.MinResponse} ms, max {record.MaxResponse} ms, avg {record.AverageResponse} ms");
            if (Interlocked.Decrement(ref state.counter) == 0)
            {
                Save();
                FilterRawStatistics();
            }
        }
        private void UpdateRecords()
        {
            var records = new Dictionary<string, StatisticsRecord>();
            UpdateRecordsState state = new UpdateRecordsState();
            state.counter = _controller.GetCurrentConfiguration().configs.Count;
            foreach (var server in _controller.GetCurrentConfiguration().configs)
            {
                var id = server.Identifier();
                List<int> inboundSpeedRecords = null;
                List<int> outboundSpeedRecords = null;
                List<int> latencyRecords = null;
                _inboundSpeedRecords.TryGetValue(id, out inboundSpeedRecords);
                _outboundSpeedRecords.TryGetValue(id, out outboundSpeedRecords);
                _latencyRecords.TryGetValue(id, out latencyRecords);
                StatisticsRecord record = new StatisticsRecord(id, inboundSpeedRecords, outboundSpeedRecords, latencyRecords);
                /* duplicate server identifier */
                if (records.ContainsKey(id))
                    records[id] = record;
                else
                    records.Add(id, record);
                if (Config.Ping)
                {
                    MyPing ping = new MyPing(server, Repeat);
                    ping.Completed += ping_Completed;
                    ping.Start(new PingState { state = state, record = record });
                }
                else if (!record.IsEmptyData())
                {
                    AppendRecord(id, record);
                }
            }

            if (!Config.Ping)
            {
                Save();
                FilterRawStatistics();
            }
        }