Browse Source

first commit

master
fajiao 3 years ago
parent
commit
dc0e963938
  1. 40
      EC.Entity/CameraInfo/IpcInfo.cs
  2. 15
      EC.Entity/CameraInfo/LogInfo.cs
  3. 29
      EC.Entity/CameraInfo/NvrInfo.cs
  4. 12
      EC.Entity/CameraInfo/PollInfo.cs
  5. 12
      EC.Entity/CameraInfo/UserInfo.cs
  6. 23
      EC.Entity/EC.Entity.csproj
  7. 80
      EC.Entity/PublicModel/BaseEntity.cs
  8. 22
      EC.Entity/PublicModel/Enums.cs
  9. 232
      EC.Entity/Video/MonitorCamera.cs
  10. 87
      EC.Entity/Video/MsVideoRecorder.cs
  11. 14
      EC.Entity/Warning/DrawPoint.cs
  12. 39
      EC.Entity/Warning/DrawShape.cs
  13. 40
      EC.Entity/Warning/WarningBoxModel.cs
  14. 14
      EC.Entity/Warning/WarningModel.cs
  15. 47
      EC.Service/CameraInfo/BaseDbContext.cs
  16. 62
      EC.Service/CameraInfo/IpcInfoContext.cs
  17. 50
      EC.Service/CameraInfo/LogInfoContext.cs
  18. 75
      EC.Service/CameraInfo/NvrInfoContext.cs
  19. 42
      EC.Service/CameraInfo/PollInfoContext.cs
  20. 34
      EC.Service/CameraInfo/UserInfoContext.cs
  21. 18
      EC.Service/Config/ConfigHelper.cs
  22. 12
      EC.Service/EC.Service.csproj
  23. 16
      EC.UsingEventAggregator/EC.UsingEventAggregator.csproj
  24. 62
      EC.UsingEventAggregator/FLogger.cs
  25. 82
      EC.UsingEventAggregator/MessageSentEvent.cs
  26. 213
      ECDefense.sln
  27. 111
      ECMonitor/App.xaml
  28. 91
      ECMonitor/App.xaml.cs
  29. 10
      ECMonitor/AssemblyInfo.cs
  30. 103
      ECMonitor/Code/Config/ConfigHelper.cs
  31. 106
      ECMonitor/Code/DB/DBDataHelper.cs
  32. 43
      ECMonitor/Code/DB/LoadFromAPIServer.cs
  33. 14
      ECMonitor/Code/DB/RequestModel.cs
  34. 89
      ECMonitor/Code/Models/BaseModel.cs
  35. 46
      ECMonitor/Code/Models/VideoShowModel.cs
  36. 19
      ECMonitor/Code/StaticData.cs
  37. 115
      ECMonitor/Code/SysemNotifyIcon/WPFSystemTray.cs
  38. 161
      ECMonitor/ECMonitor.csproj
  39. 81
      ECMonitor/MVVM/ExtendCommand.cs
  40. 45
      ECMonitor/MVVM/ExtendEventCommand.cs
  41. 87
      ECMonitor/MVVM/PasswordBoxHelper.cs
  42. 6
      ECMonitor/MVVM/VerifyExceptionBehavior.cs
  43. 64
      ECMonitor/MVVM/VerifyRule.cs
  44. 19
      ECMonitor/MVVM/VerifyRuleType.cs
  45. 50
      ECMonitor/MVVM/WPFAssist.cs
  46. 154
      ECMonitor/MainWindow.xaml
  47. 263
      ECMonitor/MainWindow.xaml.cs
  48. 131
      ECMonitor/MainWindowViewModel.cs
  49. 61
      ECMonitor/Manager/CameraManager.cs
  50. 56
      ECMonitor/Manager/MessageManager.cs
  51. 50
      ECMonitor/Manager/ShowVideoManager.cs
  52. 133
      ECMonitor/Manager/VideoPlayManager.cs
  53. 81
      ECMonitor/Manager/WebSocketManager.cs
  54. 82
      ECMonitor/Manager/ZMQManager.cs
  55. 24
      ECMonitor/NavigationModule.cs
  56. 226
      ECMonitor/Page/CameraMonitor/CameraAdjust.xaml
  57. 135
      ECMonitor/Page/CameraMonitor/CameraAdjust.xaml.cs
  58. 13
      ECMonitor/Page/CameraMonitor/CameraAdjustViewModel.cs
  59. 29
      ECMonitor/Page/CameraMonitor/CameraTree.xaml
  60. 49
      ECMonitor/Page/CameraMonitor/CameraTree.xaml.cs
  61. 26
      ECMonitor/Page/CameraMonitor/CameraTreeViewModel.cs
  62. 83
      ECMonitor/Page/CameraMonitor/CameraVideo.xaml
  63. 358
      ECMonitor/Page/CameraMonitor/CameraVideo.xaml.cs
  64. 13
      ECMonitor/Page/CameraMonitor/CameraVideoViewModel.cs
  65. 21
      ECMonitor/Page/CameraMonitor/Main.xaml
  66. 21
      ECMonitor/Page/CameraMonitor/Main.xaml.cs
  67. 13
      ECMonitor/Page/CameraMonitor/MainViewModel.cs
  68. 31
      ECMonitor/Page/Name/RegionsName.cs
  69. 52
      ECMonitor/Page/Name/ViewsName.cs
  70. 127
      ECMonitor/Page/SystemSet/Main.xaml
  71. 44
      ECMonitor/Page/SystemSet/Main.xaml.cs
  72. 26
      ECMonitor/Page/SystemSet/MainViewModel.cs
  73. 345
      ECMonitor/Page/SystemSet/ManageIpc.xaml
  74. 18
      ECMonitor/Page/SystemSet/ManageIpc.xaml.cs
  75. 281
      ECMonitor/Page/SystemSet/ManageIpcViewModel.cs
  76. 274
      ECMonitor/Page/SystemSet/ManageNvr.xaml
  77. 21
      ECMonitor/Page/SystemSet/ManageNvr.xaml.cs
  78. 276
      ECMonitor/Page/SystemSet/ManageNvrViewModel.cs
  79. 16
      ECMonitor/Page/SystemSet/ManageSet.xaml
  80. 15
      ECMonitor/Page/SystemSet/ManageSet.xaml.cs
  81. 13
      ECMonitor/Page/SystemSet/ManageSetViewModel.cs
  82. 247
      ECMonitor/Page/SystemSet/SearchIpc.xaml
  83. 16
      ECMonitor/Page/SystemSet/SearchIpc.xaml.cs
  84. 346
      ECMonitor/Page/SystemSet/SearchIpcViewModel.cs
  85. 21
      ECMonitor/Page/Test/Main.xaml
  86. 15
      ECMonitor/Page/Test/Main.xaml.cs
  87. 16
      ECMonitor/Page/Test/MainViewModel.cs
  88. 275
      ECMonitor/PlayerDraw/Code/BlackboardClass.cs
  89. 117
      ECMonitor/PlayerDraw/Code/BlackboardData.cs
  90. 67
      ECMonitor/PlayerDraw/Code/DataBase.cs
  91. 195
      ECMonitor/PlayerDraw/Code/Draw.cs
  92. 17
      ECMonitor/PlayerDraw/Code/DrawTypes.cs
  93. 406
      ECMonitor/PlayerDraw/Code/ECDrawing.cs
  94. 31
      ECMonitor/PlayerDraw/Code/Model/StrokeEx.cs
  95. 148
      ECMonitor/PlayerDraw/FrmWarningDraw.xaml
  96. 402
      ECMonitor/PlayerDraw/FrmWarningDraw.xaml.cs
  97. 12
      ECMonitor/PlayerDraw/UC/UCVideoDraw.xaml
  98. 28
      ECMonitor/PlayerDraw/UC/UCVideoDraw.xaml.cs
  99. BIN
      ECMonitor/PlayerDraw/close.png
  100. BIN
      ECMonitor/PlayerDraw/保存.png

40
EC.Entity/CameraInfo/IpcInfo.cs

@ -0,0 +1,40 @@
#nullable disable
using EC.Entity.PublicModel;
using System.ComponentModel.DataAnnotations.Schema;
namespace EC.Entity.CameraInfo
{
public partial class IpcInfo : BaseEntity
{
[NotMapped]
public int Number { get; set; }
public long IpcId { get; set; }
public string IpcName { get; set; }
public string NvrName { get; set; }
public string IpcType { get; set; }
public string IpcIp { get; set; }
public string OnvifAddr { get; set; }
public string MediaAddr { get; set; }
public string PtzAddr { get; set; }
public string RtspMain { get; set; }
public string RtspSub { get; set; }
public string IpcPosition { get; set; }
public string IpcImage { get; set; }
public long? IpcX { get; set; }
public long? IpcY { get; set; }
public string UserName { get; set; }
public string UserPwd { get; set; }
public string IpcEnable { get; set; }
[NotMapped]
public bool IpcEnableBool
{
get => IpcEnable != null && IpcEnable.Equals("启用");
set => IpcEnable = value ? "启用" : "禁用";
}
public string IpcAddr { get; set; }
}
}

15
EC.Entity/CameraInfo/LogInfo.cs

@ -0,0 +1,15 @@
#nullable disable
namespace EC.Entity.CameraInfo
{
public partial class LogInfo
{
public long LogId { get; set; }
public string TriggerTime { get; set; }
public string UserName { get; set; }
public string LogCh { get; set; }
public string LogType { get; set; }
public string LogContent { get; set; }
public string LogMark { get; set; }
}
}

29
EC.Entity/CameraInfo/NvrInfo.cs

@ -0,0 +1,29 @@
#nullable disable
using System.ComponentModel.DataAnnotations.Schema;
namespace EC.Entity.CameraInfo
{
public partial class NvrInfo
{
[NotMapped]
public int Number { get; set; }
public long NvrId { get; set; }
public string NvrName { get; set; }
public string NvrType { get; set; }
public string NvrIp { get; set; }
public string UserName { get; set; }
public string UserPwd { get; set; }
public string NvrEnable { get; set; }
[NotMapped]
public bool NvrEnableBool
{
get => NvrEnable != null && NvrEnable.Equals("启用");
set => NvrEnable = value ? "启用" : "禁用";
}
public string NvrAddr { get; set; }
}
}

12
EC.Entity/CameraInfo/PollInfo.cs

@ -0,0 +1,12 @@
#nullable disable
namespace EC.Entity.CameraInfo
{
public partial class PollInfo
{
public long PollId { get; set; }
public string PollGroup { get; set; }
public string RtspMain { get; set; }
public string RtspSub { get; set; }
}
}

12
EC.Entity/CameraInfo/UserInfo.cs

@ -0,0 +1,12 @@
#nullable disable
namespace EC.Entity.CameraInfo
{
public partial class UserInfo
{
public string UserName { get; set; }
public string UserPwd { get; set; }
public string UserType { get; set; }
public string UserAdmin { get; set; }
}
}

23
EC.Entity/EC.Entity.csproj

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows7.0</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Military\**" />
<EmbeddedResource Remove="Military\**" />
<None Remove="Military\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.9" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\公共库\EC.Utils\EC.Utils.csproj" />
</ItemGroup>
</Project>

80
EC.Entity/PublicModel/BaseEntity.cs

@ -0,0 +1,80 @@
using Newtonsoft.Json;
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Reflection;
namespace EC.Entity.PublicModel
{
public class BaseEntity : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public bool SetValue(string propertyName, string value)
{
if (!ContainProperty(propertyName)) { return false; }
try
{
Type type = GetType();
object objVal = Convert.ChangeType(value, type.GetProperty(propertyName).PropertyType);
type.GetProperty(propertyName).SetValue(this, objVal, null);
OnPropertyChanged(propertyName);
return true;
}
catch
{
return false;
}
}
public object GetValue(string propertyName)
{
if (!ContainProperty(propertyName)) { return null; }
try
{
Type type = GetType();
object objVal = type.GetProperty(propertyName).GetValue(this, null);
return objVal;
}
catch
{
return null;
}
}
/// <summary>
/// 利用反射来判断对象是否包含某个属性
/// </summary>
/// <param name="instance">object</param>
/// <param name="propertyName">需要判断的属性</param>
/// <returns>是否包含</returns>
public bool ContainProperty(string propertyName)
{
if (this != null && !string.IsNullOrEmpty(propertyName))
{
PropertyInfo _findedPropertyInfo = GetType().GetProperty(propertyName);
return _findedPropertyInfo != null;
}
return false;
}
[NotMapped]
public string FaultUri { get; set; } = "-1";
public virtual bool IsUriGain(string uri)
{
return !(string.IsNullOrEmpty(uri) || uri.Equals(FaultUri, StringComparison.Ordinal));
}
public virtual T DeepCopy<T>()
{
string json = JsonConvert.SerializeObject(this);
return JsonConvert.DeserializeObject<T>(json);
}
}
}

22
EC.Entity/PublicModel/Enums.cs

@ -0,0 +1,22 @@
namespace EC.Entity.PublicModel
{
public enum VidoeType
{
Default,
/// <summary>
/// 海康
/// </summary>
HK,
/// <summary>
/// 大华
/// </summary>
DH,
/// <summary>
/// 宇视觉
/// </summary>
YS
}
}

232
EC.Entity/Video/MonitorCamera.cs

@ -0,0 +1,232 @@
using System;
namespace EC.Entity.Video
{
public class MonitorCamera
{
public MonitorCamera()
{
}
/// <summary>
/// 主键
/// </summary>
public string Id { get; set; }
/// <summary>
/// 站点id
/// </summary>
public string SiteId { get; set; }
/// <summary>
/// 相机名称
/// </summary>
public string CameraName { get; set; }
/// <summary>
/// 相机类型
/// </summary>
public int Type { get; set; }
/// <summary>
/// 相机ip
/// </summary>
public string Ip { get; set; }
/// <summary>
/// 相机端口
/// </summary>
public int Port { get; set; }
/// <summary>
/// 认证用户名
/// </summary>
public string User { get; set; }
/// <summary>
/// 认证密码
/// </summary>
public string Password { get; set; }
/// <summary>
/// 纬度
/// </summary>
public decimal Latitude { get; set; }
/// <summary>
/// 经度
/// </summary>
public decimal Longitude { get; set; }
/// <summary>
/// 高度
/// </summary>
public decimal Height { get; set; }
/// <summary>
/// Rtsp地址
/// </summary>
public string PreRtsp { get; set; }
/// <summary>
/// 分析 Rtsp 地址
/// </summary>
public string AnalysisRtsp { get; set; }
/// <summary>
/// 录像 Rtsp 地址通道3
/// </summary>
public string RecordRtsp { get; set; }
/// <summary>
/// 云台控制ip
/// </summary>
public string CloudCtrlIp { get; set; }
/// <summary>
/// 云台控制端口
/// </summary>
public int CloudCtrlPort { get; set; }
/// <summary>
/// 流媒体服务器id
/// </summary>
public string StreamingMediaId { get; set; }
/// <summary>
/// 录像机id
/// </summary>
public string VideoRecorderId { get; set; }
/// <summary>
///
/// </summary>
public int Factory { get; set; }
/// <summary>
/// 相机预览通道
/// </summary>
public int Channel { get; set; }
/// <summary>
/// 样式
/// </summary>
public int Style { get; set; }
/// <summary>
/// 左夹角
/// </summary>
public double LeftAngle { get; set; }
/// <summary>
/// 右夹角
/// </summary>
public double RightAngle { get; set; }
/// <summary>
/// 视野中央有效距离
/// </summary>
public double ViewDistance { get; set; }
/// <summary>
/// 采样帧率
/// </summary>
public int FrameRate { get; set; }
/// <summary>
/// 最大跟踪范围
/// </summary>
public int MaxRange { get; set; }
/// <summary>
/// 状态
/// </summary>
public int Status { get; set; }
/// <summary>
/// 零方位角(正北夹角)
/// </summary>
public double ZeroAzimuth { get; set; }
/// <summary>
/// 安装垂直角(上下-90°~90°)
/// </summary>
public double FixedAngle { get; set; }
/// <summary>
/// 最大仰角
/// </summary>
public double MaxElevation { get; set; }
/// <summary>
/// 最大可视距离
/// </summary>
public double MaxVisibleDistance { get; set; }
/// <summary>
/// 变倍因子
/// </summary>
public double ZoomFactor { get; set; }
/// <summary>
/// 创建人
/// </summary>
public string CreateBy { get; set; }
/// <summary>
/// 创建日期
/// </summary>
public DateTime? CreateTime { get; set; }
/// <summary>
/// 更新人
/// </summary>
public string UpdateBy { get; set; }
/// <summary>
/// 更新日期
/// </summary>
public DateTime? UpdateTime { get; set; }
public MonitorCamera(string cameraIp, int port, string userName, string passWord, int factory = 0, int type = 0)
{
Ip = cameraIp;
Port = port;
User = userName;
Password = passWord;
Factory = factory;
Type = type;
}
public string RtspURL(int width = 640)
{
if (width < 1200)
{
if (!string.IsNullOrEmpty(RecordRtsp))
{
return RecordRtsp;
}
}
if (!string.IsNullOrEmpty(PreRtsp))
{
return PreRtsp;
}
string rtspformat = "rtsp://{0}:{1}@{2}:554";
//switch (Factory)
//{
// case (int)Video.HK:
// rtspformat = "rtsp://{0}:{1}@{2}:554/Streaming/Channels/102?transportmode=unicast&profile=Profile_2";
// break;
// case (int)VidoeType.DH:
// rtspformat = "rtsp://{0}:{1}@{2}:554/cam/realmonitor?channel=1&subtype=1&unicast=true&proto=Onvif";
// break;
// //case VidoeType.YS:
// // return "";
//}
string url = string.Format(rtspformat, User, Password, Ip);
return url;
}
}
}

87
EC.Entity/Video/MsVideoRecorder.cs

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
namespace EC.Entity.Video
{
public class MsVideoRecorder
{
public MsVideoRecorder()
{
}
/// <summary>
/// 主键
/// </summary>
public string Id { get; set; }
/// <summary>
/// 所属部门
/// </summary>
public string SysOrgCode { get; set; }
/// <summary>
/// 设备名称
/// </summary>
public string DeviceName { get; set; }
/// <summary>
/// 设备类型
/// </summary>
public int DeviceType { get; set; }
/// <summary>
/// 设备编号
/// </summary>
public string DeviceNum { get; set; }
/// <summary>
/// 设备地址
/// </summary>
public string DeviceAddress { get; set; }
/// <summary>
/// 用户姓名
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 用户密码
/// </summary>
public string UserPassword { get; set; }
/// <summary>
/// 是否启用
/// </summary>
public int IsEnable { get; set; }
/// <summary>
/// 安装位置
/// </summary>
public string FixedPosition { get; set; }
/// <summary>
///
/// </summary>
public List<MonitorCamera> MsCameraSettingList { get; set; }
/// <summary>
/// 创建人
/// </summary>
public string CreateBy { get; set; }
/// <summary>
/// 创建日期
/// </summary>
public DateTime? CreateTime { get; set; }
/// <summary>
/// 更新人
/// </summary>
public string UpdateBy { get; set; }
/// <summary>
/// 更新日期
/// </summary>
public DateTime? UpdateTime { get; set; }
}
}

14
EC.Entity/Warning/DrawPoint.cs

@ -0,0 +1,14 @@
namespace EC.Entity.Warning
{
public class DrawPoint
{
public DrawPoint(double x, double y)
{
X = x;
Y = y;
}
public double X { get; set; }
public double Y { get; set; }
}
}

39
EC.Entity/Warning/DrawShape.cs

@ -0,0 +1,39 @@
using System.Collections.Generic;
namespace EC.Entity.Warning
{
public class DrawShape
{
public DrawShape()
{
PointList = new List<DrawPoint>();
}
//public DrawShapeModel(string ip, StrokeEx storke)
//{
// List<StylusPoint> stylusPoints = storke.StylusPoints.ToList();
// foreach (StylusPoint stylusPoint in stylusPoints)
// {
// }
//}
public string Ip { get; set; }
/// <summary>
/// 画图形状
/// </summary>
public int DrawType { get; set; }
/// <summary>
/// 预警级别
/// </summary>
public int WarningLevel { get; set; }
public List<DrawPoint> PointList { get; set; }
/// <summary>
/// 预警方向 Line 上(0)下(1)左(2)右(3)
/// </summary>
public int WaringDirection { get; set; }
}
}

40
EC.Entity/Warning/WarningBoxModel.cs

@ -0,0 +1,40 @@
namespace EC.Entity.Warning
{
public class WarningBoxModel
{
/// <summary>
///英文标签
/// </summary>
public string label { get; set; }
/// <summary>
/// 原标签位置
/// </summary>
public int cls { get; set; }
/// <summary>
/// 相似度
/// </summary>
public double conf { get; set; }
/// <summary>
/// 左上角x
/// </summary>
public double x { get; set; }
/// <summary>
/// 左上角Y
/// </summary>
public double y { get; set; }
/// <summary>
/// 右下角x
/// </summary>
public double x1 { get; set; }
/// <summary>
/// 右下角y
/// </summary>
public double y1 { get; set; }
}
}

14
EC.Entity/Warning/WarningModel.cs

@ -0,0 +1,14 @@
using System.Collections.Generic;
namespace EC.Entity.Warning
{
public class WarningModel
{
public int warninglevel { get; set; }
public string ip { get; set; }
public string filename { get; set; }
public int width { get; set; }
public int height { get; set; }
public List<WarningBoxModel> boxs { get; set; }
}
}

47
EC.Service/CameraInfo/BaseDbContext.cs

@ -0,0 +1,47 @@
using EC.Service.Config;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace EC.Service.CameraInfo
{
public partial class BaseDbContext<T> : DbContext where T : class
{
public BaseDbContext()
{
}
public BaseDbContext(DbContextOptions<BaseDbContext<T>> options)
: base(options)
{
}
public virtual DbSet<T> Infos { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlite(ConfigHelper.GetDbConnection());
}
}
protected void OnModelCreatingPartial(ModelBuilder modelBuilder)
{
}
#region Select
public Task<List<T>> GetListAsync()
{
Task<List<T>> task = Task.Run(() =>
{
return new List<T>(Infos);
});
return task;
}
#endregion Select
}
}

62
EC.Service/CameraInfo/IpcInfoContext.cs

@ -0,0 +1,62 @@
using EC.Entity.CameraInfo;
using Microsoft.EntityFrameworkCore;
#nullable disable
namespace EC.Service.CameraInfo
{
public class IpcInfoContext : BaseDbContext<IpcInfo>
{
public IpcInfoContext()
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<IpcInfo>(entity =>
{
entity.HasKey(e => e.IpcId);
entity.ToTable("IpcInfo");
entity.Property(e => e.IpcId).HasColumnName("IpcID");
entity.Property(e => e.IpcAddr).HasColumnType("VARCHAR (100)");
entity.Property(e => e.IpcEnable).HasColumnType("VARCHAR (2)");
entity.Property(e => e.IpcImage).HasColumnType("VARCHAR (30)");
entity.Property(e => e.IpcName)
.IsRequired()
.HasColumnType("VARCHAR (30)");
entity.Property(e => e.IpcPosition).HasColumnType("VARCHAR (50)");
entity.Property(e => e.IpcType).HasColumnType("VARCHAR (30)");
entity.Property(e => e.IpcX).HasColumnType("INTEGER (4)");
entity.Property(e => e.IpcY).HasColumnType("INTEGER (4)");
entity.Property(e => e.MediaAddr).HasColumnType("VARCHAR (150)");
entity.Property(e => e.NvrName).HasColumnType("VARCHAR (30)");
entity.Property(e => e.OnvifAddr).HasColumnType("VARCHAR (150)");
entity.Property(e => e.PtzAddr).HasColumnType("VARCHAR (150)");
entity.Property(e => e.RtspMain).HasColumnType("VARCHAR (250)");
entity.Property(e => e.RtspSub).HasColumnType("VARCHAR (250)");
entity.Property(e => e.UserName).HasColumnType("VARCHAR (20)");
entity.Property(e => e.UserPwd).HasColumnType("VARCHAR (20)");
});
OnModelCreatingPartial(modelBuilder);
}
}
}

50
EC.Service/CameraInfo/LogInfoContext.cs

@ -0,0 +1,50 @@
using EC.Entity.CameraInfo;
using Microsoft.EntityFrameworkCore;
#nullable disable
namespace EC.Service.CameraInfo
{
public class LogInfoContext : BaseDbContext<LogInfo>
{
public LogInfoContext()
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<LogInfo>(entity =>
{
entity.HasKey(e => e.LogId);
entity.ToTable("LogInfo");
entity.Property(e => e.LogId)
.ValueGeneratedNever()
.HasColumnName("LogID");
entity.Property(e => e.LogCh).HasColumnType("VARCHAR (50)");
entity.Property(e => e.LogContent)
.IsRequired()
.HasColumnType("VARCHAR (100)");
entity.Property(e => e.LogMark).HasColumnType("VARCHAR (200)");
entity.Property(e => e.LogType)
.IsRequired()
.HasColumnType("VARCHAR (10)");
entity.Property(e => e.TriggerTime)
.IsRequired()
.HasColumnType("VARCHAR (19)");
entity.Property(e => e.UserName)
.IsRequired()
.HasColumnType("VARCHAR (20)");
});
OnModelCreatingPartial(modelBuilder);
}
}
}

75
EC.Service/CameraInfo/NvrInfoContext.cs

@ -0,0 +1,75 @@
using EC.Entity.CameraInfo;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Threading.Tasks;
#nullable disable
namespace EC.Service.CameraInfo
{
public class NvrInfoContext : BaseDbContext<NvrInfo>
{
public NvrInfoContext()
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<NvrInfo>(entity =>
{
entity.HasKey(e => e.NvrId);
entity.ToTable("NvrInfo");
entity.Property(e => e.NvrId).HasColumnName("NvrID");
entity.Property(e => e.NvrAddr).HasColumnType("VARCHAR (100)");
entity.Property(e => e.NvrEnable)
.IsRequired()
.HasColumnType("VARCHAR (2)");
entity.Property(e => e.NvrIp)
.IsRequired()
.HasColumnType("VARCHAR (18)")
.HasColumnName("NvrIP");
entity.Property(e => e.NvrName)
.IsRequired()
.HasColumnType("VARCHAR (30)");
entity.Property(e => e.NvrType).HasColumnType("VARCHAR (20)");
entity.Property(e => e.UserName).HasColumnType("VARCHAR (20)");
entity.Property(e => e.UserPwd).HasColumnType("VARCHAR (20)");
});
OnModelCreatingPartial(modelBuilder);
}
#region Operate
public List<string> GetNvrDeviceList()
{
List<string> list = new() { "海康", "大华", "宇视", "深广", "泰杰", "其它" };
return list;
}
public async Task<List<string>> GetNvrNameListAsync()
{
List<string> list = new();
List<NvrInfo> infos = await GetListAsync();
foreach (NvrInfo info in infos)
{
if (!list.Contains(info.NvrName))
{
list.Add(info.NvrName);
}
}
return list;
}
#endregion Operate
}
}

42
EC.Service/CameraInfo/PollInfoContext.cs

@ -0,0 +1,42 @@
using EC.Entity.CameraInfo;
using Microsoft.EntityFrameworkCore;
#nullable disable
namespace EC.Service.CameraInfo
{
public class PollInfoContext : BaseDbContext<PollInfo>
{
public PollInfoContext()
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<PollInfo>(entity =>
{
entity.HasKey(e => e.PollId);
entity.ToTable("PollInfo");
entity.Property(e => e.PollId)
.ValueGeneratedNever()
.HasColumnName("PollID");
entity.Property(e => e.PollGroup)
.IsRequired()
.HasColumnType("VARCHAR (20)");
entity.Property(e => e.RtspMain)
.IsRequired()
.HasColumnType("VARCHAR (250)");
entity.Property(e => e.RtspSub)
.IsRequired()
.HasColumnType("VARCHAR (250)");
});
OnModelCreatingPartial(modelBuilder);
}
}
}

34
EC.Service/CameraInfo/UserInfoContext.cs

@ -0,0 +1,34 @@
using EC.Entity.CameraInfo;
using Microsoft.EntityFrameworkCore;
#nullable disable
namespace EC.Service.CameraInfo
{
public class UserInfoContext : BaseDbContext<UserInfo>
{
public UserInfoContext()
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<UserInfo>(entity =>
{
entity.HasKey(e => e.UserName);
entity.ToTable("UserInfo");
entity.Property(e => e.UserName).HasColumnType("VARCHAR (20)");
entity.Property(e => e.UserAdmin).HasColumnType("VARCHAR (30)");
entity.Property(e => e.UserPwd).HasColumnType("VARCHAR (20)");
entity.Property(e => e.UserType).HasColumnType("VARCHAR (10)");
});
OnModelCreatingPartial(modelBuilder);
}
}
}

18
EC.Service/Config/ConfigHelper.cs

@ -0,0 +1,18 @@
using EC.Utils.Config;
namespace EC.Service.Config
{
public class ConfigHelper : ConfigurationHelper
{
/// <summary>
#region 数据库
public static string GetDbConnection()
{
return ConfigurationHelper.GetDbConnection("ConnectionString");
}
#endregion 数据库
}
}

12
EC.Service/EC.Service.csproj

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\EC.Entity\EC.Entity.csproj" />
<ProjectReference Include="..\公共库\EC.Utils\EC.Utils.csproj" />
</ItemGroup>
</Project>

16
EC.UsingEventAggregator/EC.UsingEventAggregator.csproj

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Prism.Core" Version="8.1.97" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EC.Entity\EC.Entity.csproj" />
<ProjectReference Include="..\公共库\EC.Onvif\EC.Onvif.csproj" />
</ItemGroup>
</Project>

62
EC.UsingEventAggregator/FLogger.cs

@ -0,0 +1,62 @@
using System;
namespace EC.UsingEventAggregator
{
public enum LoggerLevel
{
Debug,
Info,
Error,
}
public class MyLogger
{
public MyLogger(string message, LoggerLevel level = LoggerLevel.Debug)
{
Message = message;
Level = level;
}
public string Message { get; set; }
public LoggerLevel Level { get; set; }
}
/// <summary>
/// 文件Logger
/// </summary>
public class FLogger
{
public static event Action<string> SubMessage;
public static event Action<MyLogger> SubLog;
//public static void PubMessge(string message)
//{
// SubMessage?.Invoke(message);
//}
public static void PubLog(string message, LoggerLevel level = LoggerLevel.Debug)
{
SubLog?.Invoke(new MyLogger(message, level));
}
public static void Debug(string message)
{
SubLog?.Invoke(new MyLogger(message, LoggerLevel.Debug));
}
public static void Info(string message)
{
SubLog?.Invoke(new MyLogger(message, LoggerLevel.Info));
}
public static void Error(string message)
{
SubLog?.Invoke(new MyLogger(message, LoggerLevel.Error));
}
public static void Error(Exception ex)
{
SubLog?.Invoke(new MyLogger(ex.Message, LoggerLevel.Error));
}
}
}

82
EC.UsingEventAggregator/MessageSentEvent.cs

