Fixed exception with .ElementAt(0) call at empty collection

This commit is contained in:
KharchenkoVV 2021-09-02 10:13:20 +05:00
parent a7962492af
commit 1debac9505

View File

@ -470,24 +470,30 @@ namespace AsbCloudInfrastructure.Services
private static IEnumerable<OperationParams> MakeOperationsExt(IEnumerable<WellOperation> operations) private static IEnumerable<OperationParams> MakeOperationsExt(IEnumerable<WellOperation> operations)
{ {
var sortedOperations = operations.OrderBy(o => o.StartDate); var ops = new List<OperationParams>();
var count = operations.Count();
var ops = new List<OperationParams>(count); if (operations.Any())
var item = operations.ElementAt(0);
var wellDepth = item.WellDepth;
var pre = new OperationParams(item);
var current = new OperationParams(item);
for (int i = 1; i < count; i++)
{ {
item = operations.ElementAt(i); var sortedOperations = operations.OrderBy(o => o.StartDate);
current = new OperationParams(item){ WellDepth = Helper.Max(wellDepth, item.WellDepth) }; var count = operations.Count();
pre.DeltaDepth = current.WellDepth - wellDepth; ops = new List<OperationParams>(count);
wellDepth = current.WellDepth; var item = operations.ElementAt(0);
pre.Hours = (current.Start - pre.Start).TotalHours; var wellDepth = item.WellDepth;
ops.Add(pre); var pre = new OperationParams(item);
pre = current; var current = new OperationParams(item);
for (int i = 1; i < count; i++)
{
item = operations.ElementAt(i);
current = new OperationParams(item) { WellDepth = Helper.Max(wellDepth, item.WellDepth) };
pre.DeltaDepth = current.WellDepth - wellDepth;
wellDepth = current.WellDepth;
pre.Hours = (current.Start - pre.Start).TotalHours;
ops.Add(pre);
pre = current;
}
ops.Add(current);
} }
ops.Add(current);
return ops; return ops;
} }
} }