Camera Information System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

68 lines
1.7 KiB

using Cis.Application.Cb;
using EC.Helper.Onvif;
using System.Collections.Concurrent;
namespace Cis.Application.Core.Component.Onvif;
public class OnvifServer : IOnvifServer, ISingleton
{
#region Attr
/// <summary>
/// {cameraId, OnvifClient}
/// </summary>
private ConcurrentDictionary<long, OnvifClient> OnvifClientDict { get; set; } = new();
#endregion Attr
public OnvifServer()
{
}
#region Base Method
public bool Register(CbCamera camera)
{
bool ret = OnvifClientDict.ContainsKey(camera.Id);
if (ret) return false;
OnvifClient client = new(camera.Ip, camera.UserName, camera.Password);
ret = client.Init().Result;
if (!ret) return false;
ret = OnvifClientDict.TryAdd(camera.Id, client);
return ret;
}
public async Task<bool> RegisterAsync(CbCamera camera)
{
bool ret = OnvifClientDict.ContainsKey(camera.Id);
if (ret) return false;
OnvifClient client = new(camera.Ip, camera.UserName, camera.Password);
ret = await client.Init();
if (!ret) return false;
ret = OnvifClientDict.TryAdd(camera.Id, client);
return ret;
}
public bool Delete(long cameraId)
{
return OnvifClientDict.TryRemove(cameraId, out _);
}
public bool IsExists(long cameraId)
{
return OnvifClientDict.ContainsKey(cameraId);
}
public OnvifClient Get(long cameraId)
{
OnvifClientDict.TryGetValue(cameraId, out OnvifClient client);
return client;
}
public bool TryGet(long cameraId, out OnvifClient client)
{
return OnvifClientDict.TryGetValue(cameraId, out client);
}
#endregion Base Method
}