跳到主要内容

github/tai

公开

Tai · Windows 软件与网站使用时长统计。上游 Planshit/Tai 的源码镜像,非灵栈原创;MIT 许可。来源:https://github.com/Planshit/Tai 。本次为手动同步,暂不提供安装包。

提交记录
修改Core/Servicers/Instances/Data.cs+10 −28看文件
@@ -1,5 +1,6 @@
11using Core.Librarys.SQLite;
22using Core.Models;
3新增:using Core.Models.Config;
34using Core.Servicers.Interfaces;
45using System;
56using System.Collections.Generic;
@@ -11,10 +12,9 @@ namespace Core.Servicers.Instances
1112{
1213 public class Data : IData
1314 {
14删除:
1515 public void Set(string processName, string processDescription, string file, int seconds)
1616 {
17删除: if (string.IsNullOrEmpty(processName) || string.IsNullOrEmpty(file) || seconds <= 0)
17新增: if (string.IsNullOrEmpty(processName) || seconds <= 0)
1818 {
1919 return;
2020 }
@@ -22,7 +22,7 @@ namespace Core.Servicers.Instances
2222 using (var db = new StatisticContext())
2323 {
2424 var today = DateTime.Now.Date;
25删除: var res = db.DailyLog.SingleOrDefault(m => m.Date == today && m.ProcessName == processName && m.ProcessDescription == processDescription && m.File == file);
25新增: var res = db.DailyLog.SingleOrDefault(m => m.Date == today && m.ProcessName == processName);
2626 if (res == null)
2727 {
2828 //数据库中没有时则创建
@@ -48,7 +48,7 @@ namespace Core.Servicers.Instances
4848 m =>
4949 m.DataTime == nowtime
5050 && m.ProcessName == processName
51删除: && m.File == file);
51新增: );
5252 if (hourslog == null)
5353 {
5454 // 没有时创建
@@ -85,7 +85,7 @@ namespace Core.Servicers.Instances
8585 using (var db = new StatisticContext())
8686 {
8787 var today = DateTime.Now.Date;
88删除: var res = db.DailyLog.SqlQuery("Select Sum(Time) as Time,ProcessName,File,ID,Date,ProcessDescription from DailyLogModels WHERE Date between '" + start.ToString("yyyy-MM-dd HH:mm:ss") + "' AND '" + end.ToString("yyyy-MM-dd HH:mm:ss") + "' GROUP BY ProcessName,File ").ToList();
88新增: var res = db.DailyLog.SqlQuery("Select Sum(Time) as Time,ProcessName,File,ID,Date,ProcessDescription from DailyLogModels WHERE Date between '" + start.ToString("yyyy-MM-dd HH:mm:ss") + "' AND '" + end.ToString("yyyy-MM-dd HH:mm:ss") + "' GROUP BY ProcessName ").ToList();
8989 return res.ToList();
9090 }
9191 }
@@ -162,7 +162,7 @@ namespace Core.Servicers.Instances
162162 }
163163 }
164164
165删除: public List<DailyLogModel> GetProcessMonthLogList(string file, DateTime month)
165新增: public List<DailyLogModel> GetProcessMonthLogList(string processName, DateTime month)
166166 {
167167 using (var db = new StatisticContext())
168168 {
@@ -171,9 +171,9 @@ namespace Core.Servicers.Instances
171171 m =>
172172 m.Date.Year == month.Year
173173 && m.Date.Month == month.Month
174删除: //&& m.ProcessName == processName
174新增: && m.ProcessName == processName
175175 //&& m.ProcessDescription == processDescription
176删除: && m.File == file
176新增: //&& m.File == file
177177 );
178178 if (res != null)
179179 {
@@ -183,26 +183,10 @@ namespace Core.Servicers.Instances
183183 }
184184 }
185185
186删除: public DailyLogModel GetLast(string file)
187删除: {
188删除: using (var db = new StatisticContext())
189删除: {
190186
191删除: var res = db.DailyLog.Where(
192删除: m =>
193删除: m.File == file
194删除: ).OrderByDescending(m => m.ID).Take(1);
195删除: if (res != null)
196删除: {
197删除: return res.FirstOrDefault();
198删除: }
199删除: return null;
200删除: }
201删除: }
202删除:
203删除: public void Clear(string processName, string file, DateTime month)
187新增: public void Clear(string processName, DateTime month)
204188 {
205删除: if (string.IsNullOrEmpty(processName) || string.IsNullOrEmpty(file))
189新增: if (string.IsNullOrEmpty(processName))
206190 {
207191 return;
208192 }
@@ -212,10 +196,8 @@ namespace Core.Servicers.Instances
212196 db.DailyLog.RemoveRange(
213197 db.DailyLog.Where(m =>
214198 m.ProcessName == processName
215删除: && m.File == file
216199 && m.Date.Year == month.Year
217200 && m.Date.Month == month.Month));
218删除:
219201 db.SaveChanges();
220202 }
221203 }
修改Core/Servicers/Interfaces/IData.cs+3 −10看文件
@@ -51,24 +51,17 @@ namespace Core.Servicers.Interfaces
5151 /// <summary>
5252 /// 获取指定进程某个月的数据
5353 /// </summary>
54删除: /// <param name="file"></param>
54新增: /// <param name="processName"></param>
5555 /// <param name="month"></param>
5656 /// <returns></returns>
57删除: List<DailyLogModel> GetProcessMonthLogList(string file, DateTime month);
57新增: List<DailyLogModel> GetProcessMonthLogList(string processName, DateTime month);
5858
59删除: /// <summary>
60删除: /// 获取一个进程最后一条记录
61删除: /// </summary>
62删除: /// <param name="file"></param>
63删除: /// <returns></returns>
64删除: DailyLogModel GetLast(string file);
6559
6660 /// <summary>
6761 /// 清空指定进程某月的数据
6862 /// </summary>
6963 /// <param name="processName"></param>
70删除: /// <param name="file"></param>
71删除: void Clear(string processName, string file, DateTime month);
64新增: void Clear(string processName, DateTime month);
7265
7366 /// <summary>
7467 /// 获取指定进程某天的数据
修改UI/ViewModels/DetailPageVM.cs+6 −4看文件
@@ -1,4 +1,5 @@
11using Core.Librarys;
2新增:using Core.Models;
23using Core.Models.Config;
34using Core.Servicers.Interfaces;
45using System;
@@ -126,7 +127,7 @@ namespace UI.ViewModels
126127 {
127128 if (Process != null)
128129 {
129删除: var info = data.GetLast(Process.PopupText);
130新增: var info = Process.Data as DailyLogModel;
130131 if (info != null)
131132 {
132133 ProcessName = info.ProcessName;
@@ -186,8 +187,8 @@ namespace UI.ViewModels
186187 {
187188 if (Process != null)
188189 {
189删除:
190删除: var monthData = data.GetProcessMonthLogList(Process.PopupText, Date);
190新增: var info = Process.Data as DailyLogModel;
191新增: var monthData = data.GetProcessMonthLogList(info.ProcessName, Date);
191192 int monthTotal = monthData.Sum(m => m.Time);
192193 Total = Timer.Fromat(monthTotal);
193194
@@ -232,7 +233,7 @@ namespace UI.ViewModels
232233 if (Process != null)
233234 {
234235 main.Toast("正在处理");
235删除: data.Clear(ProcessName, Process.PopupText, Date);
236新增: data.Clear(ProcessName, Date);
236237
237238 await LoadData();
238239 await LoadInfo();
@@ -250,6 +251,7 @@ namespace UI.ViewModels
250251 foreach (var item in list)
251252 {
252253 var bindModel = new ChartsDataModel();
254新增: bindModel.Data = item;
253255 bindModel.Name = string.IsNullOrEmpty(item.ProcessDescription) ? item.ProcessName : item.ProcessDescription;
254256 bindModel.Value = item.Time;
255257 bindModel.Tag = Timer.Fromat(item.Time);