Exemplo n.º 1
0
        public async Task <string> InsertLogForAllMeters()
        {
            var meters = await _trafficMeterRepoistory.GetAllAsync();

            if (meters != null)
            {
                foreach (var meter in meters)
                {
                    if (meter != null)
                    {
                        //var newCongestion = await UpdateCongestionLevel(meter);
                        meter.Congestion = (int)CongestionTypes.Low;

                        await _trafficMeterRepoistory.UpdateAsync(meter);

                        Random rand = new Random();

                        TrafficLog newLog = new TrafficLog
                        {
                            MeterId = meter.Id,
                            Time    = DateTime.Now,
                            Speed   = rand.Next(40, 130)
                        };

                        await _trafficLogRepoistory.InsertAsync(newLog);

                        _traffixUpdateProvider.MeterUpdated(meter.Region, meter, newLog);
                    }
                }
                return("LOGS ADDED");
            }
            throw new HttpResponseException(HttpStatusCode.BadRequest);
        }
Exemplo n.º 2
0
        //public object ExecuteScalar(string query, ParameterType[] parameters)
        //{
        //    return ExecuteScalar(ConnectionStringSet, System.Data.CommandType.StoredProcedure, query, parameters);
        //}
        //public object ExecuteScalar(System.Data.CommandType commandType, string query, ParameterType[] parameters)
        //{
        //    return ExecuteScalar(ConnectionStringSet, commandType, query, parameters);
        //}
        //public object ExecuteScalar(string connectionString, string query, ParameterType[] parameters)
        //{
        //    return ExecuteScalar(connectionString, System.Data.CommandType.StoredProcedure, query, parameters);
        //}
        //public object ExecuteScalar(string connectionString, System.Data.CommandType commandType, string query, ParameterType[] parameters)
        //{
        //    object result = null;
        //    using (var connection = new ConnectionType())
        //    using (var command = new CommandType())
        //    {
        //        command.Connection = connection;
        //        command.CommandText = query;
        //        command.CommandType = commandType;
        //        if (parameters != null)
        //            Array.ForEach(parameters, p => command.Parameters.Add(p));

        //        connection.ConnectionString = connectionString;
        //        connection.Open();
        //        result = command.ExecuteScalar();
        //    }
        //    return result;
        //}

        // LogWrite

        public void writeLog(string query, ParameterType[] parameters)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("exec " + query + " ");

            if (parameters != null)
            {
                for (int i = 0; i < parameters.Length; i++)
                {
                    if (parameters[i].ParameterName.ToString().Contains("date") || parameters[i].ParameterName.ToString().Contains("created"))
                    {
                        parameters[i].Value = ((DateTime)parameters[i].Value).ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    sb.Append(parameters[i].ParameterName + " = '" + parameters[i].Value + "'");
                    if (i + 1 < parameters.Length)
                    {
                        sb.Append(", ");
                    }
                }
            }
            var trafficLog = new TrafficLog();

            trafficLog.Created  = DateTime.Now;
            trafficLog.CodeText = sb.ToString();
            trafficLog.LogType  = LogType.Write;

            DAL.SDK.Kit.Instance.TrafficLogs.WriteLog(trafficLog);
        }
