using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using Shared.SimpleControl;
|
using System.Collections.Generic;
|
|
namespace Shared
|
{
|
[System.Serializable]
|
public class MonitorInfo
|
{
|
static MonitorInfo ()
|
{
|
// 如果是第一次安装使用,就调用这个方法,初始化一些基本的数据
|
if (null == Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.List<string>> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (AllMonitorListFilesPath)))) {
|
//初始化摄像头列表
|
IO.FileUtils.WriteFileByBytes (AllMonitorListFilesPath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (new System.Collections.Generic.List<string> ())));
|
}
|
}
|
|
/// <summary>
|
/// 摄像头类型为URL
|
/// </summary>
|
public string URL {
|
get;
|
set;
|
}
|
|
/// <summary>
|
/// 摄像头类型选择
|
/// </summary>
|
public string Type {
|
get;
|
set;
|
}
|
|
/// <summary>
|
/// 用户名称
|
/// </summary>
|
public string UserName {
|
get;
|
set;
|
}
|
/// <summary>
|
/// 用户密码
|
/// </summary
|
public string Password {
|
get;
|
set;
|
}
|
|
/// <summary>
|
/// 摄像机名
|
/// </summary>
|
public string Name {
|
get; set;
|
}
|
|
/// <summary>
|
/// 摄像头列表的文件名
|
/// </summary>
|
public static string AllMonitorListFilesPath = "MonitorList";
|
|
/// <summary>
|
/// 所有的摄像头的信息
|
/// </summary>
|
public static System.Collections.Generic.List<MonitorInfo> Lists = new System.Collections.Generic.List<MonitorInfo> ();
|
|
/// <summary>
|
/// 所有的摄像头列表路径
|
/// </summary>
|
public static System.Collections.Generic.List<string> FilePathList {
|
get {
|
var filePathList = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.List<string>> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (AllMonitorListFilesPath)));
|
if (filePathList == null)
|
filePathList = new List<string> ();
|
return filePathList;
|
}
|
}
|
|
/// <summary>
|
/// 根据摄像头路径恢复摄像头对象
|
/// </summary>
|
public static MonitorInfo GetMonitorByFilePath (string monitorFilePath)
|
{
|
var monitor = Newtonsoft.Json.JsonConvert.DeserializeObject<MonitorInfo> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (monitorFilePath)));
|
|
if (null == monitor) {
|
System.Console.WriteLine ("摄像头文件路径不对,文件路径为:" + monitorFilePath);
|
return null;
|
}
|
return monitor;
|
}
|
|
|
/// <summary>
|
/// 添加摄像头
|
/// </summary>
|
public void Add (string monitorFilePath)
|
{
|
if (string.IsNullOrEmpty (monitorFilePath) || IO.FileUtils.Exists (monitorFilePath)) {
|
return;
|
}
|
var monitorFilePathList = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.List<string>> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (AllMonitorListFilesPath)));
|
monitorFilePathList.Add (monitorFilePath);
|
//保存摄像头列表
|
IO.FileUtils.WriteFileByBytes (AllMonitorListFilesPath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (monitorFilePathList)));
|
Save (monitorFilePath);
|
}
|
|
public void Save (string monitorFilePath)
|
{
|
if (string.IsNullOrEmpty (monitorFilePath)) {
|
return;
|
}
|
|
//保存摄像头信息
|
IO.FileUtils.WriteFileByBytes (monitorFilePath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (this)));
|
}
|
|
/// <summary>
|
/// 删除摄像头
|
/// </summary>
|
public static void Remove (string monitorFilePath)
|
{
|
var monitor = MonitorInfo.GetMonitorByFilePath (monitorFilePath);
|
if (null == monitor) {
|
return;
|
}
|
var monitorFilePathList = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.List<string>> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (AllMonitorListFilesPath)));
|
monitorFilePathList.Remove (monitorFilePath);
|
IO.FileUtils.WriteFileByBytes (AllMonitorListFilesPath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (monitorFilePathList)));
|
IO.FileUtils.DeleteFile (monitorFilePath);
|
|
}
|
|
/// <summary>
|
/// 摄像头重新编辑
|
/// </summary>
|
public void ReEdit (string oldMonitorFilePath, string newMonitorFilePath)
|
{
|
if (string.IsNullOrEmpty (newMonitorFilePath)) {
|
return;
|
}
|
//信息已经更改
|
if (oldMonitorFilePath != newMonitorFilePath && 2 <= oldMonitorFilePath.Split ('_').Length) {
|
|
var monitorFilePathList = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.List<string>> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (AllMonitorListFilesPath)));
|
for (int i = 0; i < monitorFilePathList.Count; i++) {
|
var monitorFilePath = monitorFilePathList [i];
|
if (monitorFilePath == oldMonitorFilePath) {
|
monitorFilePathList [i] = newMonitorFilePath;
|
break;
|
}
|
}
|
IO.FileUtils.WriteFileByBytes (AllMonitorListFilesPath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (monitorFilePathList)));
|
var oldRoomName = oldMonitorFilePath.Split ('_') [1];
|
IO.FileUtils.DeleteFile (oldMonitorFilePath);
|
}
|
|
Save (newMonitorFilePath);
|
}
|
|
|
}
|
}
|