1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using System;
- using System.Collections.Generic;
- using System.Data.Entity;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using XdCxRhDW.Repostory.EFContext;
- using XdCxRhDW.Repostory.Model;
- namespace XdCxRhDW.Repostory
- {
- public static class XlCache
- {
- public static List<XlInfo> GetAll()
- {
- try
- {
- DateTime now = DateTime.Now;
- List<XlInfo> xlInfos = new List<XlInfo>();
- for (int i = 0; i < 30; i++)
- {
- using (RHDWPartContext db = RHDWPartContext.GetContext(now.AddDays(-i)))
- {
- var items = db.XlInfos.OrderBy(p => p.SatName).OrderByDescending(p => p.TimeBJ).ToList();
- xlInfos.AddRange(items);
- }
- }
- return xlInfos;
- }
- catch (Exception ex)
- {
- Serilog.Log.Error(ex, "加载星历信息异常");
- return null;
- }
- }
- public static async Task<List<XlInfo>> GetAllAsync()
- {
- try
- {
- List<XlInfo> list = new List<XlInfo>();
- if (!Directory.Exists("DbPart")) return list;
- var yearDirs = Directory.EnumerateDirectories(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DbPart")).OrderByDescending(p => Convert.ToInt32(new DirectoryInfo(p).Name));//年目录,倒叙排列
- foreach (var yearDir in yearDirs)
- {
- //每一天的db文件,倒序排列
- var dayFiles = Directory.EnumerateFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, yearDir),"*.db").OrderByDescending(p => Convert.ToInt32(new DirectoryInfo(p).Name.Substring(0, 4)));
- foreach (var dayFile in dayFiles)
- {
- using (RHDWPartContext db = RHDWPartContext.GetContext(dayFile))
- {
- list.AddRange(await db.XlInfos.ToListAsync());
- if (list.Count > 2000)
- return list;
- }
- }
- }
- return list;
- }
- catch (Exception ex)
- {
- Serilog.Log.Error(ex, "加载星历信息异常");
- return null;
- }
- }
- }
- }
|