internal static Guid CreateCalculationRec(string connStr, DateTime CalcBeg_Time, CalcRec.HydrCalcDataRec[] recs) { var hc = new PPM.Pipeline.Fact.ApiModels.Service.HydraulicCalculation() { Id = Guid.NewGuid(), StartCalculationTime = CalcBeg_Time, StopCalculationTime = DateTime.UtcNow, SegmentsCount = (recs == null) ? -1 : recs.Length, }; int[] nStatus = new int[(int)CalcRec.CalcStatus.MaxValue]; if (recs != null) { foreach (var r in recs) { nStatus[(int)r.CalcStatus]++; } } hc.CalculatedCount = nStatus[(int)CalcRec.CalcStatus.Success]; hc.ErrorsCount = nStatus[(int)CalcRec.CalcStatus.Failed]; using (new StopwatchMs("Save into HYDRAULIC_CALCULATION")) using (var loader = new Microsoft.Data.SqlClient.SqlBulkCopy(connStr)) { loader.DestinationTableName = "HYDRAULIC_CALCULATION"; var reader = new BulkDataReader <int>(new[] { 0 }, (_, j, vals) => { int i = 0; vals[i++] = hc.Id; vals[i++] = hc.StartCalculationTime; vals[i++] = hc.StopCalculationTime; vals[i++] = hc.CalculationStatusRd; vals[i++] = hc.PipesCount; vals[i++] = hc.SegmentsCount; vals[i++] = hc.CalculatedCount; vals[i++] = hc.ErrorsCount; vals[i++] = hc.WithSheduler; vals[i++] = hc.Initiator; vals[i++] = Guid.Empty; // FILE_ID }, 11); loader.WriteToServer(reader); } return(hc.Id); }
public static void SaveResults(string connStr, CalcRec.HydrCalcDataRec[] recs, ulong[] edgesIDs, DateTime Calc_Time, Guid Calculation_ID) { var dictO2P = new Dictionary <ulong, Guid>(); using (new StopwatchMs("Загрузка справочника преобразования ID OIS в ID PPM")) using (var conn = new Microsoft.Data.SqlClient.SqlConnection(connStr)) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "SELECT OIS_ID, PPM_ID FROM OIS_2_PPM WHERE OIS_TABLE_NAME = 'PipeProstoyUchastok'"; using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { dictO2P[Convert.ToUInt64(rdr[0])] = rdr.GetGuid(1); } } } } using (new StopwatchMs("Bulk save into HYDRAULIC_CALCULATION_RESULT")) using (var loader = new Microsoft.Data.SqlClient.SqlBulkCopy(connStr)) { loader.DestinationTableName = "HYDRAULIC_CALCULATION_RESULT"; //loader.BatchSize = 1; var reader = new BulkDataReader <CalcRec.HydrCalcDataRec>(recs, (iEdge, r, vals) => { int i = 0; var pu_id = edgesIDs[iEdge]; vals[i++] = dictO2P.TryGetValue(pu_id, out var g) ? g : Guid.Empty; vals[i++] = Calc_Time; vals[i++] = Calculation_ID; r.GetValues(vals, ref i); }, 44); loader.WriteToServer(reader); } }