LotSizingDataModel.Core 2.0.1
Core domain model, shared abstractions and XML-serializable entities.
Loading...
Searching...
No Matches
WarehouseReference.cs
Go to the documentation of this file.
1using System;
2using System.Xml.Serialization;
4
6
7/// <summary>
8/// Identifies the type of warehouse referenced by a relationship.
9/// </summary>
10[Serializable]
11[XmlType(TypeName = "warehouseReferenceKind")]
13{
14 /// <summary>
15 /// The reference identifies a standalone warehouse
16 /// through its own warehouse identifier e.
17 /// </summary>
18 [XmlEnum("standaloneWarehouse")]
20
21 /// <summary>
22 /// The reference identifies a plant warehouse
23 /// through the identifier u of its owning plant.
24 /// </summary>
25 [XmlEnum("plantWarehouse")]
27}
28
29/// <summary>
30/// Represents a serializable reference to a warehouse.
31///
32/// A standalone warehouse is referenced by its warehouse identifier.
33/// A plant warehouse is referenced by the identifier of its owning plant.
34///
35/// This class avoids serializing complete Warehouse objects inside
36/// relationships and therefore prevents object duplication and XML cycles.
37/// </summary>
38[Serializable]
39[XmlType(TypeName = "warehouseReference")]
40public sealed class WarehouseReference : ModelObject
41{
42 private WarehouseReferenceKind _kind;
43 private int _referenceId;
44
45 /// <summary>
46 /// Initializes an empty warehouse reference.
47 ///
48 /// This public parameterless constructor is required
49 /// by <see cref="XmlSerializer"/>.
50 /// </summary>
52 {
53 }
54
55 /// <summary>
56 /// Initializes a warehouse reference.
57 /// </summary>
58 /// <param name="kind">
59 /// Kind of warehouse being referenced.
60 /// </param>
61 /// <param name="referenceId">
62 /// Standalone-warehouse identifier or owning-plant identifier,
63 /// depending on <paramref name="kind"/>.
64 /// </param>
67 int referenceId)
68 {
69 // Initialize warehouse reference properties (validation occurs in setters)
70 Kind = kind;
71 ReferenceId = referenceId;
72 }
73
74 /// <summary>
75 /// Gets or sets the kind of warehouse being referenced.
76 /// </summary>
77 [XmlAttribute("kind")]
79 {
80 get => _kind;
81 set
82 {
83 // Validate that the enum value is defined
84 if (!Enum.IsDefined(typeof(WarehouseReferenceKind), value))
85 {
86 throw new ArgumentOutOfRangeException(
87 nameof(value),
88 value,
89 "The warehouse reference kind is not valid.");
90 }
91
92 // Update the backing field and notify property change if value differs
93 SetProperty(ref _kind, value);
94 }
95 }
96
97 /// <summary>
98 /// Gets or sets the referenced identifier.
99 ///
100 /// For a standalone warehouse, this is its warehouse identifier e.
101 /// For a plant warehouse, this is the identifier u of its owning plant.
102 /// </summary>
103 [XmlAttribute("id")]
104 public int ReferenceId
105 {
106 get => _referenceId;
107 set
108 {
109 // Validate that the identifier is non-negative
110 if (value < 0)
111 {
112 throw new ArgumentOutOfRangeException(
113 nameof(value),
114 value,
115 "The warehouse reference identifier cannot be negative.");
116 }
117
118 // Update the backing field and notify property change if value differs
119 SetProperty(ref _referenceId, value);
120 }
121 }
122
123 /// <summary>
124 /// Creates a reference to a standalone warehouse.
125 /// </summary>
126 /// <param name="warehouseId">
127 /// Identifier e of the standalone warehouse.
128 /// </param>
130 int warehouseId)
131 {
132 // Factory method: create a reference to a standalone warehouse
133 return new WarehouseReference(
134 WarehouseReferenceKind.StandaloneWarehouse,
135 warehouseId);
136 }
137
138 /// <summary>
139 /// Creates a reference to the warehouse attached to a plant.
140 /// </summary>
141 /// <param name="plantId">
142 /// Identifier u of the plant owning the warehouse.
143 /// </param>
145 int plantId)
146 {
147 // Factory method: create a reference to a plant's warehouse
148 return new WarehouseReference(
149 WarehouseReferenceKind.PlantWarehouse,
150 plantId);
151 }
152
153 /// <summary>
154 /// Returns a readable representation of the warehouse reference.
155 /// </summary>
156 public override string ToString()
157 {
158 return $"{Kind}:{ReferenceId}";
159 }
160}
Base class for model objects that notify listeners when one of their properties changes.
Represents a warehouse attached to a plant.
Represents a standalone warehouse that is not attached to a plant.
WarehouseReference()
Initializes an empty warehouse reference.
override string ToString()
Returns a readable representation of the warehouse reference.
int ReferenceId
Gets or sets the referenced identifier.
WarehouseReference(WarehouseReferenceKind kind, int referenceId)
Initializes a warehouse reference.
WarehouseReferenceKind Kind
Gets or sets the kind of warehouse being referenced.
static WarehouseReference ForPlantWarehouse(int plantId)
Creates a reference to the warehouse attached to a plant.
static WarehouseReference ForStandaloneWarehouse(int warehouseId)
Creates a reference to a standalone warehouse.
WarehouseReferenceKind
Identifies the type of warehouse referenced by a relationship.