@ -0,0 +1,82 @@
using EC.Entity.CameraInfo;
using EC.Entity.Warning;
using EC.Onvif;
using Prism.Events;
using System.Collections.Generic;
namespace EC.UsingEventAggregator
{
public class LogModel
{
public LogModel(int level, string message, string remark = "")
{
this.level = level;
this.message = message;
this.remark = remark;
}
public int level { get; set; }
public string message { get; set; }
public string remark { get; set; }
}
public class MQModel
{
public int level { get; set; }
public string message { get; set; }
}
public class MessageSentEvent : PubSubEvent<string>
{
}
/// <summary>
/// MQ消息
/// </summary>
public class MQMessageEvent : PubSubEvent<MQModel>
{
}
/// <summary>
/// 显示日志
/// </summary>
public class ShowMessageSentEvent : PubSubEvent<LogModel>
{
}
/// <summary>
/// 保存日志
/// </summary>
public class SaveLogEvent : PubSubEvent<LogModel>
{
}
/// <summary>
/// 在主窗体播放视频
/// </summary>
public class ShowVoideInMainEvent : PubSubEvent<string>
{
}
/// <summary>
/// 预警视频数据
/// </summary>
public class WaningVoideEvent : PubSubEvent<WarningModel>
{
}
/// <summary>
/// 预警分析图片数据
/// </summary>
public class WaningImageBytesEvent : PubSubEvent<byte[]>
{
}
public class SendOnvifClientEvent : PubSubEvent<OnvifClient>
{
}
public class SendIpcInfoListEvent : PubSubEvent<List<IpcInfo>>
{
}
}

213
ECDefense.sln

@ -0,0 +1,213 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30804.86
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EC.Service", "EC.Service\EC.Service.csproj", "{C37542F7-5C6A-4998-8D1B-CED979560C8A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ECMonitor", "ECMonitor\ECMonitor.csproj", "{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EC.UsingEventAggregator", "EC.UsingEventAggregator\EC.UsingEventAggregator.csproj", "{8E4EFE09-CB77-44A6-904E-B42639136385}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "视频处理", "视频处理", "{A09E2512-EFE0-4E69-B7D1-B964B6358887}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "公共库", "公共库", "{8B78A8FF-D59D-4E86-91F3-0D5A4332E3B1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EC.Entity", "EC.Entity\EC.Entity.csproj", "{2242B8A5-3E25-499E-9B23-3E61517A543E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HKPlayers", "播放库\HKPlayers\HKPlayers.csproj", "{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EC.FFmpegAutoGen", "播放库\EC.FFmpegAutoGen\EC.FFmpegAutoGen.csproj", "{58B91E08-B095-4598-A0A4-74E3882F1881}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EC.Utils", "公共库\EC.Utils\EC.Utils.csproj", "{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EC.Onvif", "公共库\EC.Onvif\EC.Onvif.csproj", "{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|ARM = Debug|ARM
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|ARM = Release|ARM
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Debug|ARM.ActiveCfg = Debug|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Debug|ARM.Build.0 = Debug|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Debug|ARM64.Build.0 = Debug|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Debug|x64.ActiveCfg = Debug|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Debug|x64.Build.0 = Debug|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Debug|x86.ActiveCfg = Debug|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Debug|x86.Build.0 = Debug|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Release|Any CPU.Build.0 = Release|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Release|ARM.ActiveCfg = Release|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Release|ARM.Build.0 = Release|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Release|ARM64.ActiveCfg = Release|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Release|ARM64.Build.0 = Release|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Release|x64.ActiveCfg = Release|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Release|x64.Build.0 = Release|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Release|x86.ActiveCfg = Release|Any CPU
{C37542F7-5C6A-4998-8D1B-CED979560C8A}.Release|x86.Build.0 = Release|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Debug|ARM.ActiveCfg = Debug|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Debug|ARM.Build.0 = Debug|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Debug|ARM64.Build.0 = Debug|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Debug|x64.ActiveCfg = Debug|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Debug|x64.Build.0 = Debug|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Debug|x86.ActiveCfg = Debug|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Debug|x86.Build.0 = Debug|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Release|Any CPU.Build.0 = Release|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Release|ARM.ActiveCfg = Release|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Release|ARM.Build.0 = Release|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Release|ARM64.ActiveCfg = Release|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Release|ARM64.Build.0 = Release|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Release|x64.ActiveCfg = Release|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Release|x64.Build.0 = Release|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Release|x86.ActiveCfg = Release|Any CPU
{7F5DA7D9-8DCF-44C8-921D-B156C99D4F9B}.Release|x86.Build.0 = Release|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Debug|ARM.ActiveCfg = Debug|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Debug|ARM.Build.0 = Debug|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Debug|ARM64.Build.0 = Debug|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Debug|x64.ActiveCfg = Debug|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Debug|x64.Build.0 = Debug|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Debug|x86.ActiveCfg = Debug|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Debug|x86.Build.0 = Debug|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Release|Any CPU.Build.0 = Release|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Release|ARM.ActiveCfg = Release|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Release|ARM.Build.0 = Release|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Release|ARM64.ActiveCfg = Release|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Release|ARM64.Build.0 = Release|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Release|x64.ActiveCfg = Release|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Release|x64.Build.0 = Release|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Release|x86.ActiveCfg = Release|Any CPU
{8E4EFE09-CB77-44A6-904E-B42639136385}.Release|x86.Build.0 = Release|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Debug|ARM.ActiveCfg = Debug|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Debug|ARM.Build.0 = Debug|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Debug|ARM64.Build.0 = Debug|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Debug|x64.ActiveCfg = Debug|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Debug|x64.Build.0 = Debug|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Debug|x86.ActiveCfg = Debug|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Debug|x86.Build.0 = Debug|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Release|Any CPU.Build.0 = Release|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Release|ARM.ActiveCfg = Release|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Release|ARM.Build.0 = Release|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Release|ARM64.ActiveCfg = Release|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Release|ARM64.Build.0 = Release|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Release|x64.ActiveCfg = Release|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Release|x64.Build.0 = Release|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Release|x86.ActiveCfg = Release|Any CPU
{2242B8A5-3E25-499E-9B23-3E61517A543E}.Release|x86.Build.0 = Release|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Debug|ARM.ActiveCfg = Debug|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Debug|ARM.Build.0 = Debug|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Debug|ARM64.Build.0 = Debug|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Debug|x64.ActiveCfg = Debug|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Debug|x64.Build.0 = Debug|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Debug|x86.ActiveCfg = Debug|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Debug|x86.Build.0 = Debug|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Release|Any CPU.Build.0 = Release|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Release|ARM.ActiveCfg = Release|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Release|ARM.Build.0 = Release|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Release|ARM64.ActiveCfg = Release|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Release|ARM64.Build.0 = Release|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Release|x64.ActiveCfg = Release|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Release|x64.Build.0 = Release|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Release|x86.ActiveCfg = Release|Any CPU
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F}.Release|x86.Build.0 = Release|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Debug|ARM.ActiveCfg = Debug|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Debug|ARM.Build.0 = Debug|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Debug|ARM64.Build.0 = Debug|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Debug|x64.ActiveCfg = Debug|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Debug|x64.Build.0 = Debug|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Debug|x86.ActiveCfg = Debug|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Debug|x86.Build.0 = Debug|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Release|Any CPU.Build.0 = Release|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Release|ARM.ActiveCfg = Release|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Release|ARM.Build.0 = Release|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Release|ARM64.ActiveCfg = Release|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Release|ARM64.Build.0 = Release|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Release|x64.ActiveCfg = Release|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Release|x64.Build.0 = Release|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Release|x86.ActiveCfg = Release|Any CPU
{58B91E08-B095-4598-A0A4-74E3882F1881}.Release|x86.Build.0 = Release|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Debug|ARM.ActiveCfg = Debug|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Debug|ARM.Build.0 = Debug|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Debug|ARM64.Build.0 = Debug|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Debug|x64.ActiveCfg = Debug|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Debug|x64.Build.0 = Debug|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Debug|x86.ActiveCfg = Debug|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Debug|x86.Build.0 = Debug|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Release|Any CPU.Build.0 = Release|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Release|ARM.ActiveCfg = Release|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Release|ARM.Build.0 = Release|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Release|ARM64.ActiveCfg = Release|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Release|ARM64.Build.0 = Release|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Release|x64.ActiveCfg = Release|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Release|x64.Build.0 = Release|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Release|x86.ActiveCfg = Release|Any CPU
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207}.Release|x86.Build.0 = Release|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Debug|ARM.ActiveCfg = Debug|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Debug|ARM.Build.0 = Debug|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Debug|ARM64.Build.0 = Debug|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Debug|x64.ActiveCfg = Debug|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Debug|x64.Build.0 = Debug|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Debug|x86.ActiveCfg = Debug|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Debug|x86.Build.0 = Debug|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Release|Any CPU.Build.0 = Release|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Release|ARM.ActiveCfg = Release|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Release|ARM.Build.0 = Release|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Release|ARM64.ActiveCfg = Release|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Release|ARM64.Build.0 = Release|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Release|x64.ActiveCfg = Release|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Release|x64.Build.0 = Release|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Release|x86.ActiveCfg = Release|Any CPU
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5EC832FA-4BD1-466C-B221-21BAE5A3D21F} = {A09E2512-EFE0-4E69-B7D1-B964B6358887}
{58B91E08-B095-4598-A0A4-74E3882F1881} = {A09E2512-EFE0-4E69-B7D1-B964B6358887}
{D651B7BC-B1B4-4D33-A409-3C8E6C52B207} = {8B78A8FF-D59D-4E86-91F3-0D5A4332E3B1}
{EFEDF229-0330-46B4-B32E-3CA6BEA61E39} = {8B78A8FF-D59D-4E86-91F3-0D5A4332E3B1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {279F81E9-23B1-4D20-A450-2BADF996975B}
EndGlobalSection
EndGlobal

111
ECMonitor/App.xaml

@ -0,0 +1,111 @@
<prism:PrismApplication x:Class="ECMonitor.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:prism="http://prismlibrary.com/"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- This is the current way to setup your app's initial theme -->
<materialDesign:BundledTheme BaseTheme="Dark" PrimaryColor="Blue" SecondaryColor="Lime"
ColorAdjustment="{materialDesign:ColorAdjustment}" />
<!-- If you would prefer to use your own colors there is an option for that as well -->
<!--<materialDesign:CustomColorTheme BaseTheme="Light" PrimaryColor="Aqua" SecondaryColor="DarkGreen" />-->
<!-- You can also use the built in theme dictionaries as well
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
-->
<!-- Material Design,整体界面颜色 -->
<!--<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />-->
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml" />
<!--<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.LightBlue.xaml" />-->
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
</ResourceDictionary.MergedDictionaries>
<!--PRIMARY-->
<SolidColorBrush x:Key="PrimaryBodyBrush" Color="#44494f" />
<SolidColorBrush x:Key="PrimaryBarBrush" Color="#40444d" />
<SolidColorBrush x:Key="PrimaryBackGroupBrush" Color="#40444d" />
<SolidColorBrush x:Key="PrimaryButtonBrush" Color="#4c8bb7" />
<SolidColorBrush x:Key="PrimaryFontBrush" Color="#FFFFFF" />
<SolidColorBrush x:Key="PrimaryBorderBrush" Color="Aqua" />
<Color x:Key="PageBodyColor">#44494f</Color>
<Color x:Key="PageBgColor">#40444d</Color>
<Color x:Key="PageBorderColor">#32363f</Color>
<SolidColorBrush x:Key="PageBodyBrush" Color="#44494f" />
<SolidColorBrush x:Key="PageBgBrush" Color="#40444d" />
<SolidColorBrush x:Key="PageBorderBrush" Color="#32363f" />
<Style x:Key="ECButtonStyle">
<Setter Property="Control.Margin" Value="0,0,10,0" />
<Setter Property="Control.Padding" Value="10,0,10,0" />
<Setter Property="Control.FontFamily" Value="微软雅黑" />
<Setter Property="Control.FontSize" Value="18" />
<Setter Property="Control.Width" Value="20" />
<Setter Property="Control.Height" Value="20" />
<Setter Property="Control.Background" Value="#4c8bb7" />
<Setter Property="Control.FontWeight" Value="Bold" />
<Setter Property="Control.BorderBrush" Value="Transparent" />
</Style>
<Style x:Key="ECChecketStyle">
<Setter Property="Control.Margin" Value="0,0,10,0" />
<Setter Property="Control.FontFamily" Value="微软雅黑" />
<Setter Property="Control.FontSize" Value="18" />
<Setter Property="Control.Foreground" Value="#FFFFFF" />
<Setter Property="Control.Padding" Value="5,15,5,5" />
</Style>
<Style x:Key="TopRightButtonStyle">
<Setter Property="Control.Margin" Value="5,0,10,0" />
<Setter Property="Control.FontFamily" Value="微软雅黑" />
<Setter Property="Control.FontSize" Value="18" />
<Setter Property="Control.Width" Value="20" />
<Setter Property="Control.Height" Value="20" />
<Setter Property="Control.Background" Value="Transparent" />
<Setter Property="Control.FontWeight" Value="Bold" />
<Setter Property="Control.BorderBrush" Value="Transparent" />
</Style>
<Style x:Key="TopButtonStyle">
<Setter Property="Control.Margin" Value="5,0,10,0" />
<Setter Property="Control.FontFamily" Value="微软雅黑" />
<Setter Property="Control.FontSize" Value="22" />
<Setter Property="Control.Width" Value="30" />
<Setter Property="Control.Height" Value="30" />
<Setter Property="Control.Background" Value="Transparent" />
<Setter Property="Control.FontWeight" Value="Bold" />
<Setter Property="Control.BorderBrush" Value="Transparent" />
</Style>
<Style x:Key="BottomRightButtonStyle">
<Setter Property="Control.Margin" Value="10,0,0,0" />
<Setter Property="Control.FontFamily" Value="微软雅黑" />
<Setter Property="Control.FontSize" Value="18" />
<Setter Property="Control.Width" Value="20" />
<Setter Property="Control.Height" Value="20" />
<Setter Property="Control.Background" Value="Transparent" />
<Setter Property="Control.FontWeight" Value="Bold" />
<Setter Property="Control.BorderBrush" Value="Transparent" />
</Style>
<Style x:Key="TopButtonImgStyle">
<Setter Property="Control.Width" Value="20" />
<Setter Property="Control.Height" Value="20" />
</Style>
<Style x:Key="ButtonImgStyle">
<Setter Property="Control.Width" Value="15" />
<Setter Property="Control.Height" Value="15" />
</Style>
<ControlTemplate x:Key="ButtonTemplate" TargetType="{x:Type Button}">
<Border x:Name="Border" BorderThickness="0" CornerRadius="6" Margin="0,0,10,0" TextBlock.Foreground="White" Background="#4c8bb7">
<!--设置控件的边框,圆角,背景色,字体颜色-->
<ContentPresenter Margin="{TemplateBinding Padding}" HorizontalAlignment="Center" VerticalAlignment="Center">
<!--显示控件的内容-->
</ContentPresenter>
</Border>
</ControlTemplate>
</ResourceDictionary>
</Application.Resources>
</prism:PrismApplication>

91
ECMonitor/App.xaml.cs

@ -0,0 +1,91 @@
using EC.UsingEventAggregator;
using EC.Utils;
using LibVLCSharp.Shared;
using Prism.Ioc;
using Prism.Modularity;
using Prism.Unity;
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
namespace ECMonitor
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : PrismApplication
{
protected override void OnStartup(StartupEventArgs e)
{
Core.Initialize();
base.OnStartup(e);
RegisterEvents();
LogFactory.GetLogger().Info("OnStartup");
// await new IpcInfoService().Test();//test sqlite
}
protected override Window CreateShell()
{
return Container.Resolve<MainWindow>();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
}
protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
{
moduleCatalog.AddModule<NavigationModule>();
}
//protected override IModuleCatalog CreateModuleCatalog()
//{
// return new ConfigurationModuleCatalog();
//}
protected override void OnExit(ExitEventArgs e)
{
base.OnExit(e);
}
private void RegisterEvents()
{
//TaskScheduler.UnobservedTaskException += (sender, args) =>
//{
// MessageBox.Show(args.Exception.Message);
// args.SetObserved();
//};
DispatcherUnhandledException += App_DispatcherUnhandledException;
TaskScheduler.UnobservedTaskException += new EventHandler<
UnobservedTaskExceptionEventArgs>(TaskScheduler_UnobservedTaskException);
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
FLogger.Error("Error encountered! Please contact support." + Environment.NewLine + e.Exception.Message);
e.Handled = true;
}
private static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
foreach (Exception item in e.Exception.InnerExceptions)
{
FLogger.Error(string.Format("异常类型:{0}{1}来自:{2}{3}异常内容:{4}",
item.GetType(), Environment.NewLine, item.Source,
Environment.NewLine, item.Message));
}
//将异常标识为已经观察到
e.SetObserved();
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
FLogger.Error("Unhandled exception.");
}
}
}

10
ECMonitor/AssemblyInfo.cs

@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

103
ECMonitor/Code/Config/ConfigHelper.cs

@ -0,0 +1,103 @@
using EC.Utils.Config;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ECMonitor
{
public class ConfigHelper : ConfigurationHelper
{
#region
/// <summary>
/// 自动关闭预警窗体
/// </summary>
/// <returns></returns>
public static bool? AutoWarningClose()
{
return GetValueInt("AutoWarningClose") == 1;
}
/// <summary>
/// AI 检索
/// </summary>
/// <returns></returns>
public static bool? VideoAIDetection()
{
return GetValueInt("VideoAIDetection") == 1;
}
/// <summary>
/// WebSocketSvrPort
/// </summary>
/// <returns></returns>
public static int WebSocketSvrPort()
{
return GetValueInt("WebSocketSvrPort");
}
public static string APIServer()
{
return GetValue("APIServer");
}
/// <summary>
/// 可选初始窗体图标 0:(1个窗体),1:4个窗体, 2:9个窗体
/// </summary>
/// <returns></returns>
public static int MainBarButtonSelectedIndex()
{
return GetValueInt("MainBarButtonSelectedIndex");
}
public static string AIInputPath()
{
return GetValue("AIInputPath");
}
public static string AIOutPath()
{
return GetValue("AIOutPath");
}
#endregion
#region ZMQ 配置
/// 发布地址
/// </summary>
/// <returns></returns>
public static string PUBServer()
{
return GetMQValue("PUBServer");
}
/// <summary>
/// 订阅地址
/// </summary>
/// <returns></returns>
public static string SUBServer()
{
return GetMQValue("SUBServer");
}
//AI服务地址
public static string AISvrServer()
{
return GetMQValue("AISvrServer");
}
/// <summary>
/// AI图片数据订阅 地址
/// </summary>
/// <returns></returns>
public static string SUBImageServer()
{
return GetMQValue("SUBImageServer");
}
#endregion
/// <summary>
/// 数据库服务地址
/// </summary>
/// <returns></returns>
public static string DBSvrServer()
{
return GetMQValue("DBSvrServer");
}
}
}

106
ECMonitor/Code/DB/DBDataHelper.cs

@ -0,0 +1,106 @@

using EC.Entity.PublicModel;
using EC.Entity.Video;
using EC.Entity.Warning;
using EC.Utils;
using EC.Utils.ZMQ;
using NetMQ;
using NetMQ.Sockets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ECMonitor.Code.DB
{
public class DBDataHelper
{
//public static string _apiUrl = ConfigHelper.APIServer();
public static string _dbSvrServer = ConfigHelper.DBSvrServer();
public static ZMQRequestHelper requestHelper=null;
public static ZMQRequestHelper RequestContext() {
if (requestHelper == null)
{
requestHelper = new ZMQRequestHelper(_dbSvrServer);
}
return requestHelper;
}
/// <summary>
/// 获取相机数据
/// </summary>
/// <returns></returns>
public static List<MsVideoRecorder> LoadCameraData()
{
List<MsVideoRecorder> msVideoRecorderList = new List<MsVideoRecorder>();
try
{
RequestModel requestModel = new RequestModel();
requestModel.method = DBMethod.GetGroupAndCameraList;
requestModel.jsonstr = "all";
ResultModel resultModel = RequestContext().RequestFromServer(requestModel);
if (resultModel.result == DBMethod.Success)
{
msVideoRecorderList = resultModel.jsonstr.ToObject<List<MsVideoRecorder>>();
}
}
catch (Exception ex)
{
LogFactory.GetLogger().Error(ex);
}
return msVideoRecorderList;
}
/// <summary>
/// 保存预警划线
/// </summary>
/// <param name="drawShapeModelList"></param>
internal static bool SaveDrawShape(List<DrawShape> drawShapeModelList)
{
RequestModel requestModel = new RequestModel();
requestModel.method = DBMethod.SaveDrawShape;
requestModel.jsonstr = drawShapeModelList.ToJson();
LogFactory.GetLogger().Debug(requestModel.jsonstr);
ResultModel resultModel =RequestContext().RequestFromServer(requestModel);
if (resultModel.result == DBMethod.Success)
{
return true;
}else
{
return false;
}
}
internal static List<DrawShape> GetDrawShape(string ip)
{
List<DrawShape> drawShapeModelList = new List<DrawShape>();
try
{
RequestModel requestModel = new RequestModel();
requestModel.method = DBMethod.GetDrawShape;
requestModel.jsonstr = ip;
LogFactory.GetLogger().Debug(requestModel.jsonstr);
ResultModel resultModel = RequestContext().RequestFromServer(requestModel);
if (resultModel.result == DBMethod.Success)
{
drawShapeModelList = Json.ToObject<List<DrawShape>>(resultModel.jsonstr);
}
}catch(Exception ex)
{
LogFactory.GetLogger().Debug(ex);
}
return drawShapeModelList;
}
}
}

43
ECMonitor/Code/DB/LoadFromAPIServer.cs

@ -0,0 +1,43 @@
using EC.Entity.Video;
using EC.Utils;
using System;
using System.Collections.Generic;
namespace ECMonitor.Code
{
public class LoadFromAPIServer
{
public static string _apiUrl = ConfigHelper.APIServer();
/// <summary>
/// 获取相机数据
/// </summary>
/// <returns></returns>
public static List<MsVideoRecorder> LoadCameraData()
{
List<MsVideoRecorder> msVideoRecorderList = new List<MsVideoRecorder>();
try
{
var respStr = HttpMethods.HttpGet(_apiUrl);
var respObj = Json.ToJObject(respStr);
var success = (bool)respObj["success"];
if (success)
{
var message = (string)respObj["message"];
var code = (int)respObj["code"];
var timestamp = (string)respObj["timestamp"];
msVideoRecorderList = Json.ToList<MsVideoRecorder>(respObj["result"]?.ToString());
}
}
catch (Exception ex)
{
LogFactory.GetLogger().Error(ex);
}
return msVideoRecorderList;
}
}
}

14
ECMonitor/Code/DB/RequestModel.cs

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ECMonitor.Code.ServerData
{
public class RequestModel
{
public string Key { get; set; }
public string jsonstr { get; set; }
}
}

89
ECMonitor/Code/Models/BaseModel.cs

@ -0,0 +1,89 @@
using EC.UsingEventAggregator;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Regions;
using System.Collections.Specialized;
namespace ECMonitor.Code.Models
{
public class BaseModel : BindableBase
{
public IRegionManager _regionManager { get; set; }
public IEventAggregator _ea { get; set; }
private string _title = "";
public string Title
{
get { return _title; }
set { SetProperty(ref _title, value); }
}
public DelegateCommand<string> SendMessageCommand { get; private set; }
public BaseModel(IRegionManager regionManager, IEventAggregator ea)
{
_regionManager = regionManager;
_ea = ea;
_regionManager.Regions.CollectionChanged += Regions_CollectionChanged;
SendMessageCommand = new DelegateCommand<string>(SendMessage);
_ea.GetEvent<ShowMessageSentEvent>().Subscribe(MessageReceived);
}
public virtual void Regions_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
var region = (IRegion)e.NewItems[0];
region.Views.CollectionChanged += Views_CollectionChanged;
}
}
public virtual void Views_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
}
else if (e.Action == NotifyCollectionChangedAction.Remove)
{
}
}
public virtual void SendMessage(string message)
{
SendMessage(new LogModel(1, message));
}
/// <summary>
/// 发送消息
/// </summary>
/// <param name="log"></param>
public virtual void SendMessage(LogModel log)
{
_ea.GetEvent<ShowMessageSentEvent>().Publish(log);
}
public virtual void MessageReceived(LogModel log)
{
//Messages.Add(message);
}
#region 日志
public void Debug(string message)
{
}
public void Info(string message)
{
}
public void Error(string message)
{
}
#endregion 日志
}
}

46
ECMonitor/Code/Models/VideoShowModel.cs

@ -0,0 +1,46 @@
using EC.Entity.Video;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ECMonitor.Code.Models
{
public class VideoShowModel
{
public VideoShowModel()
{
UPDateTime();
}
public string Message { get; set; }
public string CameraIp { get; set; }
public MonitorCamera Camera { get; set; }
/// <summary>
/// 控件注册名称
/// </summary>
public string UCName { get; set; }
/// <summary>
/// 更新时间
/// </summary>
private DateTime upDateTime;
public void UPDateTime()
{
upDateTime = new DateTime();
}
/// <summary>
/// 判断预警是否接触
/// </summary>
/// <returns></returns>
public bool IsTimeOut()
{
DateTime now = new DateTime();
double difSeconds = DateUnit.DateDiffSeconds(upDateTime, now);
return difSeconds > 30;
}
internal string RtspURL()
{
return Camera.RtspURL();
}
}
}

19
ECMonitor/Code/StaticData.cs

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ECMonitor.Code
{
/// <summary>
/// 静态变量类
/// </summary>
public class StaticData
{
/// <summary>
/// 选中的播放器的IP
/// </summary>
public static string MainPlayerIp { get; set; }
}
}

115
ECMonitor/Code/SysemNotifyIcon/WPFSystemTray.cs

@ -0,0 +1,115 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ECMonitor.Code.SysemNotifyIcon
{
public class WPFSystemTray
{
/// <summary>
/// 设置系统托盘
/// </summary>
/// <param name="pars">最小化参数</param>
/// <param name="dbClick"></param>
/// <returns></returns>
public static NotifyIcon SetSystemTray(SystemTrayParameter pars, List<SystemTrayMenu> menuList)
{
NotifyIcon notifyIcon = new NotifyIcon();
notifyIcon.Visible = true;
if (!string.IsNullOrWhiteSpace(pars.Icon))
{
notifyIcon.Icon = new System.Drawing.Icon(pars.Icon);//程序图标
}
if (!string.IsNullOrWhiteSpace(pars.MinText))
{
notifyIcon.Text = pars.MinText;//最小化到托盘时,鼠标悬浮时显示的文字
}
if (!string.IsNullOrWhiteSpace(pars.TipText))
{
notifyIcon.BalloonTipText = pars.TipText; //设置系统托盘启动时显示的文本
notifyIcon.ShowBalloonTip(pars.Time == 0 ? 100 : pars.Time);//显示时长
}
notifyIcon.MouseDoubleClick += pars.dbClick; //双击事件
notifyIcon.ContextMenuStrip = GetMenuStrip(menuList);
return notifyIcon;
}
/// <summary>
/// 设置系统托盘的菜单属性
/// </summary>
/// <param name="menus"></param>
/// <returns></returns>
static ContextMenuStrip GetMenuStrip(List<SystemTrayMenu> menus)
{
ContextMenuStrip menu = new ContextMenuStrip();
ToolStripMenuItem[] menuArray = new ToolStripMenuItem[menus.Count];
int i = 0;
foreach (SystemTrayMenu item in menus)
{
ToolStripMenuItem menuItem = new ToolStripMenuItem();
menuItem.Text = item.Txt;
menuItem.Click += item.Click;
if (!string.IsNullOrWhiteSpace(item.Icon) && System.IO.File.Exists(item.Icon)) { menuItem.Image = System.Drawing.Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + item.Icon); }
menuArray[i++] = menuItem;
}
menu.Items.AddRange(menuArray);
return menu;
}
}
/// <summary>
/// 系统托盘参数
/// </summary>
public class SystemTrayParameter
{
public SystemTrayParameter(string Icon, string MinText, string TipText, int Time, MouseEventHandler dbClick)
{
this.Icon = Icon;
this.MinText = MinText;
this.TipText = TipText;
this.Time = Time;
this.dbClick = dbClick;
}
/// <summary>
/// 托盘显示图标
/// </summary>
public string Icon { get; set; }
/// <summary>
/// 最小化悬浮时文本
/// </summary>
public string MinText { get; set; }
/// <summary>
/// 最小化启动时文本
/// </summary>
public string TipText { get; set; }
/// <summary>
/// 最小化启动时文本显示时长
/// </summary>
public int Time { get; set; }
/// <summary>
/// 最小化双击事件
/// </summary>
public MouseEventHandler dbClick { get; set; }
}
/// <summary>
/// 右键菜单
/// </summary>
public class SystemTrayMenu
{
/// <summary>
/// 菜单文本
/// </summary>
public string Txt { get; set; }
/// <summary>
/// 菜单图标
/// </summary>
public string Icon { get; set; }
/// <summary>
/// 菜单单击事件
/// </summary>
public EventHandler Click { get; set; }
}
}

161
ECMonitor/ECMonitor.csproj

