提交记录修改Core/Core.csproj+2 −2看文件
修改Core/Event/EventHandler.cs+1 −1看文件
修改Core/Servicers/Instances/Data.cs+15 −8看文件
改名Core/Servicers/Instances/DateObserver.cs → Core/Servicers/Instances/DateTimeObserver.cs+14 −18看文件
修改Core/Servicers/Instances/Main.cs+18 −39看文件
修改Core/Servicers/Interfaces/IData.cs+2 −2看文件
改名Core/Servicers/Interfaces/IDateObserver.cs → Core/Servicers/Interfaces/IDateTimeObserver.cs+5 −4看文件
修改UI/App.xaml.cs+1 −1看文件
| @@ -134,7 +134,7 @@ | ||
| 134 | 134 | <Compile Include="Servicers\Instances\Categorys.cs" /> |
| 135 | 135 | <Compile Include="Servicers\Instances\Data.cs" /> |
| 136 | 136 | <Compile Include="Librarys\Logger.cs" /> |
| 137 | 删除: <Compile Include="Servicers\Instances\DateObserver.cs" /> | |
| 137 | 新增: <Compile Include="Servicers\Instances\DateTimeObserver.cs" /> | |
| 138 | 138 | <Compile Include="Servicers\Instances\Main.cs" /> |
| 139 | 139 | <Compile Include="Servicers\Instances\Observer.cs" /> |
| 140 | 140 | <Compile Include="Servicers\Instances\Sleepdiscover.cs" /> |
| @@ -142,7 +142,7 @@ | ||
| 142 | 142 | <Compile Include="Servicers\Interfaces\ICategorys.cs" /> |
| 143 | 143 | <Compile Include="Servicers\Interfaces\IAppData.cs" /> |
| 144 | 144 | <Compile Include="Servicers\Interfaces\IData.cs" /> |
| 145 | 删除: <Compile Include="Servicers\Interfaces\IDateObserver.cs" /> | |
| 145 | 新增: <Compile Include="Servicers\Interfaces\IDateTimeObserver.cs" /> | |
| 146 | 146 | <Compile Include="Servicers\Interfaces\IMain.cs" /> |
| 147 | 147 | <Compile Include="Servicers\Interfaces\IObserver.cs" /> |
| 148 | 148 | <Compile Include="Servicers\Interfaces\ISleepdiscover.cs" /> |
| @@ -9,6 +9,6 @@ using System.Threading.Tasks; | ||
| 9 | 9 | namespace Core.Event |
| 10 | 10 | { |
| 11 | 11 | public delegate void SleepdiscoverEventHandler(SleepStatus sleepStatus); |
| 12 | 删除: | |
| 13 | 12 | public delegate void AppConfigEventHandler(ConfigModel oldConfig, ConfigModel newConfig); |
| 13 | 新增: public delegate void DateTimeObserverEventHandler(object sender, DateTime e); | |
| 14 | 14 | } |
| @@ -19,8 +19,14 @@ namespace Core.Servicers.Instances | ||
| 19 | 19 | { |
| 20 | 20 | this.appData = appData; |
| 21 | 21 | } |
| 22 | 删除: public void Set(string processName, string processDescription, string file, int seconds) | |
| 22 | 新增: public void Set(string processName, string processDescription, string file, int seconds, DateTime? time_ = null) | |
| 23 | 23 | { |
| 24 | 新增: DateTime time = !time_.HasValue ? DateTime.Now : time_.Value; | |
| 25 | 新增: var today = time.Date; | |
| 26 | 新增: | |
| 27 | 新增: // 当前时段 | |
| 28 | 新增: var nowtime = new DateTime(today.Year, today.Month, today.Day, time.Hour, 0, 0); | |
| 29 | 新增: | |
| 24 | 30 | if (string.IsNullOrEmpty(processName) || seconds <= 0) |
| 25 | 31 | { |
| 26 | 32 | return; |
| @@ -35,7 +41,7 @@ namespace Core.Servicers.Instances | ||
| 35 | 41 | } |
| 36 | 42 | |
| 37 | 43 | |
| 38 | 删除: var today = DateTime.Now.Date; | |
| 44 | 新增: | |
| 39 | 45 | using (var db = new TaiDbContext()) |
| 40 | 46 | { |
| 41 | 47 | var res = db.DailyLog.SingleOrDefault(m => m.Date == today && m.AppModelID == app.ID); |
| @@ -56,8 +62,6 @@ namespace Core.Servicers.Instances | ||
| 56 | 62 | |
| 57 | 63 | // 分时段记录数据 |
| 58 | 64 | |
| 59 | 删除: // 当前时段 | |
| 60 | 删除: var nowtime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, 0, 0); | |
| 61 | 65 | var hourslog = db.HoursLog.SingleOrDefault( |
| 62 | 66 | m => |
| 63 | 67 | m.DataTime == nowtime |
| @@ -185,8 +189,14 @@ namespace Core.Servicers.Instances | ||
| 185 | 189 | return GetDateRangelogList(weekStartDate, weekEndDate); |
| 186 | 190 | } |
| 187 | 191 | |
| 188 | 删除: public void Set(string processName, int seconds) | |
| 192 | 新增: public void Set(string processName, int seconds, DateTime? time_ = null) | |
| 189 | 193 | { |
| 194 | 新增: DateTime time = !time_.HasValue ? DateTime.Now : time_.Value; | |
| 195 | 新增: var today = time.Date; | |
| 196 | 新增: | |
| 197 | 新增: // 当前时段 | |
| 198 | 新增: var nowtime = new DateTime(today.Year, today.Month, today.Day, time.Hour, 0, 0); | |
| 199 | 新增: | |
| 190 | 200 | if (string.IsNullOrEmpty(processName) || seconds <= 0) |
| 191 | 201 | { |
| 192 | 202 | return; |
| @@ -200,7 +210,6 @@ namespace Core.Servicers.Instances | ||
| 200 | 210 | |
| 201 | 211 | using (var db = new TaiDbContext()) |
| 202 | 212 | { |
| 203 | 删除: var today = DateTime.Now.Date; | |
| 204 | 213 | var res = db.DailyLog.SingleOrDefault(m => m.Date == today && m.AppModelID == app.ID); |
| 205 | 214 | if (res != null) |
| 206 | 215 | { |
| @@ -209,8 +218,6 @@ namespace Core.Servicers.Instances | ||
| 209 | 218 | |
| 210 | 219 | // 分时段记录数据 |
| 211 | 220 | |
| 212 | 删除: // 当前时段 | |
| 213 | 删除: var nowtime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, 0, 0); | |
| 214 | 221 | var hourslog = db.HoursLog.SingleOrDefault( |
| 215 | 222 | m => |
| 216 | 223 | m.DataTime == nowtime |
| @@ -1,6 +1,8 @@ | ||
| 1 | 删除:using Core.Servicers.Interfaces; | |
| 1 | 新增:using Core.Event; | |
| 2 | 新增:using Core.Servicers.Interfaces; | |
| 2 | 3 | using System; |
| 3 | 4 | using System.Collections.Generic; |
| 5 | 新增:using System.Diagnostics; | |
| 4 | 6 | using System.Linq; |
| 5 | 7 | using System.Text; |
| 6 | 8 | using System.Threading.Tasks; |
| @@ -8,19 +10,11 @@ using System.Windows.Threading; | ||
| 8 | 10 | |
| 9 | 11 | namespace Core.Servicers.Instances |
| 10 | 12 | { |
| 11 | 删除: public class DateObserver : IDateObserver | |
| 13 | 新增: public class DateTimeObserver : IDateTimeObserver | |
| 12 | 14 | { |
| 13 | 删除: public event EventHandler OnDateChanging; | |
| 14 | 删除: | |
| 15 | 删除: | |
| 16 | 删除: | |
| 15 | 新增: public event DateTimeObserverEventHandler OnDateTimeChanging; | |
| 17 | 16 | private DispatcherTimer timer; |
| 18 | 17 | |
| 19 | 删除: public DateObserver() | |
| 20 | 删除: { | |
| 21 | 删除: } | |
| 22 | 删除: | |
| 23 | 删除: | |
| 24 | 18 | public void Start() |
| 25 | 19 | { |
| 26 | 20 | SetTimer(); |
| @@ -31,13 +25,13 @@ namespace Core.Servicers.Instances | ||
| 31 | 25 | timer = new DispatcherTimer(); |
| 32 | 26 | timer.Tick += Timer_Tick; |
| 33 | 27 | DateTime now = DateTime.Now; |
| 34 | 删除: DateTime tmorrow = new DateTime(now.Year, now.Month, now.Day, 23, 59, 30); | |
| 35 | 删除: int diffseconds = (int)tmorrow.Subtract(now).TotalSeconds; | |
| 36 | 删除: if (diffseconds < 0) | |
| 28 | 新增: DateTime updateTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, 59, 59); | |
| 29 | 新增: int diffMilliseconds = (int)updateTime.Subtract(now).TotalMilliseconds; | |
| 30 | 新增: if (diffMilliseconds < 0) | |
| 37 | 31 | { |
| 38 | 删除: diffseconds = 0; | |
| 32 | 新增: diffMilliseconds = 1; | |
| 39 | 33 | } |
| 40 | 删除: timer.Interval = new TimeSpan(0, 0, diffseconds); | |
| 34 | 新增: timer.Interval = new TimeSpan(0, 0, 0, 0, diffMilliseconds); | |
| 41 | 35 | timer.Start(); |
| 42 | 36 | } |
| 43 | 37 | |
| @@ -45,11 +39,13 @@ namespace Core.Servicers.Instances | ||
| 45 | 39 | { |
| 46 | 40 | timer.Stop(); |
| 47 | 41 | |
| 48 | 删除: OnDateChanging?.Invoke(this, EventArgs.Empty); | |
| 42 | 新增: DateTime nowTime = DateTime.Now; | |
| 43 | 新增: | |
| 44 | 新增: OnDateTimeChanging?.Invoke(this, nowTime); | |
| 49 | 45 | |
| 50 | 46 | await Task.Run(async () => |
| 51 | 47 | { |
| 52 | 删除: await Task.Delay(60000); | |
| 48 | 新增: await Task.Delay(1000); | |
| 53 | 49 | SetTimer(); |
| 54 | 50 | }); |
| 55 | 51 | } |
| @@ -23,7 +23,7 @@ namespace Core.Servicers.Instances | ||
| 23 | 23 | private readonly IData data; |
| 24 | 24 | private readonly ISleepdiscover sleepdiscover; |
| 25 | 25 | private readonly IAppConfig appConfig; |
| 26 | 删除: private readonly IDateObserver dateObserver; | |
| 26 | 新增: private readonly IDateTimeObserver dateTimeObserver; | |
| 27 | 27 | private readonly IAppData appData; |
| 28 | 28 | private readonly ICategorys categories; |
| 29 | 29 | // 忽略的进程 |
| @@ -49,10 +49,6 @@ namespace Core.Servicers.Instances | ||
| 49 | 49 | /// </summary> |
| 50 | 50 | private DateTime activeStartTime = DateTime.Now; |
| 51 | 51 | |
| 52 | 删除: ///// <summary> | |
| 53 | 删除: ///// 活动计时器 | |
| 54 | 删除: ///// </summary> | |
| 55 | 删除: //private Timer activeTimer; | |
| 56 | 52 | /// <summary> |
| 57 | 53 | /// 睡眠状态 |
| 58 | 54 | /// </summary> |
| @@ -64,46 +60,34 @@ namespace Core.Servicers.Instances | ||
| 64 | 60 | private ConfigModel config; |
| 65 | 61 | |
| 66 | 62 | public event EventHandler OnUpdateTime; |
| 67 | 删除: ///// <summary> | |
| 68 | 删除: ///// 当前焦点使用时长(秒) | |
| 69 | 删除: ///// </summary> | |
| 70 | 删除: //private int activeSeconds = 0; | |
| 63 | 新增: | |
| 71 | 64 | public Main( |
| 72 | 65 | IObserver observer, |
| 73 | 66 | IData data, |
| 74 | 67 | ISleepdiscover sleepdiscover, |
| 75 | 68 | IAppConfig appConfig, |
| 76 | 删除: IDateObserver dateObserver, | |
| 69 | 新增: IDateTimeObserver dateTimeObserver, | |
| 77 | 70 | IAppData appData, ICategorys categories) |
| 78 | 71 | { |
| 79 | 72 | this.observer = observer; |
| 80 | 73 | this.data = data; |
| 81 | 74 | this.sleepdiscover = sleepdiscover; |
| 82 | 75 | this.appConfig = appConfig; |
| 83 | 删除: this.dateObserver = dateObserver; | |
| 76 | 新增: this.dateTimeObserver = dateTimeObserver; | |
| 84 | 77 | this.appData = appData; |
| 85 | 78 | this.categories = categories; |
| 86 | 79 | |
| 87 | 80 | observer.OnAppActive += Observer_OnAppActive; |
| 88 | 81 | sleepdiscover.SleepStatusChanged += Sleepdiscover_SleepStatusChanged; |
| 89 | 删除: //activeTimer = new Timer(); | |
| 90 | 删除: //activeTimer.Interval = 1000; | |
| 91 | 删除: //activeTimer.Elapsed += ActiveTimer_Elapsed; | |
| 92 | 82 | appConfig.ConfigChanged += AppConfig_ConfigChanged; |
| 93 | 删除: dateObserver.OnDateChanging += DateObserver_OnDateChanging; | |
| 83 | 新增: dateTimeObserver.OnDateTimeChanging += DateTimeObserver_OnDateTimeChanging; | |
| 94 | 84 | } |
| 95 | 85 | |
| 96 | 删除: //private void ActiveTimer_Elapsed(object sender, ElapsedEventArgs e) | |
| 97 | 删除: //{ | |
| 98 | 删除: // activeSeconds++; | |
| 99 | 删除: //} | |
| 100 | 删除: | |
| 101 | 删除: private void DateObserver_OnDateChanging(object sender, EventArgs e) | |
| 86 | 新增: private void DateTimeObserver_OnDateTimeChanging(object sender, DateTime time) | |
| 102 | 87 | { |
| 103 | 88 | if (sleepStatus == SleepStatus.Wake) |
| 104 | 89 | { |
| 105 | 删除: Debug.WriteLine("日期变更前:" + DateTime.Now.ToString()); | |
| 106 | 删除: UpdateTime(); | |
| 90 | 新增: UpdateTime(time); | |
| 107 | 91 | } |
| 108 | 92 | } |
| 109 | 93 | |
| @@ -144,7 +128,7 @@ namespace Core.Servicers.Instances | ||
| 144 | 128 | config = appConfig.GetConfig(); |
| 145 | 129 | |
| 146 | 130 | // 日期变化观察 |
| 147 | 删除: dateObserver.Start(); | |
| 131 | 新增: dateTimeObserver.Start(); | |
| 148 | 132 | |
| 149 | 133 | // 启动进程观察 |
| 150 | 134 | observer.Start(); |
| @@ -249,7 +233,7 @@ namespace Core.Servicers.Instances | ||
| 249 | 233 | } |
| 250 | 234 | } |
| 251 | 235 | |
| 252 | 删除: private void HandleLinks(string processName, int seconds) | |
| 236 | 新增: private void HandleLinks(string processName, int seconds, DateTime? time = null) | |
| 253 | 237 | { |
| 254 | 238 | try |
| 255 | 239 | { |
| @@ -268,7 +252,7 @@ namespace Core.Servicers.Instances | ||
| 268 | 252 | if (IsProcessRuning(linkProcess)) |
| 269 | 253 | { |
| 270 | 254 | // 同步更新 |
| 271 | 删除: data.Set(linkProcess, seconds); | |
| 255 | 新增: data.Set(linkProcess, seconds, time); | |
| 272 | 256 | } |
| 273 | 257 | |
| 274 | 258 | } |
| @@ -297,7 +281,7 @@ namespace Core.Servicers.Instances | ||
| 297 | 281 | } |
| 298 | 282 | #endregion |
| 299 | 283 | |
| 300 | 删除: private void UpdateTime() | |
| 284 | 新增: private void UpdateTime(DateTime? time = null) | |
| 301 | 285 | { |
| 302 | 286 | if (!string.IsNullOrEmpty(activeProcess)) |
| 303 | 287 | { |
| @@ -312,24 +296,19 @@ namespace Core.Servicers.Instances | ||
| 312 | 296 | seconds -= 300; |
| 313 | 297 | } |
| 314 | 298 | |
| 315 | 删除: if (seconds <= 0) | |
| 299 | 新增: if (seconds > 0) | |
| 316 | 300 | { |
| 317 | 删除: return; | |
| 318 | 删除: } | |
| 301 | 新增: data.Set(activeProcess, activeProcessDescription, activeProcessFile, seconds, time); | |
| 319 | 302 | |
| 320 | 删除: | |
| 321 | 删除: | |
| 322 | 删除: Logger.Info("【" + sleepStatus + "】进程:" + activeProcess + " 更新时间:" + seconds + ",开始时间:" + activeStartTime.ToString() + ",当前时间:" + DateTime.Now.ToString()); | |
| 323 | 删除: | |
| 324 | 删除: | |
| 325 | 删除: data.Set(activeProcess, activeProcessDescription, activeProcessFile, seconds); | |
| 326 | 删除: | |
| 327 | 删除: // 关联进程更新 | |
| 328 | 删除: HandleLinks(activeProcess, seconds); | |
| 303 | 新增: // 关联进程更新 | |
| 304 | 新增: HandleLinks(activeProcess, seconds, time); | |
| 305 | 新增: } | |
| 329 | 306 | |
| 330 | 307 | activeStartTime = DateTime.Now; |
| 331 | 308 | |
| 332 | 309 | OnUpdateTime?.Invoke(this, null); |
| 310 | 新增: | |
| 311 | 新增: Logger.Info("【" + sleepStatus + "】进程:" + activeProcess + " 更新时间:" + seconds + ",开始时间:" + activeStartTime.ToString() + ",当前时间:" + DateTime.Now.ToString()); | |
| 333 | 312 | } |
| 334 | 313 | } |
| 335 | 314 | |
| @@ -18,7 +18,7 @@ namespace Core.Servicers.Interfaces | ||
| 18 | 18 | /// <param name="processDescription"></param> |
| 19 | 19 | /// <param name="file"></param> |
| 20 | 20 | /// <param name="seconds"></param> |
| 21 | 删除: void Set(string processName, string processDescription, string file, int seconds); | |
| 21 | 新增: void Set(string processName, string processDescription, string file, int seconds, DateTime? time = null); | |
| 22 | 22 | |
| 23 | 23 | /// <summary> |
| 24 | 24 | /// 获取今天的数据 |
| @@ -48,7 +48,7 @@ namespace Core.Servicers.Interfaces | ||
| 48 | 48 | /// </summary> |
| 49 | 49 | /// <param name="processName"></param> |
| 50 | 50 | /// <param name="seconds"></param> |
| 51 | 删除: void Set(string processName, int seconds); | |
| 51 | 新增: void Set(string processName, int seconds, DateTime? time = null); | |
| 52 | 52 | |
| 53 | 53 | /// <summary> |
| 54 | 54 | /// 获取指定进程某个月的数据 |
| @@ -1,4 +1,5 @@ | ||
| 1 | 删除:using System; | |
| 1 | 新增:using Core.Event; | |
| 2 | 新增:using System; | |
| 2 | 3 | using System.Collections.Generic; |
| 3 | 4 | using System.Linq; |
| 4 | 5 | using System.Text; |
| @@ -9,15 +10,15 @@ namespace Core.Servicers.Interfaces | ||
| 9 | 10 | /// <summary> |
| 10 | 11 | /// 日期变更观察(用于监听日期变化 |
| 11 | 12 | /// </summary> |
| 12 | 删除: public interface IDateObserver | |
| 13 | 新增: public interface IDateTimeObserver | |
| 13 | 14 | { |
| 14 | 15 | /// <summary> |
| 15 | 16 | /// 启动 |
| 16 | 17 | /// </summary> |
| 17 | 18 | void Start(); |
| 18 | 19 | /// <summary> |
| 19 | 删除: /// 日期即将变化时发生(前30秒) | |
| 20 | 新增: /// 日期即将变化时发生(前1秒) | |
| 20 | 21 | /// </summary> |
| 21 | 删除: event EventHandler OnDateChanging; | |
| 22 | 新增: event DateTimeObserverEventHandler OnDateTimeChanging; | |
| 22 | 23 | } |
| 23 | 24 | } |
| @@ -186,7 +186,7 @@ namespace UI | ||
| 186 | 186 | services.AddSingleton<IData, Data>(); |
| 187 | 187 | services.AddSingleton<ISleepdiscover, Sleepdiscover>(); |
| 188 | 188 | services.AddSingleton<IAppConfig, AppConfig>(); |
| 189 | 删除: services.AddSingleton<IDateObserver, DateObserver>(); | |
| 189 | 新增: services.AddSingleton<IDateTimeObserver, DateTimeObserver>(); | |
| 190 | 190 | services.AddSingleton<IAppData, AppData>(); |
| 191 | 191 | services.AddSingleton<ICategorys, Categorys>(); |
| 192 | 192 | |

