2using System.Collections.Generic;
4using System.Xml.Serialization;
17[XmlType(TypeName =
"plant")]
20 private bool _manufacturedItemIdsDeclared;
21 private List<int> _manufacturedItemIds =
new();
23 private List<WorkCenter> _workCenters =
new();
65 [XmlElement(
"warehouse")]
72 ArgumentNullException.ThrowIfNull(value);
87 [XmlArray(
"workCenters")]
88 [XmlArrayItem(
"workCenter")]
95 List<WorkCenter> newValue =
96 value ??
new List<WorkCenter>();
99 if (ReferenceEquals(_workCenters, newValue))
104 _workCenters = newValue;
114 [XmlArray(
"manufacturedItemIds")]
115 [XmlArrayItem(
"itemId")]
118 get => _manufacturedItemIds;
119 set => SetProperty(ref _manufacturedItemIds, value ??
new List<int>());
130 get => _manufacturedItemIdsDeclared || ManufacturedItemIds.Count > 0;
131 set => SetProperty(ref _manufacturedItemIdsDeclared, value);
146 ArgumentNullException.ThrowIfNull(workCenter);
149 bool identifierAlreadyUsed =
152 current => current.Id == workCenter.Id);
154 if (identifierAlreadyUsed)
156 throw new InvalidOperationException(
157 $
"A work center with identifier {workCenter.Id} " +
158 $
"already exists in plant {Id}.");
162 _workCenters.Add(workCenter);
179 ArgumentNullException.ThrowIfNull(workCenter);
182 bool removed = _workCenters.Remove(workCenter);
205 return _workCenters.FirstOrDefault(
206 workCenter => workCenter.Id == workCenterId);
int Id
Gets or sets the numerical identifier of the entity.
IdentifiedEntity()
Initializes a new instance of the IdentifiedEntity class.
virtual void OnPropertyChanged([CallerMemberName] string? propertyName=null)
Raises the PropertyChanged event.
string Name
Gets or sets the entity name.
List< WorkCenter > WorkCenters
Gets or sets the work centers belonging to the plant.
List< int > ManufacturedItemIds
Gets or sets the identifiers of the items the plant is declared to manufacture. An item may be declar...
void AddWorkCenter(WorkCenter workCenter)
Adds a work center to the plant.
Plant(int id, string name, PlantWarehouse warehouse)
Initializes a plant with an identifier, a name and its associated warehouse.
bool ManufacturedItemIdsSpecified
Gets or sets whether the manufactured-item list was explicitly declared. An empty declared list diffe...
Plant()
Initializes an empty plant.
bool RemoveWorkCenter(WorkCenter workCenter)
Removes a work center from the plant.
WorkCenter? FindWorkCenter(int workCenterId)
Finds a work center by its identifier.
PlantWarehouse Warehouse
Gets or sets the warehouse attached to the plant.
Represents a warehouse attached to a plant.
Represents a production work center belonging to a plant.