@ -0,0 +1,161 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Code\Interfaces\**" />
<Compile Remove="Sets\**" />
<EmbeddedResource Remove="Code\Interfaces\**" />
<EmbeddedResource Remove="Sets\**" />
<None Remove="Code\Interfaces\**" />
<None Remove="Sets\**" />
<Page Remove="Code\Interfaces\**" />
<Page Remove="Sets\**" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Code\DB\RequestModel.cs" />
<Compile Remove="UC\Videos\UCFFmpegAIBoxPlayer.xaml.cs" />
<Compile Remove="UC\Videos\UCRtspVlcVideo.xaml.cs" />
<Compile Remove="Views\RtspMonitor.xaml.cs" />
</ItemGroup>
<ItemGroup>
<None Remove="camera1.png" />
<None Remove="close.png" />
<None Remove="login.png" />
<None Remove="logon.png" />
<None Remove="max2.png" />
<None Remove="min1.png" />
<None Remove="PlayerDraw\close.png" />
<None Remove="PlayerDraw\保存.png" />
<None Remove="PlayerDraw\删 除 .png" />
<None Remove="PlayerDraw\删除 关闭 叉.png" />
<None Remove="PlayerDraw\选取.png" />
<None Remove="set1.png" />
<None Remove="top.png" />
<None Remove="topbar.png" />
<None Remove="UC\Videos\pen.png" />
<None Remove="UC\Videos\画板 10 副本 48.png" />
<None Remove="UC\Videos\设计_画图.png" />
<None Remove="Views\报警 %281%29.png" />
<None Remove="zgx.ico" />
<None Remove="报警.png" />
</ItemGroup>
<ItemGroup>
<Page Remove="UC\Videos\UCFFmpegAIBoxPlayer.xaml" />
<Page Remove="UC\Videos\UCRtspVlcVideo.xaml" />
<Page Remove="Views\RtspMonitor.xaml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FFmpeg.AutoGen" Version="4.4.0" />
<PackageReference Include="Fleck" Version="1.2.0" />
<PackageReference Include="LibVLCSharp" Version="3.5.1" />
<PackageReference Include="LibVLCSharp.WPF" Version="3.5.1" />
<PackageReference Include="MaterialDesignColors" Version="2.0.1" />
<PackageReference Include="MaterialDesignThemes" Version="4.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Prism.Unity" Version="8.1.97" />
<PackageReference Include="Prism.Wpf" Version="8.1.97" />
<PackageReference Include="ShowMeTheXAML" Version="2.0.0" />
<PackageReference Include="ShowMeTheXAML.AvalonEdit" Version="2.0.0" />
<PackageReference Include="ShowMeTheXAML.MSBuild" Version="2.0.0" />
<PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" />
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EC.Entity\EC.Entity.csproj" />
<ProjectReference Include="..\EC.Service\EC.Service.csproj" />
<ProjectReference Include="..\EC.UsingEventAggregator\EC.UsingEventAggregator.csproj" />
<ProjectReference Include="..\公共库\EC.Onvif\EC.Onvif.csproj" />
<ProjectReference Include="..\播放库\EC.FFmpegAutoGen\EC.FFmpegAutoGen.csproj" />
<ProjectReference Include="..\播放库\HKPlayers\HKPlayers.csproj" />
</ItemGroup>
<ItemGroup>
<Resource Include="camera1.png" />
<Resource Include="close.png" />
<Resource Include="login.png" />
<Resource Include="logon.png" />
<Resource Include="max2.png" />
<Resource Include="min1.png" />
<Resource Include="PlayerDraw\close.png" />
<Resource Include="PlayerDraw\保存.png" />
<Resource Include="PlayerDraw\删 除 .png" />
<Resource Include="PlayerDraw\删除 关闭 叉.png" />
<Resource Include="PlayerDraw\选取.png" />
<Resource Include="Resources\Images\zgx.ico" />
<Resource Include="Resources\Images\报警.png" />
<Resource Include="set1.png" />
<Resource Include="top.png" />
<Resource Include="topbar.png" />
<Resource Include="UC\Videos\pen.png" />
<Resource Include="UC\Videos\画板 10 副本 48.png" />
<Resource Include="UC\Videos\设计_画图.png" />
<Resource Include="Views\报警 (1).png" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Page Update="Page\Test\Main.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
<Page Update="Resources\Themes\Themes.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="UC\Videos\UCAIFilePlayer.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="UC\Videos\UCAIWarningPlayer.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="db\CameraInfo.db">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
</Target>
<ProjectExtensions><VisualStudio><UserProperties /></VisualStudio></ProjectExtensions>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="Copy $(ProjectDir)appsettings.json $(OutDir)appsettings.json" />
</Target>
</Project>

81
ECMonitor/MVVM/ExtendCommand.cs

@ -0,0 +1,81 @@
using System;
using System.Windows.Input;
namespace ECMonitor.MVVM
{
public class ExtendCommand<T> : ICommand
{
/// <summary>
/// 检查命令是否可以执行的事件,在UI事件发生导致控件状态或数据发生变化时触发
/// </summary>
public event EventHandler CanExecuteChanged
{
add
{
if (_canExecute != null)
{
CommandManager.RequerySuggested += value;
}
}
remove
{
if (_canExecute != null)
{
CommandManager.RequerySuggested -= value;
}
}
}
/// <summary>
/// 判断命令是否可以执行的方法
/// </summary>
private Func<T, bool> _canExecute;
/// <summary>
/// 命令需要执行的方法
/// </summary>
private Action<T> _execute;
/// <summary>
/// 创建一个命令
/// </summary>
/// <param name="execute">命令要执行的方法</param>
public ExtendCommand(Action<T> execute) : this(execute, null)
{
}
/// <summary>
/// 创建一个命令
/// </summary>
/// <param name="execute">命令要执行的方法</param>
/// <param name="canExecute">判断命令是否能够执行的方法</param>
public ExtendCommand(Action<T> execute, Func<T, bool> canExecute)
{
_execute = execute;
_canExecute = canExecute;
}
/// <summary>
/// 判断命令是否可以执行
/// </summary>
/// <param name="parameter">命令传入的参数</param>
/// <returns>是否可以执行</returns>
public bool CanExecute(object parameter)
{
if (_canExecute == null) return true;
return _canExecute((T)parameter);
}
/// <summary>
/// 执行命令
/// </summary>
/// <param name="parameter"></param>
public void Execute(object parameter)
{
if (_execute != null && CanExecute(parameter))
{
_execute((T)parameter);
}
}
}
}

45
ECMonitor/MVVM/ExtendEventCommand.cs

@ -0,0 +1,45 @@
using Microsoft.Xaml.Behaviors;
using System.Windows;
using System.Windows.Input;
namespace ECMonitor.MVVM
{
public class ExtendEventCommand : TriggerAction<DependencyObject>
{
/// <summary>
/// 事件要绑定的命令
/// </summary>
public ICommand Command
{
get { return (ICommand)GetValue(CommandProperty); }
set { SetValue(CommandProperty, value); }
}
// Using a DependencyProperty as the backing store for MsgName. This enables animation, styling, binding, etc...
public static readonly DependencyProperty CommandProperty =
DependencyProperty.Register("Command", typeof(ICommand), typeof(ExtendEventCommand), new PropertyMetadata(null));
/// <summary>
/// 绑定命令的参数,保持为空就是事件的参数
/// </summary>
public object CommandParateter
{
get { return (object)GetValue(CommandParateterProperty); }
set { SetValue(CommandParateterProperty, value); }
}
// Using a DependencyProperty as the backing store for CommandParateter. This enables animation, styling, binding, etc...
public static readonly DependencyProperty CommandParateterProperty =
DependencyProperty.Register("CommandParateter", typeof(object), typeof(ExtendEventCommand), new PropertyMetadata(null));
//执行事件
protected override void Invoke(object parameter)
{
if (CommandParateter != null)
parameter = CommandParateter;
var cmd = Command;
if (cmd != null)
cmd.Execute(parameter);
}
}
}

87
ECMonitor/MVVM/PasswordBoxHelper.cs

@ -0,0 +1,87 @@
using System.Windows;
using System.Windows.Controls;
namespace ECMonitor.MVVM
{
public static class PasswordBoxHelper
{
public static readonly DependencyProperty PasswordProperty =
DependencyProperty.RegisterAttached("Password",
typeof(string), typeof(PasswordBoxHelper),
new FrameworkPropertyMetadata(string.Empty, OnPasswordPropertyChanged));
public static readonly DependencyProperty AttachProperty =
DependencyProperty.RegisterAttached("Attach",
typeof(bool), typeof(PasswordBoxHelper), new PropertyMetadata(false, Attach));
private static readonly DependencyProperty IsUpdatingProperty =
DependencyProperty.RegisterAttached("IsUpdating", typeof(bool),
typeof(PasswordBoxHelper));
public static void SetAttach(DependencyObject dp, bool value)
{
dp.SetValue(AttachProperty, value);
}
public static bool GetAttach(DependencyObject dp)
{
return (bool)dp.GetValue(AttachProperty);
}
public static string GetPassword(DependencyObject dp)
{
return (string)dp.GetValue(PasswordProperty);
}
public static void SetPassword(DependencyObject dp, string value)
{
dp.SetValue(PasswordProperty, value);
}
private static bool GetIsUpdating(DependencyObject dp)
{
return (bool)dp.GetValue(IsUpdatingProperty);
}
private static void SetIsUpdating(DependencyObject dp, bool value)
{
dp.SetValue(IsUpdatingProperty, value);
}
private static void OnPasswordPropertyChanged(DependencyObject sender,
DependencyPropertyChangedEventArgs e)
{
PasswordBox passwordBox = sender as PasswordBox;
passwordBox.PasswordChanged -= PasswordChanged;
if (!(bool)GetIsUpdating(passwordBox))
{
passwordBox.Password = (string)e.NewValue;
}
passwordBox.PasswordChanged += PasswordChanged;
}
private static void Attach(DependencyObject sender,
DependencyPropertyChangedEventArgs e)
{
PasswordBox passwordBox = sender as PasswordBox;
if (passwordBox == null)
return;
if ((bool)e.OldValue)
{
passwordBox.PasswordChanged -= PasswordChanged;
}
if ((bool)e.NewValue)
{
passwordBox.PasswordChanged += PasswordChanged;
}
}
private static void PasswordChanged(object sender, RoutedEventArgs e)
{
PasswordBox passwordBox = sender as PasswordBox;
SetIsUpdating(passwordBox, true);
SetPassword(passwordBox, passwordBox.Password);
SetIsUpdating(passwordBox, false);
}
}
}

6
ECMonitor/MVVM/VerifyExceptionBehavior.cs

@ -0,0 +1,6 @@
namespace ECMonitor.MVVM
{
internal class VerifyExceptionBehavior
{
}
}

64
ECMonitor/MVVM/VerifyRule.cs

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Controls;
using System.Windows.Data;
namespace ECMonitor.MVVM
{
public class VerifyRule : ValidationRule
{
public VerifyRuleType Type { get; set; } = VerifyRuleType.Unknown;
public List<object> WhatList { get; set; }
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
string strVal = value != null ? (string)value : string.Empty;
ValidationResult vRet = Type switch
{
VerifyRuleType.NotEmpty => VerifyNotEmpty(strVal),
VerifyRuleType.IP => VerifyIP(strVal),
VerifyRuleType.Unknown => VerifyUnkown(strVal),
VerifyRuleType.Temp => VerifyTemp(strVal),
_ => VerifyUnkown(strVal),
};
WhatList = new();
WhatList.Add(new { Type, vRet.IsValid, value, strVal, vRet });
return vRet;
}
#region Verify Region
private static ValidationResult VerifyNotEmpty(string value)
{
bool ret = !string.IsNullOrWhiteSpace(value);
string errMsg = "不能为空!";
return ret ? ValidationResult.ValidResult : new ValidationResult(false, errMsg);
}
private static ValidationResult VerifyIP(string value)
{
bool ret = VerifyUnit.CheckIp(value);
string errMsg = "IP格式错误!";
return ret ? ValidationResult.ValidResult : new ValidationResult(false, errMsg);
}
private static ValidationResult VerifyTemp(string value)
{
bool ret = !string.IsNullOrWhiteSpace(value);
string errMsg = "临时错误!";
return ret ? ValidationResult.ValidResult : new ValidationResult(false, errMsg);
}
private static ValidationResult VerifyUnkown(string value)
{
bool ret = false;
string errMsg = "未知错误!";
return ret ? ValidationResult.ValidResult : new ValidationResult(false, errMsg);
}
#endregion Verify Region
}
}

19
ECMonitor/MVVM/VerifyRuleType.cs

@ -0,0 +1,19 @@
using System.ComponentModel;
namespace ECMonitor.MVVM
{
public enum VerifyRuleType
{
[Description("Temp")]
Temp = -2,
[Description("Unknown")]
Unknown = -1,
[Description("NotEmpty")]
NotEmpty = 1,
[Description("IP")]
IP = 2,
}
}

50
ECMonitor/MVVM/WPFAssist.cs

@ -0,0 +1,50 @@
using System.Windows.Controls;
namespace ECMonitor.MVVM
{
public class WPFAssist
{
/// <summary>
/// 获取DataGrid的所有行是否存在验证错误。
/// </summary>
/// <param name="dg">要检查的DataGrid实例</param>
/// <returns>true 有错,false 无错</returns>
public static bool GetDataGridRowsHasError(DataGrid dg)
{
bool hasError = false;
ValidationError err = null;
for (int i = 0; i < dg.Items.Count; i++)
{
DataGridRow row = (DataGridRow)dg.ItemContainerGenerator.ContainerFromIndex(i);
hasError = Validation.GetHasError(row);
if (hasError)
{
break;
}
}
return hasError;
}
/// <summary>
/// 获取DataGrid的第一个被发现的验证错误结果。
/// </summary>
/// <param name="dg">被检查的DataGrid实例。</param>
/// <returns>错误结果。</returns>
public static ValidationError GetDataGridRowsFirstError(DataGrid dg)
{
bool hasError = false;
ValidationError err = null;
for (int i = 0; i < dg.Items.Count; i++)
{
DataGridRow row = (DataGridRow)dg.ItemContainerGenerator.ContainerFromIndex(i);
hasError = Validation.GetHasError(row);
if (hasError)
{
err = Validation.GetErrors(row)[0];
break;
}
}
return err;
}
}
}

154
ECMonitor/MainWindow.xaml

@ -0,0 +1,154 @@
<Window x:Class="ECMonitor.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:prism="http://prismlibrary.com/"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:names="clr-namespace:ECMonitor.Page.Name"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
x:Name="mainWindow"
Title="视频监控" Height="800" Width="1080" Icon="/resources/Images/zgx.ico" WindowStyle="None" WindowStartupLocation="CenterScreen" WindowState="Maximized">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding LoadCommand}" CommandParameter="{Binding ElementName=mainWindow}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<materialDesign:DialogHost Identifier="RootDialog"
DialogTheme="Inherit" SnackbarMessageQueue="{Binding ElementName=MainSnackbar, Path=MessageQueue}">
<Grid Background="{DynamicResource PrimaryBodyBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="58*" />
<RowDefinition Height="1000*" />
</Grid.RowDefinitions>
<DockPanel Grid.Row="0" MouseMove="DockPanel_MouseMove">
<DockPanel.Background>
<ImageBrush ImageSource="/topbar.png" TileMode="Tile" Stretch="UniformToFill" />
</DockPanel.Background>
<DockPanel DockPanel.Dock="Left" Width="400">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<Image Source="/logon.png" ></Image>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock
HorizontalAlignment="left"
VerticalAlignment="Center"
FontSize="15"
Margin="10 0 0 0"
Text="{Binding Title}" />
</StackPanel>
</StackPanel>
</DockPanel>
<DockPanel DockPanel.Dock="Top" Height="18">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Name="btnMin" Style="{DynamicResource TopRightButtonStyle}" Margin="0,0,10,0" Click="btnMin_Click">
<WrapPanel>
<Image Source="/min1.png" />
</WrapPanel>
</Button>
<Button Name="btnMax" Style="{DynamicResource TopRightButtonStyle}" Margin="0,0,10,0" Click="btnMax_Click">
<WrapPanel>
<Image Source="/max2.png" Width="10" />
</WrapPanel>
</Button>
<Button Name="btnClose" Style="{DynamicResource TopRightButtonStyle}" Margin="0,0,10,0" Click="btnClose_Click">
<WrapPanel>
<Image Source="/close.png" />
</WrapPanel>
</Button>
</StackPanel>
</DockPanel>
<StackPanel Orientation="Horizontal">
<ToggleButton
x:Name="MenuToggleButton"
Style="{StaticResource MaterialDesignHamburgerToggleButton}"
IsChecked="False"
Command="{Binding ShowLeftDock}"
Width="24"
Height="24"
AutomationProperties.Name="HamburgerToggleButton" />
</StackPanel>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Right" HorizontalAlignment="Right">
<Button
Name="btnVodieo"
Command="{Binding NavigateCommand}" CommandParameter="{x:Static names:ViewsName.CameraMonitorMain}"
Click="btnVodieo_Click"
Style="{StaticResource MaterialDesignRaisedDarkButton}"
Background="#4c8bb7"
BorderBrush="Transparent"
materialDesign:ButtonAssist.CornerRadius="15"
IsEnabled="{Binding DataContext.ControlsEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}" Cursor="Hand">
<WrapPanel>
<Image Source="/camera1.png" Style="{DynamicResource TopButtonImgStyle}" />
<TextBlock Text="视频监控" VerticalAlignment="Center" Margin="6,0,0,0" />
</WrapPanel>
</Button>
<Button
Name="btnSet"
Command="{Binding NavigateCommand}" CommandParameter="{x:Static names:ViewsName.SystemSetMain}"
Style="{StaticResource MaterialDesignRaisedDarkButton}"
Background="Transparent"
BorderBrush="Transparent"
materialDesign:ButtonAssist.CornerRadius="15"
IsEnabled="{Binding DataContext.ControlsEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}" Click="btnSet_Click" Cursor="Hand">
<WrapPanel>
<Image Source="/set1.png" Width="15" />
<TextBlock Text="系统设置" VerticalAlignment="Center" Margin="6,0,0,0" />
</WrapPanel>
</Button>
<materialDesign:PopupBox
DockPanel.Dock="Right"
PlacementMode="BottomAndAlignRightEdges"
StaysOpen="False">
<StackPanel>
<Grid Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock
Text="Light"
Margin="0 0 10 0" />
<ToggleButton
x:Name="DarkModeToggleButton"
Grid.Column="1" />
<TextBlock
Text="Dark"
Margin="10 0 0 0"
Grid.Column="2" />
<TextBlock
Text="Enabled"
Margin="0 10 10 0"
Grid.Row="1" />
</Grid>
</StackPanel>
</materialDesign:PopupBox>
</StackPanel>
</DockPanel>
<ContentControl Grid.Row="1" prism:RegionManager.RegionName="{x:Static names:RegionsName.MainWindowCenter}" />
<materialDesign:Snackbar
x:Name="MainSnackbar"
MessageQueue="{materialDesign:MessageQueue}"
Grid.Row="1" />
</Grid>
</materialDesign:DialogHost>
</Window>

263
ECMonitor/MainWindow.xaml.cs

@ -0,0 +1,263 @@
using EC.UsingEventAggregator;
using EC.Utils;
using ECMonitor.Code.SysemNotifyIcon;
using Prism.Events;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
//using System.Drawing;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace ECMonitor
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private IRegionManager _regionManager;
private IEventAggregator _ea;
public MainWindow(IRegionManager regionManager, IEventAggregator ea)
{
_regionManager = regionManager;
_ea = ea;
this.ResizeMode = ResizeMode.CanMinimize;
InitializeComponent();
//var paletteHelper = new PaletteHelper();
//var theme = paletteHelper.GetTheme();
//theme.SetBaseTheme(Theme.Dark);
//paletteHelper.SetTheme(theme);
//系统托盘
SystemTrayParameter pars = new SystemTrayParameter("zgx.ico", "守护中", "", 0, notifyIcon_MouseDoubleClick);
this.notifyIcon = WPFSystemTray.SetSystemTray(pars, GetList());
_ea.GetEvent<ShowMessageSentEvent>().Subscribe(MessageReceived);
FLogger.SubLog += SubShowMessage;
FLogger.SubLog += SaveLog;
}
#region PageEvent
/// <summary>
/// 引发窗口关闭前响应,可阻止系统关闭
/// </summary>
/// <param name="e"></param>
protected override void OnClosing(CancelEventArgs e)
{
if (!EXIT_APP)
{
e.Cancel = true;
this.ShowInTaskbar = false;
HideWindow();
}
}
/// <summary>
/// 窗口关闭前响应,不可阻止系统关闭
/// </summary>
/// <param name="e"></param>
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
//关闭系统托盘
notifyIcon.Dispose();
}
#endregion PageEvent
#region 系统托盘
private bool EXIT_APP = false;
private System.Windows.Forms.NotifyIcon notifyIcon;
//托盘右键菜单集合
private List<SystemTrayMenu> GetList()
{
List<SystemTrayMenu> ls = new List<SystemTrayMenu>();
ls.Add(new SystemTrayMenu() { Txt = "打开主面板", Icon = "", Click = mainWin_Click });
ls.Add(new SystemTrayMenu() { Txt = "退出", Icon = "/img/exit.png", Click = Exit_Click });
return ls;
}
//双击事件
private void notifyIcon_MouseDoubleClick(object sender, System.Windows.Forms.MouseEventArgs e)
{
ShowWindow();
}
#region 托盘右键菜单
//打开主面板
private void mainWin_Click(object sender, EventArgs e)
{
ShowWindow();
}
//退出
private void Exit_Click(object sender, EventArgs e)
{
EXIT_APP = true;
this.Close();
//System.Windows.Forms.Application.ExitThread();
Environment.Exit(0);
// System.Windows.Application.Current.Shutdown();
}
public void ShowWindow()
{
this.Dispatcher.Invoke(new Action(() =>
{
if (this.WindowState == WindowState.Minimized)
{
this.WindowState = WindowState.Normal;
}
this.ShowInTaskbar = true;
this.Show();
this.Activate();
}));
}
private void HideWindow()
{
//this.WindowState = WindowState.Minimized;
this.Hide();
this.notifyIcon.ShowBalloonTip(3000, "", "程序在后台运行中,双击图标打开", System.Windows.Forms.ToolTipIcon.None); //弹出气泡提示
}
#endregion 托盘右键菜单
#endregion 系统托盘
#region 系统按钮
private void btnClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
// Exit_Click(sender, e);
}
private void SetFormSize()
{
double x1 = SystemParameters.PrimaryScreenWidth;//得到屏幕整体宽度
double y1 = SystemParameters.PrimaryScreenHeight;//得到屏幕整体高度
double xy = x1 + y1;
x1 = x1 * 0.9;
y1 = y1 * 0.9;
this.Width = x1;
this.Height = y1;
}
private void btnMax_Click(object sender, RoutedEventArgs e)
{
if (this.WindowState == WindowState.Maximized)
{
this.WindowState = WindowState.Normal;
}
else
{
this.WindowState = WindowState.Maximized;
}
}
private void btnMin_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void DockPanel_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
this.DragMove();
}
}
#endregion 系统按钮
#region top 按钮颜色
private SolidColorBrush barkgroudcolor = new SolidColorBrush(Color.FromRgb(0x4c, 0x8b, 0xb7));
private void btnVodieo_Click(object sender, RoutedEventArgs e)
{
btnVodieo.Background = barkgroudcolor;
btnSet.Background = Brushes.Transparent;
}
private void btnSet_Click(object sender, RoutedEventArgs e)
{
btnVodieo.Background = Brushes.Transparent;
btnSet.Background = barkgroudcolor;
}
#endregion top 按钮颜色
#region 统一底部 弹窗提示
public void MessageReceived(LogModel log)
{
MainSnackbar.MessageQueue?.Enqueue(log.message);
}
//public async Task<object> MessageTips(string message)
//{
// var sampleMessageDialog = new SampleMessageDialog
// {
// Message = { Text = message }
// };
// return await DialogHost.Show(sampleMessageDialog, "RootDialog");
//}
#endregion 统一底部 弹窗提示
#region 公共 基础函数
private int linenumber = 0;
private void SubShowMessage(MyLogger log)
{
if (log.Level >= (LoggerLevel)0)
{
linenumber++;
this.Dispatcher.Invoke(new Action(() =>
{
if (linenumber > 500)
{
//richText.Document.Blocks.Clear();
}
// richText.AppendText(log.Message + '\n');
}));
}
}
private void SaveLog(MyLogger log)
{
switch (log.Level)
{
case LoggerLevel.Debug:
LogFactory.GetLogger().Debug(log.Message);
break;
case LoggerLevel.Info:
LogFactory.GetLogger().Info(log.Message);
break;
case LoggerLevel.Error:
LogFactory.GetLogger().Error(log.Message);
break;
}
}
#endregion 公共 基础函数
}
}

131
ECMonitor/MainWindowViewModel.cs

@ -0,0 +1,131 @@
using EC.Entity.Warning;
using EC.UsingEventAggregator;
using EC.Utils;
using EC.Utils.ZMQ;
using ECMonitor.Code;
using ECMonitor.Code.Models;
using ECMonitor.Manager;
using ECMonitor.Page.Name;
using ECMonitor.Views;
using Prism.Commands;
using Prism.Events;
using Prism.Regions;
using System;
using System.Windows;
namespace ECMonitor
{
public class MainWindowViewModel : BaseModel
{
private MainWindow _w;
private ZMQManager _mqManager { get; set; }
private WebSocketManager _webSocketManager = null;
private FrmVideoPlayer _frmVideoPlayer;
private FrmVideoWanging _frmVideoWanging;
public DelegateCommand<Window> LoadCommand { get; private set; }
public DelegateCommand<string> NavigateCommand { get; private set; }
public MainWindowViewModel(IRegionManager regionManager, IEventAggregator ea) : base(regionManager, ea)
{
MessageManager.Init(ea);
LoadCommand = new DelegateCommand<Window>(Load);
NavigateCommand = new DelegateCommand<string>(Navigate);
regionManager.RegisterViewWithRegion(RegionsName.MainWindowCenter, typeof(Page.CameraMonitor.Main));
_mqManager = new ZMQManager();
_mqManager.OnDataReceived += ZMQDataReceived;
_webSocketManager = new WebSocketManager();
_webSocketManager.OnDataReceived += WebSocketDataReceived;
StartServer();
_frmVideoPlayer = new FrmVideoPlayer(ea);
_frmVideoWanging = new FrmVideoWanging(ea);
}
private void Navigate(string navigatePath)
{
if (navigatePath != null)
{
_regionManager.RequestNavigate(RegionsName.MainWindowCenter, navigatePath);
}
}
//窗口载入
private void Load(Window w)
{
_w = (MainWindow)w;
w.Closed += (sender, e) =>
{
StopServer();
};
}
private void StartServer()
{
_mqManager.Start();
_webSocketManager.Start();
}
private void StopServer()
{
_mqManager?.Stop();
_webSocketManager.Stop();
}
//关闭窗口
private void CloseWindow()
{
// canClose = true;
_w.Close();
}
#region ZMQ WebSocket
/// <summary>
/// ZMQ 消息
/// </summary>
/// <param name="sender"></param>
/// <param name="msgModel"></param>
private void ZMQDataReceived(object sender, PubSubModel msgModel)
{
SubMessageIn(msgModel);
}
private void SubMessageIn(PubSubModel msgModel)
{
if (msgModel.TopicLower().StartsWith(ZMQTopic.Show_Single_Video))//单个视频显示
{
_frmVideoPlayer.Play(msgModel.msg);
}
else if (msgModel.TopicLower().StartsWith(ZMQTopic.MainFrom_Show_Video))//在主窗体显示
{
_ea.GetEvent<ShowVoideInMainEvent>().Publish(msgModel.msg);
_w.ShowWindow();
}
//else if (msgModel.TopicLower() == ZMQTopic.Warning_Show_Video)//预警视频只是显示
//{
// _frmVideoWanging.NewWarningPlay(msgModel.msg);
//}
else if (msgModel.TopicLower() == ZMQTopic.AI_Detect_Warning_Data)//视频预警输入
{
try
{
WarningModel warningModel = msgModel.msg.ToObject<WarningModel>();
_frmVideoWanging.NewWarningPlay(warningModel.ip);
_ea.GetEvent<WaningVoideEvent>().Publish(warningModel);
}
catch (Exception ex)
{
LogFactory.GetLogger().Error(ex);
}
}
}
private void WebSocketDataReceived(object sender, PubSubModel pubSubModel)
{
SubMessageIn(pubSubModel);
}
#endregion ZMQ WebSocket
}
}

61
ECMonitor/Manager/CameraManager.cs

@ -0,0 +1,61 @@
using EC.Entity.Video;
using ECMonitor.Code.DB;
using System.Collections.Generic;
namespace ECMonitor.Code
{
public class CameraManager
{
public static List<MonitorCamera> CameraList = new List<MonitorCamera>();
public static List<MsVideoRecorder> LoadData()
{
var msVideoRecorderList = DBDataHelper.LoadCameraData();
///添加测试
//msVideoRecorderList.Add(TestMsVideoRecorder());
CameraList.Clear();
foreach (MsVideoRecorder msVideoRecorder in msVideoRecorderList)
{
CameraList.AddRange(msVideoRecorder.MsCameraSettingList);
}
return msVideoRecorderList;
}
public static MsVideoRecorder TestMsVideoRecorder()
{
MsVideoRecorder msVideoRecorder = new MsVideoRecorder();
msVideoRecorder.MsCameraSettingList.Add(new MonitorCamera("192.168.1.108", 37777, "admin", "hk123456", 2));
msVideoRecorder.MsCameraSettingList.Add(new MonitorCamera("192.168.1.65", 80000, "admin", "hk123456", 5));
msVideoRecorder.MsCameraSettingList.Add(new MonitorCamera("120.198.209.123", 80000, "admin", "hk123456", 5));
msVideoRecorder.MsCameraSettingList.Add(new MonitorCamera("218.204.221.100", 80000, "admin", "hk123456", 5));
msVideoRecorder.MsCameraSettingList.Add(new MonitorCamera("120.236.237.23", 80000, "admin", "hk123456", 5));
return msVideoRecorder;
}
public static void Add(MonitorCamera camera)
{
CameraList.Add(camera);
}
public static MonitorCamera GetCamera(string cameraIp)
{
if (string.IsNullOrEmpty(cameraIp))
{
return null;
}
if (CameraList.Count == 0)
{
LoadData();
}
var tempCamera = CameraList.Find(c => c.Ip == cameraIp);
if (tempCamera == null)//获取 新更新 的相机
{
LoadData();
tempCamera = CameraList.Find(c => c.Ip == cameraIp);
}
return tempCamera;
}
}
}

56
ECMonitor/Manager/MessageManager.cs

@ -0,0 +1,56 @@
using EC.UsingEventAggregator;
using ECMonitor.UC;
using MaterialDesignThemes.Wpf;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ECMonitor.Manager
{
public class MessageManager
{
static IEventAggregator _ea { get; set; }
public static void Init(IEventAggregator ea)
{
_ea = ea;
}
public static void ShowMessage( string msg, bool isErr=false)
{
int level = 0;
if (isErr)
{
level = 3;
}
LogModel log = new LogModel(level, msg);
_ea.GetEvent<ShowMessageSentEvent>().Publish(log);
}
public static void ShowMessage( int level, string msg, string remark="")
{
LogModel log = new LogModel(level, msg,remark);
_ea.GetEvent<ShowMessageSentEvent>().Publish(log);
}
static object messageLock = new object();
/// <summary>
/// 弹窗显示
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public static Task<object> MessageBox(string message)
{
lock (messageLock)
{
var sampleMessageDialog = new SampleMessageDialog
{
Message = { Text = message }
};
return DialogHost.Show(sampleMessageDialog, "RootDialog");
}
}
}
}

50
ECMonitor/Manager/ShowVideoManager.cs

@ -0,0 +1,50 @@
using EC.Entity.Video;
using ECMonitor.Code.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ECMonitor.Code
{
public class ShowVideoManager
{
public int UCVideoIndex = 0;
public List<VideoShowModel> UCVideoList = new List<VideoShowModel>();
public VideoShowModel CreateVideoShowModel(string cameraIp)
{
VideoShowModel ucVideoShowModel = new VideoShowModel();
ucVideoShowModel.CameraIp = cameraIp;
ucVideoShowModel.UCName = "UCRegVideo" + UCVideoIndex++;
MonitorCamera camera = CameraManager.GetCamera(cameraIp);
if (camera != null)
{
ucVideoShowModel.Camera = camera;
}
else {
ucVideoShowModel.Message = "没有视频";
}
UCVideoList.Add(ucVideoShowModel);
return ucVideoShowModel;
}
/// <summary>
/// 获取显示模块
/// </summary>
/// <param name="cameraIp"></param>
/// <returns></returns>
public VideoShowModel GetVideoShowModel(string cameraIp)
{
return UCVideoList.Find(c => c.CameraIp == cameraIp);
}
internal void Remove(VideoShowModel videoShow)
{
UCVideoList.Remove(videoShow);
}
}
}

133
ECMonitor/Manager/VideoPlayManager.cs

