public static async void fillDBPoints() { List <PuskStopReader.PuskStopReaderRecord> request = new List <PuskStopReader.PuskStopReaderRecord>(); foreach (string gg in new string[] { "01", "04", "05", "07", "03" }) { int ggInt = Int32.Parse(gg); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "GG_RUN", iess = gg + "VT_GC02D-45.MCR@GRARM", inverted = true, gg = ggInt }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "GG_STOP", iess = gg + "VT_GC02D-45.MCR@GRARM", inverted = false, gg = ggInt }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "GG_UST", iess = gg + "VT_GC03D-01.MCR@GRARM", inverted = false, gg = ggInt }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "MNU_1", iess = gg + "VT_PS01DI-01.MCR@GRARM", inverted = false, gg = ggInt, ValueIess = gg + "VT_PS00A-01.MCR@GRARM" }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "MNU_2", iess = gg + "VT_PS02DI-01.MCR@GRARM", inverted = false, gg = ggInt, ValueIess = gg + "VT_PS00A-01.MCR@GRARM" }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "MNU_3", iess = gg + "VT_PS03DI-01.MCR@GRARM", inverted = false, gg = ggInt, ValueIess = gg + "VT_PS00A-01.MCR@GRARM" }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "LN_1", iess = gg + "VT_PS04DI-01.MCR@GRARM", inverted = false, gg = ggInt, ValueIess = gg + "VT_PS00AI-07.MCR@GRARM" }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "LN_2", iess = gg + "VT_PS05DI-01.MCR@GRARM", inverted = false, gg = ggInt, ValueIess = gg + "VT_PS00AI-07.MCR@GRARM" }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "DN_1", iess = gg + "VT_DS01DI-01.MCR@GRARM", inverted = false, gg = ggInt, ValueIess = gg + "VT_DS00AI-01.MCR@GRARM" }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "DN_2", iess = gg + "VT_DS02DI-01.MCR@GRARM", inverted = false, gg = ggInt, ValueIess = gg + "VT_DS00AI-01.MCR@GRARM" }); } foreach (string gg in new string[] { "02", "06", "08", "09", "10" }) { int ggInt = Int32.Parse(gg); string suffix = ""; suffix = ggInt <= 2 ? ".UNIT01@BLOCK1" : ggInt <= 6 ? ".UNIT05@BLOCK3" : ggInt <= 8 ? ".UNIT07@BLOCK4" : ".UNIT09@BLOCK5"; request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "GG_RUN", iess = gg + "VT_GC00D-115" + suffix, inverted = true, gg = ggInt }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "GG_STOP", iess = gg + "VT_GC00D-115" + suffix, inverted = false, gg = ggInt }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "GG_UST", iess = gg + "VT_GC05D-01" + suffix, inverted = false, gg = ggInt }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "MNU_1", iess = gg + "VT_PS01DI-03" + suffix, inverted = false, gg = ggInt, ValueIess = gg + "VT_PS00A-11" + suffix }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "MNU_2", iess = gg + "VT_PS02DI-03" + suffix, inverted = false, gg = ggInt, ValueIess = gg + "VT_PS00A-11" + suffix }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "MNU_3", iess = gg + "VT_PS03DI-03" + suffix, inverted = false, gg = ggInt, ValueIess = gg + "VT_PS00A-11" + suffix }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "LN_1", iess = gg + "VT_PS04DI-03" + suffix, inverted = false, gg = ggInt, ValueIess = gg + "VT_PS04AI-01" + suffix }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "DN_1", iess = gg + "VT_DS01DI-03" + suffix, inverted = false, gg = ggInt, ValueIess = gg + "VT_DS00AI-01" + suffix }); request.Add(new PuskStopReader.PuskStopReaderRecord() { DBRecord = "DN_2", iess = gg + "VT_DS02DI-03" + suffix, inverted = false, gg = ggInt, ValueIess = gg + "VT_DS00AI-01" + suffix }); } DiagDBEntities diagDB = new DiagDBEntities(); foreach (PuskStopReader.PuskStopReaderRecord rec in request) { string ggStr = rec.iess.Substring(0, 2); int gg = Int32.Parse(ggStr); string typeAnalog = "---"; if (!string.IsNullOrEmpty(rec.ValueIess)) { int pos = rec.DBRecord.IndexOf("_"); typeAnalog = rec.DBRecord.Substring(0, pos); } IEnumerable <PuskStopPoint> req = from p in diagDB.PuskStopPoints where p.gg == gg && (p.pointType == rec.DBRecord || p.pointType == typeAnalog) select p; if (req.Count() > 0) { foreach (PuskStopPoint p in req) { diagDB.PuskStopPoints.Remove(p); } diagDB.SaveChanges(); } PuskStopPoint pt = new PuskStopPoint(); pt.gg = gg; pt.inverted = rec.inverted; pt.pointType = rec.DBRecord; pt.point = rec.iess; pt.analog = false; diagDB.PuskStopPoints.Add(pt); if (!string.IsNullOrEmpty(rec.ValueIess)) { int pos = rec.DBRecord.IndexOf("_"); typeAnalog = rec.DBRecord.Substring(0, pos); pt = new PuskStopPoint(); pt.gg = gg; pt.inverted = false; pt.analog = true; pt.pointType = typeAnalog; pt.point = rec.ValueIess; diagDB.PuskStopPoints.Add(pt); } diagDB.SaveChanges(); } }
public static async Task <bool> FillAnalogData(DateTime DateStart, DateTime DateEnd, List <string> Types) { DiagDBEntities diagDB = new DiagDBEntities(); for (int gg = 1; gg <= 10; gg++) { if (gg == 8) { continue; } try { EDSClass.Disconnect(); } catch { } EDSClass.Connect(); Logger.Info(string.Format("GG{0}", gg)); List <PuskStopPoint> points = (from p in diagDB.PuskStopPoints where p.gg == gg && p.analog == true && Types.Contains(p.pointType) select p).ToList(); List <AnalogData> existData = (from a in diagDB.AnalogDatas where a.gg == gg && Types.Contains(a.pointType) && a.Date >= DateStart && a.Date <= DateEnd select a).ToList(); Dictionary <string, string> pointsDict = new Dictionary <string, string>(); foreach (String type in Types) { try { PuskStopPoint pt = (from p in diagDB.PuskStopPoints where p.gg == gg && p.pointType == type select p).First(); pointsDict.Add(type, pt.point); } catch { pointsDict.Add(type, ""); } } List <PuskStopInfo> data = ( from d in diagDB.PuskStopInfoes where d.TimeOn <= DateEnd && d.TimeOff >= DateStart && d.GG == gg && d.TypeData.Contains("GG_RUN") select d).ToList(); foreach (PuskStopInfo ggRec in data) { Logger.Info(String.Format("GG {0} {1} -{2}", gg, ggRec.TimeOn, ggRec.TimeOff)); foreach (string type in Types) { if (string.IsNullOrEmpty(pointsDict[type])) { continue; } foreach (DateTime dt in new DateTime[] { ggRec.TimeOn, ggRec.TimeOff }) { IEnumerable <AnalogData> datas = (from a in existData where a.Date == dt && a.pointType == type select a); AnalogData dat = null; if (datas.Count() == 0) { dat = new AnalogData(); diagDB.AnalogDatas.Add(dat); dat.pointType = type; dat.gg = gg; dat.Date = dt; dat.value = await EDSClass.getValFromServer(pointsDict[type], dt); } else { dat = datas.First(); } } } diagDB.SaveChanges(); } DateTime date = DateTime.Parse(DateStart.ToString("dd.MM.yyyy HH:00")); while (date <= DateEnd) { Logger.Info(String.Format("GG {0} {1} ", gg, date)); if (gg == 5 && date < DateTime.Parse("01.06.2019")) { date = DateTime.Parse("01.06.2019"); continue; } if (gg == 3 && date < DateTime.Parse("07.05.2020")) { date = DateTime.Parse("07.05.2020"); continue; } if (gg == 1 && date < DateTime.Parse("21.04.2021")) { date = DateTime.Parse("21.04.2020"); continue; } foreach (string type in Types) { if (string.IsNullOrEmpty(pointsDict[type])) { continue; } IEnumerable <AnalogData> datas = (from a in existData where a.Date == date && a.pointType == type select a); AnalogData dat = null; if (datas.Count() == 0) { dat = new AnalogData(); diagDB.AnalogDatas.Add(dat); dat.pointType = type; dat.gg = gg; dat.Date = date; dat.value = await EDSClass.getValFromServer(pointsDict[type], date); } else { dat = datas.First(); } } date = date.AddHours(3); } } return(true); }
public static async Task <bool> process(DateTime dateStart, DateTime dateEnd) { DateTime date = dateStart.AddSeconds(0);; DateTime start = DateTime.Now; DiagDBEntities diagDB = new DiagDBEntities(); Dictionary <int, List <PuskStopReader.PuskStopReaderRecord> > requestsDict = new Dictionary <int, List <PuskStopReader.PuskStopReaderRecord> >(); for (int gg = 1; gg <= 10; gg++) { if (gg == 8) { continue; } List <PuskStopReader.PuskStopReaderRecord> request = new List <PuskStopReader.PuskStopReaderRecord>(); IEnumerable <PuskStopPoint> req = from p in diagDB.PuskStopPoints where p.gg == gg && p.analog == false select p; foreach (PuskStopPoint pt in req) { PuskStopReader.PuskStopReaderRecord rec = new PuskStopReader.PuskStopReaderRecord(); rec.DBRecord = pt.pointType; rec.iess = pt.point; rec.inverted = pt.inverted; rec.gg = pt.gg; IEnumerable <PuskStopPoint> req2 = from p in diagDB.PuskStopPoints where p.gg == gg && p.analog == true && pt.pointType.Contains(p.pointType) select p; if (req2.Count() > 0) { PuskStopPoint inner = req2.First(); rec.ValueIess = inner.point; } request.Add(rec); } requestsDict.Add(gg, request); } while (date < dateEnd) { Logger.Info(date.ToString()); for (int gg = 1; gg <= 10; gg++) { if (gg == 8) { continue; } if (gg == 3 && date < DateTime.Parse("07.05.2020")) { continue; } if (gg == 5 && date < DateTime.Parse("01.06.2019")) { continue; } if (gg == 1 && date < DateTime.Parse("21.04.2021")) { continue; } Logger.Info(String.Format("ГГ {0} Дата {1}", gg, date)); List <PuskStopReader.PuskStopReaderRecord> request = requestsDict[gg]; bool ok = await PuskStopReader.FillPuskStopData(request, date, date.AddHours(3)); } date = date.AddHours(3); } DateTime end = DateTime.Now; Logger.Info((end - start).TotalMinutes.ToString()); Logger.Info("Finish"); return(true); }