public static int ImportAlarmStats(this HttpPostedFileBase httpPostedFile, IAlarmRepository repository) { IEnumerable<AlarmStat> statList = httpPostedFile.ImportCsvInfo( x => { StreamReader reader = new StreamReader(x, Encoding.GetEncoding("GB2312")); List<AlarmStatCsv> infoList = CsvContext.Read<AlarmStatCsv>(reader, CsvFileDescription.CommaDescription).ToList(); return infoList.Select(info => new AlarmStat(info)); }); int result = 0; foreach (AlarmStat stat in statList) { AlarmStat item = repository.GetAll().FirstOrDefault(x => x.ENodebId == stat.ENodebId && x.SectorId == stat.SectorId && x.AlarmId == stat.AlarmId); if (item == null || item.HappenTime > stat.HappenTime.AddDays(1) || item.HappenTime < stat.HappenTime.AddDays(-1)) { repository.Insert(stat); result++; } } return result; }
public bool DumpOneStat() { var stat = AlarmStats.Pop(); if (stat == null) { throw new NullReferenceException("alarm stat is null!"); } var item = _repository.FirstOrDefault( x => x.HappenTime == stat.HappenTime && x.ENodebId == stat.ENodebId && x.SectorId == stat.SectorId && x.AlarmId == stat.AlarmId); if (item == null) { _repository.Insert(stat); } else { item.RecoverTime = stat.RecoverTime; } _repository.SaveChanges(); return(true); }
public static int ImportAlarmHuawei(this HttpPostedFileBase httpPostedFile, IAlarmRepository repository) { IEnumerable<AlarmStat> statList = httpPostedFile.ImportCsvInfo( x => { StreamReader reader = new StreamReader(x, Encoding.GetEncoding("GB2312")); List<AlarmStatHuawei> infoList = CsvContext.Read<AlarmStatHuawei>(reader, CsvFileDescription.CommaDescription).ToList(); return infoList.Select(info => new AlarmStat(info)); }); int result = 0; foreach (AlarmStat stat in statList) { repository.Insert(stat); result++; } return result; }