Update StatisticsHandler.cs

pull/70/head
2dust 2019-08-29 17:30:44 +08:00
parent 3cdff624ba
commit 3154df1bde
1 changed files with 116 additions and 66 deletions

View File

@ -80,9 +80,17 @@ namespace v2rayN.Handler
public void Close() public void Close()
{ {
try
{
exitFlag_ = true; exitFlag_ = true;
channel_.ShutdownAsync(); channel_.ShutdownAsync();
} }
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
}
}
public void run() public void run()
{ {
@ -92,11 +100,22 @@ namespace v2rayN.Handler
{ {
if (enabled_ && channel_.State == ChannelState.Ready) if (enabled_ && channel_.State == ChannelState.Ready)
{ {
var res = client_.QueryStats(new QueryStatsRequest() { Pattern = "", Reset = true }); QueryStatsResponse res = null;
try
{
res = client_.QueryStats(new QueryStatsRequest() { Pattern = "", Reset = true });
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
}
if (res != null)
{
var addr = config_.address(); var addr = config_.address();
var port = config_.port(); var port = config_.port();
var cur = Statistic.FindIndex(item => item.address == addr && item.port == port); var path = config_.path();
var cur = Statistic.FindIndex(item => item.address == addr && item.port == port && item.path == path);
ulong up = 0, ulong up = 0,
down = 0; down = 0;
@ -119,11 +138,16 @@ namespace v2rayN.Handler
if (UpdateUI) if (UpdateUI)
updateFunc_(TotalUp, TotalDown, Up, Down, Statistic); updateFunc_(TotalUp, TotalDown, Up, Down, Statistic);
}
Thread.Sleep(config_.statisticsFreshRate); Thread.Sleep(config_.statisticsFreshRate);
channel_.ConnectAsync(); channel_.ConnectAsync();
} }
} }
catch { } catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
}
} }
} }
@ -131,6 +155,8 @@ namespace v2rayN.Handler
{ {
up = 0; down = 0; up = 0; down = 0;
try
{
foreach (var stat in source) foreach (var stat in source)
{ {
@ -157,6 +183,11 @@ namespace v2rayN.Handler
} }
} }
} }
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
}
}
public void saveToFile() public void saveToFile()
{ {
@ -190,7 +221,10 @@ namespace v2rayN.Handler
} }
} }
} }
catch { } catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
}
// 当天流量记录文件 // 当天流量记录文件
var dailyPath = Path.Combine(logPath_, $"{DateTime.Now.ToLongDateString()}.txt"); var dailyPath = Path.Combine(logPath_, $"{DateTime.Now.ToLongDateString()}.txt");
@ -209,7 +243,10 @@ namespace v2rayN.Handler
} }
} }
} }
catch { } catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
}
} }
public void loadFromFile() public void loadFromFile()
@ -278,7 +315,10 @@ namespace v2rayN.Handler
} }
} }
} }
catch { } catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
}
} }
// 当天流量记录文件 // 当天流量记录文件
@ -324,12 +364,17 @@ namespace v2rayN.Handler
} }
} }
} }
catch { } catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
}
} }
} }
private void DeleteExpiredLog() private void DeleteExpiredLog()
{
try
{ {
if (!Directory.Exists(logPath_)) return; if (!Directory.Exists(logPath_)) return;
var dirInfo = new DirectoryInfo(logPath_); var dirInfo = new DirectoryInfo(logPath_);
@ -347,5 +392,10 @@ namespace v2rayN.Handler
} }
} }
} }
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
}
}
} }
} }