@ -0,0 +1,133 @@
using ECMonitor.UC.Videos;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace ECMonitor.Manager
{
public class VideoPlayManager
{
private int _videoIndex = 0;
private List<IUCPlayer> UCVideoList = new List<IUCPlayer>();
/// <summary>
/// 获取显示模块
/// </summary>
/// <param name="cameraIp"></param>
/// <returns></returns>
public UserControl GetUserControl(string cameraIp)
{
return UCVideoList.Find(c => c.GetCameraIp() == cameraIp).GetControl();
}
public IUCPlayer GetUCVideo(string cameraIp)
{
return UCVideoList.Find(c => c.GetCameraIp() == cameraIp);
}
internal void Add(IUCPlayer videoShow)
{
videoShow.SetIndex(UCVideoList.Count);
UCVideoList.Add(videoShow);
}
internal void Remove(IUCPlayer videoShow)
{
UCVideoList.Remove(videoShow);
int icont = UCVideoList.Count;
for(int i = 0; i < icont; i++)
{
UCVideoList[i].SetIndex(i);
}
}
internal List<IUCPlayer> GetUCVideoList()
{
return UCVideoList;
}
internal void SetALLUnSelected()
{
foreach (IUCPlayer videoPlay in UCVideoList)
{
videoPlay.SetSelected(false);
}
}
public IUCPlayer CreateVideo(IEventAggregator ea,double _videoWidth, double _videoHeight, int videoType=0,bool showCloseButton=true)
{
switch (videoType)
{
case 0://Rtsp
UCFFmpegPlayer rtspVideo = new UCFFmpegPlayer(ea,_videoWidth, _videoHeight, _videoIndex++, showCloseButton,true);
rtspVideo._videoType = videoType;
UCVideoList.Add(rtspVideo);
return rtspVideo;
//case 1://海康直连
// return null
// break;
default:
UCFFmpegPlayer defaultVideo = new UCFFmpegPlayer(ea,_videoWidth, _videoHeight, _videoIndex++, showCloseButton);
defaultVideo._videoType = videoType;
UCVideoList.Add(defaultVideo);
return defaultVideo;
}
}
/// <summary>
/// 创建视频预警线规划
/// </summary>
/// <param name="ea"></param>
/// <param name="_videoWidth"></param>
/// <param name="_videoHeight"></param>
/// <param name="videoType"></param>
/// <returns></returns>
public IUCPlayer CreateWarnCreateLinePlayer(IEventAggregator ea, double _videoWidth, double _videoHeight, int videoType = 0 )
{
UCFFmpegPlayer rtspVideo = new UCFFmpegPlayer(ea, _videoWidth, _videoHeight, _videoIndex++, false, false);
rtspVideo._videoType = videoType;
UCVideoList.Add(rtspVideo);
return rtspVideo;
}
public IUCPlayer CreateWaringVideo(IEventAggregator ea, double _videoWidth, double _videoHeight, int videoType = 0, bool showCloseButton = false)
{
UCAIWarningPlayer rtspVideo = new UCAIWarningPlayer(ea, _videoWidth, _videoHeight, _videoIndex++, showCloseButton);
rtspVideo._videoType = videoType;
UCVideoList.Add(rtspVideo);
return rtspVideo;
}
public IUCPlayer CreateVideoAI(double _videoWidth, double _videoHeight, int videoType = 0, bool showCloseButton = true)
{
switch (videoType)
{
case 0://Rtsp
UCFFmpegAIPlayer rtspVideo = new UCFFmpegAIPlayer(_videoWidth, _videoHeight, _videoIndex++, showCloseButton);
rtspVideo.VideoType = videoType;
UCVideoList.Add(rtspVideo);
return rtspVideo;
//case 1://海康直连
// return null
// break;
default:
rtspVideo = new UCFFmpegAIPlayer(_videoWidth, _videoHeight, _videoIndex++, showCloseButton);
rtspVideo.VideoType = videoType;
UCVideoList.Add(rtspVideo);
return rtspVideo;
}
}
}
}

81
ECMonitor/Manager/WebSocketManager.cs

@ -0,0 +1,81 @@

using EC.Utils.ZMQ;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EC.Utils;
using Fleck;
namespace ECMonitor.Manager
{
public class WebSocketManager
{
WebSocketServer _webSocketServer = null;
List<IWebSocketConnection> allSockets = new List<IWebSocketConnection>();
public event EventHandler<PubSubModel> OnDataReceived; //定义一个委托类型的事件
public WebSocketManager( )
{
FleckLog.Level = LogLevel.Debug;
_webSocketServer = new WebSocketServer("ws://0.0.0.0:"+ ConfigHelper.WebSocketSvrPort());
}
public void Start()
{
_webSocketServer.Start(socket =>
{
socket.OnOpen = () =>
{
// Console.WriteLine("Open!");
allSockets.Add(socket);
};
socket.OnClose = () =>
{
Console.WriteLine("Close!");
allSockets.Remove(socket);
};
socket.OnMessage = message =>
{
//Console.WriteLine(message);
// allSockets.ToList().ForEach(s => s.Send("Echo: " + message));
WebSocketDataReceived(socket,message);
};
});
}
public void Stop()
{
allSockets.ToList().ForEach(s => s.Close());
_webSocketServer.Dispose();
}
private void WebSocketDataReceived(object sender, string message)
{
try
{
if (message.IndexOf("topic") > 0)
{
PubSubModel pubSubModel = message.ToObject<PubSubModel>();
if (pubSubModel != null)
{
OnDataReceived?.Invoke(this, pubSubModel);
}
}
}
catch(Exception ex) {
LogFactory.GetLogger().Error(ex);
}
}
}
}

82
ECMonitor/Manager/ZMQManager.cs

@ -0,0 +1,82 @@
using EC.Utils.ZMQ;
using EC.UsingEventAggregator;
using EC.Utils.Config;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EC.Utils;
namespace ECMonitor.Code
{
public class ZMQManager
{
/// <summary>
/// 通用zmq
/// </summary>
static ZMQHelper _zmqHelper;
public event EventHandler<PubSubModel> OnDataReceived; //定义一个委托类型的事件
public void Start()
{
try
{
string pubserver = ConfigHelper.PUBServer();
string subserver = ConfigHelper.SUBServer();
List<string> topics = SUBTopicList();
_zmqHelper = new ZMQHelper(pubserver, subserver, topics);
_zmqHelper.OnSubData += SubDataReceived;
_zmqHelper.Start();
}catch(Exception ex)
{
FLogger.Error(ex);
}
}
internal static List<string> SUBTopicList()
{
List<string> topicList = new List<string>();
topicList.Add("Topic");
topicList.Add(ZMQTopic.Show_Single_Video + ConfigHelper.AppId);
topicList.Add(ZMQTopic.MainFrom_Show_Video + ConfigHelper.AppId);
topicList.Add(ZMQTopic.MainFrom_Show_Video);
topicList.Add(ZMQTopic.AI_Detect_Warning_Data);
return topicList;
}
public void Stop()
{
_zmqHelper?.Stop();
}
private void SubDataReceived(object sender, PubSubModel msgModel)
{
try
{
OnDataReceived?.Invoke(sender, msgModel);
}
catch (Exception ex)
{
LogFactory.GetLogger().Error(ex);
}
}
public void Send(string topic, string msg)
{
_zmqHelper.Send( topic, msg);
}
}
}

24
ECMonitor/NavigationModule.cs

@ -0,0 +1,24 @@
using ECMonitor.Page.Name;
using Prism.Ioc;
using Prism.Modularity;
namespace ECMonitor
{
public class NavigationModule : IModule
{
public void OnInitialized(IContainerProvider containerProvider)
{
}
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<Page.CameraMonitor.Main>(name: ViewsName.CameraMonitorMain);
containerRegistry.RegisterForNavigation<Page.SystemSet.Main>(name: ViewsName.SystemSetMain);
containerRegistry.RegisterForNavigation<Page.SystemSet.ManageSet>(name: ViewsName.SystemSetManageSet);
containerRegistry.RegisterForNavigation<Page.SystemSet.ManageNvr>(name: ViewsName.SystemSetManageNvr);
containerRegistry.RegisterForNavigation<Page.SystemSet.ManageIpc>(name: ViewsName.SystemSetManageIpc);
containerRegistry.RegisterForNavigation<Page.SystemSet.SearchIpc>(name: ViewsName.SystemSetSearchIpc);
}
}
}

226
ECMonitor/Page/CameraMonitor/CameraAdjust.xaml

@ -0,0 +1,226 @@
<UserControl x:Class="ECMonitor.Page.CameraMonitor.CameraAdjust"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="300">
<UserControl.Resources>
<SolidColorBrush x:Key="Background" Color="#40444d" />
<SolidColorBrush x:Key="BackgroundInterval" Color="#292D36" />
<SolidColorBrush x:Key="ButtonNormal" Color="AntiqueWhite" />
<SolidColorBrush x:Key="ButtonLight" Color="DeepSkyBlue" />
<SolidColorBrush x:Key="ButtonMouseOver" Color="DeepSkyBlue" />
<SolidColorBrush x:Key="ButtonMousePress" Color="Aqua" />
<ControlTemplate x:Key="ArrowButtonTemplate" TargetType="{x:Type Button}">
<Polygon x:Name="ButtonPolygon" Stretch="Fill" Points="0,0 200,0 100,-100" Stroke="Black" StrokeThickness="0">
<Polygon.Fill>
<SolidColorBrush Color="AntiqueWhite" Opacity="0.8" />
</Polygon.Fill>
</Polygon>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="ButtonPolygon" Property="Fill" Value="{StaticResource ButtonMouseOver}" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="ButtonPolygon" Property="Fill" Value="{StaticResource ButtonMousePress}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style x:Key="ArrowButtonStyle" TargetType="Button">
<Setter Property="Width" Value="18" />
<Setter Property="Height" Value="9" />
<Setter Property="Cursor" Value="Hand" />
</Style>
<ControlTemplate x:Key="ResetButtonTemplate" TargetType="{x:Type Button}">
<Grid>
<Ellipse x:Name="Ellipse" Stroke="{StaticResource ButtonLight}" StrokeThickness="2" Fill="{StaticResource Background}" />
<Path x:Name="Icon" Width="20" Height="20" Fill="AntiqueWhite" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center"
Data="F1 M 24,13C 27.1521,13 29.9945,14.3258 32,16.4501L 32,11L 35,14L 35,22L 27,22L 24,19L 29.5903,19C 28.217,17.4656 26.2212,16.5 24,16.5C 20.1969,16.5 17.055,19.3306 16.5661,23L 13.0448,23C 13.5501,17.3935 18.262,13 24,13 Z M 24,31.5C 27.8031,31.5 30.945,28.6694 31.4339,25L 34.9552,25C 34.4499,30.6065 29.738,35 24,35C 20.8479,35 18.0055,33.6742 16,31.5499L 16,37L 13,34L 13,26L 21,26L 24,29L 18.4097,29C 19.783,30.5344 21.7787,31.5 24,31.5 Z" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Ellipse" Property="Fill" Value="{StaticResource BackgroundInterval}" />
<Setter TargetName="Icon" Property="Fill" Value="{StaticResource ButtonMouseOver}" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Ellipse" Property="Fill" Value="{StaticResource BackgroundInterval}" />
<Setter TargetName="Icon" Property="Fill" Value="{StaticResource ButtonMousePress}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style x:Key="ResetButtonStyle" TargetType="Button">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="Cursor" Value="Hand" />
</Style>
<ControlTemplate x:Key="PlusButtonTemplate" TargetType="{x:Type Button}">
<!--<Grid Margin="5" Cursor="Hand">
<Ellipse x:Name="Ellipse" Stroke="{StaticResource BackgroundInterval}" StrokeThickness="2" Fill="{StaticResource Background}" />
<materialDesign:PackIcon Kind="Plus" Foreground="AliceBlue" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>-->
<Border x:Name="Border" CornerRadius="100" Background="{StaticResource Background}" BorderBrush="{StaticResource BackgroundInterval}" BorderThickness="2">
<materialDesign:PackIcon Kind="Plus" Foreground="{StaticResource ButtonNormal}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="Background" Value="{StaticResource ButtonMouseOver}" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Border" Property="Background" Value="Transparent" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="MinusButtonTemplate" TargetType="{x:Type Button}">
<Border x:Name="Border" CornerRadius="100" Background="{StaticResource Background}" BorderBrush="{StaticResource BackgroundInterval}" BorderThickness="2">
<materialDesign:PackIcon Kind="Minus" Foreground="{StaticResource ButtonNormal}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="Background" Value="{StaticResource ButtonMouseOver}" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Border" Property="Background" Value="Transparent" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style x:Key="PressButtonStyle" TargetType="Button">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="Margin" Value="7" />
<Setter Property="Cursor" Value="Hand" />
</Style>
</UserControl.Resources>
<StackPanel>
<Border CornerRadius="100" Background="{StaticResource Background}" BorderBrush="{StaticResource BackgroundInterval}" BorderThickness="10" Height="175" Width="175" Margin="0,20,0,0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Button x:Name="luBtn" Grid.Row="0" Grid.Column="0" Template="{StaticResource ArrowButtonTemplate}"
Style="{StaticResource ArrowButtonStyle}" HorizontalAlignment="Right" VerticalAlignment="Bottom" RenderTransformOrigin="0.0,0.5">
<Button.RenderTransform>
<RotateTransform Angle="-45" />
</Button.RenderTransform>
</Button>
<Button x:Name="uBtn" Grid.Row="0" Grid.Column="1" Template="{StaticResource ArrowButtonTemplate}"
Style="{StaticResource ArrowButtonStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5">
<Button.RenderTransform>
<RotateTransform Angle="0" />
</Button.RenderTransform>
</Button>
<Button x:Name="ruBtn" Grid.Row="0" Grid.Column="2" Template="{StaticResource ArrowButtonTemplate}"
Style="{StaticResource ArrowButtonStyle}" HorizontalAlignment="Left" VerticalAlignment="Bottom" RenderTransformOrigin="0.9,0.45">
<Button.RenderTransform>
<RotateTransform Angle="45" />
</Button.RenderTransform>
</Button>
<Button x:Name="lBtn" Grid.Row="1" Grid.Column="0" Template="{StaticResource ArrowButtonTemplate}"
Style="{StaticResource ArrowButtonStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5">
<Button.RenderTransform>
<RotateTransform Angle="-90" />
</Button.RenderTransform>
</Button>
<Border x:Name="cBtn" Grid.Row="1" Grid.Column="1" CornerRadius="100" BorderBrush="{StaticResource BackgroundInterval}" BorderThickness="5">
<Button Template="{StaticResource ResetButtonTemplate}"
Style="{StaticResource ResetButtonStyle}">
</Button>
</Border>
<Button x:Name="rBtn" Grid.Row="1" Grid.Column="2" Template="{StaticResource ArrowButtonTemplate}"
Style="{StaticResource ArrowButtonStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5">
<Button.RenderTransform>
<RotateTransform Angle="90" />
</Button.RenderTransform>
</Button>
<Button x:Name="ldBtn" Grid.Row="2" Grid.Column="0" Template="{StaticResource ArrowButtonTemplate}"
Style="{StaticResource ArrowButtonStyle}" HorizontalAlignment="Right" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.9">
<Button.RenderTransform>
<RotateTransform Angle="-135" />
</Button.RenderTransform>
</Button>
<Button x:Name="dBtn" Grid.Row="2" Grid.Column="1" Template="{StaticResource ArrowButtonTemplate}"
Style="{StaticResource ArrowButtonStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5">
<Button.RenderTransform>
<RotateTransform Angle="180" />
</Button.RenderTransform>
</Button>
<Button x:Name="rdBtn" Grid.Row="2" Grid.Column="2" Template="{StaticResource ArrowButtonTemplate}"
Style="{StaticResource ArrowButtonStyle}" HorizontalAlignment="Left" VerticalAlignment="Top" RenderTransformOrigin="0.45,0.9">
<Button.RenderTransform>
<RotateTransform Angle="135" />
</Button.RenderTransform>
</Button>
</Grid>
</Border>
<Border Height="175" Width="175" Margin="0,10,0,0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center"
Style="{StaticResource MaterialDesignCaptionTextBlock}" Foreground="{StaticResource ButtonNormal}" Text="变倍" />
<Button Grid.Row="0" Grid.Column="1" Template="{StaticResource PlusButtonTemplate}"
Style="{StaticResource PressButtonStyle}">
</Button>
<Button Grid.Row="0" Grid.Column="3" Template="{StaticResource MinusButtonTemplate}"
Style="{StaticResource PressButtonStyle}">
</Button>
<TextBlock Grid.Row="1" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center"
Style="{StaticResource MaterialDesignCaptionTextBlock}" Foreground="{StaticResource ButtonNormal}" Text="变焦" />
<Button Grid.Row="1" Grid.Column="1" Template="{StaticResource PlusButtonTemplate}"
Style="{StaticResource PressButtonStyle}">
</Button>
<Button Grid.Row="1" Grid.Column="3" Template="{StaticResource MinusButtonTemplate}"
Style="{StaticResource PressButtonStyle}">
</Button>
<TextBlock Grid.Row="2" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center"
Style="{StaticResource MaterialDesignCaptionTextBlock}" Foreground="{StaticResource ButtonNormal}" Text="光圈" />
<Button Grid.Row="2" Grid.Column="1" Template="{StaticResource PlusButtonTemplate}"
Style="{StaticResource PressButtonStyle}">
</Button>
<Button Grid.Row="2" Grid.Column="3" Template="{StaticResource MinusButtonTemplate}"
Style="{StaticResource PressButtonStyle}">
</Button>
<TextBlock Grid.Row="3" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center"
Style="{StaticResource MaterialDesignCaptionTextBlock}" Foreground="{StaticResource ButtonNormal}" Text="步长" />
<Slider x:Name="stepSlider" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="7,0,7,0"
Minimum="1" Maximum="10" Value="6" TickFrequency="1" materialDesign:SliderAssist.OnlyShowFocusVisualWhileDragging="True"
Style="{StaticResource MaterialDesignDiscreteSlider}" Cursor="Hand" />
</Grid>
</Border>
</StackPanel>
</UserControl>

135
ECMonitor/Page/CameraMonitor/CameraAdjust.xaml.cs

@ -0,0 +1,135 @@
using EC.Onvif;
using EC.UsingEventAggregator;
using Prism.Events;
using System.Windows;
using System.Windows.Controls;
namespace ECMonitor.Page.CameraMonitor
{
/// <summary>
/// UCMainRight.xaml 的交互逻辑
/// </summary>
public partial class CameraAdjust : UserControl
{
private IEventAggregator _ea { get; set; }
private OnvifClient _onvifClient { get; set; }
public CameraAdjust(IEventAggregator ea)
{
InitializeComponent();
_ea = ea;
_ea.GetEvent<SendOnvifClientEvent>().Subscribe(SetCurOnvifClient);
InitBtnListenEvent();
}
#region Get & Set
private void SetCurOnvifClient(OnvifClient obj)
{
_onvifClient = obj;
}
#endregion Get & Set
#region ListenEvent
private void InitBtnListenEvent()
{
//luBtn.Click += OperateOnvifMouseDown;
//lBtn.Click += OperateOnvifMouseDown;
//ldBtn.Click += OperateOnvifMouseDown;
//uBtn.Click += OperateOnvifMouseDown;
//dBtn.Click += OperateOnvifMouseDown;
//ruBtn.Click += OperateOnvifMouseDown;
//rBtn.Click += OperateOnvifMouseDown;
//rdBtn.Click += OperateOnvifMouseDown;
luBtn.AddHandler(MouseDownEvent, new RoutedEventHandler(OperateOnvifMouseDown), true);
lBtn.AddHandler(MouseDownEvent, new RoutedEventHandler(OperateOnvifMouseDown), true);
ldBtn.AddHandler(MouseDownEvent, new RoutedEventHandler(OperateOnvifMouseDown), true);
uBtn.AddHandler(MouseDownEvent, new RoutedEventHandler(OperateOnvifMouseDown), true);
cBtn.AddHandler(MouseDownEvent, new RoutedEventHandler(OperateOnvifMouseDown), true);
dBtn.AddHandler(MouseDownEvent, new RoutedEventHandler(OperateOnvifMouseDown), true);
ruBtn.AddHandler(MouseDownEvent, new RoutedEventHandler(OperateOnvifMouseDown), true);
rBtn.AddHandler(MouseDownEvent, new RoutedEventHandler(OperateOnvifMouseDown), true);
rdBtn.AddHandler(MouseDownEvent, new RoutedEventHandler(OperateOnvifMouseDown), true);
luBtn.AddHandler(MouseUpEvent, new RoutedEventHandler(OperateOnvifMouseUp), true);
lBtn.AddHandler(MouseUpEvent, new RoutedEventHandler(OperateOnvifMouseUp), true);
ldBtn.AddHandler(MouseUpEvent, new RoutedEventHandler(OperateOnvifMouseUp), true);
uBtn.AddHandler(MouseUpEvent, new RoutedEventHandler(OperateOnvifMouseUp), true);
cBtn.AddHandler(MouseUpEvent, new RoutedEventHandler(OperateOnvifMouseUp), true);
dBtn.AddHandler(MouseUpEvent, new RoutedEventHandler(OperateOnvifMouseUp), true);
ruBtn.AddHandler(MouseUpEvent, new RoutedEventHandler(OperateOnvifMouseUp), true);
rBtn.AddHandler(MouseUpEvent, new RoutedEventHandler(OperateOnvifMouseUp), true);
rdBtn.AddHandler(MouseUpEvent, new RoutedEventHandler(OperateOnvifMouseUp), true);
}
private bool IsOperateOnvif { get; set; }
private void OperateOnvifMouseDown(object sender, RoutedEventArgs e)
{
if (_onvifClient == null || IsOperateOnvif)
return;
IsOperateOnvif = true;
var btnName = ((Button)sender).Name;
var step = (float)stepSlider.Value;
var dist = step * OnvifClient.atomDist;
var speed = step * OnvifClient.atomSpeed;
float[] ptz = new float[] { 0, 0, 0 };//ptx,pty,zx
switch (btnName)
{
case "luBtn":
ptz = new float[] { -1, 1, 0 };
break;
case "uBtn":
ptz = new float[] { 0, 1, 0 };
break;
case "ruBtn":
ptz = new float[] { 1, 1, 0 };
break;
case "lBtn":
ptz = new float[] { -1, 0, 0 };
break;
case "cBtn":
ptz = new float[] { 0, 0, 0 };
break;
case "rBtn":
ptz = new float[] { 1, 0, 0 };
break;
case "ldBtn":
ptz = new float[] { -1, -1, 0 };
break;
case "dBtn":
ptz = new float[] { 0, -1, 0 };
break;
case "rdBtn":
ptz = new float[] { 1, -1, 0 };
break;
}
//_onvifClient.RelativeMoveAsync(ptz[0] * dist, ptz[1] * dist, ptz[2] * dist);
_onvifClient.ContinuousMoveAsync(ptz[0] * speed, ptz[1] * speed, ptz[2] * speed);
}
private void OperateOnvifMouseUp(object sender, RoutedEventArgs e)
{
if (_onvifClient == null)
return;
IsOperateOnvif = false;
_onvifClient.StopAsync();
}
#endregion ListenEvent
}
}

13
ECMonitor/Page/CameraMonitor/CameraAdjustViewModel.cs

@ -0,0 +1,13 @@
using ECMonitor.Code.Models;
using Prism.Events;
using Prism.Regions;
namespace ECMonitor.Page.CameraMonitor
{
public class CameraAdjustViewModel : BaseModel
{
public CameraAdjustViewModel(IRegionManager regionManager, IEventAggregator ea) : base(regionManager, ea)
{
}
}
}

29
ECMonitor/Page/CameraMonitor/CameraTree.xaml

@ -0,0 +1,29 @@
<UserControl x:Class="ECMonitor.Page.CameraMonitor.CameraTreeView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:mvvm="http://prismlibrary.com/"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:video="clr-namespace:EC.Entity.Video;assembly=EC.Entity"
mc:Ignorable="d"
mvvm:ViewModelLocator.AutoWireViewModel="True"
d:DesignHeight="450" d:DesignWidth="300">
<Grid MinWidth="200">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TreeView Grid.Row="0" ItemsSource="{Binding MsVideoRecorderList,Mode=OneWay}" MinWidth="200" MouseDoubleClick="TreeView_MouseDoubleClick">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type video:MsVideoRecorder}" ItemsSource="{Binding MsCameraSettingList}">
<TextBlock Text="{Binding DeviceName}" Margin="3,2" />
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type video:MonitorCamera}">
<TextBlock Text="{Binding CameraName}" Margin="3 2" />
</DataTemplate>
</TreeView.Resources>
</TreeView>
</Grid>
</UserControl>

49
ECMonitor/Page/CameraMonitor/CameraTree.xaml.cs

@ -0,0 +1,49 @@
using EC.Entity.Video;
using EC.UsingEventAggregator;
using Prism.Events;
using Prism.Regions;
using System.Windows.Controls;
using System.Windows.Input;
namespace ECMonitor.Page.CameraMonitor
{
/// <summary>
/// UCMainLeft.xaml 的交互逻辑
/// </summary>
public partial class CameraTreeView : UserControl
{
public IRegionManager _regionManager { get; set; }
public IEventAggregator _ea { get; set; }
public CameraTreeView(IRegionManager regionManager, IEventAggregator ea)
{
_regionManager = regionManager;
_ea = ea;
InitializeComponent();
}
/// <summary>
/// TreesView's SelectedItem is read-only. Hence we can't bind it. There is a way to obtain a selected item.
/// </summary>
/// <param name="sender"></param>
/// <param name="mouseButtonEventArgs"></param>
private void TreeView_MouseDoubleClick(object sender, MouseButtonEventArgs mouseButtonEventArgs)
{
var node = (TreeView)sender;
var item = node.SelectedItem;
var type = item?.GetType();
if (type == null)
return;
if (type == typeof(MsVideoRecorder))
{
var recoder = (MsVideoRecorder)item;
}
else if (type == typeof(MonitorCamera))
{
var camera = (MonitorCamera)item;
_ea.GetEvent<ShowVoideInMainEvent>().Publish(camera.Ip);
}
}
}
}

26
ECMonitor/Page/CameraMonitor/CameraTreeViewModel.cs

@ -0,0 +1,26 @@
using EC.Entity.Video;
using ECMonitor.Code;
using ECMonitor.Code.Models;
using Prism.Events;
using Prism.Regions;
using System.Collections.Generic;
namespace ECMonitor.Page.CameraMonitor
{
public class CameraTreeViewModel : BaseModel
{
private IEventAggregator _ea;
public List<MsVideoRecorder> MsVideoRecorderList { get; set; }
public CameraTreeViewModel(IRegionManager regionManager, IEventAggregator ea) : base(regionManager, ea)
{
_ea = ea;
LoadData();
}
private void LoadData()
{
MsVideoRecorderList = CameraManager.LoadData();
}
}
}

83
ECMonitor/Page/CameraMonitor/CameraVideo.xaml

@ -0,0 +1,83 @@
<UserControl x:Class="ECMonitor.Page.CameraMonitor.CameraVideo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:prism="http://prismlibrary.com/"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" Loaded="UserControl_Loaded" SizeChanged="UserControl_SizeChanged">
<Grid Background="{DynamicResource PrimaryBackGroupBrush}">
<Grid.RowDefinitions>
<RowDefinition Height=" *" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<WrapPanel x:Name="panMain" Grid.Row="0" Grid.Column="0" Margin="2,2,2,2">
</WrapPanel>
<!--panMain1用于最大化-->
<WrapPanel x:Name="panMain1" Grid.Row="0" Grid.Column="0" Panel.ZIndex="1" Margin="2,2,2,2">
</WrapPanel>
<StackPanel
Orientation="Horizontal"
Grid.Column="0"
Grid.Row="1"
Margin="0,0,0,0"
Background="{DynamicResource PrimaryBodyBrush}">
<!-- the following based on https://material.io/guidelines/components/buttons.html#buttons-toggle-buttons -->
<ListBox
Style="{StaticResource MaterialDesignToolToggleListBox}"
SelectedIndex="0"
Padding="0,0,0,0" SelectionChanged="BarButtons_SelectionChanged"
Name="barButtons">
<ListBoxItem Padding="5,0,5,0">
<Border BorderThickness="2" BorderBrush="#FFFFFF" Height="20" Width="20">
<Border Grid.Row="0" Background="#FFFFFF" Height="10" Width="10" Margin="2,2" />
</Border>
</ListBoxItem>
<ListBoxItem Padding="5,0,5,0">
<Grid Width="20" Height="20">
<Grid.RowDefinitions>
<RowDefinition Height=" 50*" />
<RowDefinition Height="50*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=" 50*" />
<ColumnDefinition Width="50*" />
</Grid.ColumnDefinitions>
<Border Grid.Row="0" Grid.Column="0" Background="#FFFFFF" Width="9" Height="9" Margin="0,0" />
<Border Grid.Row="1" Grid.Column="0" Background="#FFFFFF" Width="9" Height="9" Margin="0,0" />
<Border Grid.Row="1" Grid.Column="1" Background="#FFFFFF" Width="9" Height="9" Margin="0,0" />
<Border Grid.Row="0" Grid.Column="1" Background="#FFFFFF" Width="9" Height="9" Margin="0,0" />
</Grid>
</ListBoxItem>
<ListBoxItem Padding="5,0,5,0">
<Grid Width="20" Height="20">
<Grid.RowDefinitions>
<RowDefinition Height="10*" />
<RowDefinition Height="10*" />
<RowDefinition Height="10*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10*" />
<ColumnDefinition Width="10*" />
<ColumnDefinition Width="10*" />
</Grid.ColumnDefinitions>
<Border Grid.Row="0" Grid.Column="0" Background="#FFFFFF" Width="6" Height="6" Margin="0,0,1,1" />
<Border Grid.Row="0" Grid.Column="1" Background="#FFFFFF" Width="6" Height="6" Margin="0,0,1,1" />
<Border Grid.Row="0" Grid.Column="2" Background="#FFFFFF" Width="6" Height="6" Margin="0,0,1,1" />
<Border Grid.Row="1" Grid.Column="0" Background="#FFFFFF" Width="6" Height="6" Margin="0,0,1,1" />
<Border Grid.Row="1" Grid.Column="1" Background="#FFFFFF" Width="6" Height="6" Margin="0,0,1,1" />
<Border Grid.Row="1" Grid.Column="2" Background="#FFFFFF" Width="6" Height="6" Margin="0,0,1,1" />
<Border Grid.Row="2" Grid.Column="0" Background="#FFFFFF" Width="6" Height="6" Margin="0,0,1,1" />
<Border Grid.Row="2" Grid.Column="1" Background="#FFFFFF" Width="6" Height="6" Margin="0,0,1,1" />
<Border Grid.Row="2" Grid.Column="2" Background="#FFFFFF" Width="6" Height="6" Margin="0,0,1,1" />
</Grid>
</ListBoxItem>
</ListBox>
</StackPanel>
</Grid>
</UserControl>

358
ECMonitor/Page/CameraMonitor/CameraVideo.xaml.cs

