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
{
///
/// 获取数据库所有双行根数
///
/// 最大条数.超过此条数时不再继续查询,为0则不限制条数
///
public static async Task> GetAllAsync()
{
try
{
using (RHDWContext db = new RHDWContext())
{
var res = await db.XlInfos.OrderByDescending(p => p.TimeBJ).OrderByDescending(p => p.Lon).ToListAsync();
return res;
}
}
catch (Exception ex)
{
Serilog.Log.Error(ex, "加载星历信息异常");
return null;
}
}
///
/// 获取某个星某个时刻最近的双行根(可能返回null)
///
/// 卫星编号
/// 时刻
///
public static async Task GetLatestAsync(int satCode, DateTime timeBj)
{
try
{
using (RHDWContext db = new RHDWContext())
{
var res= await db.XlInfos.Where(p => p.SatCode == satCode).OrderBy(p => (p.TimeBJ - timeBj).Duration()).FirstOrDefaultAsync();
return res;
}
}
catch (Exception ex)
{
Serilog.Log.Error(ex, $"获取卫星[{satCode}]--{timeBj:yyyyMMddHHmmss}时刻附近的双行根数出错!");
return null;
}
}
}
}