FileSqlServerSync/Server/Common/FileDirBase.cs
zhaoyouya 46315ba760 chore: 添加sqlite 数据库,remote server 增加一些接口
添加了一些数据模型,添加了一些简单的单元测试
2024-10-12 21:57:45 +08:00

80 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace Common;
public enum DirOrFile
{
Dir = 0,
File = 1,
}
public enum NextOpType
{
Add = 0,
Modify = 1,
Del = 2
}
public abstract class AFileOrDir(
string path,
DirOrFile type = DirOrFile.File,
NextOpType? nextOp = null
)
{
public DirOrFile Type { get; set; } = type;
public NextOpType? NextOp { get; set; } = nextOp;
// private string Path = path;
/// <summary>
/// 全部为绝对路径... 占用资源会大一点但是完全OK
/// </summary>
///
private string Path = path;
/// <summary>
/// 相当于Path 包装天杀的windows在路径字符串中使用两种分隔符“/” 和“\”,这导致,即使两个字符串不相同,也可能是同一个路径。现在把它们统一起来
/// </summary>
public string FormatedPath
{
get { return Path.Replace("\\", "/"); }
set { Path = value; }
}
public abstract bool IsEqual(AFileOrDir other);
public static int Compare(AFileOrDir l, AFileOrDir r)
{
var pv = l.FormatedPath.CompareTo(r.FormatedPath);
if (pv == 0)
{
pv = l.Type.CompareTo(r.Type);
}
return pv;
}
}
/// <summary>
/// 文件
/// </summary>
/// <param name="path">绝对路径</param>
/// <param name="mtime">文件的修改时间</param>/
public class File(string path, DateTime mtime, NextOpType? nextOp = null)
: AFileOrDir(path, DirOrFile.File, nextOp)
{
public DateTime MTime { get; set; } = mtime;
public override bool IsEqual(AFileOrDir other)
{
if (other is not File otherFile)
{
return false;
}
else
{
var r =
this.MTime == otherFile.MTime
&& this.FormatedPath == otherFile.FormatedPath
&& this.NextOp == otherFile.NextOp;
return r;
}
}
}