@ -0,0 +1,358 @@
using EC.Entity.Video;
using EC.UsingEventAggregator;
using ECMonitor.Code;
using ECMonitor.Manager;
using ECMonitor.UC.Videos;
using Prism.Events;
using Prism.Regions;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
namespace ECMonitor.Page.CameraMonitor
{
/// <summary>
/// MainVideo.xaml 的交互逻辑
/// </summary>
public partial class CameraVideo : UserControl
{
public IRegionManager _regionManager { get; set; }
public IEventAggregator _ea { get; set; }
private VideoPlayManager _videoPlayManager { get; set; } = new VideoPlayManager();
private double _videoWidth = 400;
private double _videoHeight = 300;
//窗体长宽比,防止窗体变化时 窗体变形
private double _videoWH { get; set; } = -1;
/// <summary>
/// 当前选中播放器好
/// </summary>
private int _playerSelectIndex { get; set; } = 0;
/// <summary>
/// 当天窗体内播放器数量
/// </summary>
private int _videoNumber { get; set; } = 1;
/// <summary>
/// 上一次选择 按钮 窗体数 1窗 4窗
/// </summary>
private int _barButtonSelectedIndex = 0;
public CameraVideo(IRegionManager regionManager, IEventAggregator ea)
{
_regionManager = regionManager;
_ea = ea;
InitializeComponent();
_ea.GetEvent<ShowVoideInMainEvent>().Subscribe(PlayVideoReceived);
}
private void BarButtons_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (barButtons.SelectedIndex == -1)
{
barButtons.SelectedIndex = _barButtonSelectedIndex;
return;
}
if (barButtons.SelectedIndex != _barButtonSelectedIndex)
{
BarButtonsSelectedChange(barButtons.SelectedIndex);
}
}
private void BarButtonsSelectedChange(int selectedIndex)
{
if (_barButtonSelectedIndex == selectedIndex)
{
return;
}
_barButtonSelectedIndex = selectedIndex;
switch (selectedIndex)
{
case 0:
ChangePlayerGridByRowNum(1);
break;
case 1:
ChangePlayerGridByRowNum(2);
break;
case 2:
ChangePlayerGridByRowNum(3);
break;
}
_playerSelectIndex = 0;
_videoPlayManager.SetALLUnSelected();
_videoPlayManager.GetUCVideoList()[_playerSelectIndex]?.SetSelected(true);
}
/// <summary>
/// 设置窗体每行播放器数量
/// </summary>
/// <param name="rowNumber"></param>
private void ChangePlayerGridByRowNum(int rowNumber = 1)
{
if (_videoWH < 0)
{
return;
}
double width = panMain.ActualWidth;
double height = _videoWH * width;
//Padding =2,2,2,2
width = width - 4;
height = height - 4;
_videoWidth = width / rowNumber - 4;
_videoHeight = height / rowNumber - 4;
int showVideoNumber = rowNumber * rowNumber;
_videoNumber = showVideoNumber;
int addedVideoNumber = _videoPlayManager.GetUCVideoList().Count();
int dif = showVideoNumber - addedVideoNumber;
//已经添加的 多余界面
if (dif < 0)
{
//设置界面大小
for (int i = 0; i < showVideoNumber; i++)
{
var videoPlay = _videoPlayManager.GetUCVideoList()[i];
videoPlay.ReSetSize(_videoWidth, _videoHeight);
string ucname = videoPlay.GetName();
var rtspVideo = (UserControl)this.panMain.FindName(ucname);
if (rtspVideo == null)//如果没有添加的添加
{
this.panMain.Children.Add(videoPlay.GetControl());
this.panMain.RegisterName(videoPlay.GetName(), videoPlay.GetControl());
}
}
//从界面删除
for (int i = showVideoNumber; i < addedVideoNumber; i++)
{
var videoPlay = _videoPlayManager.GetUCVideoList()[i];
string ucname = videoPlay.GetName();
var rtspVideo = (UserControl)this.panMain.FindName(ucname);
if (rtspVideo != null)
{
videoPlay.Stop();
// videoPlay.SetIsShow(false);
this.panMain.Children.Remove(rtspVideo);
this.panMain.UnregisterName(ucname);
}
}
}
else if (dif >= 0) ///已经添加的少于界面
{
//设置界面大小
for (int i = 0; i < addedVideoNumber; i++)
{
var videoPlay = _videoPlayManager.GetUCVideoList()[i];
videoPlay.ReSetSize(_videoWidth, _videoHeight);
string ucname = videoPlay.GetName();
var rtspVideo = (UserControl)this.panMain.FindName(ucname);
if (rtspVideo == null)
{
this.panMain.Children.Add(videoPlay.GetControl());
this.panMain.RegisterName(videoPlay.GetName(), videoPlay.GetControl());
}
}
//添加新的视频窗体
for (int i = 0; i < dif; i++)
{
var iUCVideo = _videoPlayManager.CreateVideo(_ea, _videoWidth, _videoHeight);
var ucvideo = iUCVideo.GetControl();
ucvideo.Margin = new Thickness(2, 2, 2, 2);
this.panMain.Children.Add(ucvideo);
this.panMain.RegisterName(ucvideo.Name, ucvideo);
iUCVideo.PlayerMouseDown += PlayerMouseDown;
iUCVideo.PlayerMouseDoubleClick += PlayerMouseDoubleClick;
iUCVideo.OnFromClose += OnFromClose;
}
}
}
private void OnFromClose(object sender, int index)
{
StaticData.MainPlayerIp = "";
}
//双击 最大化、最小化
private void PlayerMouseDoubleClick(object sender, int index)
{
IUCPlayer player = (sender as IUCPlayer);
double width = panMain.ActualWidth;
double height = _videoWH * width;
//Padding =2,2,2,2
width = width - 4;
height = height - 4;
bool isMax = player.SetMaximized(width, height);
if (isMax)
{
this.panMain.Children.Remove(player.GetControl());
this.panMain.UnregisterName(player.GetName());
this.panMain1.Children.Add(player.GetControl());
this.panMain1.RegisterName(player.GetName(), player.GetControl());
}
else
{
this.panMain1.Children.Remove(player.GetControl());
this.panMain1.UnregisterName(player.GetName());
this.panMain.Children.Insert(index, player.GetControl());
this.panMain.RegisterName(player.GetName(), player.GetControl());
}
}
/// <summary>
/// 选中设置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PlayerMouseDown(object sender, int videoIndex)
{
_videoPlayManager.SetALLUnSelected();
IUCPlayer ucPlayer = (sender as IUCPlayer);
ucPlayer.SetSelected(true);
_playerSelectIndex = videoIndex;
//rightRegion.
if (ucPlayer.IsPlaying())
{
//MonitorCamera curCamera = ucPlayer.GetCamera();
var curOnvifClient = ucPlayer.GetOnvifClient();
_ea.GetEvent<SendOnvifClientEvent>().Publish(curOnvifClient);
}
else
{
_ea.GetEvent<SendOnvifClientEvent>().Publish(null);
}
///
}
//private void CreateVideo(string cameraIp)
//{
// IUCVideo ucVideo = _videoPlayManager.GetUCVideo(cameraIp);
// if (ucVideo != null)
// {
// ucVideo.UPDateTime();
// return;
// }
// MonitorCamera camera = CameraManager.GetCamera(cameraIp);
// if (camera == null)
// {
// ShowLog("相机Ip:" + cameraIp + "不存在", true);
// return;
// }
// UCRtspVlcVideo rtspVideo = new UCRtspVlcVideo(_videoWidth,_videoHeight);
// this.panMain.Children.Add(rtspVideo);
// rtspVideo.Play();
// this.panMain.RegisterName(rtspVideo.Name, rtspVideo);
// _videoPlayManager.Add(ucVideo);
//}
//private void btnStop_Click(object sender, RoutedEventArgs e)
//{
// var rtspVideo = _videoPlayManager.GetUCVideo("192.168.1.65");
// if (rtspVideo != null)
// {
// rtspVideo.Stop();
// }
//}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
_videoWidth = panMain.ActualWidth;
_videoHeight = panMain.ActualHeight;
_videoWH = _videoHeight / _videoWidth;
barButtons.SelectedIndex = ConfigHelper.MainBarButtonSelectedIndex();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
// await MessageManager.MessageBox("测试");
// Play("192.168.1.651");
_ea.GetEvent<ShowVoideInMainEvent>().Publish("192.168.1.65");
}
public virtual void PlayVideoReceived(string cameraIp)
{
Play(cameraIp);
}
private void Play(string ip)
{
var videoPlay = _videoPlayManager.GetUCVideoList()[_playerSelectIndex];
if (videoPlay == null)
{
MessageManager.ShowMessage("当前选中的播放器 SelectIndex=" + _playerSelectIndex.ToString(), true);
return;
}
if (!videoPlay.IsNullPlay())
{
if (videoPlay.GetCameraIp() == ip)
{
if (videoPlay.IsPlaying())
{
return;
}
}
videoPlay.Stop();
Thread.Sleep(1000);
}
MonitorCamera camera = CameraManager.GetCamera(ip);
if (camera == null)
{
MessageManager.ShowMessage(ip + "相机不存在", true);
return;
}
bool play = videoPlay.Play(camera);
AddSelectVideoIndex();
}
public void AddSelectVideoIndex()
{
_playerSelectIndex++;
if (_playerSelectIndex >= _videoNumber)
{
_playerSelectIndex = 0;
}
_videoPlayManager.SetALLUnSelected();
var ucPlayer = _videoPlayManager.GetUCVideoList()[_playerSelectIndex];
if (ucPlayer != null)
{
ucPlayer.SetSelected(true);
if (ucPlayer.IsPlaying())
{
//MonitorCamera curCamera = ucPlayer.GetCamera();
var curOnvifClient = ucPlayer.GetOnvifClient();
_ea.GetEvent<SendOnvifClientEvent>().Publish(curOnvifClient);
}
else
{
_ea.GetEvent<SendOnvifClientEvent>().Publish(null);
}
}
}
//窗体尺寸该表
private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (_videoWH < 0) return;
int toSelectIndex = _barButtonSelectedIndex;
_barButtonSelectedIndex = -1;
BarButtonsSelectedChange(toSelectIndex);
}
}
}

13
ECMonitor/Page/CameraMonitor/CameraVideoViewModel.cs

@ -0,0 +1,13 @@
using ECMonitor.Code.Models;
using Prism.Events;
using Prism.Regions;
namespace ECMonitor.Page.CameraMonitor
{
public sealed class CameraVideoViewModel : BaseModel
{
public CameraVideoViewModel(IRegionManager regionManager, IEventAggregator ea) : base(regionManager, ea)
{
}
}
}

21
ECMonitor/Page/CameraMonitor/Main.xaml

@ -0,0 +1,21 @@
<UserControl x:Class="ECMonitor.Page.CameraMonitor.Main"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:prism="http://prismlibrary.com/"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:names="clr-namespace:ECMonitor.Page.Name"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<ContentControl Grid.Column="0" prism:RegionManager.RegionName="{x:Static names:RegionsName.CameraMonitorLeft}" />
<ContentControl Grid.Column="1" prism:RegionManager.RegionName="{x:Static names:RegionsName.CameraMonitorCenter}" />
<ContentControl Grid.Column="2" prism:RegionManager.RegionName="{x:Static names:RegionsName.CameraMonitorRight}" />
</Grid>
</UserControl>

21
ECMonitor/Page/CameraMonitor/Main.xaml.cs

@ -0,0 +1,21 @@
using ECMonitor.Page.Name;
using Prism.Events;
using Prism.Regions;
using System.Windows.Controls;
namespace ECMonitor.Page.CameraMonitor
{
/// <summary>
/// FrmMain.xaml 的交互逻辑
/// </summary>
public partial class Main : UserControl
{
public Main(IRegionManager regionManager, IEventAggregator ea)
{
InitializeComponent();
_ = regionManager.RegisterViewWithRegion(RegionsName.CameraMonitorLeft, typeof(CameraTreeView));
_ = regionManager.RegisterViewWithRegion(RegionsName.CameraMonitorCenter, typeof(CameraVideo));
_ = regionManager.RegisterViewWithRegion(RegionsName.CameraMonitorRight, typeof(CameraAdjust));
}
}
}

13
ECMonitor/Page/CameraMonitor/MainViewModel.cs

@ -0,0 +1,13 @@
using ECMonitor.Code.Models;
using Prism.Events;
using Prism.Regions;
namespace ECMonitor.Page.CameraMonitor
{
public class MainViewModel : BaseModel
{
public MainViewModel(IRegionManager regionManager, IEventAggregator ea) : base(regionManager, ea)
{
}
}
}

31
ECMonitor/Page/Name/RegionsName.cs

@ -0,0 +1,31 @@
namespace ECMonitor.Page.Name
{
public static class RegionsName
{
#region MainWindow
public static string MainWindowTop { get; } = "MainWindowTopRegion";
public static string MainWindowCenter { get; } = "MainWindowCenterRegion";
#endregion MainWindow
#region CameraMonitor
public static string CameraMonitorLeft { get; } = "CameraMonitorLeftRegion";
public static string CameraMonitorCenter { get; } = "CameraMonitorCenterRegion";
public static string CameraMonitorRight { get; } = "CameraMonitorRightRegion";
#endregion CameraMonitor
#region SystemSet
public static string SystemSetLeft { get; } = "SystemSetLeftRegion";
public static string SystemSetCenter { get; } = "SystemSetCenterRegion";
public static string SystemSetManageIpcCenter { get; } = "SystemSetManageIpcCenterRegion";
#endregion SystemSet
}
}

52
ECMonitor/Page/Name/ViewsName.cs

@ -0,0 +1,52 @@
namespace ECMonitor.Page.Name
{
public static class ViewsName
{
#region MainWindow
public static string MainWindow { get; } = "MainWindow";
#endregion MainWindow
#region CameraMonitor
public static string CameraMonitorMain { get; } = "CameraMonitorMain";
public static string CameraMonitorTree { get; } = "CameraMonitorTree";
public static string CameraMonitorVideo { get; } = "CameraMonitorVideo";
public static string CameraMonitorAdjust { get; } = "CameraMonitorAdjust";
#endregion CameraMonitor
#region SystemSet
/// <summary>
/// 主页面
/// </summary>
public static string SystemSetMain { get; } = "SystemSetMain";
/// <summary>
/// 系统设置页面
/// </summary>
public static string SystemSetManageSet { get; } = "SystemSetManageSet";
/// <summary>
/// 录像机页面
/// </summary>
public static string SystemSetManageNvr { get; } = "SystemSetManageNvr";
/// <summary>
/// 摄像机页面
/// </summary>
public static string SystemSetManageIpc { get; } = "SystemSetManageIpc";
/// <summary>
/// 搜索摄像机页面
/// </summary>
public static string SystemSetSearchIpc { get; } = "SystemSetSearchIpc";
#endregion SystemSet
}
}

127
ECMonitor/Page/SystemSet/Main.xaml

@ -0,0 +1,127 @@
<UserControl x:Class="ECMonitor.Page.SystemSet.Main"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:prism="http://prismlibrary.com/"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:names="clr-namespace:ECMonitor.Page.Name"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<SolidColorBrush x:Key="BtnInActiveBrush" Color="Transparent" />
<SolidColorBrush x:Key="BtnActiveBrush" Color="#478cb6" />
<Style x:Key="leftBtnBorder" TargetType="{x:Type Border}">
<Setter Property="Margin" Value="0,0,0,6" />
<Setter Property="Padding" Value="0" />
<Setter Property="CornerRadius" Value="5" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style x:Key="leftBtn" TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignFlatButton}">
<Setter Property="Width" Value="90" />
<Setter Property="Height" Value="65" />
<Setter Property="Padding" Value="0" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style x:Key="leftBtnPanel" TargetType="{x:Type StackPanel}">
<!--<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />-->
</Style>
<Style x:Key="leftBtnImg" TargetType="{x:Type Image}">
<Setter Property="Width" Value="30" />
<Setter Property="Height" Value="30" />
<Setter Property="Margin" Value="0,0,0,5" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style x:Key="leftBtnTxt" TargetType="{x:Type TextBlock}">
<Setter Property="FontSize" Value="13" />
<Setter Property="Foreground" Value="White" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</UserControl.Resources>
<Grid Background="{DynamicResource PageBgBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0" BorderBrush="{StaticResource PageBorderBrush}" BorderThickness="0,0,1,0">
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch"
Background="{DynamicResource PageBodyBrush}">
<ListBox x:Name="listBox" Style="{StaticResource MaterialDesignToolVerticalToggleListBox}"
Background="Transparent" Padding="0,10,0,0" SelectedIndex="0">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="border" Style="{StaticResource leftBtnBorder}">
<ContentPresenter></ContentPresenter>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="border" Property="Background" Value="{StaticResource BtnActiveBrush}" />
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter TargetName="border" Property="Background" Value="{StaticResource BtnInActiveBrush}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="Background" Value="{StaticResource BtnActiveBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<EventSetter Event="Selected" Handler="ListBoxItem_Selected" />
</Style>
</ListBox.ItemContainerStyle>
<!--<ListBoxItem>
<Button Style="{StaticResource leftBtn}"
Command="{Binding NavigateCommand}" CommandParameter="{x:Static names:ViewsName.SystemSetManageSet}">
<StackPanel Style="{StaticResource leftBtnPanel}">
<Image Style="{StaticResource leftBtnImg}" Source="/set1.png" />
<TextBlock Style="{StaticResource leftBtnTxt}" Text="系统设置 " />
</StackPanel>
</Button>
</ListBoxItem>-->
<ListBoxItem>
<Button Style="{StaticResource leftBtn}"
Command="{Binding NavigateCommand}" CommandParameter="{x:Static names:ViewsName.SystemSetManageNvr}">
<StackPanel Style="{StaticResource leftBtnPanel}">
<Image Style="{StaticResource leftBtnImg}" Source="/camera1.png" />
<TextBlock Style="{StaticResource leftBtnTxt}" Text="录像机管理" />
</StackPanel>
</Button>
</ListBoxItem>
<ListBoxItem>
<Button Style="{StaticResource leftBtn}"
Command="{Binding NavigateCommand}" CommandParameter="{x:Static names:ViewsName.SystemSetManageIpc}">
<StackPanel Style="{StaticResource leftBtnPanel}">
<Image Style="{StaticResource leftBtnImg}" Source="/camera1.png" />
<TextBlock Style="{StaticResource leftBtnTxt}" Text="摄像机管理" />
</StackPanel>
</Button>
</ListBoxItem>
</ListBox>
</StackPanel>
</Border>
<ContentControl Grid.Column="1" Margin="8"
prism:RegionManager.RegionName="{x:Static names:RegionsName.SystemSetCenter}" />
</Grid>
</UserControl>

44
ECMonitor/Page/SystemSet/Main.xaml.cs

@ -0,0 +1,44 @@
using ECMonitor.Page.Name;
using Prism.Regions;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
namespace ECMonitor.Page.SystemSet
{
public partial class Main : UserControl
{
public Main(IRegionManager regionManager)
{
InitializeComponent();
_ = regionManager.RegisterViewWithRegion(RegionsName.SystemSetCenter, typeof(ManageNvr));
InitPage();
}
#region Init
private void InitPage()
{
}
#endregion Init
#region Event
private void ListBoxItem_Selected(object sender, RoutedEventArgs e)
{
ListBoxItem item = (ListBoxItem)sender;
Button button = (Button)item.Content;
//模拟按钮点击
MethodInfo method = button.GetType().GetMethod("OnClick", BindingFlags.NonPublic | BindingFlags.Instance);
_ = (method?.Invoke(button, null));
//模拟按钮点击
//IInvokeProvider invokeProv = new ButtonAutomationPeer(button).GetPattern(PatternInterface.Invoke) as IInvokeProvider;
//invokeProv?.Invoke();
}
#endregion Event
}
}

26
ECMonitor/Page/SystemSet/MainViewModel.cs

@ -0,0 +1,26 @@
using ECMonitor.Code.Models;
using ECMonitor.Page.Name;
using Prism.Commands;
using Prism.Events;
using Prism.Regions;
namespace ECMonitor.Page.SystemSet
{
public class MainViewModel : BaseModel
{
public DelegateCommand<string> NavigateCommand { get; private set; }
public MainViewModel(IRegionManager regionManager, IEventAggregator ea) : base(regionManager, ea)
{
NavigateCommand = new DelegateCommand<string>(Navigate);
}
private void Navigate(string navigatePath)
{
if (navigatePath != null)
{
_regionManager.RequestNavigate(RegionsName.SystemSetCenter, navigatePath);
}
}
}
}

345
ECMonitor/Page/SystemSet/ManageIpc.xaml

@ -0,0 +1,345 @@
<UserControl x:Class="ECMonitor.Page.SystemSet.ManageIpc"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:prism="http://prismlibrary.com/"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mvvm="clr-namespace:ECMonitor.MVVM"
xmlns:names="clr-namespace:ECMonitor.Page.Name"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"
x:Name="ThatPage">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding LoadedCommand}" CommandParameter="{Binding ElementName=ThatPage}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<UserControl.Resources>
<SolidColorBrush x:Key="BtnInActiveBrush" Color="#393d46" />
<SolidColorBrush x:Key="BtnActiveBrush" Color="#478cb6" />
<SolidColorBrush x:Key="DGHeaderBrush" Color="#424242" />
<SolidColorBrush x:Key="DGBorderBrush" Color="{StaticResource PageBorderColor}" Opacity="0.8" />
<SolidColorBrush x:Key="DGLineBrush" Color="{StaticResource PageBorderColor}" Opacity="0.9" />
<Style x:Key="topBtn" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Margin" Value="0,0,6,0" />
<Setter Property="Background" Value="{StaticResource BtnInActiveBrush}" />
<Setter Property="Foreground" Value="WhiteSmoke" />
<Setter Property="BorderBrush" Value="{StaticResource PageBorderBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="materialDesign:ButtonAssist.CornerRadius" Value="5" />
<Style.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="{StaticResource BtnActiveBrush}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource BtnActiveBrush}" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="topBtnPanel" TargetType="{x:Type StackPanel}">
<Setter Property="Orientation" Value="Horizontal" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style x:Key="topBtnImg" TargetType="{x:Type Control}">
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style x:Key="topBtnTxt" TargetType="{x:Type TextBlock}">
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</UserControl.Resources>
<Grid Background="{DynamicResource PageBodyBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="3*" />
<RowDefinition Height="2*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<Button Style="{StaticResource topBtn}" Command="{Binding AddCommand}">
<StackPanel Style="{StaticResource topBtnPanel}">
<materialDesign:PackIcon Kind="AddThick" Style="{StaticResource topBtnImg}" />
<TextBlock Text="添加" Style="{StaticResource topBtnTxt}" />
</StackPanel>
</Button>
<Button Style="{StaticResource topBtn}" Command="{Binding DeleteCommand}">
<StackPanel Style="{StaticResource topBtnPanel}">
<materialDesign:PackIcon Kind="MinusThick" Style="{StaticResource topBtnImg}" />
<TextBlock Text="删除" Style="{StaticResource topBtnTxt}" />
</StackPanel>
</Button>
<Button Style="{StaticResource topBtn}" Command="{Binding SaveCommand}">
<StackPanel Style="{StaticResource topBtnPanel}">
<materialDesign:PackIcon Kind="CheckThick" Style="{StaticResource topBtnImg}" />
<TextBlock Text="保存" Style="{StaticResource topBtnTxt}" />
</StackPanel>
</Button>
<!--<Button Style="{StaticResource topBtn}" Command="{Binding RevokeCommand}">
<StackPanel Style="{StaticResource topBtnPanel}">
<materialDesign:PackIcon Kind="CloseThick" Style="{StaticResource topBtnImg}" />
<TextBlock Text="撤销" Style="{StaticResource topBtnTxt}" />
</StackPanel>
</Button>-->
<Button Style="{StaticResource topBtn}" Command="{Binding RefreshCommand}" Cursor="Hand">
<StackPanel Style="{StaticResource topBtnPanel}">
<materialDesign:PackIcon Kind="Refresh" Style="{StaticResource topBtnImg}" />
<TextBlock Text="刷新" Style="{StaticResource topBtnTxt}" />
</StackPanel>
</Button>
<!--<Button Style="{StaticResource topBtn}" Command="{Binding ImportCommand}">
<StackPanel Style="{StaticResource topBtnPanel}">
<materialDesign:PackIcon Kind="ArrowDownThick" Style="{StaticResource topBtnImg}" />
<TextBlock Text="导入" Style="{StaticResource topBtnTxt}" />
</StackPanel>
</Button>
<Button Style="{StaticResource topBtn}" Command="{Binding ExportCommand}">
<StackPanel Style="{StaticResource topBtnPanel}">
<materialDesign:PackIcon Kind="ArrowUpThick" Style="{StaticResource topBtnImg}" />
<TextBlock Text="导出" Style="{StaticResource topBtnTxt}" />
</StackPanel>
</Button>-->
</StackPanel>
<DockPanel Grid.Row="1">
<DataGrid x:Name="InfoGrid" ItemsSource="{Binding InfoList,Mode=TwoWay }">
<DataGrid.Style>
<Style TargetType="DataGrid" BasedOn="{StaticResource MaterialDesignDataGrid}">
<Setter Property="Background" Value="{StaticResource PageBodyBrush}" />
<Setter Property="GridLinesVisibility" Value="All" />
<Setter Property="HorizontalGridLinesBrush" Value="{StaticResource DGLineBrush}" />
<Setter Property="VerticalGridLinesBrush" Value="{StaticResource DGLineBrush}" />
<Setter Property="BorderBrush" Value="{StaticResource DGLineBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="HeadersVisibility" Value="Column" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="AutoGenerateColumns" Value="False" />
<Setter Property="CanUserAddRows" Value="False" />
<Setter Property="CanUserDeleteRows" Value="False" />
<Setter Property="CanUserResizeRows" Value="False" />
<Setter Property="CanUserResizeColumns" Value="True" />
<Setter Property="CanUserReorderColumns" Value="False" />
<Setter Property="CanUserSortColumns" Value="False" />
</Style>
</DataGrid.Style>
<DataGrid.RowHeaderStyle>
<Style TargetType="DataGridRowHeader" BasedOn="{StaticResource MaterialDesignDataGridRowHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>
</DataGrid.RowHeaderStyle>
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader" BasedOn="{StaticResource MaterialDesignDataGridColumnHeader}">
<Setter Property="Background" Value="{StaticResource DGHeaderBrush}" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGrid.ColumnHeaderStyle>
<i:Interaction.Triggers>
<i:EventTrigger EventName="CellEditEnding">
<mvvm:ExtendEventCommand Command="{Binding UpdateCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<DataGrid.Columns>
<materialDesign:DataGridTextColumn
Header="序号" Width="60" IsReadOnly="True"
Binding="{Binding Number, UpdateSourceTrigger=PropertyChanged}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</materialDesign:DataGridTextColumn>
<!--<DataGridTextColumn
Binding="{Binding IpcId}" Header="编号" Width="60"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</DataGridTextColumn>-->
<materialDesign:DataGridTextColumn
Header="名称" Width="120"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
<DataGridTextColumn.Binding>
<Binding Path="IpcName" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<mvvm:VerifyRule Type="{x:Static mvvm:VerifyRuleType.NotEmpty}" ValidatesOnTargetUpdated="True" />
</Binding.ValidationRules>
</Binding>
</DataGridTextColumn.Binding>
</materialDesign:DataGridTextColumn>
<materialDesign:DataGridComboBoxColumn
Header="录像机" Width="120"
ItemsSourceBinding="{Binding DataContext.NvrNameList, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}">
<DataGridComboBoxColumn.SelectedValueBinding>
<Binding Path="NvrName" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<mvvm:VerifyRule Type="{x:Static mvvm:VerifyRuleType.NotEmpty}" ValidatesOnTargetUpdated="True" />
</Binding.ValidationRules>
</Binding>
</DataGridComboBoxColumn.SelectedValueBinding>
</materialDesign:DataGridComboBoxColumn>
<materialDesign:DataGridTextColumn
Header="类型" Width="90"
Binding="{Binding IpcType, UpdateSourceTrigger=PropertyChanged}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</materialDesign:DataGridTextColumn>
<materialDesign:DataGridTextColumn
Header="地址" Width="120"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
<DataGridTextColumn.Binding>
<Binding Path="IpcIp" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<mvvm:VerifyRule Type="{x:Static mvvm:VerifyRuleType.IP}" ValidatesOnTargetUpdated="True" />
</Binding.ValidationRules>
</Binding>
</DataGridTextColumn.Binding>
</materialDesign:DataGridTextColumn>
<materialDesign:DataGridTextColumn
Header="用户姓名" Width="120"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
<DataGridTextColumn.Binding>
<Binding Path="UserName" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<mvvm:VerifyRule Type="{x:Static mvvm:VerifyRuleType.NotEmpty}" ValidatesOnTargetUpdated="True" />
</Binding.ValidationRules>
</Binding>
</DataGridTextColumn.Binding>
</materialDesign:DataGridTextColumn>
<materialDesign:DataGridTextColumn
Header="用户密码" Width="120"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
<DataGridTextColumn.Binding>
<Binding Path="UserPwd" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<mvvm:VerifyRule Type="{x:Static mvvm:VerifyRuleType.NotEmpty}" ValidatesOnTargetUpdated="True" />
</Binding.ValidationRules>
</Binding>
</DataGridTextColumn.Binding>
</materialDesign:DataGridTextColumn>
<materialDesign:DataGridTextColumn
Header="主码流地址" Width="*"
Binding="{Binding RtspMain, UpdateSourceTrigger=PropertyChanged}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</materialDesign:DataGridTextColumn>
<materialDesign:DataGridTextColumn
Header="子码流地址" Width="*"
Binding="{Binding RtspSub, UpdateSourceTrigger=PropertyChanged}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</materialDesign:DataGridTextColumn>
<!--<DataGridTextColumn
Binding="{Binding IpcPosition}" Header="经纬度" Width="*"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</DataGridTextColumn>-->
<DataGridCheckBoxColumn
Header="启用" Width="60"
Binding="{Binding IpcEnableBool, UpdateSourceTrigger=PropertyChanged}"
ElementStyle="{StaticResource MaterialDesignDataGridCheckBoxColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridCheckBoxColumnEditingStyle}">
</DataGridCheckBoxColumn>
<materialDesign:DataGridTextColumn
Header="安装位置" Width="*"
Binding="{Binding IpcAddr, UpdateSourceTrigger=PropertyChanged}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</materialDesign:DataGridTextColumn>
<!--<DataGridCheckBoxColumn
Binding="{Binding IsSelected, UpdateSourceTrigger=PropertyChanged}"
ElementStyle="{StaticResource MaterialDesignDataGridCheckBoxColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridCheckBoxColumnEditingStyle}">
<DataGridCheckBoxColumn.Header>
<Border Background="Transparent">
<CheckBox />
<CheckBox IsChecked="{Binding Data.IsAllItems1Selected, Source={StaticResource DataContextProxy}}" />
</Border>
</DataGridCheckBoxColumn.Header>
<DataGridCheckBoxColumn.HeaderStyle>
<Style
TargetType="{x:Type DataGridColumnHeader}"
BasedOn="{StaticResource MaterialDesignDataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGridCheckBoxColumn.HeaderStyle>
</DataGridCheckBoxColumn>
<DataGridTextColumn
Binding="{Binding IpcImage}"
Header="IpcImage"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</DataGridTextColumn>
<DataGridTextColumn
Binding="{Binding IpcX}"
Header="IpcX"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</DataGridTextColumn>
<DataGridTextColumn
Binding="{Binding IpcY}"
Header="IpcY"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</DataGridTextColumn>
<DataGridTextColumn
Binding="{Binding OnvifAddr}" Header="Onvif地址"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</DataGridTextColumn>
<DataGridTextColumn
Binding="{Binding MediaAddr}" Header="Media地址"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</DataGridTextColumn>
<DataGridTextColumn
Binding="{Binding PtzAddr}" Header="Ptz地址"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</DataGridTextColumn>-->
</DataGrid.Columns>
</DataGrid>
</DockPanel>
<ContentControl Grid.Row="2"
prism:RegionManager.RegionName="{x:Static names:RegionsName.SystemSetManageIpcCenter}" />
</Grid>
</UserControl>

