NetProcess.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Oreo.NetMonitor.Models
  9. {
  10. /// <summary>
  11. /// 联网进程
  12. /// </summary>
  13. public class NetProcess
  14. {
  15. public NetProcess()
  16. {
  17. Ports = new List<ProcessPort>();
  18. }
  19. /// <summary>
  20. /// 当前进程
  21. /// </summary>
  22. public Process CurrentProcess
  23. {
  24. get
  25. {
  26. return Process.GetProcessById(ProcessID);
  27. }
  28. }
  29. /// <summary>
  30. /// 联网端口列表
  31. /// </summary>
  32. public List<ProcessPort> Ports { get; set; }
  33. public long UpBag { get; set; }
  34. public long DownBag { get; set; }
  35. /// <summary>
  36. /// 上传
  37. /// </summary>
  38. public long UpLoad { get; set; }
  39. /// <summary>
  40. /// 下载
  41. /// </summary>
  42. public long DownLoad { get; set; }
  43. public long UpLoadCount { get; set; }
  44. public long DownLoadCount { get; set; }
  45. public long FlowCount { get; set; }
  46. /// <summary>
  47. /// 应用图标
  48. /// </summary>
  49. public Icon ProcessICon { get; set; }
  50. public int ProcessID { get; set; }
  51. public string ProcessName { get; set; }
  52. /// <summary>
  53. /// 添加流量
  54. /// </summary>
  55. /// <param name="currentFlowCount">当前瞬时流量</param>
  56. /// <param name="port"></param>
  57. /// <returns></returns>
  58. public bool AddFlow(long currentFlowCount, int port, bool isUpload)
  59. {
  60. if (Ports != null && Ports.Count > 0)
  61. {
  62. ProcessPort _pp = Ports.FirstOrDefault(x => x.Port == port);
  63. if (_pp != null)
  64. {
  65. if (isUpload)
  66. {
  67. UpLoad += currentFlowCount;
  68. }
  69. else
  70. {
  71. DownLoad += currentFlowCount;
  72. }
  73. return true;
  74. }
  75. }
  76. return false;
  77. }
  78. }
  79. }