TDMSFileInfo.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.IO;
  3. using TDMS.Common;
  4. namespace TDMS
  5. {
  6. /// <summary>
  7. /// TDMS文件的相关信息
  8. /// </summary>
  9. public class TDMSFileInfo
  10. {
  11. /// <summary>
  12. /// TDMS文件的相关信息。本库统一使用TDMS文件格式。
  13. /// </summary>
  14. public TDMSFileInfo(string filePath)
  15. {
  16. if(string.IsNullOrEmpty(filePath))
  17. throw new TDMSErrorException("file path cannot null or empty.", new ArgumentNullException(nameof(filePath)));
  18. // 检查filePath是否是正确的文件与路径格式
  19. if(!Util.IsValidPath(filePath))
  20. throw new TDMSErrorException("file path is not in a correct format.", new ArgumentException(nameof(filePath)));
  21. FilePath = filePath;
  22. var ext = Path.GetExtension(filePath);
  23. if(string.IsNullOrEmpty(ext)
  24. || ext.TrimStart('.').ToUpper() != Constants.DDC_FILE_TYPE_TDM_STREAMING)
  25. { //如果没有后缀名或者后缀名不是TDMS格式,则自动添加“tdms”后缀名
  26. FilePath = $"{filePath}.{Constants.DDC_FILE_TYPE_TDM_STREAMING.ToLower()}";
  27. }
  28. }
  29. /// <summary>
  30. /// TDMS文件的路径
  31. /// </summary>
  32. public string FilePath { get; }
  33. /// <summary>
  34. /// 文件对象的类型。仅为DDC_FILE_TYPE_TDM_STREAMING格式。
  35. /// </summary>
  36. public string FileType => Constants.DDC_FILE_TYPE_TDM_STREAMING.ToLower(); //本库统一使用TDMS文件格式
  37. /// <summary>
  38. /// 文件对象的name属性值。该属性存储在文件中,可以通过DDC_SetFileProperty和DDC_GetFileProperty函数访问
  39. /// </summary>
  40. public string Name { get; set; } = string.Empty;
  41. /// <summary>
  42. /// 文件对象的description属性的值。该属性存储在文件中,可以通过DDC_SetFileProperty和DDC_GetFileProperty函数访问。
  43. /// </summary>
  44. public string Description { get; set; } = string.Empty;
  45. /// <summary>
  46. /// 文件对象的title属性值。该属性存储在文件中,可以通过DDC_SetFileProperty和DDC_GetFileProperty函数访问。
  47. /// </summary>
  48. public string Title { get; set; } = string.Empty;
  49. /// <summary>
  50. /// 文件对象的author属性值。该属性存储在文件中,可以通过DDC_SetFileProperty和DDC_GetFileProperty函数访问。
  51. /// </summary>
  52. public string Author { get; set; } = string.Empty;
  53. /// <summary>
  54. /// 文件对象的datetime属性值(通常是文件的创建时间)。该属性存储在文件中,可以通过DDC_SetFileProperty和DDC_GetFileProperty函数访问。
  55. /// </summary>
  56. public DateTime DateTime { get; set; } = DateTime.Now;
  57. /// <summary>
  58. /// 信息中表达的文件是否存在
  59. /// </summary>
  60. public bool Exists => File.Exists(FilePath);
  61. }
  62. }