18
ECMonitor/Page/SystemSet/ManageIpc.xaml.cs

@ -0,0 +1,18 @@
using ECMonitor.Page.Name;
using Prism.Regions;
using System.Windows.Controls;
namespace ECMonitor.Page.SystemSet
{
/// <summary>
/// ManageIpc.xaml 的交互逻辑
/// </summary>
public partial class ManageIpc : UserControl
{
public ManageIpc(IRegionManager regionManager)
{
InitializeComponent();
_ = regionManager.RegisterViewWithRegion(RegionsName.SystemSetManageIpcCenter, typeof(SearchIpc));
}
}
}

281
ECMonitor/Page/SystemSet/ManageIpcViewModel.cs

@ -0,0 +1,281 @@
using EC.Entity.CameraInfo;
using EC.Service.CameraInfo;
using EC.UsingEventAggregator;
using ECMonitor.Code.Models;
using ECMonitor.MVVM;
using Prism.Commands;
using Prism.Events;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading;
using System.Windows.Controls;
namespace ECMonitor.Page.SystemSet
{
public class ManageIpcViewModel : BaseModel
{
private ManageIpc ThatPage { get; set; }
public ObservableCollection<IpcInfo> InfoList { get; set; } = new();
private ReaderWriterLockSlim InfoListrwl { get; } = new();
private List<int> AddNumberList { get; } = new();
private List<int> UpdateNumberList { get; } = new();
public ObservableCollection<string> NvrNameList { get; set; } = new();
#region Command
public DelegateCommand<UserControl> LoadedCommand { get; private set; }
public DelegateCommand AddCommand { get; private set; }
public DelegateCommand DeleteCommand { get; private set; }
public ExtendCommand<DataGridCellEditEndingEventArgs> UpdateCommand { get; private set; }
public DelegateCommand SaveCommand { get; private set; }
public DelegateCommand RevokeCommand { get; private set; }
public DelegateCommand RefreshCommand { get; private set; }
public DelegateCommand ImportCommand { get; private set; }
public DelegateCommand ExportCommand { get; private set; }
#endregion Command
public ManageIpcViewModel(IRegionManager regionManager, IEventAggregator ea) : base(regionManager, ea)
{
LoadedCommand = new DelegateCommand<UserControl>(LoadedPageAction);
AddCommand = new DelegateCommand(AddInfoAction);
DeleteCommand = new DelegateCommand(DeleteInfoAction);
UpdateCommand = new ExtendCommand<DataGridCellEditEndingEventArgs>(UpdateInfoAction);
SaveCommand = new DelegateCommand(SaveInfosAction);
RevokeCommand = new DelegateCommand(RevokeInfoAction);
RefreshCommand = new DelegateCommand(RefreshAction);
ImportCommand = new DelegateCommand(ImportInfosAction);
ExportCommand = new DelegateCommand(ExportInfosAction);
_ea.GetEvent<SendIpcInfoListEvent>().Subscribe(SubscribeIpcInfoListAction);
}
#region Event Action
private void LoadedPageAction(UserControl view)
{
if (ThatPage != null) { return; }
ThatPage = (ManageIpc)view;
RefreshAction();
}
#endregion Event Action
#region Operate Action
private void AddInfoAction()
{
IpcInfo info = new();
info.Number = GetInfoNewNumber();
info.IpcName = $"摄像机#{info.Number}";
info.IpcEnableBool = true;
OperateInfoListByLock(() => { AddInfo(info); });
DataGrid infoGrid = ThatPage.InfoGrid;
infoGrid.SelectedIndex = infoGrid.Items.Count - 1;
}
private async void DeleteInfoAction()
{
DataGrid infoGrid = ThatPage.InfoGrid;
IpcInfo info = (IpcInfo)infoGrid.SelectedItem;
int index = ThatPage.InfoGrid.SelectedIndex;
if (info == null) { return; }
if (info.IpcId <= 0)
{
OperateInfoListByLock(() => { RemoveInfo(info); });
infoGrid.SelectedIndex = (index < infoGrid.Items.Count) ? index : infoGrid.Items.Count - 1;
return;
}
using IpcInfoContext ctx = new();
_ = ctx.Remove(info);
int ret = await ctx.SaveChangesAsync();
if (ret > 0)
{
OperateInfoListByLock(() => { RemoveInfo(info); });
infoGrid.SelectedIndex = (index < infoGrid.Items.Count) ? index : infoGrid.Items.Count - 1;
}
}
private void UpdateInfoAction(DataGridCellEditEndingEventArgs e)
{
if (e.EditAction != DataGridEditAction.Commit) { return; }
var elm = e.EditingElement;
DataGridRow row = e.Row;
DataGridColumn column = e.Column;
IpcInfo info = (IpcInfo)row.Item;
if (info != null && info.IpcId > 0)
{
if (!UpdateNumberList.Exists(item => item.Equals(info.Number)))
{
UpdateNumberList.Add(info.Number);
}
}
}
private async void SaveInfosAction()
{
//ValidationError validationError = WPFAssist.GetDataGridRowsFirstError(ThatPage.InfoGrid);
//if (WPFAssist.GetDataGridRowsHasError(ThatPage.InfoGrid)) { return; }
List<IpcInfo> list = null;
using IpcInfoContext ctx = new();
int ret = 0;
if (AddNumberList.Count > 0)
{
list ??= GetInfoList();
foreach (int number in AddNumberList)
{
IpcInfo info = list.Find(item => item.Number.Equals(number));
if (info != null) { _ = ctx.Add(info); }
}
ret = await ctx.SaveChangesAsync();
if (ret > 0) { AddNumberList.Clear(); }
else { return; }
}
if (UpdateNumberList.Count > 0)
{
list ??= GetInfoList();
foreach (int number in UpdateNumberList)
{
IpcInfo info = list.Find(item => item.Number.Equals(number));
if (info != null) { _ = ctx.Update(info); }
}
ret = await ctx.SaveChangesAsync();
if (ret > 0) { UpdateNumberList.Clear(); }
else { return; }
}
RefreshAction();
}
private void RevokeInfoAction()
{
}
private void RefreshAction()
{
OperateInfoListByLock(() =>
{
AddNumberList.Clear();
UpdateNumberList.Clear();
LoadNvrNameList();
LoadInfoList();
});
}
private void ImportInfosAction()
{
}
private void ExportInfosAction()
{
}
#endregion Operate Action
#region Operate InfoList
private void OperateInfoListByLock(Action action)
{
if (InfoListrwl.IsWriteLockHeld) { return; }
if (!InfoListrwl.TryEnterWriteLock(100)) { return; }
try
{
action?.Invoke();
}
finally
{
InfoListrwl.ExitWriteLock();
}
}
private async void LoadInfoList()
{
InfoList.Clear();
using IpcInfoContext ctx = new();
List<IpcInfo> list = await ctx.GetListAsync();
int number = 0;
foreach (IpcInfo info in list)
{
info.Number = ++number;
InfoList.Add(info);
}
}
private void AddInfo(IpcInfo info)
{
InfoList.Add(info);
if (!AddNumberList.Exists(item => item.Equals(info.Number)))
{
AddNumberList.Add(info.Number);
}
}
private void RemoveInfo(IpcInfo info)
{
_ = InfoList.Remove(info);
_ = AddNumberList.RemoveAll(item => item.Equals(info.Number));
_ = UpdateNumberList.RemoveAll(item => item.Equals(info.Number));
}
private List<IpcInfo> GetInfoList()
{
return new(InfoList);
}
private int GetInfoNewNumber()
{
int number = InfoList.Count > 0 ? InfoList[^1].Number + 1 : 1;
return number;
}
private void SubscribeIpcInfoListAction(List<IpcInfo> infoList)
{
OperateInfoListByLock(() =>
{
foreach (IpcInfo item in infoList)
{
item.Number = GetInfoNewNumber();
item.IpcName = $"摄像机#{item.Number}";
AddInfo(item);
}
});
}
#endregion Operate InfoList
#region Operate OtherList
private async void LoadNvrNameList()
{
NvrNameList.Clear();
using NvrInfoContext ctx = new();
List<string> list = await ctx.GetNvrNameListAsync();
list.ForEach(item => { NvrNameList.Add(item); });
}
#endregion Operate OtherList
}
}

274
ECMonitor/Page/SystemSet/ManageNvr.xaml

@ -0,0 +1,274 @@
<UserControl x:Class="ECMonitor.Page.SystemSet.ManageNvr"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:prism="http://prismlibrary.com/"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mvvm="clr-namespace:ECMonitor.MVVM"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"
x:Name="ThatPage">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding LoadedCommand}" CommandParameter="{Binding ElementName=ThatPage}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<UserControl.Resources>
<SolidColorBrush x:Key="BtnInActiveBrush" Color="#393d46" />
<SolidColorBrush x:Key="BtnActiveBrush" Color="#478cb6" />
<SolidColorBrush x:Key="DGHeaderBrush" Color="#424242" />
<SolidColorBrush x:Key="DGBorderBrush" Color="{StaticResource PageBorderColor}" Opacity="0.8" />
<SolidColorBrush x:Key="DGLineBrush" Color="{StaticResource PageBorderColor}" Opacity="0.9" />
<Style x:Key="topBtn" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Margin" Value="0,0,6,0" />
<Setter Property="Background" Value="{StaticResource BtnInActiveBrush}" />
<Setter Property="Foreground" Value="WhiteSmoke" />
<Setter Property="BorderBrush" Value="{StaticResource PageBorderBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="materialDesign:ButtonAssist.CornerRadius" Value="5" />
<Style.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="{StaticResource BtnActiveBrush}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource BtnActiveBrush}" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="topBtnPanel" TargetType="{x:Type StackPanel}">
<Setter Property="Orientation" Value="Horizontal" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style x:Key="topBtnImg" TargetType="{x:Type Control}">
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style x:Key="topBtnTxt" TargetType="{x:Type TextBlock}">
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</UserControl.Resources>
<Grid Background="{DynamicResource PageBodyBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<Button Style="{StaticResource topBtn}" Command="{Binding AddCommand}">
<StackPanel Style="{StaticResource topBtnPanel}">
<materialDesign:PackIcon Kind="AddThick" Style="{StaticResource topBtnImg}" />
<TextBlock Text="添加" Style="{StaticResource topBtnTxt}" />
</StackPanel>
</Button>
<Button Style="{StaticResource topBtn}" Command="{Binding DeleteCommand}">
<StackPanel Style="{StaticResource topBtnPanel}">
<materialDesign:PackIcon Kind="MinusThick" Style="{StaticResource topBtnImg}" />
<TextBlock Text="删除" Style="{StaticResource topBtnTxt}" />
</StackPanel>
</Button>
<Button Style="{StaticResource topBtn}" Command="{Binding SaveCommand}">
<StackPanel Style="{StaticResource topBtnPanel}">
<materialDesign:PackIcon Kind="CheckThick" Style="{StaticResource topBtnImg}" />
<TextBlock Text="保存" Style="{StaticResource topBtnTxt}" />
</StackPanel>
</Button>
<!--<Button Style="{StaticResource topBtn}" Command="{Binding RevokeCommand}">
<StackPanel Style="{StaticResource topBtnPanel}">
<materialDesign:PackIcon Kind="CloseThick" Style="{StaticResource topBtnImg}" />
<TextBlock Text="撤销" Style="{StaticResource topBtnTxt}" />
</StackPanel>
</Button>-->
<Button Style="{StaticResource topBtn}" Command="{Binding RefreshCommand}">
<StackPanel Style="{StaticResource topBtnPanel}">
<materialDesign:PackIcon Kind="Refresh" Style="{StaticResource topBtnImg}" />
<TextBlock Text="刷新" Style="{StaticResource topBtnTxt}" />
</StackPanel>
</Button>
<!--<Button Style="{StaticResource topBtn}" Command="{Binding ImportCommand}">
<StackPanel Style="{StaticResource topBtnPanel}">
<materialDesign:PackIcon Kind="ArrowDownThick" Style="{StaticResource topBtnImg}" />
<TextBlock Text="导入" Style="{StaticResource topBtnTxt}" />
</StackPanel>
</Button>
<Button Style="{StaticResource topBtn}" Command="{Binding ExportCommand}">
<StackPanel Style="{StaticResource topBtnPanel}">
<materialDesign:PackIcon Kind="ArrowUpThick" Style="{StaticResource topBtnImg}" />
<TextBlock Text="导出" Style="{StaticResource topBtnTxt}" />
</StackPanel>
</Button>-->
</StackPanel>
<DockPanel Grid.Row="1">
<DataGrid x:Name="InfoGrid" ItemsSource="{Binding InfoList,Mode=TwoWay}">
<DataGrid.Style>
<Style TargetType="DataGrid" BasedOn="{StaticResource MaterialDesignDataGrid}">
<Setter Property="Background" Value="{StaticResource PageBodyBrush}" />
<Setter Property="GridLinesVisibility" Value="All" />
<Setter Property="HorizontalGridLinesBrush" Value="{StaticResource DGLineBrush}" />
<Setter Property="VerticalGridLinesBrush" Value="{StaticResource DGLineBrush}" />
<Setter Property="BorderBrush" Value="{StaticResource DGLineBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="HeadersVisibility" Value="Column" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="AutoGenerateColumns" Value="False" />
<Setter Property="CanUserAddRows" Value="False" />
<Setter Property="CanUserDeleteRows" Value="False" />
<Setter Property="CanUserResizeRows" Value="False" />
<Setter Property="CanUserResizeColumns" Value="True" />
<Setter Property="CanUserReorderColumns" Value="False" />
<Setter Property="CanUserSortColumns" Value="False" />
</Style>
</DataGrid.Style>
<DataGrid.RowHeaderStyle>
<Style TargetType="DataGridRowHeader" BasedOn="{StaticResource MaterialDesignDataGridRowHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>
</DataGrid.RowHeaderStyle>
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader" BasedOn="{StaticResource MaterialDesignDataGridColumnHeader}">
<Setter Property="Background" Value="{StaticResource DGHeaderBrush}" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGrid.ColumnHeaderStyle>
<i:Interaction.Triggers>
<i:EventTrigger EventName="CellEditEnding">
<mvvm:ExtendEventCommand Command="{Binding UpdateCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<DataGrid.Columns>
<materialDesign:DataGridTextColumn
Header="序号" Width="60" IsReadOnly="True"
Binding="{Binding Number}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</materialDesign:DataGridTextColumn>
<!--<materialDesign:DataGridTextColumn
Binding="{Binding NvrId}" Header="编号" Width="60"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</materialDesign:DataGridTextColumn>-->
<materialDesign:DataGridTextColumn
Header="名称" Width="120"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
<DataGridTextColumn.Binding>
<Binding Path="NvrName" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<mvvm:VerifyRule Type="{x:Static mvvm:VerifyRuleType.NotEmpty}" ValidatesOnTargetUpdated="True" />
</Binding.ValidationRules>
</Binding>
</DataGridTextColumn.Binding>
</materialDesign:DataGridTextColumn>
<materialDesign:DataGridComboBoxColumn
Header="类型" Width="90"
ItemsSourceBinding="{Binding DataContext.NvrDeviceList, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}">
<DataGridComboBoxColumn.SelectedValueBinding>
<Binding Path="NvrType" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<mvvm:VerifyRule Type="{x:Static mvvm:VerifyRuleType.NotEmpty}" ValidatesOnTargetUpdated="True" />
</Binding.ValidationRules>
</Binding>
</DataGridComboBoxColumn.SelectedValueBinding>
</materialDesign:DataGridComboBoxColumn>
<materialDesign:DataGridTextColumn
Header="地址" Width="120"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
<DataGridTextColumn.Binding>
<Binding Path="NvrIp" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<mvvm:VerifyRule Type="{x:Static mvvm:VerifyRuleType.IP}" ValidatesOnTargetUpdated="True" />
</Binding.ValidationRules>
</Binding>
</DataGridTextColumn.Binding>
</materialDesign:DataGridTextColumn>
<materialDesign:DataGridTextColumn
Header="用户姓名" Width="120"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
<DataGridTextColumn.Binding>
<Binding Path="UserName" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<mvvm:VerifyRule Type="{x:Static mvvm:VerifyRuleType.NotEmpty}" ValidatesOnTargetUpdated="True" />
</Binding.ValidationRules>
</Binding>
</DataGridTextColumn.Binding>
</materialDesign:DataGridTextColumn>
<materialDesign:DataGridTextColumn
Header="用户密码" Width="120"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
<DataGridTextColumn.Binding>
<Binding Path="UserPwd" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<mvvm:VerifyRule Type="{x:Static mvvm:VerifyRuleType.NotEmpty}" ValidatesOnTargetUpdated="True" />
</Binding.ValidationRules>
</Binding>
</DataGridTextColumn.Binding>
</materialDesign:DataGridTextColumn>
<DataGridCheckBoxColumn
Header="启用" Width="60"
Binding="{Binding NvrEnableBool, UpdateSourceTrigger=PropertyChanged}"
ElementStyle="{StaticResource MaterialDesignDataGridCheckBoxColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridCheckBoxColumnEditingStyle}">
</DataGridCheckBoxColumn>
<materialDesign:DataGridTextColumn
Header="安装位置" Width="*"
Binding="{Binding NvrAddr, UpdateSourceTrigger=PropertyChanged}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</materialDesign:DataGridTextColumn>
<!--<DataGridCheckBoxColumn Binding="{Binding IsSelected, UpdateSourceTrigger=PropertyChanged}"
ElementStyle="{StaticResource MaterialDesignDataGridCheckBoxColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridCheckBoxColumnEditingStyle}">
<DataGridCheckBoxColumn.Header>
<Border Background="Transparent">
<CheckBox />
-->
<!--<CheckBox IsChecked="{Binding Data.IsAllItems1Selected, Source={StaticResource DataContextProxy}}" />-->
<!--
</Border>
</DataGridCheckBoxColumn.Header>
<DataGridCheckBoxColumn.HeaderStyle>
<Style
TargetType="{x:Type DataGridColumnHeader}"
BasedOn="{StaticResource MaterialDesignDataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGridCheckBoxColumn.HeaderStyle>
</DataGridCheckBoxColumn>-->
</DataGrid.Columns>
</DataGrid>
</DockPanel>
</Grid>
</UserControl>

21
ECMonitor/Page/SystemSet/ManageNvr.xaml.cs

@ -0,0 +1,21 @@
using System.Windows.Controls;
namespace ECMonitor.Page.SystemSet
{
/// <summary>
/// ManageNvr.xaml 的交互逻辑
/// </summary>
public partial class ManageNvr : UserControl
{
public ManageNvr()
{
InitializeComponent();
Init();
}
private void Init()
{
}
}
}

276
ECMonitor/Page/SystemSet/ManageNvrViewModel.cs

@ -0,0 +1,276 @@
using EC.Entity.CameraInfo;
using EC.Service.CameraInfo;
using ECMonitor.Code.Models;
using ECMonitor.MVVM;
using Prism.Commands;
using Prism.Events;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading;
using System.Windows.Controls;
namespace ECMonitor.Page.SystemSet
{
public class ManageNvrViewModel : BaseModel
{
private ManageNvr ThatPage { get; set; }
public ObservableCollection<NvrInfo> InfoList { get; set; } = new();
private ReaderWriterLockSlim InfoListrwl { get; } = new();
private List<int> AddNumberList { get; } = new();
private List<int> UpdateNumberList { get; } = new();
public ObservableCollection<string> NvrDeviceList { get; set; } = new();
#region Command
public DelegateCommand<UserControl> LoadedCommand { get; private set; }
public DelegateCommand<DataGrid> LoadedCommand2 { get; private set; }
public DelegateCommand AddCommand { get; private set; }
public DelegateCommand DeleteCommand { get; private set; }
public ExtendCommand<DataGridCellEditEndingEventArgs> UpdateCommand { get; private set; }
public DelegateCommand SaveCommand { get; private set; }
public DelegateCommand RevokeCommand { get; private set; }
public DelegateCommand RefreshCommand { get; private set; }
public DelegateCommand ImportCommand { get; private set; }
public DelegateCommand ExportCommand { get; private set; }
#endregion Command
public ManageNvrViewModel(IRegionManager regionManager, IEventAggregator ea) : base(regionManager, ea)
{
LoadedCommand = new DelegateCommand<UserControl>(LoadedPageAction);
AddCommand = new DelegateCommand(AddInfoAction);
DeleteCommand = new DelegateCommand(DeleteInfoAction);
UpdateCommand = new ExtendCommand<DataGridCellEditEndingEventArgs>(UpdateInfoAction);
SaveCommand = new DelegateCommand(SaveInfosAction);
RevokeCommand = new DelegateCommand(RevokeInfoAction);
RefreshCommand = new DelegateCommand(RefreshAction);
ImportCommand = new DelegateCommand(ImportInfosAction);
ExportCommand = new DelegateCommand(ExportInfosAction);
}
#region Event Action
private void LoadedPageAction(UserControl view)
{
if (ThatPage != null) { return; }
ThatPage = (ManageNvr)view;
RefreshAction();
}
#endregion Event Action
#region Operate Action
private void AddInfoAction()
{
NvrInfo info = new();
info.Number = GetInfoNewNumber();
info.NvrName = $"录像机#{info.Number}";
info.NvrEnableBool = true;
OperateInfoListByLock(() => { AddInfo(info); });
DataGrid infoGrid = ThatPage.InfoGrid;
infoGrid.SelectedIndex = infoGrid.Items.Count - 1;
}
private async void DeleteInfoAction()
{
DataGrid infoGrid = ThatPage.InfoGrid;
NvrInfo info = (NvrInfo)infoGrid.SelectedItem;
int index = infoGrid.SelectedIndex;
if (info == null) { return; }
if (info.NvrId <= 0)
{
OperateInfoListByLock(() => { RemoveInfo(info); });
infoGrid.SelectedIndex = (index < infoGrid.Items.Count) ? index : infoGrid.Items.Count - 1;
return;
}
int ret = 0;
using IpcInfoContext ctx1 = new();
List<IpcInfo> ipcInfoList = await ctx1.GetListAsync();
ipcInfoList.ForEach(ipc => { if (ipc.NvrName.Equals(info.NvrName)) { ctx1.Remove(ipc); } });
ret = await ctx1.SaveChangesAsync();
if (ret > 0)
{
using NvrInfoContext ctx2 = new();
_ = ctx2.Remove(info);
ret = await ctx2.SaveChangesAsync();
if (ret > 0)
{
OperateInfoListByLock(() => { RemoveInfo(info); });
infoGrid.SelectedIndex = (index < infoGrid.Items.Count) ? index : infoGrid.Items.Count - 1;
}
}
}
private void UpdateInfoAction(DataGridCellEditEndingEventArgs e)
{
if (e.EditAction != DataGridEditAction.Commit) { return; }
var elm = e.EditingElement;
DataGridRow row = e.Row;
DataGridColumn column = e.Column;
NvrInfo info = (NvrInfo)row.Item;
if (info != null && info.NvrId > 0)
{
if (!UpdateNumberList.Exists(item => item.Equals(info.Number)))
{
UpdateNumberList.Add(info.Number);
}
}
}
private async void SaveInfosAction()
{
//ValidationError validationError = WPFAssist.GetDataGridRowsFirstError(ThatPage.InfoGrid);
//if (WPFAssist.GetDataGridRowsHasError(ThatPage.InfoGrid)) { return; }
List<NvrInfo> list = null;
using NvrInfoContext ctx = new();
int ret = 0;
if (AddNumberList.Count > 0)
{
list ??= GetInfoList();
foreach (int number in AddNumberList)
{
NvrInfo info = list.Find(item => item.Number.Equals(number));
if (info != null) { _ = ctx.Add(info); }
}
ret = await ctx.SaveChangesAsync();
if (ret > 0) { AddNumberList.Clear(); }
else { return; }
}
if (UpdateNumberList.Count > 0)
{
list ??= GetInfoList();
foreach (int number in UpdateNumberList)
{
NvrInfo info = list.Find(item => item.Number.Equals(number));
if (info != null) { _ = ctx.Update(info); }
}
ret = await ctx.SaveChangesAsync();
if (ret > 0) { UpdateNumberList.Clear(); }
else { return; }
}
RefreshAction();
}
private void RevokeInfoAction()
{
}
private void RefreshAction()
{
OperateInfoListByLock(() =>
{
AddNumberList.Clear();
UpdateNumberList.Clear();
LoadNvrDeviceList();
LoadInfoList();
});
}
private void ImportInfosAction()
{
}
private void ExportInfosAction()
{
}
#endregion Operate Action
#region Operate InfoList
private void OperateInfoListByLock(Action action)
{
if (InfoListrwl.IsWriteLockHeld) { return; }
if (!InfoListrwl.TryEnterWriteLock(100)) { return; }
try
{
action?.Invoke();
}
finally
{
InfoListrwl.ExitWriteLock();
}
}
private async void LoadInfoList()
{
InfoList.Clear();
using NvrInfoContext ctx = new();
List<NvrInfo> list = await ctx.GetListAsync();
int number = 0;
foreach (NvrInfo info in list)
{
info.Number = ++number;
InfoList.Add(info);
}
}
private void AddInfo(NvrInfo info)
{
InfoList.Add(info);
if (!AddNumberList.Exists(item => item.Equals(info.Number)))
{
AddNumberList.Add(info.Number);
}
}
private void RemoveInfo(NvrInfo info)
{
_ = InfoList.Remove(info);
_ = AddNumberList.RemoveAll(item => item.Equals(info.Number));
_ = UpdateNumberList.RemoveAll(item => item.Equals(info.Number));
}
private List<NvrInfo> GetInfoList()
{
return new(InfoList);
}
private int GetInfoNewNumber()
{
int number = InfoList.Count > 0 ? InfoList[^1].Number + 1 : 1;
return number;
}
#endregion Operate InfoList
#region Operate OtherList
private void LoadNvrDeviceList()
{
NvrDeviceList.Clear();
using NvrInfoContext ctx = new();
List<string> list = ctx.GetNvrDeviceList();
list.ForEach(item => { NvrDeviceList.Add(item); });
}
#endregion Operate OtherList
}
}

16
ECMonitor/Page/SystemSet/ManageSet.xaml

@ -0,0 +1,16 @@
<UserControl x:Class="ECMonitor.Page.SystemSet.ManageSet"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Background="{DynamicResource PageBodyBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="系统设置" FontSize="48" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</UserControl>

15
ECMonitor/Page/SystemSet/ManageSet.xaml.cs

@ -0,0 +1,15 @@
using System.Windows.Controls;
namespace ECMonitor.Page.SystemSet
{
/// <summary>
/// ManageSet.xaml 的交互逻辑
/// </summary>
public partial class ManageSet : UserControl
{
public ManageSet()
{
InitializeComponent();
}
}
}

13
ECMonitor/Page/SystemSet/ManageSetViewModel.cs

@ -0,0 +1,13 @@
using ECMonitor.Code.Models;
using Prism.Events;
using Prism.Regions;
namespace ECMonitor.Page.SystemSet
{
public class ManageSetViewModel : BaseModel
{
public ManageSetViewModel(IRegionManager regionManager, IEventAggregator ea) : base(regionManager, ea)
{
}
}
}

247
ECMonitor/Page/SystemSet/SearchIpc.xaml

