XlCache.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using DxHelper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data.Entity;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using XdCxRhDW.Repostory.EFContext;
  10. using XdCxRhDW.Repostory.Model;
  11. namespace XdCxRhDW.App
  12. {
  13. public static class XlCache
  14. {
  15. public static List<XlInfo> GetAll()
  16. {
  17. try
  18. {
  19. DateTime now = DateTime.Now;
  20. List<XlInfo> xlInfos = new List<XlInfo>();
  21. for (int i = 0; i < 30; i++)
  22. {
  23. using (RHDWPartContext db = RHDWPartContext.GetContext(now.AddDays(-i)))
  24. {
  25. var items = db.XlInfos.OrderBy(p => p.SatName).OrderByDescending(p => p.TimeBJ).ToList();
  26. xlInfos.AddRange(items);
  27. }
  28. }
  29. return xlInfos;
  30. }
  31. catch (Exception ex)
  32. {
  33. Serilog.Log.Error(ex, "加载星历信息异常");
  34. return null;
  35. }
  36. }
  37. public static async Task<List<XlInfo>> GetAllAsync()
  38. {
  39. try
  40. {
  41. List<XlInfo> list = new List<XlInfo>();
  42. if (!Directory.Exists("DbPart")) return list;
  43. var yearDirs = Directory.EnumerateDirectories("DbPart").OrderByDescending(p => Convert.ToInt32(new DirectoryInfo(p).Name));//年目录,倒叙排列
  44. foreach (var yearDir in yearDirs)
  45. {
  46. //每一天的db文件,倒序排列
  47. var dayFiles = Directory.EnumerateFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, yearDir),"*.db").OrderByDescending(p => Convert.ToInt32(new DirectoryInfo(p).Name.Substring(0, 4)));
  48. foreach (var dayFile in dayFiles)
  49. {
  50. using (RHDWPartContext db = RHDWPartContext.GetContext(dayFile))
  51. {
  52. list.AddRange(await db.XlInfos.ToListAsync());
  53. if (list.Count > 2000)
  54. return list;
  55. }
  56. }
  57. }
  58. return list;
  59. }
  60. catch (Exception ex)
  61. {
  62. Serilog.Log.Error(ex, "加载星历信息异常");
  63. return null;
  64. }
  65. }
  66. }
  67. }