15 foreach (var resource
in root.Descendants().Where(element =>
16 element.Name.LocalName ==
"transportResource" && element.Parent?.Name.LocalName ==
"transportResources"))
18 var metadata = resource.Nodes().OfType<XProcessingInstruction>()
19 .Where(node => node.Target == LegacyTarget).ToArray();
20 var ns = resource.Name.Namespace;
21 if (metadata.Length + resource.Elements(ns +
"physicalFleet").Take(2).Count() > 1)
22 throw new InvalidOperationException(
"Plusieurs définitions de la flotte physique sont présentes pour le même moyen.");
23 if (metadata.Length == 0)
29 using var document = JsonDocument.Parse(metadata[0].Data);
30 var data = document.RootElement;
31 fleet =
new XElement(ns +
"physicalFleet",
32 new XAttribute(
"vehicleCount", data.GetProperty(
"VehicleCount").GetInt32()),
33 new XAttribute(
"capacityPerVehicle", data.GetProperty(
"CapacityPerVehicle").GetDecimal()),
34 new XElement(ns +
"initialAllocation", data.GetProperty(
"InitialAllocation").EnumerateArray().Select(row =>
35 new XElement(ns +
"allocation",
new XAttribute(
"count", row.GetProperty(
"Count").GetInt32()),
36 Reference(row.GetProperty(
"Warehouse"), ns +
"warehouse")))),
37 new XElement(ns +
"emptyMovements", data.GetProperty(
"EmptyMovements").EnumerateArray().Select(row =>
38 new XElement(ns +
"movement",
new XAttribute(
"duration", row.GetProperty(
"Duration").GetInt32()),
39 Reference(row.GetProperty(
"Origin"), ns +
"origin"),
40 Reference(row.GetProperty(
"Destination"), ns +
"destination")))));
42 catch (Exception error) when (error is JsonException or FormatException or InvalidOperationException
43 or System.Collections.Generic.KeyNotFoundException)
45 throw new InvalidOperationException(
"Les anciennes données de flotte sont illisibles.", error);
47 metadata[0].ReplaceWith(fleet);