@ -0,0 +1,247 @@
<UserControl x:Class="ECMonitor.Page.SystemSet.SearchIpc"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:prism="http://prismlibrary.com/"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mvvm="clr-namespace:ECMonitor.MVVM"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"
x:Name="ThatPage">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding LoadedCommand}" CommandParameter="{Binding ElementName=ThatPage}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<UserControl.Resources>
<SolidColorBrush x:Key="BtnInActiveBrush" Color="#393d46" />
<SolidColorBrush x:Key="BtnActiveBrush" Color="#478cb6" />
<SolidColorBrush x:Key="DGHeaderBrush" Color="#424242" />
<SolidColorBrush x:Key="DGBorderBrush" Color="{StaticResource PageBorderColor}" Opacity="0.8" />
<SolidColorBrush x:Key="DGLineBrush" Color="{StaticResource PageBorderColor}" Opacity="0.9" />
<Style x:Key="paramPanel" TargetType="{x:Type StackPanel}">
<Setter Property="Orientation" Value="Horizontal" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style x:Key="paramLabel" TargetType="{x:Type Label}" BasedOn="{StaticResource MaterialDesignLabel}">
</Style>
<Style x:Key="paramTextBox" TargetType="{x:Type TextBox}" BasedOn="{StaticResource MaterialDesignTextBox}">
<Setter Property="Width" Value="100" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="SlateGray" />
<Setter Property="Foreground" Value="AntiqueWhite" />
<Setter Property="materialDesign:TextFieldAssist.TextFieldCornerRadius" Value="4" />
</Style>
<Style x:Key="paramPasswordBox" TargetType="{x:Type PasswordBox}" BasedOn="{StaticResource MaterialDesignPasswordBox}">
<Setter Property="Width" Value="100" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="SlateGray" />
<Setter Property="Foreground" Value="AntiqueWhite" />
<Setter Property="materialDesign:TextFieldAssist.TextFieldCornerRadius" Value="4" />
<Setter Property="materialDesign:TextFieldAssist.HasClearButton" Value="True" />
</Style>
<!--<Style x:Key="paramComboBox" TargetType="{x:Type ComboBox}" BasedOn="{StaticResource {x:Type ComboBox}}">-->
<Style x:Key="paramComboBox" TargetType="{x:Type ComboBox}" BasedOn="{StaticResource MaterialDesignComboBox}">
<Setter Property="Width" Value="100" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="SlateGray" />
<Setter Property="Foreground" Value="AntiqueWhite" />
<!--<Setter Property="SelectedIndex" Value="0" />-->
<Setter Property="materialDesign:TextFieldAssist.TextFieldCornerRadius" Value="4" />
</Style>
<Style x:Key="btnPanel" TargetType="{x:Type StackPanel}">
<Setter Property="Orientation" Value="Horizontal" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style x:Key="paramButton" TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignFlatDarkBgButton}">
<Setter Property="Margin" Value="0,0,6,0" />
<Setter Property="Background" Value="{StaticResource BtnInActiveBrush}" />
<Setter Property="Foreground" Value="WhiteSmoke" />
<Setter Property="BorderBrush" Value="{StaticResource PageBorderBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="FontSize" Value="12" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="materialDesign:ButtonAssist.CornerRadius" Value="5" />
<Style.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="{StaticResource BtnActiveBrush}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource BtnActiveBrush}" />
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<Grid Background="{DynamicResource PageBodyBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<DockPanel Grid.Column="0">
<DataGrid x:Name="InfoGrid" ItemsSource="{Binding InfoList, Mode=OneWay}">
<DataGrid.Style>
<Style TargetType="DataGrid" BasedOn="{StaticResource MaterialDesignDataGrid}">
<Setter Property="Background" Value="{StaticResource PageBodyBrush}" />
<Setter Property="GridLinesVisibility" Value="All" />
<Setter Property="HorizontalGridLinesBrush" Value="{StaticResource DGLineBrush}" />
<Setter Property="VerticalGridLinesBrush" Value="{StaticResource DGLineBrush}" />
<Setter Property="BorderBrush" Value="{StaticResource DGLineBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="HeadersVisibility" Value="Column" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="AutoGenerateColumns" Value="False" />
<Setter Property="CanUserAddRows" Value="False" />
<Setter Property="CanUserDeleteRows" Value="False" />
<Setter Property="CanUserResizeRows" Value="False" />
<Setter Property="CanUserResizeColumns" Value="True" />
<Setter Property="CanUserReorderColumns" Value="False" />
<Setter Property="CanUserSortColumns" Value="False" />
</Style>
</DataGrid.Style>
<DataGrid.RowHeaderStyle>
<Style TargetType="DataGridRowHeader" BasedOn="{StaticResource MaterialDesignDataGridRowHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>
</DataGrid.RowHeaderStyle>
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader" BasedOn="{StaticResource MaterialDesignDataGridColumnHeader}">
<Setter Property="Background" Value="{StaticResource DGHeaderBrush}" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.Columns>
<materialDesign:DataGridTextColumn
Header="类型" Width="90" IsReadOnly="True"
Binding="{Binding IpcType, UpdateSourceTrigger=PropertyChanged}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</materialDesign:DataGridTextColumn>
<materialDesign:DataGridTextColumn
Header="地址" Width="120" IsReadOnly="True"
Binding="{Binding IpcIp, UpdateSourceTrigger=PropertyChanged}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</materialDesign:DataGridTextColumn>
<materialDesign:DataGridTextColumn
Header="设备地址" Width="*" IsReadOnly="True"
Binding="{Binding OnvifAddr, UpdateSourceTrigger=PropertyChanged}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</materialDesign:DataGridTextColumn>
<materialDesign:DataGridTextColumn
Header="媒体地址" Width="*" IsReadOnly="True"
Binding="{Binding MediaAddr, UpdateSourceTrigger=PropertyChanged}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</materialDesign:DataGridTextColumn>
<materialDesign:DataGridTextColumn
Header="云台地址" Width="*" IsReadOnly="True"
Binding="{Binding PtzAddr, UpdateSourceTrigger=PropertyChanged}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</materialDesign:DataGridTextColumn>
<materialDesign:DataGridTextColumn
Header="主码流" Width="*" IsReadOnly="True"
Binding="{Binding RtspMain, UpdateSourceTrigger=PropertyChanged}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</materialDesign:DataGridTextColumn>
<materialDesign:DataGridTextColumn
Header="子码流" Width="*" IsReadOnly="True"
Binding="{Binding RtspSub, UpdateSourceTrigger=PropertyChanged}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}">
</materialDesign:DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</DockPanel>
<Border Grid.Column="1" BorderBrush="{StaticResource PageBorderBrush}" BorderThickness="1">
<StackPanel VerticalAlignment="Top">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Style="{StaticResource paramPanel}">
<Label Content="录 像 机 " Style="{StaticResource paramLabel}" />
<ComboBox x:Name="NvrInfoComboBox" Style="{StaticResource paramComboBox}"
ItemsSource="{Binding NvrInfoList}" DisplayMemberPath="NvrName" SelectedValue="{Binding SelectedNvrInfo}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<mvvm:ExtendEventCommand Command="{Binding NvrInfoComboBoxSelectionChangedCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</StackPanel>
<StackPanel Grid.Row="1" Style="{StaticResource paramPanel}">
<Label Content="用户姓名" Style="{StaticResource paramLabel}" />
<TextBox Text="{Binding UserName,Mode=TwoWay}" Style="{StaticResource paramTextBox}" />
</StackPanel>
<StackPanel Grid.Row="2" Style="{StaticResource paramPanel}">
<Label Content="用户密码" Style="{StaticResource paramLabel}" />
<PasswordBox mvvm:PasswordBoxHelper.Password="{Binding Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource paramPasswordBox}" />
</StackPanel>
<StackPanel Grid.Row="3" Style="{StaticResource paramPanel}">
<Label Content="选择网卡" Style="{StaticResource paramLabel}" />
<ComboBox x:Name="NetworkCardComboBox" Style="{StaticResource paramComboBox}"
ItemsSource="{Binding NetworkCardList}" DisplayMemberPath="Name" SelectedValue="{Binding SelectedNetworkCard}">
</ComboBox>
</StackPanel>
<StackPanel Grid.Row="4" Style="{StaticResource paramPanel}">
<Label Content="搜索时长" Style="{StaticResource paramLabel}" />
<ComboBox x:Name="TimeoutComboBox" Style="{StaticResource paramComboBox}"
ItemsSource="{Binding TimeoutList}" SelectedValue="{Binding SelectedTimeout}">
</ComboBox>
</StackPanel>
<StackPanel Grid.Row="5" Style="{StaticResource btnPanel}">
<Button Style="{StaticResource paramButton}" Content="广播搜索" Command="{Binding BroadcastSearchCommand}" />
<Button Style="{StaticResource paramButton}" Content="刷 新" Command="{Binding RefreshCommand}" />
</StackPanel>
<StackPanel Grid.Row="6" Style="{StaticResource btnPanel}">
<Button Style="{StaticResource paramButton}" Content="获取所有" Command="{Binding GainAllCommand}" />
<Button Style="{StaticResource paramButton}" Content="获取当前" Command="{Binding GainSelectedCommand}" />
</StackPanel>
<StackPanel Grid.Row="7" Style="{StaticResource btnPanel}">
<Button Style="{StaticResource paramButton}" Content="添加所有" Command="{Binding PublishAllCommand}" />
<Button Style="{StaticResource paramButton}" Content="添加当前" Command="{Binding PublishSelectedCommand}" />
</StackPanel>
</Grid>
</StackPanel>
</Border>
</Grid>
</UserControl>

16
ECMonitor/Page/SystemSet/SearchIpc.xaml.cs

@ -0,0 +1,16 @@
using System.Windows.Controls;
namespace ECMonitor.Page.SystemSet
{
/// <summary>
/// SearchIpc.xaml 的交互逻辑
/// </summary>
public partial class SearchIpc : UserControl
{
public SearchIpc()
{
InitializeComponent();
}
}
}

346
ECMonitor/Page/SystemSet/SearchIpcViewModel.cs

@ -0,0 +1,346 @@
using EC.Entity.CameraInfo;
using EC.Onvif;
using EC.Onvif.Common;
using EC.Onvif.Device;
using EC.Onvif.Media;
using EC.Onvif.RemoteDiscovery;
using EC.Service.CameraInfo;
using EC.UsingEventAggregator;
using ECMonitor.Code.Models;
using ECMonitor.MVVM;
using Prism.Commands;
using Prism.Events;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace ECMonitor.Page.SystemSet
{
public class SearchIpcViewModel : BaseModel
{
private SearchIpc ThatPage { get; set; }
public ObservableCollection<IpcInfo> InfoList { get; set; } = new();
private ReaderWriterLockSlim InfoListrwl { get; } = new();
#region Parameter
public ObservableCollection<NvrInfo> NvrInfoList { get; set; } = new();
public NvrInfo SelectedNvrInfo { get; set; }
private string _userName { get; set; }
public string UserName
{ get { return _userName; } set { _userName = value; RaisePropertyChanged(nameof(UserName)); } }
private string _password { get; set; }
public string Password
{ get { return _password; } set { _password = value; RaisePropertyChanged(nameof(Password)); } }
public ObservableCollection<System.Net.NetworkInformation.NetworkInterface> NetworkCardList { get; set; } = new();
public System.Net.NetworkInformation.NetworkInterface SelectedNetworkCard { get; set; }
public ObservableCollection<int> TimeoutList { get; set; } = new();
public int SelectedTimeout { get; set; }
#endregion Parameter
#region Command
public DelegateCommand<UserControl> LoadedCommand { get; private set; }
public ExtendCommand<SelectionChangedEventArgs> NvrInfoComboBoxSelectionChangedCommand { get; private set; }
public DelegateCommand RefreshCommand { get; private set; }
public DelegateCommand BroadcastSearchCommand { get; private set; }
public DelegateCommand UnicastSearchCommand { get; private set; }
public DelegateCommand GainAllCommand { get; private set; }
public DelegateCommand GainSelectedCommand { get; private set; }
public DelegateCommand PublishAllCommand { get; private set; }
public DelegateCommand PublishSelectedCommand { get; private set; }
#endregion Command
public SearchIpcViewModel(IRegionManager regionManager, IEventAggregator ea) : base(regionManager, ea)
{
LoadedCommand = new DelegateCommand<UserControl>(LoadedPageAction);
NvrInfoComboBoxSelectionChangedCommand = new ExtendCommand<SelectionChangedEventArgs>(NvrInfoComboBoxSelectionChangedAction);
RefreshCommand = new DelegateCommand(RefreshAction);
BroadcastSearchCommand = new DelegateCommand(BroadcastSearchAction);
UnicastSearchCommand = new DelegateCommand(UnicastSearchAction);
GainAllCommand = new DelegateCommand(GainAllAction);
GainSelectedCommand = new DelegateCommand(GainSelectedAction);
PublishAllCommand = new DelegateCommand(PublishAllIpcInfoAction);
PublishSelectedCommand = new DelegateCommand(PublishSelectedIpcInfoAction);
}
#region Event Action
private void LoadedPageAction(UserControl view)
{
if (ThatPage != null) { return; }
ThatPage = (SearchIpc)view;
RefreshAction();
}
private void NvrInfoComboBoxSelectionChangedAction(SelectionChangedEventArgs e)
{
NvrInfo selectedNvrInfo = (NvrInfo)ThatPage.NvrInfoComboBox.SelectedItem;
UserName = selectedNvrInfo?.UserName;
Password = selectedNvrInfo?.UserPwd;
}
#endregion Event Action
#region Operate Action
private void RefreshAction()
{
OperateInfoListByLock(() =>
{
LoadNvrInfoList();
LoadNetworkCardList();
LoadTimeoutList();
});
}
/// <summary>
/// 广播搜索
/// </summary>
private void BroadcastSearchAction()
{
OperateInfoListByLock(async () =>
{
InfoList.Clear();
Discovery onvifDiscovery = new();
IEnumerable<DiscoveryDevice> deviceList = await onvifDiscovery.DiscoverByAdapter(new[] { SelectedNetworkCard }, SelectedTimeout);
foreach (DiscoveryDevice device in deviceList)
{
IpcInfo info = new();
info.IpcType = device.Mfr;
info.IpcIp = device.Address;
info.OnvifAddr = device.XAdresses.Count > 0 ? device.XAdresses[0] : string.Empty;
info.IpcEnableBool = true;
InfoList.Add(info);
}
});
}
/// <summary>
/// 单播搜索
/// </summary>
private void UnicastSearchAction()
{
}
/// <summary>
/// 获取所有
/// </summary>
private void GainAllAction()
{
OperateInfoListByLock(async () =>
{
foreach (IpcInfo info in InfoList)
{
if (!VerifyUnit.CheckIp(info.IpcIp))
{
continue;
}
await GainInfo(info);
}
});
}
/// <summary>
/// 获取选中
/// </summary>
private void GainSelectedAction()
{
OperateInfoListByLock(async () =>
{
IpcInfo info = (IpcInfo)ThatPage.InfoGrid.SelectedItem;
if (info == null) { return; }
await GainInfo(info);
});
}
/// <summary>
/// 添加所有
/// </summary>
private void PublishAllIpcInfoAction()
{
List<IpcInfo> list = new();
string nvrName = SelectedNvrInfo.NvrName;
foreach (IpcInfo item in InfoList)
{
IpcInfo info = item.DeepCopy<IpcInfo>();
info.NvrName = nvrName;
list.Add(info);
}
_ea.GetEvent<SendIpcInfoListEvent>().Publish(list);
}
/// <summary>
/// 添加当前
/// </summary>
private void PublishSelectedIpcInfoAction()
{
IpcInfo item = (IpcInfo)ThatPage.InfoGrid.SelectedItem;
if (item == null) { return; }
List<IpcInfo> list = new();
string nvrName = SelectedNvrInfo.NvrName;
IpcInfo info = item.DeepCopy<IpcInfo>();
info.NvrName = nvrName;
list.Add(info);
_ea.GetEvent<SendIpcInfoListEvent>().Publish(list);
}
#endregion Operate Action
#region Operate List
private void OperateInfoListByLock(Action action)
{
if (InfoListrwl.IsWriteLockHeld) { return; }
if (!InfoListrwl.TryEnterWriteLock(100)) { return; }
try
{
action?.Invoke();
}
finally
{
InfoListrwl.ExitWriteLock();
}
}
private async void LoadNvrInfoList()
{
NvrInfoList.Clear();
using NvrInfoContext ctx = new();
List<NvrInfo> list = await ctx.GetListAsync();
list.ForEach(info => NvrInfoList.Add(info));
ThatPage.NvrInfoComboBox.SelectedIndex = 0;
}
private void LoadNetworkCardList()
{
NetworkCardList.Clear();
IEnumerable<System.Net.NetworkInformation.NetworkInterface> adapterList = OnvifUdpClient.GetVaildNetworkAdapters();
foreach (System.Net.NetworkInformation.NetworkInterface adapter in adapterList)
{
NetworkCardList.Add(adapter);
}
ThatPage.NetworkCardComboBox.SelectedIndex = 0;
}
private void LoadTimeoutList()
{
TimeoutList.Clear();
TimeoutList.Add(2);
TimeoutList.Add(5);
TimeoutList.Add(10);
TimeoutList.Add(15);
TimeoutList.Add(30);
ThatPage.TimeoutComboBox.SelectedIndex = 0;
}
#endregion Operate List
#region Helper
private StreamSetup RtspStreamSetup { get; } = new()
{
Stream = StreamType.RTPUnicast,
Transport = new() { Protocol = TransportProtocol.RTSP }
};
private async Task GainInfo(IpcInfo info)
{
bool isMediaGain = info.IsUriGain(info.MediaAddr);
bool isPtzGain = info.IsUriGain(info.PtzAddr);
bool isRtspGain = info.IsUriGain(info.RtspMain) || info.IsUriGain(info.RtspSub);
if (!isMediaGain || !isPtzGain)
{
try
{
DeviceClient device = await OnvifClientFactory.CreateDeviceClientAsync(info.IpcIp, UserName, Password);
if (string.IsNullOrEmpty(info.IpcType))
{
GetDeviceInformationResponse resp = await device.GetDeviceInformationAsync(new());
info.SetValue("IpcType", resp.Manufacturer);
}
GetCapabilitiesResponse caps;
if (!isMediaGain)
{
caps = await device.GetCapabilitiesAsync(new[] { CapabilityCategory.Media });
info.SetValue("MediaAddr", caps.Capabilities.Media.XAddr);
};
if (!isPtzGain)
{
caps = await device.GetCapabilitiesAsync(new[] { CapabilityCategory.PTZ });
info.SetValue("PtzAddr", caps.Capabilities.PTZ.XAddr);
};
}
catch (Exception)
{
}
finally
{
if (!info.IsUriGain(info.MediaAddr)) { info.SetValue("MediaAddr", info.FaultUri); }
if (!info.IsUriGain(info.PtzAddr)) { info.SetValue("PtzAddr", info.FaultUri); }
}
}
if (!isRtspGain)
{
try
{
MediaClient media = await OnvifClientFactory.CreateMediaClientAsync(info.IpcIp, UserName, Password);
info.SetValue("UserName", UserName);
info.SetValue("UserPwd", Password);
GetProfilesResponse profiles = await media.GetProfilesAsync();
string profileToken;
if (profiles.Profiles.Length >= 1)
{
profileToken = profiles.Profiles[0].token;
MediaUri streamUri = await media.GetStreamUriAsync(RtspStreamSetup, profileToken);
info.SetValue("RtspMain", streamUri.Uri);
}
if (profiles.Profiles.Length >= 2)
{
profileToken = profiles.Profiles[1].token;
MediaUri streamUri = await media.GetStreamUriAsync(RtspStreamSetup, profileToken);
info.SetValue("RtspSub", streamUri.Uri);
}
}
catch (Exception)
{
}
finally
{
if (!info.IsUriGain(info.RtspMain)) { info.SetValue("RtspMain", info.FaultUri); }
if (!info.IsUriGain(info.RtspSub)) { info.SetValue("RtspSub", info.FaultUri); }
}
}
}
#endregion Helper
}
}

21
ECMonitor/Page/Test/Main.xaml

@ -0,0 +1,21 @@
<UserControl x:Class="ECMonitor.Page.Test.Main"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:prism="http://prismlibrary.com/"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!--<ContentControl Grid.Column="0" />-->
<TextBlock Grid.Column="0" Text="ViewTest" FontSize="48" HorizontalAlignment="Center" VerticalAlignment="Center" />
<ContentControl Grid.Column="1" />
<!--<ContentControl Grid.Column="0" prism:RegionManager.RegionName="ContentRegionLeft" />-->
<!--<ContentControl Grid.Column="1" prism:RegionManager.RegionName="ContentRegionCenter" />-->
</Grid>
</UserControl>

15
ECMonitor/Page/Test/Main.xaml.cs

@ -0,0 +1,15 @@
using System.Windows.Controls;
namespace ECMonitor.Page.Test
{
/// <summary>
/// FrmSetMain.xaml 的交互逻辑
/// </summary>
public partial class Main : UserControl
{
public Main()
{
InitializeComponent();
}
}
}

16
ECMonitor/Page/Test/MainViewModel.cs

@ -0,0 +1,16 @@
using ECMonitor.Code.Models;
using Prism.Events;
using Prism.Regions;
namespace ECMonitor.Page.Test
{
public class MainViewModel : BaseModel
{
private IEventAggregator _ea;
public MainViewModel(IRegionManager regionManager, IEventAggregator ea) : base(regionManager, ea)
{
_ea = ea;
}
}
}

275
ECMonitor/PlayerDraw/Code/BlackboardClass.cs

@ -0,0 +1,275 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
namespace ECMonitor.PlayerDraw.Code
{
public enum ColorEnum
{
绿,
,
,
,
,
,
,
,
,
}
/// <summary>
/// 表示部分音频文件的类型
/// </summary>
public enum FileTypes
{
MKV = 2669,
MP4 = 00,
INI = 255254,
MP3 = 7368,
WAV = 8273,
WMA = 4838,
AVI = 8273,
WMV = 4838,
}
public class BlackboardClass
{
/// <summary>
/// 初始化BlackboardClass
/// </summary>
public BlackboardClass()
{
}
/// <summary>
/// 添加或删除启动项
/// </summary>
/// <param name="isStart">true为添加启动项,否则为删除启动项</param>
/// <param name="startName">启动项的名称</param>
/// <param name="applicationPath">要开机启动的应用程序的exe文件的路径</param>
/// <returns>表示是否完成添加或删除任务</returns>
public static bool RunItem(bool isStart, string startName, string applicationPath)
{
bool result = true;
RegistryKey HKLM = Registry.CurrentUser;
RegistryKey run = HKLM.CreateSubKey(@"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\");
if (isStart)
{
try
{
run.SetValue(startName, applicationPath);
HKLM.Close();
}
catch (Exception)
{
}
}
else
{
try
{
run.DeleteValue(startName);
HKLM.Close();
}
catch (Exception)
{
}
}
result = run.GetValue("智能版") != null;
HKLM.Close();
return result;
}
/// <summary>
/// 初始化BlackboardClass
/// </summary>
/// <param name="moveControl">要移动的控件</param>
public BlackboardClass(UserControl moveControl)
{
MoveControl = moveControl;
}
/// <summary>
/// 要移动的控件
/// </summary>
public UserControl MoveControl { get; set; }
/// <summary>
/// 提供一个Thumb在Grid上的DragDelta处理程序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void ThumbMove(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
if (MoveControl != null)
{
double top = MoveControl.Margin.Top + e.VerticalChange,//上边距
left = MoveControl.Margin.Left + e.HorizontalChange;//左边距
MoveControl.Margin = new System.Windows.Thickness(left, top, 0, 0);
}
}
public static bool IsAudio(string path)
{
FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
BinaryReader read = new BinaryReader(fileStream);
byte code;
string fileTypeCode = String.Empty;
try
{
for (int i = 0; i < 2; i++)
{
code = read.ReadByte();
fileTypeCode += code.ToString();
}
}
catch (Exception)
{
return false;
}
fileStream.Close();
read.Close();
int tryVal;
return !Int32.TryParse(((FileTypes)Enum.Parse(typeof(FileTypes), fileTypeCode)).ToString(), out tryVal);
}
/// <summary>
/// 改变颜色
/// </summary>
/// <param name="color">要返回的颜色</param>
public static Color ChangeColor(ColorEnum color)
{
switch (color)
{
case ColorEnum.:
return Colors.White;
case ColorEnum.:
return Colors.Yellow;
case ColorEnum.:
return Colors.Black;
case ColorEnum.:
return Colors.Red;
case ColorEnum.:
return Colors.Gray;
case ColorEnum.:
return Colors.Blue;
case ColorEnum.绿:
return Colors.Green;
case ColorEnum.:
return Colors.Cyan;
case ColorEnum.:
return Colors.Purple;
case ColorEnum.:
return Colors.Orange;
default:
return new Color();
}
}
public void ChangSize(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
double wibth = this.MoveControl.ActualWidth;
double heigth = this.MoveControl.ActualHeight;
switch ((sender as Thumb).Name)
{
case "LeftTop":
double left = MoveControl.Margin.Left,
top = MoveControl.Margin.Top;
if (MoveControl.ActualWidth - e.HorizontalChange <= this.MoveControl.MaxWidth &&
MoveControl.ActualWidth - e.HorizontalChange >= this.MoveControl.MinWidth)
{
wibth = MoveControl.ActualWidth - e.HorizontalChange;
left = MoveControl.Margin.Left + e.HorizontalChange;
}
if (MoveControl.ActualHeight - e.VerticalChange <= this.MoveControl.MaxHeight &&
MoveControl.ActualHeight - e.VerticalChange >= this.MoveControl.MinHeight)
{
heigth = MoveControl.ActualHeight - e.VerticalChange;
top = MoveControl.Margin.Top + e.VerticalChange;
}
MoveControl.Margin = new Thickness(left, top, 0, 0);
break;
case "LeftBottom":
left = this.MoveControl.Margin.Left;
double bottom = this.MoveControl.Margin.Bottom;
if (MoveControl.ActualWidth - e.HorizontalChange <= this.MoveControl.MaxWidth &&
MoveControl.ActualWidth - e.HorizontalChange >= this.MoveControl.MinWidth)
{
wibth = MoveControl.ActualWidth - e.HorizontalChange;
left = MoveControl.Margin.Left + e.HorizontalChange;
}
if (MoveControl.ActualHeight + e.VerticalChange <= this.MoveControl.MaxHeight &&
MoveControl.ActualHeight + e.VerticalChange >= this.MoveControl.MinHeight)
{
heigth = MoveControl.ActualHeight + e.VerticalChange;
bottom = MoveControl.Margin.Bottom - e.VerticalChange;
}
MoveControl.Margin = new Thickness(left, MoveControl.Margin.Top, 0, bottom);
break;
case "RightTop":
top = this.MoveControl.Margin.Top;
if (MoveControl.ActualWidth + e.HorizontalChange <= this.MoveControl.MaxWidth &&
MoveControl.ActualWidth + e.HorizontalChange >= this.MoveControl.MinWidth)
wibth = MoveControl.ActualWidth + e.HorizontalChange;
if (MoveControl.ActualHeight - e.VerticalChange <= this.MoveControl.MaxHeight &&
MoveControl.ActualHeight - e.VerticalChange >= this.MoveControl.MinHeight)
{
heigth = MoveControl.ActualHeight - e.VerticalChange;
top = MoveControl.Margin.Top + e.VerticalChange;
}
MoveControl.Margin = new Thickness(MoveControl.Margin.Left,
top, 0, MoveControl.Margin.Bottom);
break;
default:
double right = this.MoveControl.Margin.Right;
bottom = this.MoveControl.Margin.Bottom;
if (MoveControl.ActualWidth + e.HorizontalChange <= this.MoveControl.MaxWidth &&
MoveControl.ActualWidth + e.HorizontalChange >= this.MoveControl.MinWidth)
{
wibth = MoveControl.ActualWidth + e.HorizontalChange;
right = MoveControl.Margin.Right - e.HorizontalChange;
}
if (MoveControl.ActualHeight + e.VerticalChange <= this.MoveControl.MaxHeight &&
MoveControl.ActualHeight + e.VerticalChange >= this.MoveControl.MinHeight)
{
heigth = MoveControl.ActualHeight + e.VerticalChange;
bottom = this.MoveControl.Margin.Bottom - e.VerticalChange;
}
MoveControl.Margin = new Thickness(MoveControl.Margin.Left,
MoveControl.Margin.Top, right, bottom);
break;
}
MoveControl.Width = wibth;
MoveControl.Height = heigth;
}
}
}

117
ECMonitor/PlayerDraw/Code/BlackboardData.cs

@ -0,0 +1,117 @@
using EC.Entity.Warning;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace ECMonitor.PlayerDraw.Code
{
/// <summary>
/// 记录Blackboard的相关数据
/// </summary>
[Serializable]
public class BlackboardData : BindableBase
{
public BlackboardData()
{
}
private double lineWidthValue = 5D;
private int lineColor = (int)ColorEnum.;
private bool? isRun = true;
private int blackboardColor = (int)ColorEnum.绿;
/// <summary>
/// 黑板颜色
/// </summary>
public int BlackboardColor
{
get { return blackboardColor; }
set{ SetProperty(ref blackboardColor, value); }
}
/// <summary>
/// 表示是否开机启动此程序
/// </summary>
public bool? IsRun
{
get
{
return isRun;
}
set
{
isRun = BlackboardClass.RunItem(value.Value, "视频监控", Process.GetCurrentProcess().MainModule.FileName);
SetProperty(ref isRun, value);
}
}
[NonSerialized]
private int drawType =5;//画图类型
/// <summary>
/// 画图类型
/// </summary>
public int DrawType
{
get { return drawType; }
set
{
SetProperty(ref drawType, value);
}
}
[NonSerialized]
private bool? draw = false;//绘图模式是否已启动
/// <summary>
/// 绘图模式是否已启动
/// </summary>
public bool? Draw
{
get { return draw; }
set
{
SetProperty(ref draw, value);
}
}
/// <summary>
/// 线条的颜色
/// </summary>
public int LineColor
{
get { return lineColor; }
set
{
SetProperty(ref lineColor, value);
}
}
/// <summary>
/// 线条粗细的值
/// </summary>
public double LineWidthValue
{
get { return lineWidthValue; }
set
{
SetProperty(ref lineWidthValue, value);
}
}
}
}

67
ECMonitor/PlayerDraw/Code/DataBase.cs

@ -0,0 +1,67 @@
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ECMonitor.PlayerDraw.Code
{
/// <summary>
/// 数据模型基类
/// </summary>
[Serializable]
public abstract class DataBase : BindableBase, INotifyPropertyChanged
{
public DataBase(string fileName)
{
string directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"Computer Madman");
if (!Directory.Exists(directory))
Directory.CreateDirectory(directory);
DataPath = Path.Combine(directory, fileName);
}
[NonSerialized]
string dataPath;
/// <summary>
/// 保存文件的路径
/// </summary>
public string DataPath
{
get
{
return dataPath;
}
set
{
dataPath = value;
}
}
/// <summary>
/// 在更改属性值时发生。
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// 用于触发INotifyPropertyChanged的PropertyChanged事件
/// </summary>
/// <param name="propertyName">属性名</param>
protected void DataChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
private string _title = "";
public string Title
{
get { return _title; }
set { SetProperty(ref _title, value); }
}
}
}

195
ECMonitor/PlayerDraw/Code/Draw.cs

@ -0,0 +1,195 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
namespace ECMonitor.PlayerDraw.Code
{
/// <summary>
/// 画图类
/// </summary>
public class Draw
{
/// <summary>
/// 初始化对象
/// </summary>
/// <param name="broad">画布</param>
public Draw(InkCanvas broad)
{
this.broad = broad;
arcs = new StylusPointCollection[8];
for (int i = 0; i < arcs.Length; i++)
{
arcs[i] = new StylusPointCollection();
}
}
InkCanvas broad;
public StrokeEx Line(StylusPoint a, StylusPoint b, int warningLevel)
{
StylusPointCollection points = new StylusPointCollection { a, b };
StrokeEx line = new StrokeEx(points);
line.DrawType = DrawTypes.线;
line.WarningLevel = warningLevel;
line.DrawingAttributes = broad.DefaultDrawingAttributes.Clone();
line.DrawingAttributes.Color = BlackboardClass.ChangeColor((ColorEnum)warningLevel);
return line;
}
/// <summary>
/// 以矩形的两个对角坐标为根据画矩形
/// </summary>
/// <param name="a">一个顶点坐标</param>
/// <param name="c">与a相对点的坐标</param>
/// <returns></returns>
public StrokeEx Rectangle(StylusPoint a, StylusPoint c,int warningLevel)
{
StylusPoint b = new StylusPoint(c.X, a.Y),
d = new StylusPoint(a.X, c.Y);
StylusPointCollection points = new StylusPointCollection { a, b, c, d, a };
StrokeEx rectangle = new StrokeEx(points);
rectangle.DrawType = DrawTypes.;
rectangle.WarningLevel = warningLevel;
rectangle.DrawingAttributes = broad.DefaultDrawingAttributes.Clone();
rectangle.DrawingAttributes.StylusTip = StylusTip.Rectangle;
rectangle.DrawingAttributes.Color = BlackboardClass.ChangeColor((ColorEnum)warningLevel);
return rectangle;
}
/// <summary>
/// 绘制三角形
/// </summary>
/// <param name="a">点a</param>
/// <param name="b">点b</param>
/// <param name="c">点c</param>
/// <returns></returns>
public Stroke Triangle(StylusPoint a, StylusPoint b, StylusPoint c)
{
StylusPointCollection points = new StylusPointCollection { a, b, c, a };
StrokeEx triangle = new StrokeEx(points);
triangle.DrawType = DrawTypes.;
triangle.DrawingAttributes = broad.DefaultDrawingAttributes.Clone();
return triangle;
}
/// <summary>
/// 绘制多边形
/// </summary>
/// <param name="points">多边形的顶点</param>
/// <returns></returns>
public Stroke Polygon(StylusPointCollection points, int warningLevel)
{
points.Add(points[0]);
StrokeEx polygon = new StrokeEx(points);
polygon.DrawType = DrawTypes.;
polygon.WarningLevel = warningLevel;
polygon.DrawingAttributes = broad.DefaultDrawingAttributes.Clone();
polygon.DrawingAttributes.Color = BlackboardClass.ChangeColor((ColorEnum)warningLevel);
return polygon;
}
public Stroke Lines(StylusPointCollection points, int warningLevel)
{
StrokeEx polygon = new StrokeEx(points);
polygon.DrawType = DrawTypes.;
polygon.WarningLevel = warningLevel;
polygon.DrawingAttributes = broad.DefaultDrawingAttributes.Clone();
polygon.DrawingAttributes.Color = BlackboardClass.ChangeColor((ColorEnum)warningLevel);
return polygon;
}
public Stroke Circle(StylusPoint o, StylusPoint p,int warningLevel)
{
StylusPointCollection points = OriginalArc(o, p);
StrokeEx circle = new StrokeEx(points);
circle.DrawType = DrawTypes.;
circle.WarningLevel = warningLevel;
circle.DrawingAttributes = broad.DefaultDrawingAttributes.Clone();
circle.DrawingAttributes.Color = BlackboardClass.ChangeColor((ColorEnum)warningLevel);
for (int i = 0; i < arcs.Length; i++)
{
arcs[i] = new StylusPointCollection();
}
return circle;
}
private StylusPointCollection OriginalArc(StylusPoint o, StylusPoint p)
{
StylusPointCollection points = new StylusPointCollection();
double r =
Math.Sqrt(Math.Pow(p.X - o.X, 2) + Math.Pow(p.Y - o.Y, 2));//该圆的半径
double d = 3 - 2 * r;
StylusPoint motionPoint = new StylusPoint();
motionPoint.X = 0;
motionPoint.Y = r;
CirclePoints(o, motionPoint);
while (motionPoint.X < motionPoint.Y)
{
if (d < 0)
d = d + 4 * motionPoint.X + 6;
else
{
d = d + 4 * (motionPoint.X - motionPoint.Y) + 10;
motionPoint.Y--;
}
motionPoint.X++;
CirclePoints(o, motionPoint);
}
for (int i = 0; i < arcs.Length; i++)
{
if (i % 2 != 0)
{
for (int index = arcs[i].Count - 1; index >= 0; index--)
{
points.Add(arcs[i][index]);
}
}
else
points.Add(arcs[i]);
}
return points;
}
StylusPointCollection[] arcs;//表示一个圆的八个弧
private void CirclePoints(StylusPoint o, StylusPoint p)
{
arcs[0].Add(new StylusPoint(p.X + o.X, p.Y + o.Y));
arcs[1].Add(new StylusPoint(p.Y + o.X, p.X + o.Y));
arcs[2].Add(new StylusPoint(-p.Y + o.X, p.X + o.Y));
arcs[3].Add(new StylusPoint(-p.X + o.X, p.Y + o.Y));
arcs[4].Add(new StylusPoint(-p.X + o.X, -p.Y + o.Y));
arcs[5].Add(new StylusPoint(-p.Y + o.X, -p.X + o.Y));
arcs[6].Add(new StylusPoint(p.Y + o.X, -p.X + o.Y));
arcs[7].Add(new StylusPoint(p.X + o.X, -p.Y + o.Y));
}
}
}
/*
*
线
*
*/

