Ai
120 Star 767 Fork 310

chatop2020/AKStream

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
LiteDBHelper.cs 2.61 KB
一键复制 编辑 原始数据 按行查看 历史
chatop 提交于 2023-02-17 01:49 +08:00 . check dbtype get right quote to order by sub sql
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using LibCommon.Enums;
using LibCommon.Structs;
using LiteDB;
namespace LibCommon
{
public class LiteDBHelper
{
/// <summary>
/// 核心的LiteDatabase数据库操作对象,这个对象私有只在类内使用。
/// </summary>
private LiteDatabase _liteDb;
public object LiteDBLockObj = new object();
/// <summary>
/// 创建一个LiteDB对象,有一个参数表明对应的文件路径。
/// </summary>
/// <param name="dbpath">对应数据库文件的路径,默认位置为程序目录下"VideoOnlineInfo.ldb"</param>
public LiteDBHelper(string dbpath = "AKStream.ldb")
{
/*启动时删除所有.ldb文件*/
DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory);
if (di != null)
{
var deleteList = new List<string>();
var fileList = di.GetFiles();
if (fileList != null && fileList.Length > 0)
{
foreach (var filei in fileList)
{
if (filei.FullName.ToLower().EndsWith(".ldb"))
{
deleteList.Add(filei.FullName);
}
}
if (deleteList.Count > 0)
{
foreach (var delf in deleteList)
{
if (File.Exists(delf))
{
File.Delete(delf);
}
}
}
}
}
/*启动时删除所有.ldb文件*/
_liteDb = new LiteDatabase(dbpath);
VideoOnlineInfo =
(LiteCollection<VideoChannelMediaInfo>)_liteDb.GetCollection<VideoChannelMediaInfo>("VideoOnlineInfo");
BsonMapper.Global.RegisterType<IPAddress>
(
serialize: (ip) => ip.ToString(),
deserialize: (bson) => IPAddress.Parse(bson.AsString)
);
BsonMapper.Global.RegisterType<StreamSourceType>
(
serialize: (type) => type.ToString(),
deserialize: (bson) => (StreamSourceType)Enum.Parse(typeof(StreamSourceType), bson)
);
}
/// <summary>
/// 所有的VideoChannelMediaInfo列表。
/// </summary>
public LiteCollection<VideoChannelMediaInfo> VideoOnlineInfo { get; set; }
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/chatop2020/AKStream.git
git@gitee.com:chatop2020/AKStream.git
chatop2020
AKStream
AKStream
master

搜索帮助