コード例 #1
0
        public recode_info Insert(recode_info entity)
        {
            var generatedId = GetDBClient().Insert <recode_info>(entity, true);

            entity.record_id = int.Parse((string)generatedId);
            return(entity);
        }
コード例 #2
0
        /// <summary>
        /// 写入新的数据
        /// </summary>
        /// <param name="thisProcess"></param>
        /// <param name="lastProcess"></param>
        /// <param name="beginTime"></param>
        public recode_info AddNewRecord(Process thisProcess, Process lastProcess)
        {
            var recordDate = new recode_info();

            recordDate.this_prosses_id    = thisProcess.Id.ToString();
            recordDate.this_prosses_title = thisProcess.MainWindowTitle;
            recordDate.this_prosses_name  = thisProcess.ProcessName;
            if (lastProcess == null)
            {
                recordDate.last_prosses_id    = "";
                recordDate.last_prosses_title = "";
            }
            else
            {
                recordDate.last_prosses_id    = lastProcess.Id.ToString();
                recordDate.last_prosses_title = lastProcess.MainWindowTitle;
            }
            recordDate.begin_time  = Common.GetTimeStamp(DateTime.Now);
            recordDate.end_time    = Common.GetTimeStamp(DateTime.Now);
            recordDate.date        = Common.GetDateInt(DateTime.Now);
            recordDate.create_time = Common.GetTimeStamp(DateTime.Now).ToString();
            return(Insert(recordDate));
        }
コード例 #3
0
 public void Update(recode_info entity)
 {
     GetDBClient().Update <recode_info>(entity, new { record_id = entity.record_id });
 }
コード例 #4
0
ファイル: MainWindow.xaml.cs プロジェクト: zy1911/Watcher
        public void GetProssesList()
        {
            _timmerLock = true;
            var ps = Process.GetProcesses(Environment.MachineName);

            ProcessList       = new List <string>();
            RunningDictionary = new Dictionary <IntPtr, ProcessInfo>();
            var activiteNo = GetForegroundWindow();

            foreach (var p in ps)
            {
                if (p.MainWindowHandle != IntPtr.Zero && p.MainWindowTitle != "" && !RunningDictionary.ContainsKey(p.MainWindowHandle))
                {
                    try
                    {
                        GetIcon(p.MainModule.FileName, p.ProcessName);
                    }
                    catch (Exception ex)
                    {
                        // ignored
                    }

                    RunningDictionary.Add(p.MainWindowHandle, new ProcessInfo()
                    {
                        ProcessInfoData = p,
                    });
                    ProcessList.Add(p.MainWindowTitle);
                }
            }

            string activiteProssesName = RunningDictionary.ContainsKey(activiteNo)
                ? RunningDictionary[activiteNo].ProcessInfoData.MainWindowTitle
                : "未选中应用";
            var currentTime = Common.GetTimeStamp(DateTime.Now);

            // 切换应用时触发
            if (RunningDictionary.ContainsKey(activiteNo) && activiteNo != NowProssesId)
            {
                if (_currentRecordInfo != null)
                {
                    // 更新旧进程的结束时间
                    MainRecordDbService.Update(new { end_time = currentTime, spend_time = (currentTime - _currentRecordInfo.begin_time) }, new { _currentRecordInfo.record_id });
                }

                // 插入新进程的数据
                var runningProcess = RunningDictionary[activiteNo].ProcessInfoData;
                _currentRecordInfo = MainRecordDbService.AddNewRecord(runningProcess, NowProcess);
                NowProssesId       = activiteNo;
                NowProcess         = runningProcess;

                // 添加前端变化
                SeriesCollection[0].Values.Add(currentTime - _currentRecordInfo.begin_time + 1);
                Labels.Add(NowProcess.ProcessName);

                if (SeriesCollection[0].Values.Count == 9)
                {
                    SeriesCollection[0].Values.RemoveAt(0);
                    Labels.RemoveAt(0);
                }

                try
                {
                    Dispatcher.Invoke(() =>
                    {
                        ForegroundTextBox.Text  = activiteProssesName;
                        MainListBox.ItemsSource = RunningDictionary.Values;
                        MainRowSeries.Series    = SeriesCollection;

                        DataContext = this;// 触发UI 进程进行数据刷新
                    });
                }
                catch (Exception e)
                {
                    MessageBox.Show("内部启动错误: " + e.Message + e.Data, "Watcher  Error", MessageBoxButton.OK, MessageBoxImage.Warning);
                    Application.Current.Shutdown();
                }
            }
            else
            {
                Dispatcher.Invoke(() =>
                {
                    if (SeriesCollection[0].Values.Count > 0)
                    {
                        SeriesCollection[0].Values[SeriesCollection[0].Values.Count - 1] =
                            Common.GetTimeStamp(DateTime.Now) - _currentRecordInfo.begin_time;
                    }
                });

                if (_countUpdate == 5 && _currentRecordInfo != null)// 五秒主动更新一次数据库
                {
                    currentTime = Common.GetTimeStamp(DateTime.Now);
                    MainRecordDbService.Update(new { end_time = currentTime, spend_time = (currentTime - _currentRecordInfo.begin_time + 1) }, new { _currentRecordInfo.record_id });
                    _countUpdate = 0;
                }
                if (_currentRecordInfo != null)
                {
                    // 更新图表信息
                    Dispatcher.Invoke(() =>
                    {
                        MainRowSeries.Series         = SeriesCollection;
                        ForegroundSecondTextBox.Text = " 运行" + (currentTime - _currentRecordInfo.begin_time + 1) + "秒";
                        ForegroundTextBox.Text       = activiteProssesName;
                        DataContext = this;
                    });
                }
                _countUpdate++;
            }

            SetMouseInfo();

            _timmerLock = false;
        }