17
ECMonitor/PlayerDraw/Code/DrawTypes.cs

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ECMonitor.PlayerDraw.Code
{
public enum DrawTypes
{
线,
,
,
,
}
}

406
ECMonitor/PlayerDraw/Code/ECDrawing.cs

@ -0,0 +1,406 @@
using EC.Entity.Warning;
using ECMonitor.Code.DB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
namespace ECMonitor.PlayerDraw.Code
{
public class ECDrawing
{
Button drawFinished;
Polygon drawPolygon;//预览多边形
Rectangle circular;//预览圆
InkCanvas writeBorad;//画布
Grid contenter { get; set; }// 控件容器
StylusPointCollection drawPoints { get; set; } = new StylusPointCollection();//添加到画布图像的点
PointCollection drawingPoints { get; set; } = new PointCollection();//预览图形的点
BlackboardData data { get; set; }
public ECDrawing(BlackboardData data, Grid contenter, InkCanvas writeBorad)
{
this.data = data;
this.contenter = contenter;
this.writeBorad = writeBorad;
this.writeBorad.EditingModeChanged += writeBorad_EditingModeChanged;
this.data.PropertyChanged += data_PropertyChanged;
}
void writeBorad_EditingModeChanged(object sender, RoutedEventArgs e)
{
StopDraw();
}
void data_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (drawPoints.Count() != 0 && (e.PropertyName == "DrawType" || e.PropertyName == "Draw"))
{
StopDraw();
}
}
private void StopDraw()
{
drawPoints.Clear();
if (drawPolygon != null)
{
contenter.Children.Remove(drawPolygon);
drawPolygon = null;
}
if (circular != null)
{
contenter.Children.Remove(circular);
drawPolygon = null;
}
if (drawFinished != null)
{
contenter.Children.Remove(drawFinished);
drawFinished = null;
}
drawingPoints.Clear();
}
public void MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (this.data.Draw == true && writeBorad.EditingMode == InkCanvasEditingMode.None &&
(drawPolygon != null || circular != null))
{
Draw createDraw = new Draw(writeBorad);
Point point = e.GetPosition(writeBorad);
if (!drawingPoints.Contains(point))
{
drawPoints.Add(new StylusPoint(point.X, point.Y));
drawingPoints.Add(point);
}
DrawTypes drawType = (DrawTypes)data.DrawType;
switch (drawType)
{
case DrawTypes.:
if (drawPoints.Count == 2)
{
writeBorad.Strokes.Add(createDraw.Rectangle(drawPoints[0], drawPoints[1], data.LineColor));
drawPoints.Clear();
drawingPoints.Clear();
contenter.Children.Remove(drawPolygon);
drawPolygon = null;
}
break;
case DrawTypes.线:
if (drawPoints.Count == 2)
{
writeBorad.Strokes.Add(createDraw.Line(drawPoints[0], drawPoints[1], data.LineColor));
drawPoints.Clear();
drawingPoints.Clear();
contenter.Children.Remove(drawPolygon);
drawPolygon = null;
}
break;
case DrawTypes.:
if (drawPoints.Count == 2)
{
writeBorad.Strokes.Add(createDraw.Circle(drawPoints[0], drawPoints[1], data.LineColor));
drawPoints.Clear();
drawingPoints.Clear();
contenter.Children.Remove(circular);
circular = null;
}
break;
case DrawTypes.:
if (drawPoints.Count == 3)
{
writeBorad.Strokes.Add(createDraw.Triangle(drawPoints[0], drawPoints[1], drawPoints[2]));
drawPoints.Clear();
drawingPoints.Clear();
contenter.Children.Remove(drawPolygon);
drawPolygon = null;
}
break;
case DrawTypes.:
if (drawFinished == null)
{
drawFinished = new Button
{
Content = "完成",
Background = Brushes.Green,
BorderBrush = Brushes.Black,
BorderThickness = new Thickness(1),
FontSize = 18,
Foreground = Brushes.Black,
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Left,
};
Panel.SetZIndex(drawFinished, 20);
drawFinished.Click +=
delegate (object a, RoutedEventArgs b)
{
drawPoints.RemoveAt(drawPoints.Count - 1);
writeBorad.Strokes.Add(createDraw.Polygon(drawPoints.Clone(), data.LineColor));
drawPoints.Clear();
drawingPoints.Clear();
contenter.Children.Remove(drawPolygon);
drawPolygon = null;
contenter.Children.Remove(drawFinished);
drawFinished = null;
};
contenter.Children.Add(drawFinished);
}
drawFinished.Margin = new Thickness(point.X, point.Y, 0, 0);
break;
//case DrawTypes.折线:
// if (drawFinished == null)
// {
// drawFinished = new Button
// {
// Content = "完成",
// Background = Brushes.Green,
// BorderBrush = Brushes.Black,
// BorderThickness = new Thickness(1),
// FontSize = 18,
// Foreground = Brushes.Black,
// VerticalAlignment = VerticalAlignment.Top,
// HorizontalAlignment = HorizontalAlignment.Left,
// };
// Panel.SetZIndex(drawFinished, 20);
// drawFinished.Click +=
// delegate (object a, RoutedEventArgs b)
// {
// drawPoints.RemoveAt(drawPoints.Count - 1);
// writeBorad.Strokes.Add(createDraw.Lines(drawPoints.Clone(), data.LineColor));
// drawPoints.Clear();
// drawingPoints.Clear();
// contenter.Children.Remove(drawPolygon);
// drawPolygon = null;
// contenter.Children.Remove(drawFinished);
// drawFinished = null;
// };
// contenter.Children.Add(drawFinished);
// }
// drawFinished.Margin = new Thickness(point.X, point.Y, 0, 0);
// break;
}
writeBorad.IsEnabled = true;
}
}
public void MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && data.Draw == true &&
writeBorad.EditingMode == InkCanvasEditingMode.None && contenter.IsMouseOver)
writeBorad.IsEnabled = false;
else writeBorad.IsEnabled = true;
if (drawPoints.Count != 0)
{
Point point = new Point(e.GetPosition(writeBorad).X - 1, e.GetPosition(writeBorad).Y - 1);
DrawTypes drawType = (DrawTypes)data.DrawType;
if (drawType != DrawTypes. && drawPolygon == null)
{
drawPolygon = new Polygon
{
Stroke = Brushes.Black,
StrokeThickness = 2,
StrokeDashCap = PenLineCap.Square,
StrokeDashArray = new DoubleCollection { 6 }
};
}
switch (drawType)
{
case DrawTypes.:
if (drawPoints.Count == 1)
{
Point a = new Point(drawPoints[0].X, drawPoints[0].Y);
PointCollection points = new PointCollection { a, new Point(a.X, point.Y), point, new Point(point.X, a.Y) };
drawPolygon.Points = points.Clone();
if (!drawPolygon.IsLoaded)
contenter.Children.Add(drawPolygon);
}
break;
case DrawTypes.线:
if (drawPoints.Count == 1)
{
PointCollection points = new PointCollection
{
new Point(drawPoints[0].X,drawPoints[0].Y),
point
};
drawPolygon.Points = points.Clone();
if (!drawPolygon.IsLoaded)
contenter.Children.Add(drawPolygon);
}
break;
case DrawTypes.:
if (drawPoints.Count == 1)
{
double r = Math.Sqrt(Math.Pow(point.X - drawPoints[0].X, 2) +
Math.Pow(point.Y - drawPoints[0].Y, 2));
double top = drawPoints[0].Y - r,
left = drawPoints[0].X - r;
if (circular == null)
{
circular = new Rectangle
{
Stroke = Brushes.Black,
StrokeThickness = 2,
StrokeDashCap = PenLineCap.Square,
StrokeDashArray = new DoubleCollection { 6 },
};
contenter.Children.Add(circular);
}
circular.RadiusX = circular.RadiusY = r;
circular.VerticalAlignment = VerticalAlignment.Stretch;
circular.HorizontalAlignment = HorizontalAlignment.Stretch;
circular.Width = circular.Height = 2 * r;
circular.VerticalAlignment = VerticalAlignment.Top;
circular.HorizontalAlignment = HorizontalAlignment.Left;
circular.Margin =
new Thickness(left, top, 0, 0);
}
break;
case DrawTypes.:
if (drawPoints.Count == 2)
{
if (!drawPolygon.IsLoaded)
contenter.Children.Add(drawPolygon);
drawPolygon.Points = drawingPoints.Clone();
drawPolygon.Points.Add(point);
}
break;
case DrawTypes.:
if (!drawPolygon.IsLoaded)
contenter.Children.Add(drawPolygon);
drawPolygon.Points = drawingPoints.Clone();
drawPolygon.Points.Add(point);
break;
//case DrawTypes.折线:
// if (!drawPolygon.IsLoaded)
// contenter.Children.Add(drawPolygon);
// drawPolygon.Points = drawingPoints.Clone();
// drawPolygon.Points.Add(point);
// break;
}
}
}
public void MouseDown(object sender, MouseButtonEventArgs e)
{
//InkCanvasEditingMode.None;
//InkCanvasEditingMode.None
// InkCanvasEditingMode.GestureOnly
// InkCanvasEditingMode.NoneAndGesture
if (data.Draw == true && writeBorad.EditingMode == InkCanvasEditingMode.None && contenter.IsMouseOver)
{
Point point = e.GetPosition(contenter);
drawPoints.Add(new StylusPoint(point.X, point.Y));
drawingPoints.Add(point);
}
}
public void ClearSharpe()
{
writeBorad.Strokes.Clear();
contenter.Children.Clear();
contenter.Children.Add(writeBorad);
//contenter.Width = SystemParameters.PrimaryScreenWidth;
//contenter.Height = SystemParameters.PrimaryScreenHeight;
}
public void LoadDrawShape(string ip,double width,double height, bool reload = true)
{
if (reload)
{
ClearSharpe();
}
var drawShapeList = DBDataHelper.GetDrawShape(ip);
Draw createDraw = new Draw(writeBorad);
foreach (DrawShape shape in drawShapeList)
{
var drawType = (DrawTypes)shape.DrawType;
data.LineColor = shape.WarningLevel;
List<Point> points1 = new List<Point>();
foreach (var drPoint in shape.PointList)
{
// Point point = new Point(drPoint.X, drPoint.Y);
Point point = new Point(drPoint.X * width, drPoint.Y * height);
points1.Add(point);
}
StylusPointCollection stylusPointCollection = new StylusPointCollection(points1);
switch (drawType)
{
case DrawTypes.:
if (stylusPointCollection.Count >3)
{
writeBorad.Strokes.Add(createDraw.Rectangle(stylusPointCollection[0], stylusPointCollection[2], data.LineColor));
}
break;
case DrawTypes.线:
if (stylusPointCollection.Count == 2)
{
writeBorad.Strokes.Add(createDraw.Line(stylusPointCollection[0],stylusPointCollection[1], data.LineColor));
}
break;
case DrawTypes.:
if (stylusPointCollection.Count == 2)
{
writeBorad.Strokes.Add(createDraw.Circle(stylusPointCollection[0], stylusPointCollection[1], data.LineColor));
}
break;
case DrawTypes.:
if (stylusPointCollection.Count == 3)
{
writeBorad.Strokes.Add(createDraw.Triangle(stylusPointCollection[0], stylusPointCollection[1], stylusPointCollection[2]));
}
break;
case DrawTypes.:
//drawPoints.RemoveAt(drawPoints.Count - 1);
writeBorad.Strokes.Add(createDraw.Polygon(stylusPointCollection.Clone(), data.LineColor));
//drawPoints.Clear();
//drawingPoints.Clear();
//contenter.Children.Remove(drawPolygon);
//drawPolygon = null;
//contenter.Children.Remove(drawFinished);
//drawFinished = null;
break;
}
writeBorad.IsEnabled = false;
writeBorad.EditingMode = InkCanvasEditingMode.Select;
data.Draw = false;
}
}
}
}

31
ECMonitor/PlayerDraw/Code/Model/StrokeEx.cs

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Ink;
using System.Windows.Input;
namespace ECMonitor.PlayerDraw.Code
{
public class StrokeEx: Stroke
{
/// <summary>
/// 画图形状
/// </summary>
public DrawTypes DrawType { get; set; }
/// <summary>
/// 预警级别
/// </summary>
public int WarningLevel { get; set; }
/// <summary>
/// 线 时方向
/// </summary>
public int WaringDirection { get; set; }
public StrokeEx(StylusPointCollection stylusPoints) : base(stylusPoints)
{
}
}
}

148
ECMonitor/PlayerDraw/FrmWarningDraw.xaml

@ -0,0 +1,148 @@
<Window x:Class="ECMonitor.PlayerDraw.FrmWarningDraw"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="视频布防" Height="800" Width="1200" Loaded="Window_Loaded" SizeChanged="Window_SizeChanged" WindowStyle="None" WindowStartupLocation="CenterScreen" >
<!--<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</ResourceDictionary>
--><!--<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.TabControl.xaml" />--><!--
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>-->
<Grid Background="{DynamicResource PrimaryBackGroupBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<DockPanel Grid.Row="0" MouseMove="DockPanel_MouseMove" >
<DockPanel.Background>
<ImageBrush ImageSource="/topbar.png" TileMode="Tile" Stretch="Fill" />
</DockPanel.Background>
<DockPanel DockPanel.Dock="Left" SnapsToDevicePixels="True" Margin="0,0,5,0">
<ListBox Margin="0,0,10,0"
Style="{StaticResource MaterialDesignToolToggleListBox }"
SelectedIndex="{Binding LineColor}"
Padding="0,0,0,0" SelectionChanged="LevelButtons_SelectionChanged"
Name="barLevelButtons">
<ListBoxItem >
<StackPanel Orientation="Horizontal" ToolTip="最高级别预警" >
<Rectangle Width="10" Height="10" Fill="Green" Margin="5,0,5,0"/>
<TextBlock Text="预警" Foreground="Green"/>
</StackPanel>
</ListBoxItem>
<ListBoxItem >
<StackPanel Orientation="Horizontal" ToolTip="中等级别告警" >
<Rectangle Width="10" Height="10" Fill="Yellow" Margin="0,0,5,0"/>
<TextBlock Text="告警" Foreground="Yellow"/>
</StackPanel>
</ListBoxItem>
<ListBoxItem >
<StackPanel Orientation="Horizontal" ToolTip="最高级别报警" >
<Rectangle Width="10" Height="10" Fill="Red" Margin="0,0,5,0"/>
<TextBlock Text="报警" Foreground="Red"/>
</StackPanel>
</ListBoxItem>
</ListBox>
<ListBox Margin="5,0,5,0"
Style="{StaticResource MaterialDesignToolToggleListBox}"
SelectedIndex="{Binding DrawType}"
Padding="0,0,0,0" SelectionChanged="ShareButtons_SelectionChanged"
Name="barShareButtons">
<ListBoxItem Padding="8,0,8,0" ToolTip="线段">
<Line Width="20" Height="1" Stroke="White" X1="0" X2="20" Y1="0" Y2="0" StrokeThickness="1"/>
</ListBoxItem>
<ListBoxItem Padding="8,0,10,0" ToolTip="多边形">
<Polygon Points="0,12 8,0 13,0 22,12 20,15 15,20" StrokeThickness="2" Stroke="White"/>
</ListBoxItem>
<ListBoxItem Padding="8,0,10,0" ToolTip="矩形">
<Rectangle Width="25" Height="18" Stroke="White" StrokeThickness="2" Fill="Transparent"/>
</ListBoxItem>
<ListBoxItem Padding="8,0,0,0" ToolTip="圆形" Visibility="Hidden">
<Ellipse Width="2" Height="2" Stroke="White" StrokeThickness="2" Fill="Transparent"/>
</ListBoxItem>
<ListBoxItem Padding="8,0,10,0" ToolTip="选取">
<Image Source="/PlayerDraw/选取.png" Width="28"></Image>
</ListBoxItem>
</ListBox>
<StackPanel Orientation="Horizontal" Margin="15,0,10,0" >
<Button Name="btnDelete" ToolTip="删除" Style="{DynamicResource TopButtonStyle}" Margin="0,0,10,0" Click="btnDelete_Click" >
<WrapPanel>
<Image Stretch="Uniform" Source="/PlayerDraw/删除 关闭 叉.png" />
</WrapPanel>
</Button>
<Button Name="btnSave" ToolTip="保存" Style="{DynamicResource TopButtonStyle}" Margin="10,0,10,0" Click="btnSave_Click" >
<WrapPanel>
<Image Source="/PlayerDraw/保存.png" />
</WrapPanel>
</Button>
</StackPanel>
</DockPanel>
<DockPanel DockPanel.Dock="Top" Height="18">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Name="btnMin" Style="{DynamicResource TopRightButtonStyle}" Margin="0,0,10,0" Click="btnMin_Click">
<WrapPanel>
<Image Source="/min1.png" />
</WrapPanel>
</Button>
<!--<Button Name="btnMax" Style="{DynamicResource TopRightButtonStyle}" Margin="0,0,10,0" Click="btnMax_Click">
<WrapPanel>
<Image Source="/max2.png" Width="10" />
</WrapPanel>
</Button>-->
<Button Name="btnClose" Style="{DynamicResource TopRightButtonStyle}" Margin="0,0,10,0" Click="btnClose_Click">
<WrapPanel>
<Image Source="/close.png" />
</WrapPanel>
</Button>
</StackPanel>
</DockPanel>
</DockPanel>
<StackPanel x:Name="planMain" HorizontalAlignment="Stretch" Grid.Row="1" VerticalAlignment="Stretch" ></StackPanel>
<Grid x:Name="contenter" Grid.Row="1">
<!--写字板-->
<InkCanvas x:Name="writeBorad" Background="Transparent" PreviewMouseDown="writeBorad_PreviewMouseDown">
<!--<InkCanvas.ContextMenu>
<ContextMenu Opened="MenuOpened">
<MenuItem x:Name="copy" Header="删除" Click="Execute" >
<MenuItem.Icon>
<Image Stretch="Uniform" Source="/PlayerDraw/close.png" Width="20" Height="20"/>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</InkCanvas.ContextMenu>-->
</InkCanvas>
</Grid>
</Grid>
</Window>

402
ECMonitor/PlayerDraw/FrmWarningDraw.xaml.cs

@ -0,0 +1,402 @@
using EC.Entity.Video;
using EC.Entity.Warning;
using ECMonitor.Code;
using ECMonitor.Code.DB;
using ECMonitor.Manager;
using ECMonitor.PlayerDraw.Code;
using ECMonitor.UC.Videos;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace ECMonitor.PlayerDraw
{
/// <summary>
/// FrmWarningDraw.xaml 的交互逻辑
/// </summary>
public partial class FrmWarningDraw : Window
{
IEventAggregator _ea;
IUCPlayer _ucFFmpegPlayer;
ECDrawing draw;
private BlackboardData blackboardData;
VideoPlayManager _videoPlayManager { get; set; } = new VideoPlayManager();
public FrmWarningDraw(IEventAggregator ea)
{
InitializeComponent();
_ea = ea;
if (blackboardData == null)
{
blackboardData = new BlackboardData();// BlackboardData.Open();
}
this.DataContext = blackboardData;
SetFormSize();
contenter.Width = this.Width;
contenter.Height = this.Height - 40;
draw = new ECDrawing(blackboardData, contenter, writeBorad);
writeBorad.PreviewMouseLeftButtonDown += draw.MouseDown;
contenter.MouseMove += draw.MouseMove;
contenter.PreviewMouseLeftButtonUp += draw.MouseLeftButtonUp;
_ucFFmpegPlayer = _videoPlayManager.CreateWarnCreateLinePlayer(_ea, contenter.Width, contenter.Height, 0);
this.planMain.Children.Add(_ucFFmpegPlayer.GetControl());
}
#region 系统按钮
private void btnClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
// Exit_Click(sender, e);
}
private void SetFormSize()
{
double x1 = SystemParameters.PrimaryScreenWidth;//得到屏幕整体宽度
double y1 = SystemParameters.PrimaryScreenHeight;//得到屏幕整体高度
double xy = x1 + y1;
x1 = x1 * 0.9;
y1 = y1 * 0.9;
this.Width = x1;
this.Height = y1;
}
private void btnMax_Click(object sender, RoutedEventArgs e)
{
if (this.WindowState == WindowState.Maximized)
{
this.WindowState = WindowState.Normal;
}
else
{
this.WindowState = WindowState.Maximized;
}
}
private void btnMin_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void DockPanel_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
this.DragMove();
}
}
#endregion 系统按钮
private void Window_Loaded(object sender, RoutedEventArgs e)
{
}
public void Play(string cameraIp)
{
MonitorCamera camera = CameraManager.GetCamera(cameraIp);
Play( camera);
}
public void Play(MonitorCamera camera )
{
if (camera == null)
{
_ucFFmpegPlayer.ShowMsg("相机不存在IP=" + camera.Ip);
}
else
{
_ucFFmpegPlayer.Play(camera);
double width = this._ucFFmpegPlayer.GetControl().Width;
double height = this._ucFFmpegPlayer.GetControl().Height;
draw.LoadDrawShape(camera.Ip, width, height);
}
// ShowAndActive();
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
// SizeChange();
}
/// <summary>
/// 预警级别
/// </summary>
private int _levelSelectIndex = 2;
/// <summary>
/// 形状
/// </summary>
private int _shareSelectIndex = 0;
private void LevelButtons_SelectionChanged(object sender, RoutedEventArgs e)
{
int levelSelectIndex = this.barLevelButtons.SelectedIndex;
if (levelSelectIndex == -1)
{
this.barLevelButtons.SelectedIndex = _levelSelectIndex;
return;
}
_levelSelectIndex = levelSelectIndex;
writeBorad.DefaultDrawingAttributes.Color = BlackboardClass.ChangeColor((ColorEnum)levelSelectIndex);
//if (levelSelectIndex == -1)
//{
// this.barLevelButtons.SelectedIndex = _levelSelectIndex;
// return;
//}
//_levelSelectIndex = this.barLevelButtons.SelectedIndex;
//if (IsLoaded == false)
//{
// return;
//}
//switch (_levelSelectIndex)
//{
// case 0:
// writeBorad.DefaultDrawingAttributes.Color = Colors.Green;
// break;
// case 1:
// writeBorad.DefaultDrawingAttributes.Color = Colors.Yellow;
// break;
// case 2:
// writeBorad.DefaultDrawingAttributes.Color = Colors.Red;
// break;
//}
}
private void MenuOpened(object sender, RoutedEventArgs e)
{
//if (writeBorad.GetSelectedStrokes().Count <= 0)
//{
// copy.IsEnabled = cut.IsEnabled = false;
//}
//else
// copy.IsEnabled = cut.IsEnabled = true;
//if (!writeBorad.CanPaste())
// paste.IsEnabled = false;
//else
// paste.IsEnabled = true;
}
private void ShareButtons_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int shareSelectIndex = this.barShareButtons.SelectedIndex;
if (shareSelectIndex == -1)
{
this.barShareButtons.SelectedIndex = _shareSelectIndex;
return;
}
_shareSelectIndex = this.barShareButtons.SelectedIndex;
if (_shareSelectIndex < 4)
{
blackboardData.Draw = true;
this.writeBorad.EditingMode = InkCanvasEditingMode.None;
}else
{
this.writeBorad.EditingMode = InkCanvasEditingMode.Select;
blackboardData.Draw = false;
}
}
private void btnSelect_Click(object sender, RoutedEventArgs e)
{
this.writeBorad.EditingMode = InkCanvasEditingMode.Select;
blackboardData.Draw = false;
}
//private void ChangeEditingMode()
//{
// if (_shareSelectIndex == 5)
// {
// this.writeBorad.EditingMode = InkCanvasEditingMode.Select;
// blackboardData.Draw = false;
// }
// else
// {
// this.writeBorad.EditingMode = InkCanvasEditingMode.None;
// this.contenter.Cursor = Cursors.Pen;
// blackboardData.Draw = true;
// switch (_shareSelectIndex)
// {
// case 0:
// blackboardData.DrawType = (int)DrawTypes.线段;
// break;
// case 1:
// blackboardData.DrawType = (int)DrawTypes.折线;
// break;
// case 2:
// blackboardData.DrawType = (int)DrawTypes.多边形;
// break;
// case 3:
// blackboardData.DrawType = (int)DrawTypes.矩形;
// break;
// case 4:
// blackboardData.DrawType = (int)DrawTypes.圆;
// break;
// }
// }
//}
#region 画图 事件
//private static DependencyProperty IsDrawingProperty = DependencyProperty.Register(
// "IsDrawing", typeof(bool), typeof(FrmWarningDraw), new PropertyMetadata(false));
//private bool IsDrawing
//{
// get { return (bool)GetValue(IsDrawingProperty); }
// set { SetValue(IsDrawingProperty, value); }
//}
private void writeBorad_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
//if (e != null && e.ClickCount == 2)
// writeBorad.ContextMenu.IsOpen = true;
//else
//{
// //if (!undoStack.Contains(writeBorad.Strokes))
// //{
// // undoStack.Push(writeBorad.Strokes.Clone());
// // if (undo.Visibility == Visibility.Collapsed)
// // undo.Visibility = Visibility.Visible;
// //}
//}
}
//private void Execute(object sender, RoutedEventArgs e)
//{
// var menuItem = sender as MenuItem;
// switch (menuItem.Header.ToString())
// {
// case "打开":
// // OpenFile();
// break;
// case "复制":
// writeBorad.CopySelection();
// break;
// case "粘贴":
// writeBorad_PreviewMouseDown(null, null);
// writeBorad.Paste(Mouse.GetPosition(writeBorad));
// break;
// case "剪切":
// writeBorad.CutSelection();
// writeBorad_PreviewMouseDown(sender, null);
// break;
// case "删除":
// writeBorad_PreviewMouseDown(sender, null);
// foreach (Stroke item in writeBorad.GetSelectedStrokes())
// writeBorad.Strokes.Remove(item);
// break;
// }
//}
private void btnDelete_Click(object sender, RoutedEventArgs e)
{
writeBorad_PreviewMouseDown(sender, e as MouseButtonEventArgs);
//if (choose.IsChecked == false)
//{
// if (VerifyWindow.ShowDialog("确认清空黑板", "是否清空黑板?", this) == true)
// {
// writeBorad.Strokes.Clear();
// contenter.Children.Clear();
// contenter.Children.Add(writeBorad);
// contenter.Width = SystemParameters.PrimaryScreenWidth;
// contenter.Height = SystemParameters.PrimaryScreenHeight;
// IsWrote = false;
// }
//}
//else
//{
foreach (Stroke item in writeBorad.GetSelectedStrokes())
writeBorad.Strokes.Remove(item);
//}
}
#endregion
private void btnSave_Click(object sender, RoutedEventArgs e)
{
StrokeCollection strokes = writeBorad.Strokes;
int icount = strokes.Count;
List<DrawShape> drawShapeModelList = new List<DrawShape>();
for (int i= 0; i < icount;i++)
{
StrokeEx storke = strokes[i] as StrokeEx;
var camera = _ucFFmpegPlayer.GetCamera();
if (camera == null) {
MessageManager.ShowMessage("相机不存在");
return;
}
var ip=camera.Ip;
drawShapeModelList.Add( CreateDrawShape(ip,storke));
}
bool save= DBDataHelper.SaveDrawShape(drawShapeModelList);
if (save)
{
MessageManager.ShowMessage("保存成功");
}
else
{
MessageManager.ShowMessage("保存失败");
}
}
private DrawShape CreateDrawShape(string ip, StrokeEx storke)
{
DrawShape drawShape = new DrawShape();
drawShape.Ip = ip;
drawShape.DrawType = (int)storke.DrawType;
drawShape.WarningLevel = (int)storke.WarningLevel;
double width = _ucFFmpegPlayer.GetControl().Width;
double height = _ucFFmpegPlayer.GetControl().Height;
foreach (var point in storke.StylusPoints)
{
DrawPoint DrawPoint = new DrawPoint(point.X/ width, point.Y/ height);
drawShape.PointList.Add(DrawPoint);
}
return drawShape;
}
}
}

12
ECMonitor/PlayerDraw/UC/UCVideoDraw.xaml

@ -0,0 +1,12 @@
<UserControl x:Class="ECMonitor.PlayerDraw.UC.UCVideoDraw"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ECMonitor.PlayerDraw.UC"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
</Grid>
</UserControl>

28
ECMonitor/PlayerDraw/UC/UCVideoDraw.xaml.cs

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ECMonitor.PlayerDraw.UC
{
/// <summary>
/// UCVideoDraw.xaml 的交互逻辑
/// </summary>
public partial class UCVideoDraw : UserControl
{
public UCVideoDraw()
{
InitializeComponent();
}
}
}

BIN
ECMonitor/PlayerDraw/close.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
ECMonitor/PlayerDraw/保存.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 561 B

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save