LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
SolverAdapterLoadResult.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Xml.Serialization;
5
7
8/// <summary>
9/// Represents the result of attempting to load a solver adapter
10/// plugin.
11/// </summary>
12[Serializable]
13[XmlType(TypeName = "solverAdapterLoadResult")]
14public sealed class SolverAdapterLoadResult
15{
16 private readonly List<string> _diagnostics =
17 new();
18
19 /// <summary>
20 /// Initializes an empty solver-adapter load result.
21 /// </summary>
23 {
25 string.Empty;
26
27 TypeName =
28 string.Empty;
29
31 string.Empty;
32
34 string.Empty;
35
36 Status =
38 }
39
40 /// <summary>
41 /// Gets or sets the descriptor associated with the adapter
42 /// loading attempt.
43 /// </summary>
44 [XmlElement("descriptor")]
46 {
47 get;
48 set;
49 }
50
51 /// <summary>
52 /// Gets or sets the final adapter loading status.
53 /// </summary>
54 [XmlAttribute("status")]
56 {
57 get;
58 set;
59 }
60
61 /// <summary>
62 /// Gets or sets the full path of the adapter assembly.
63 /// </summary>
64 [XmlElement("assemblyPath")]
65 public string AssemblyPath
66 {
67 get;
68 set;
69 }
70
71 /// <summary>
72 /// Gets or sets the requested adapter type name.
73 /// </summary>
74 [XmlElement("typeName")]
75 public string TypeName
76 {
77 get;
78 set;
79 }
80
81 /// <summary>
82 /// Gets or sets the loaded adapter instance.
83 /// </summary>
84 /// <remarks>
85 /// The adapter instance is excluded from XML serialization
86 /// because it represents a live runtime object.
87 /// </remarks>
88 [XmlIgnore]
90 {
91 get;
92 set;
93 }
94
95 /// <summary>
96 /// Gets or sets the exception type associated with a load
97 /// failure.
98 /// </summary>
99 [XmlElement("exceptionType")]
100 public string ExceptionType
101 {
102 get;
103 set;
104 }
105
106 /// <summary>
107 /// Gets or sets the exception message associated with a
108 /// load failure.
109 /// </summary>
110 [XmlElement("exceptionMessage")]
111 public string ExceptionMessage
112 {
113 get;
114 set;
115 }
116
117 /// <summary>
118 /// Gets the diagnostics produced during adapter loading.
119 /// </summary>
120 [XmlArray("diagnostics")]
121 [XmlArrayItem("diagnostic")]
122 public List<string> Diagnostics =>
123 _diagnostics;
124
125 /// <summary>
126 /// Gets a value indicating whether the adapter was loaded
127 /// successfully.
128 /// </summary>
129 [XmlIgnore]
130 public bool IsLoaded =>
131 Status ==
133 Adapter is not null;
134
135 /// <summary>
136 /// Adds a diagnostic message.
137 /// </summary>
138 /// <param name="message">
139 /// Diagnostic message.
140 /// </param>
141 /// <exception cref="ArgumentException">
142 /// Thrown when <paramref name="message"/> is empty.
143 /// </exception>
144 public void AddDiagnostic(
145 string message)
146 {
147 if (string.IsNullOrWhiteSpace(
148 message))
149 {
150 throw new ArgumentException(
151 "A diagnostic message cannot be empty.",
152 nameof(message));
153 }
154
155 _diagnostics.Add(
156 message.Trim());
157 }
158
159 /// <summary>
160 /// Stores exception information without retaining the live
161 /// exception object.
162 /// </summary>
163 /// <param name="exception">
164 /// Exception to describe.
165 /// </param>
166 /// <exception cref="ArgumentNullException">
167 /// Thrown when <paramref name="exception"/> is
168 /// <see langword="null"/>.
169 /// </exception>
170 public void SetException(
171 Exception exception)
172 {
173 ArgumentNullException.ThrowIfNull(
174 exception);
175
177 exception.GetType().FullName ??
178 exception.GetType().Name;
179
181 exception.Message;
182 }
183}
Describes a solver adapter without loading or executing its native optimization engine.
ISolverAdapter? Adapter
Gets or sets the loaded adapter instance.
List< string > Diagnostics
Gets the diagnostics produced during adapter loading.
void SetException(Exception exception)
Stores exception information without retaining the live exception object.
SolverAdapterLoadResult()
Initializes an empty solver-adapter load result.
bool IsLoaded
Gets a value indicating whether the adapter was loaded successfully.
SolverAdapterLoadStatus Status
Gets or sets the final adapter loading status.
string AssemblyPath
Gets or sets the full path of the adapter assembly.
void AddDiagnostic(string message)
Adds a diagnostic message.
string ExceptionMessage
Gets or sets the exception message associated with a load failure.
string TypeName
Gets or sets the requested adapter type name.
SolverAdapterDescriptor? Descriptor
Gets or sets the descriptor associated with the adapter loading attempt.
string ExceptionType
Gets or sets the exception type associated with a load failure.
Defines the metadata and capabilities exposed by a solver adapter plugin.
SolverAdapterLoadStatus
Describes the result of loading a solver adapter plugin.