private Port(PortData data, Dictionary <string, DockChoiceAlgorithm> dockChoices, Dictionary <string, Dock.BerthingAlgorithm> berthingChoices) { Time = data.Time; if (dockChoices.TryGetValue(data.DockChoiceAlgorithm, out DockChoiceAlgorithm dockChoice)) { SetAlgorithm(dockChoice, data.DockChoiceAlgorithm); } else { SetAlgorithm(DockChoiceEmptiest, nameof(DockChoiceEmptiest)); } docks = new Dock[data.Docks.Length]; int size = 0; for (var i = 0; i < docks.Length; i++) { docks[i] = Dock.FromData(data.Docks[i], berthingChoices); size += docks[i].Size; } Size = size; }
public string Serialize() { var data = new PortData { Time = Time, DockChoiceAlgorithm = algorithmName, Docks = new DockData[docks.Length] }; for (var i = 0; i < docks.Length; i++) { data.Docks[i] = docks[i].AsData(); } return(JsonSerializer.Serialize(data, new JsonSerializerOptions { WriteIndented = true })); }