Exemplo n.º 3
0
        public async Task <string> InsertLog(InsertLogRequest data)
        {
            var auth = await _authRepository.GetByIdAsync(1);

            if (auth.Secret == data.Key)
            {
                var meter = await _trafficMeterRepoistory.GetByIdAsync(data.MeterId);

                if (meter != null)
                {
                    var newCongestion = await UpdateCongestionLevel(meter);

                    meter.Congestion = (int)newCongestion;

                    await _trafficMeterRepoistory.UpdateAsync(meter);

                    TrafficLog newLog = new TrafficLog
                    {
                        MeterId = meter.Id,
                        Time    = data.Timestamp,
                        Speed   = (int)data.Speed
                    };

                    await _trafficLogRepoistory.InsertAsync(newLog);

                    _traffixUpdateProvider.MeterUpdated(meter.Region, meter, newLog);
                    return("LOG ADDED");
                }
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            throw new HttpResponseException(HttpStatusCode.Unauthorized);
        }
Exemplo n.º 4
0
        private void UpdateTrafficList()
        {
            lock (_trafficLogList)
            {
                int trafficLogSize = this.trafficLogSize;
                if (trafficLogSize < 1)
                {
                    trafficLogSize = 1;
                }
                TrafficLog previous = _trafficLogList.Last.Value;
                TrafficLog current  = new TrafficLog(
                    new Traffic(traffic.raw),
                    new Traffic(traffic.raw, previous.raw),
                    new Traffic(traffic.kcp),
                    new Traffic(traffic.kcp, previous.kcp));
                _trafficLogList.AddLast(current);

                while (_trafficLogList.Count > trafficLogSize)
                {
                    _trafficLogList.RemoveFirst();
                }
                while (_trafficLogList.Count < trafficLogSize)
                {
                    _trafficLogList.AddFirst(new TrafficLog());
                }
            }
        }
        protected internal string GetErrorInfo(Exception exception)
        {
            var json = JsonConvert.SerializeObject(TrafficLog.List().First(), Formatting.Indented);

            var errorInfo = string.Format("\r\n---\r\n{0}\r\n---\r\n{1}", exception, json);

            return(errorInfo);
        }
Exemplo n.º 6
0
 public void InsertTrafficLog(TrafficLog trafficLog)
 {
     _dbWriteLog.ExecuteNonQueryLog("TrafficLogsInsert",
                                    new[] {
         new SqlParameter("@CodeText", trafficLog.CodeText),
         new SqlParameter("@Created", trafficLog.Created),
         new SqlParameter("@LogType", trafficLog.LogType)
     }
                                    );
 }
        private void UpdateTrafficChart()
        {
            long maxSpeedValue = 0;

            rawInboundPoints.Clear();
            rawOutboundPoints.Clear();
            kcpInboundPoints.Clear();
            kcpOutboundPoints.Clear();
            foreach (TrafficLog item in controller.trafficLogList)
            {
                rawInboundPoints.Add(item.rawSpeed.inbound);
                rawOutboundPoints.Add(item.rawSpeed.outbound);
                kcpInboundPoints.Add(item.kcpSpeed.inbound);
                kcpOutboundPoints.Add(item.kcpSpeed.outbound);

                maxSpeedValue = Math.Max(maxSpeedValue,
                                         Math.Max(
                                             Math.Max(item.rawSpeed.inbound, item.rawSpeed.outbound),
                                             Math.Max(item.kcpSpeed.inbound, item.kcpSpeed.outbound)
                                             )
                                         );
            }

            TrafficSpeed maxSpeed = new TrafficSpeed(maxSpeedValue);
            TrafficLog   last     = controller.trafficLogList.Last.Value;

            SpeedStatusLabel.Text             = SpeedStatusLabel.ToolTipText
                                              = string.Format(I18N.GetString("Raw: [In {0}, Out {1}], KCP: [In {2}, Out {3}]"),
                                                              new TrafficSpeed(last.rawSpeed.inbound),
                                                              new TrafficSpeed(last.rawSpeed.outbound),
                                                              new TrafficSpeed(last.kcpSpeed.inbound),
                                                              new TrafficSpeed(last.kcpSpeed.outbound));

            for (int i = 0; i < rawInboundPoints.Count; i++)
            {
                rawInboundPoints[i]  /= maxSpeed.scale;
                rawOutboundPoints[i] /= maxSpeed.scale;
                kcpInboundPoints[i]  /= maxSpeed.scale;
                kcpOutboundPoints[i] /= maxSpeed.scale;
            }

            TrafficChart.Series[0].Points.DataBindY(rawInboundPoints);
            TrafficChart.Series[1].Points.DataBindY(rawOutboundPoints);
            TrafficChart.Series[2].Points.DataBindY(kcpInboundPoints);
            TrafficChart.Series[3].Points.DataBindY(kcpOutboundPoints);
            TrafficChart.Series[0].ToolTip = "#SERIESNAME #VALY{F2} " + maxSpeed.unit;
            TrafficChart.Series[1].ToolTip = "#SERIESNAME #VALY{F2} " + maxSpeed.unit;
            TrafficChart.Series[2].ToolTip = "#SERIESNAME #VALY{F2} " + maxSpeed.unit;
            TrafficChart.Series[3].ToolTip = "#SERIESNAME #VALY{F2} " + maxSpeed.unit;
            TrafficChart.ChartAreas[0].AxisY.LabelStyle.Format = "{0:0.##} " + maxSpeed.unit;
        }
Exemplo n.º 8
0
        private void UpdateTrafficList()
        {
            TrafficLog previous = trafficLogList.Last.Value;
            TrafficLog current  = new TrafficLog(
                new Traffic(traffic.raw),
                new Traffic(traffic.raw, previous.raw),
                new Traffic(traffic.kcp),
                new Traffic(traffic.kcp, previous.kcp));

            trafficLogList.AddLast(current);

            while (trafficLogList.Count > trafficLogSize)
            {
                trafficLogList.RemoveFirst();
            }
            while (trafficLogList.Count < trafficLogSize)
            {
                trafficLogList.AddFirst(new TrafficLog());
            }
        }
Exemplo n.º 9
0
 public void MeterUpdated(string region, TrafficMeter meter, TrafficLog log)
 {
     Clients.All.meterUpdated(region, meter, log);
 }
Exemplo n.º 10
0
 public CommandLineOptionsWithLog(ILogWriter writer, ILogTableRequestResponse logTableRequestResponse, params string[] args) : base(args)
 {
     this.log        = new ConsoleNotifier(this.verboseLoggingEnabled(), writer);
     this.trafficLog = new TrafficLog(args.Contains("--print-all-network-traffic"), writer, logTableRequestResponse);
 }
Exemplo n.º 11
0
 public void WriteLog(TrafficLog trafficLog)
 {
     _repository.InsertTrafficLog(trafficLog);
 }