Skip to content

Commit

Permalink
修复未启用网站统计时进入睡眠状态程序崩溃的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
noberumotto committed Oct 26, 2023
1 parent f958fa6 commit 14dd487
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 42 deletions.
4 changes: 2 additions & 2 deletions Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.3")]
[assembly: AssemblyFileVersion("1.1.0.3")]
[assembly: AssemblyVersion("1.1.0.4")]
[assembly: AssemblyFileVersion("1.1.0.4")]
72 changes: 42 additions & 30 deletions Core/Servicers/Instances/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private void Sleepdiscover_SleepStatusChanged(Enums.SleepStatus sleepStatus)
Debug.WriteLine("进入睡眠状态");

// 通知sokcet客户端
_webServer.SendMsg("sleep");
_webServer?.SendMsg("sleep");
// 停止服务
Stop();

Expand All @@ -263,7 +263,7 @@ private void Sleepdiscover_SleepStatusChanged(Enums.SleepStatus sleepStatus)
// 从睡眠状态唤醒
Debug.WriteLine("从睡眠状态唤醒");

_webServer.SendMsg("wake");
_webServer?.SendMsg("wake");

Start();
}
Expand Down Expand Up @@ -457,47 +457,59 @@ private void UpdateAppDuration(AppDurationUpdatedEventArgs e)
{
if (e == null) return;

var app = e.App;
int duration = e.Duration;
DateTime startTime = e.ActiveTime;
try
{
var app = e.App;
int duration = e.Duration;
DateTime startTime = e.ActiveTime;

bool isCheck = IsCheckApp(app.Process, app.Description, app.ExecutablePath);
if (isCheck)
bool isCheck = IsCheckApp(app.Process, app.Description, app.ExecutablePath);
if (isCheck)
{
// 更新统计时长
data.UpdateAppDuration(app.Process, duration, startTime);
// 关联进程更新
HandleLinks(app.Process, duration, startTime);
OnUpdateTime?.Invoke(this, null);
}
}
catch (Exception ex)
{
// 更新统计时长
data.UpdateAppDuration(app.Process, duration, startTime);
// 关联进程更新
HandleLinks(app.Process, duration, startTime);
OnUpdateTime?.Invoke(this, null);
Logger.Error(ex.ToString());
}
}

#region 浏览器记录
private void WebSocketEvent_OnWebLog(Models.WebPage.NotifyWeb args)
{
if (_webFilter.IsIgnore(args.Url))
try
{
Debug.WriteLine($"URL已被过滤,{args.Url}");
return;
}
if (_webFilter.IsIgnore(args.Url))
{
Debug.WriteLine($"URL已被过滤,{args.Url}");
return;
}

// 记录数据
var site = new Models.WebPage.Site()
{
Url = args.Url,
Title = args.Title
};
// 记录数据
var site = new Models.WebPage.Site()
{
Url = args.Url,
Title = args.Title
};

_webData.AddUrlBrowseTime(site, args.Duration, args.ActiveDateTime);
_webData.AddUrlBrowseTime(site, args.Duration, args.ActiveDateTime);

// 处理图标
Task.Run(async () =>
// 处理图标
Task.Run(async () =>
{
string saveName = UrlHelper.GetName(args.Url) + DateTime.Now.ToString("yyyyMM") + ".ico";
string path = await FaviconDownloader.DownloadAsync(args.Icon, saveName);
_webData.UpdateUrlFavicon(site, path);
});
}catch(Exception ex)
{
string saveName = UrlHelper.GetName(args.Url) + DateTime.Now.ToString("yyyyMM") + ".ico";
string path = await FaviconDownloader.DownloadAsync(args.Icon, saveName);
_webData.UpdateUrlFavicon(site, path);
});

Logger.Error(ex.ToString());
}
}
#endregion
}
Expand Down
4 changes: 2 additions & 2 deletions Core/Servicers/Instances/Sleepdiscover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ private void StartTimer()
{
StopTimer();
timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, 10);
//timer.Interval = new TimeSpan(0, 5, 0);
//timer.Interval = new TimeSpan(0, 0, 10);
timer.Interval = new TimeSpan(0, 5, 0);
timer.Tick += Timer_Tick;
timer.Start();
}
Expand Down
29 changes: 23 additions & 6 deletions Core/Servicers/Instances/WebServer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Core.Event;
using Core.Librarys;
using Core.Librarys.Browser;
using Core.Models.WebPage;
using Core.Servicers.Interfaces;
Expand All @@ -23,22 +24,38 @@ public class WebServer : WebSocketBehavior, IWebServer
public void Start()
{
if (_isStart) return;
_webSocket = new WebSocketServer(8908, false);
_webSocket.AddWebSocketService<WebServer>("/TaiWebSentry");
_webSocket.Start();
_isStart = true;
try
{
_webSocket = new WebSocketServer(8908, false);
_webSocket.AddWebSocketService<WebServer>("/TaiWebSentry");
_webSocket.Start();
_isStart = true;
}
catch (Exception ex)
{
Librarys.Logger.Error("无法启动浏览器服务," + ex);
}
}

public void Stop()
{
if (!_isStart) return;
_webSocket.Stop();
_webSocket?.Stop();
_isStart = false;
}

public void SendMsg(string msg_)
{
_webSocket.WebSocketServices.Broadcast(msg_);
try
{
if (!_isStart) return;

_webSocket.WebSocketServices.Broadcast(msg_);
}
catch (Exception ec)
{
Librarys.Logger.Error(ec.ToString());
}
}


Expand Down
4 changes: 2 additions & 2 deletions UI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.5.0.3")]
[assembly: AssemblyFileVersion("1.5.0.3")]
[assembly: AssemblyVersion("1.5.0.4")]
[assembly: AssemblyFileVersion("1.5.0.4")]

0 comments on commit 14dd487

Please sign in to comment.