PageRenderTime 215ms CodeModel.GetById 43ms RepoModel.GetById 9ms app.codeStats 0ms

/ADX4/adx4helper.cs

https://bitbucket.org/endevea/lis
C# | 954 lines | 641 code | 108 blank | 205 comment | 181 complexity | a58f7425cbe578ab49dd42a0619bf11d MD5 | raw file
Possible License(s): LGPL-3.0
  1. //-----------------------------------------------------------------------------
  2. //
  3. // ADX4 Toolkit
  4. //
  5. // Copyright 2009. Mining Industry Geospatial Consortium.
  6. //
  7. // This file is part of the ADX4 Toolkit.
  8. //
  9. // The ADX4 toolkit is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Lesser General Public License as published
  11. // by the Free Software Foundation, either version 3 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // The ADX4 toolkit is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU Lesser General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU Lesser General Public License
  20. // along with The ADX4 toolkit. If not, see <http://www.gnu.org/licenses/>.
  21. //
  22. //-----------------------------------------------------------------------------
  23. using System;
  24. using System.Text;
  25. using System.ComponentModel;
  26. using System.Collections.Generic;
  27. using System.Runtime.Serialization.Formatters.Binary;
  28. using System.Runtime.Serialization;
  29. using System.Reflection;
  30. using System.Xml.Serialization;
  31. using System.Xml;
  32. using System.IO;
  33. namespace ADX4
  34. {
  35. #region ADX
  36. public partial class ADX
  37. {
  38. #region Constants
  39. public const String c_ADX4_Xsd = "ADX4.xsd";
  40. public const String c_ADX4Dictionary_Xsd = "ADX4Dictionary.xsd";
  41. public const String c_ADX4_NameSpace = "http://www.adx4.org/ADX/4";
  42. public const String c_ADX4Dictionary_NameSpace = "http://www.adx4.org/ADX/4/Dictionary";
  43. #endregion
  44. #region Static Events
  45. static public event XmlElementEventHandler OnLoadUnknownElements;
  46. static public event XmlAttributeEventHandler OnLoadUnknownAttributes;
  47. static public event XmlNodeEventHandler OnLoadUnknownNode;
  48. static public event UnreferencedObjectEventHandler OnLoadUnreferencedObjects;
  49. #endregion
  50. #region Static Methods
  51. static public ADX Load(String fileName)
  52. {
  53. if (fileName == null)
  54. return null;
  55. // Deserialize the ADX document from an XML file
  56. ADX document = null;
  57. try
  58. {
  59. XmlSerializer xmlSerializer = new XmlSerializer(typeof(ADX));
  60. FileStream adxStream = new FileStream(fileName, FileMode.Open);
  61. XmlReader xmlReader = XmlReader.Create(adxStream);
  62. // Ignore mal-formed XML for now
  63. XmlDeserializationEvents events = new XmlDeserializationEvents();
  64. events.OnUnknownElement = ADX.OnLoadUnknownElements;
  65. events.OnUnknownAttribute = ADX.OnLoadUnknownAttributes;
  66. events.OnUnknownNode = ADX.OnLoadUnknownNode;
  67. events.OnUnreferencedObject = ADX.OnLoadUnreferencedObjects;
  68. // Get the ADX document
  69. document = xmlSerializer.Deserialize(xmlReader, events) as ADX;
  70. adxStream.Close();
  71. }
  72. // Trap and throw the any exceptions higher up
  73. catch (System.Exception exc)
  74. {
  75. throw exc;
  76. }
  77. return document;
  78. }
  79. #endregion
  80. static public void Save(ADX document,String fileName)
  81. {
  82. if (fileName == null)
  83. return;
  84. // Serialize the ADX document into an XML file
  85. try
  86. {
  87. XmlSerializer xmlSerializer = new XmlSerializer(typeof(ADX));
  88. FileStream adxStream = new FileStream(fileName, FileMode.Create);
  89. XmlWriter xmlWriter = XmlWriter.Create(adxStream);
  90. // Write the ADX document
  91. xmlSerializer.Serialize(xmlWriter, document);
  92. adxStream.Close();
  93. }
  94. // Trap and throw the any exceptions higher up
  95. catch (System.Exception exc)
  96. {
  97. throw exc;
  98. }
  99. return ;
  100. }
  101. /// <summary>
  102. /// Performs a deep copy of this ADX document.
  103. /// </summary>
  104. /// <returns>Cloned ADX document</returns>
  105. public ADX Clone()
  106. {
  107. try
  108. {
  109. BinaryFormatter serializer = new BinaryFormatter();
  110. MemoryStream buffer = new MemoryStream();
  111. serializer.Serialize(buffer, this);
  112. buffer.Seek(0, SeekOrigin.Begin);
  113. return serializer.Deserialize(buffer) as ADX;
  114. }
  115. catch (System.Exception exc)
  116. {
  117. return null;
  118. }
  119. }
  120. }
  121. #endregion
  122. #region SampleReference
  123. /// <summary>
  124. /// Enhancements to ADX autogenerated class <seealso cref="SampleReference"/>
  125. /// </summary>
  126. public partial class SampleReference
  127. {
  128. public SampleReference()
  129. {
  130. }
  131. public SampleReference(String id)
  132. {
  133. this.IdRef = id;
  134. }
  135. }
  136. #endregion
  137. #region ProcessingGroup
  138. /// <summary>
  139. /// Enhancements to ADX autogenerated class <seealso cref="ProcessingGroup"/>
  140. /// </summary>
  141. public partial class ProcessingGroup
  142. {
  143. public override string ToString()
  144. {
  145. return String.IsNullOrEmpty(this.Id) ? "?" : this.Id;
  146. }
  147. }
  148. #endregion
  149. #region Measurement
  150. /// <summary>
  151. /// Enhancements to ADX autogenerated class <seealso cref="Measurement"/>
  152. /// </summary>
  153. public partial class Measurement
  154. {
  155. public override string ToString()
  156. {
  157. return String.IsNullOrEmpty(this.Property) ? "?" : this.Property;
  158. }
  159. }
  160. #endregion
  161. #region Result
  162. /// <summary>
  163. /// Enhancements to ADX autogenerated class <seealso cref="Result"/>
  164. /// </summary>
  165. public partial class Result
  166. {
  167. public override string ToString()
  168. {
  169. if (this.Sample == null)
  170. return "?";
  171. StringBuilder fullIdBuilder = new StringBuilder();
  172. fullIdBuilder.Length = 0;
  173. for (int i = 0; i < this.Sample.Length; i++)
  174. {
  175. fullIdBuilder.Append(this.Sample[i].IdRef);
  176. if (i < this.Sample.Length - 2)
  177. fullIdBuilder.Append(",");
  178. }
  179. return fullIdBuilder.ToString();
  180. }
  181. }
  182. #endregion
  183. #region Sample
  184. /// <summary>
  185. /// Enhancements to ADX autogenerated class <seealso cref="Samples"/>
  186. /// </summary>
  187. public partial class Samples
  188. {
  189. /// <summary>
  190. /// Finds the sample matching the specified sample reference.
  191. /// </summary>
  192. /// <param name="sampleRef">The sample reference.</param>
  193. /// <returns>Matching sample</returns>
  194. public Sample Find(SampleReference sampleRef)
  195. {
  196. foreach (Sample sample in this.Sample)
  197. if (String.Equals(sample.Id, sampleRef.IdRef))
  198. return sample;
  199. return null;
  200. }
  201. }
  202. /// <summary>
  203. /// Enhancements to ADX autogenerated class <seealso cref="Sample"/>
  204. /// </summary>
  205. [KnownType("GetKnownTypes")]
  206. public partial class Sample
  207. {
  208. static Type[] GetKnownTypes()
  209. {
  210. List<Type> subClasses = new List<Type>();
  211. foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
  212. {
  213. foreach (Type assemblyType in assembly.GetTypes())
  214. {
  215. if (assemblyType.IsSubclassOf(typeof(Sample)))
  216. subClasses.Add(assemblyType);
  217. }
  218. }
  219. return subClasses.ToArray();
  220. }
  221. }
  222. #endregion
  223. #region ChainOfCustodyBatch
  224. /// <summary>
  225. /// Enhancements to ADX autogenerated class <seealso cref="ChainOfCustodyBatch"/>
  226. /// </summary>
  227. public partial class ChainOfCustodyBatch
  228. {
  229. /// <summary>
  230. /// Finds the chain of custody sample that matches the requested sample reference.
  231. /// </summary>
  232. /// <param name="sampleRef">The sample ref.</param>
  233. /// <returns>matching chain of custody sample</returns>
  234. public ChainOfCustodySample Find(SampleReference sampleRef)
  235. {
  236. foreach (ChainOfCustodySample sample in this.SampleMaterial)
  237. {
  238. if (sample.Sample.Length != 1)
  239. continue;
  240. if (sample.Sample == null)
  241. continue;
  242. if (String.Equals(sample.Sample[0].IdRef, sampleRef.IdRef))
  243. return sample;
  244. }
  245. return null;
  246. }
  247. }
  248. #endregion
  249. #region Process
  250. /// <summary>
  251. /// Enhancements to ADX autogenerated class <seealso cref="Process"/>
  252. /// </summary>
  253. public partial class Process
  254. {
  255. /// <summary>
  256. /// Performs a deep copy of this process.
  257. /// </summary>
  258. /// <returns>Cloned process</returns>
  259. public Process Clone()
  260. {
  261. try
  262. {
  263. BinaryFormatter serializer = new BinaryFormatter();
  264. MemoryStream buffer = new MemoryStream();
  265. serializer.Serialize(buffer, this);
  266. return serializer.Deserialize(buffer) as Process;
  267. }
  268. catch (System.Exception exc)
  269. {
  270. return null;
  271. }
  272. }
  273. // TODO finish this searching procedure
  274. public Procedure FindProcedure(String procedureName)
  275. {
  276. return SearchForProcedureByName(this.Destination, procedureName);
  277. }
  278. // TODO Finish FindProcedure procedure
  279. private Procedure SearchForProcedureByName(MaterialDestination parentDestination, String procedureName)
  280. {
  281. if (String.IsNullOrEmpty(procedureName))
  282. return null;
  283. if (parentDestination == null)
  284. return null;
  285. if (parentDestination.Target == null)
  286. return null;
  287. if (parentDestination.Target.HasProcedure())
  288. {
  289. for (int i = 0; i < parentDestination.Target.Procedure.Length; i++)
  290. {
  291. if (!String.IsNullOrEmpty(parentDestination.Target.Procedure[i].Id))
  292. if (String.Equals(parentDestination.Target.Procedure[i].Id, procedureName))
  293. return parentDestination.Target.Procedure[i];
  294. }
  295. }
  296. return null;
  297. }
  298. }
  299. #endregion
  300. #region Procedure
  301. /// <summary>
  302. /// Enhancements to ADX autogenerated class <seealso cref="Procedure"/>
  303. /// </summary>
  304. ///
  305. [KnownType("GetKnownTypes")]
  306. public partial class Procedure
  307. {
  308. /// <summary>
  309. /// Gets a more readable version of the procedure name (by removing the word Procedure from the end of it).
  310. /// </summary>
  311. /// <param name="name">The name.</param>
  312. /// <returns>Readable procedure name</returns>
  313. public static String Label(String name)
  314. {
  315. return name.EndsWith("Procedure") ? name.Substring(0, name.Length - 9) : name;
  316. }
  317. /// <summary>
  318. /// Gets the destinations on this procedure.
  319. /// </summary>
  320. /// <returns>List of destinations</returns>
  321. public List<MaterialDestination> GetDestinations()
  322. {
  323. List<MaterialDestination> destinations = new List<MaterialDestination>();
  324. // Get the procedure's properties
  325. PropertyInfo[] propertyInfos = this.GetType().GetProperties();
  326. foreach (PropertyInfo propertyInfo in propertyInfos)
  327. {
  328. // Is this property a MaterialDestination ?
  329. if (propertyInfo.PropertyType.IsSubclassOf(typeof(MaterialDestination)) || propertyInfo.PropertyType == typeof(MaterialDestination))
  330. {
  331. // If so then add it to the list of destinations ?
  332. System.Object getValue = propertyInfo.GetValue(this, null);
  333. if (getValue == null)
  334. {
  335. MaterialDestination destination = new MaterialDestination();
  336. propertyInfo.SetValue(this, destination, null);
  337. destinations.Add(destination);
  338. }
  339. else if (getValue is MaterialDestination)
  340. destinations.Add(getValue as MaterialDestination);
  341. }
  342. // Is the property a list of objects ?
  343. else if (propertyInfo.PropertyType.IsArray)
  344. {
  345. System.Object getValue = propertyInfo.GetValue(this, null);
  346. if (getValue != null)
  347. {
  348. // Check each object to see if it is a MaterialDestination
  349. foreach (Object thisElement in getValue as Array)
  350. {
  351. if (thisElement is MaterialDestination)
  352. destinations.Add(thisElement as MaterialDestination);
  353. }
  354. }
  355. }
  356. }
  357. return destinations;
  358. }
  359. static Type[] GetKnownTypes()
  360. {
  361. List<Type> subClasses = new List<Type>();
  362. foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
  363. {
  364. foreach (Type assemblyType in assembly.GetTypes())
  365. {
  366. if (assemblyType.IsSubclassOf(typeof(Procedure)))
  367. subClasses.Add(assemblyType);
  368. }
  369. }
  370. return subClasses.ToArray();
  371. }
  372. }
  373. #endregion
  374. #region SplittingProcedure
  375. /// <summary>
  376. /// Enhancements to ADX autogenerated class <seealso cref="SplittingProcedure"/>
  377. /// </summary>
  378. public partial class SplittingProcedure
  379. {
  380. public SplittingProcedure()
  381. {
  382. this.destinationField = new MaterialDestination[2];
  383. this.destinationField[0] = new MaterialDestination();
  384. this.destinationField[1] = new MaterialDestination();
  385. }
  386. }
  387. #endregion
  388. #region ParticleSizeReductionProcedure
  389. /// <summary>
  390. /// Enhancements to ADX autogenerated class <seealso cref="ParticleSizeReductionProcedure"/>
  391. /// </summary>
  392. public partial class ParticleSizeReductionProcedure
  393. {
  394. public ParticleSizeReductionProcedure()
  395. {
  396. this.Screen = new Screen();
  397. }
  398. }
  399. #endregion
  400. #region Quantity
  401. /// <summary>
  402. /// Enhancements to ADX autogenerated class <seealso cref="Quantity"/>
  403. /// </summary>
  404. [System.ComponentModel.TypeConverter(typeof(QuantityConverter))]
  405. public partial class Quantity
  406. {
  407. public Quantity()
  408. {
  409. this.Value = "";
  410. this.UOM = Enum.GetName(typeof(PropertyTypeStrict), UOMStrict.Unspecified);
  411. }
  412. public override string ToString()
  413. {
  414. if (!String.Equals(this.UOM, Enum.GetName(typeof(PropertyTypeStrict), UOMStrict.Unspecified)))
  415. return String.Concat(this.Value.ToString(), " ", this.UOM.ToString());
  416. return "";
  417. }
  418. }
  419. /// <summary>
  420. /// TypeConverter to convert a quantity into a string format.
  421. /// </summary>
  422. public class QuantityConverter : ExpandableObjectConverter
  423. {
  424. public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
  425. {
  426. if (destinationType == typeof(Quantity))
  427. return true;
  428. return base.CanConvertTo(context, destinationType);
  429. }
  430. public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
  431. {
  432. if (destinationType == typeof(System.String) && value is Quantity)
  433. return value.ToString();
  434. return base.ConvertTo(context, culture, value, destinationType);
  435. }
  436. }
  437. #endregion
  438. #region Material
  439. /// <summary>
  440. /// Enhancements to ADX autogenerated class <seealso cref="MaterialTarget"/>
  441. /// </summary>
  442. [System.ComponentModel.TypeConverter(typeof(MaterialTargetConverter))]
  443. public partial class MaterialTarget
  444. {
  445. public MaterialTarget()
  446. {
  447. }
  448. }
  449. /// <summary>
  450. /// TypeConverter to convert a MaterialTarget into a string format.
  451. /// </summary>
  452. public class MaterialTargetConverter : ExpandableObjectConverter
  453. {
  454. public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
  455. {
  456. if (destinationType == typeof(MaterialTarget))
  457. return true;
  458. return base.CanConvertTo(context, destinationType);
  459. }
  460. public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
  461. {
  462. if (destinationType == typeof(System.String) && value is MaterialTarget)
  463. {
  464. MaterialTarget target = value as MaterialTarget;
  465. return "Target";
  466. }
  467. return base.ConvertTo(context, culture, value, destinationType);
  468. }
  469. }
  470. #endregion
  471. #region MaterialDestination
  472. /// <summary>
  473. /// Enhancements to ADX autogenerated class <seealso cref="MaterialDestination"/>
  474. /// </summary>
  475. [System.ComponentModel.TypeConverter(typeof(MaterialConverter))]
  476. public partial class MaterialDestination
  477. {
  478. public MaterialDestination()
  479. {
  480. this.Description = "";
  481. }
  482. /// <summary>
  483. /// Performs a deep copy of the MaterialDestination.
  484. /// </summary>
  485. /// <returns>Deep copy of the MaterialDestination</returns>
  486. public MaterialDestination Clone()
  487. {
  488. try
  489. {
  490. BinaryFormatter serializer = new BinaryFormatter();
  491. MemoryStream buffer = new MemoryStream();
  492. serializer.Serialize(buffer, this);
  493. buffer.Seek(0, SeekOrigin.Begin);
  494. return serializer.Deserialize(buffer) as MaterialDestination;
  495. }
  496. catch (System.Exception exc)
  497. {
  498. return null;
  499. }
  500. }
  501. public override string ToString()
  502. {
  503. if (this.Mass == null || String.Equals(this.Mass.UOM, Enum.GetName(typeof(PropertyTypeStrict), UOMStrict.Unspecified)))
  504. {
  505. if (String.IsNullOrEmpty(this.Name) && String.IsNullOrEmpty(this.Type))
  506. return "";
  507. if (!String.IsNullOrEmpty(this.Name) && String.IsNullOrEmpty(this.Type))
  508. return this.Name;
  509. if (String.IsNullOrEmpty(this.Name) && !String.IsNullOrEmpty(this.Type))
  510. return this.Type;
  511. return String.Concat(this.Type, " : ", this.Name);
  512. }
  513. else
  514. {
  515. if (String.IsNullOrEmpty(this.Name) && String.IsNullOrEmpty(this.Type))
  516. return this.Mass.ToString();
  517. if (!String.IsNullOrEmpty(this.Name) && String.IsNullOrEmpty(this.Type))
  518. return String.Concat(this.Name, " / ", this.Mass.ToString());
  519. if (String.IsNullOrEmpty(this.Name) && !String.IsNullOrEmpty(this.Type))
  520. return String.Concat(this.Type, " / ", this.Mass.ToString());
  521. return String.Concat(String.Concat(this.Type, " : ", this.Name), " / ", this.Mass.ToString());
  522. }
  523. }
  524. /// <summary>
  525. /// Gets a value indicating whether this instance has a valid material target.
  526. /// </summary>
  527. /// <value>
  528. /// <c>true</c> if this instance is valid target; otherwise, <c>false</c>.
  529. /// </value>
  530. public Boolean IsValidTarget
  531. {
  532. get
  533. {
  534. if (!this.HasTarget)
  535. return true;
  536. if (this.Target.HasProcedure())
  537. {
  538. if (this.Target.HasProcedureName() || this.Target.HasProcessName() || this.Target.HasProtocol())
  539. return false;
  540. }
  541. else if (this.Target.HasProcedureName() || this.Target.HasProcessName() || this.Target.HasProtocol())
  542. {
  543. if (this.Target.HasProcedure())
  544. return false;
  545. }
  546. return true;
  547. }
  548. }
  549. /// <summary>
  550. /// Determines if this destination has a valid target.
  551. /// </summary>
  552. /// <value>
  553. /// <c>true</c> if this destination has target; otherwise, <c>false</c>.
  554. /// </value>
  555. public Boolean HasTarget
  556. {
  557. get
  558. {
  559. if (this.Target == null)
  560. return false;
  561. if (!String.IsNullOrEmpty(this.Target.ProcessRef))
  562. return true;
  563. if (!String.IsNullOrEmpty(this.Target.ProcedureRef))
  564. return true;
  565. if (!String.IsNullOrEmpty(this.Target.MaterialSourceRef))
  566. return true;
  567. if (this.Target.Procedure != null && this.Target.Procedure.Length > 0)
  568. return true;
  569. return false;
  570. }
  571. }
  572. }
  573. /// <summary>
  574. /// TypeConverter to convert a MaterialDestination into a string format.
  575. /// </summary>
  576. public class MaterialConverter : ExpandableObjectConverter
  577. {
  578. public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
  579. {
  580. if (destinationType == typeof(MaterialDestination))
  581. return true;
  582. return base.CanConvertTo(context, destinationType);
  583. }
  584. public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
  585. {
  586. if (destinationType == typeof(System.String) && value is MaterialDestination)
  587. return value.ToString();
  588. return base.ConvertTo(context, culture, value, destinationType);
  589. }
  590. }
  591. #endregion
  592. #region MaterialTarget
  593. /// <summary>
  594. /// Enhancements to ADX autogenerated class <seealso cref="MaterialTarget"/>
  595. /// </summary>
  596. public partial class MaterialTarget
  597. {
  598. public MaterialTarget(MaterialTarget defaultTarget)
  599. {
  600. if (defaultTarget != null)
  601. {
  602. this.ProtocolRef = defaultTarget.ProtocolRef;
  603. this.ProcessRef = defaultTarget.ProcessRef;
  604. this.ProcedureRef = defaultTarget.ProcedureRef;
  605. this.MaterialSourceRef = defaultTarget.MaterialSourceRef;
  606. }
  607. }
  608. public override string ToString()
  609. {
  610. StringBuilder builder = new StringBuilder();
  611. if (this.HasProtocol())
  612. builder.AppendFormat("ProcotolRef = [{0}] ", this.ProtocolRef);
  613. if (this.HasProcessName())
  614. builder.AppendFormat("ProcessRef = [{0}] ", this.ProcessRef);
  615. if (this.HasProcedureName())
  616. builder.AppendFormat("ProcedureRef = [{0}] ", this.ProcedureRef);
  617. if (this.HasProcedure())
  618. builder.AppendFormat("Explicit Procedures ");
  619. return builder.ToString();
  620. }
  621. /// <summary>
  622. /// Determines whether this target has protocol.
  623. /// </summary>
  624. /// <returns>
  625. /// <c>true</c> if this target has protocol; otherwise, <c>false</c>.
  626. /// </returns>
  627. public Boolean HasProtocol()
  628. {
  629. if (!String.IsNullOrEmpty(this.ProtocolRef))
  630. return true;
  631. return false;
  632. }
  633. /// <summary>
  634. /// Determines whether this target has protocol.
  635. /// </summary>
  636. /// <returns>
  637. /// <c>true</c> if this target has protocol; otherwise, <c>false</c>.
  638. /// </returns>
  639. public Boolean HasProcessName()
  640. {
  641. if (!String.IsNullOrEmpty(this.ProcessRef))
  642. return true;
  643. return false;
  644. }
  645. /// <summary>
  646. /// Determines whether this target has a procedure name
  647. /// </summary>
  648. /// <returns>
  649. /// <c>true</c> if this target has a procedure name; otherwise, <c>false</c>.
  650. /// </returns>
  651. public Boolean HasProcedureName()
  652. {
  653. if (!String.IsNullOrEmpty(this.ProcedureRef))
  654. return true;
  655. return false;
  656. }
  657. /// <summary>
  658. /// Determines whether this target has material source name.
  659. /// </summary>
  660. /// <returns>
  661. /// <c>true</c> if this target has material source name; otherwise, <c>false</c>.
  662. /// </returns>
  663. public Boolean HasMaterialSourceName()
  664. {
  665. if (!String.IsNullOrEmpty(this.MaterialSourceRef))
  666. return true;
  667. return false;
  668. }
  669. /// <summary>
  670. /// Determines whether this target has procedure.
  671. /// </summary>
  672. /// <returns>
  673. /// <c>true</c> if this target has a procedure; otherwise, <c>false</c>.
  674. /// </returns>
  675. public Boolean HasProcedure()
  676. {
  677. if (this.Procedure != null && this.Procedure.Length > 0)
  678. foreach(Procedure curProcedure in this.Procedure)
  679. if (curProcedure != null)
  680. return true;
  681. return false;
  682. }
  683. /// <summary>
  684. /// Gets a value indicating whether this target is specified.
  685. /// </summary>
  686. /// <value>
  687. /// <c>true</c> if this target is specified; otherwise, <c>false</c>.
  688. /// </value>
  689. public Boolean IsSpecified
  690. {
  691. get
  692. {
  693. return this.HasProcedure() || this.HasProtocol() || this.HasProcessName() || this.HasProcedureName();
  694. }
  695. }
  696. }
  697. #endregion
  698. #region ProcessingPath
  699. /// <summary>
  700. /// Enhancements to ADX autogenerated class <seealso cref="ProcessingPath"/>
  701. /// </summary>
  702. public partial class ProcessingPath
  703. {
  704. /// <summary>
  705. /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
  706. /// </summary>
  707. /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
  708. /// <returns>
  709. /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
  710. /// </returns>
  711. /// <exception cref="T:System.NullReferenceException">
  712. /// The <paramref name="obj"/> parameter is null.
  713. /// </exception>
  714. public override bool Equals(object obj)
  715. {
  716. if (!(obj is ProcessingPath))
  717. return false;
  718. ProcessingPath other = obj as ProcessingPath;
  719. // Does this processing path have any tags ?
  720. if (this.Tag == null)
  721. {
  722. if (other.Tag == null)
  723. return true;
  724. if (other.Tag.Length == 0)
  725. return true;
  726. return false;
  727. }
  728. // Does the other processing path have any tags ?
  729. if (other.Tag == null)
  730. {
  731. if (this.Tag == null)
  732. return true;
  733. if (this.Tag.Length == 0)
  734. return true;
  735. return false;
  736. }
  737. // Are they the same lengths ?
  738. if (other.Tag.Length != this.Tag.Length)
  739. return false;
  740. // Compare each tag and see if they are the same
  741. for (int i = 0; i < other.Tag.Length; i++)
  742. {
  743. if (this.Tag[i] == null)
  744. {
  745. if (other.Tag[i] != null)
  746. return false;
  747. }
  748. else if (other.Tag[i] == null)
  749. {
  750. if (this.Tag[i] != null)
  751. return false;
  752. }
  753. else
  754. {
  755. if (String.Compare(this.Tag[i].Type == null ? "" : this.Tag[i].Type, other.Tag[i].Type == null ? "" : other.Tag[i].Type) != 0)
  756. return false;
  757. if (String.Compare(this.Tag[i].Name == null ? "" : this.Tag[i].Name, other.Tag[i].Name == null ? "" : other.Tag[i].Name) != 0)
  758. return false;
  759. }
  760. }
  761. return true;
  762. }
  763. /// <summary>
  764. /// Determines whether this processing path is empty.
  765. /// </summary>
  766. /// <returns>
  767. /// <c>true</c> if this processing path is empty; otherwise, <c>false</c>.
  768. /// </returns>
  769. public Boolean IsEmpty()
  770. {
  771. if (this.Tag == null || this.Tag.Length == 0)
  772. return true;
  773. return false;
  774. }
  775. public override string ToString()
  776. {
  777. if (this.Tag == null)
  778. return "";
  779. StringBuilder builder = new StringBuilder();
  780. Boolean addedFirst = false;
  781. foreach(ProcessingTag tag in this.Tag)
  782. {
  783. if (tag == null)
  784. continue;
  785. if (String.IsNullOrEmpty(tag.Name) && String.IsNullOrEmpty(tag.Type))
  786. continue;
  787. if (!String.IsNullOrEmpty(tag.Name) && String.IsNullOrEmpty(tag.Type))
  788. builder.Append(String.Concat((addedFirst ? "," : ""),tag.Name));
  789. else if (String.IsNullOrEmpty(tag.Name) && !String.IsNullOrEmpty(tag.Type))
  790. builder.Append(String.Concat((addedFirst ? "," : ""),tag.Type));
  791. else
  792. builder.Append(String.Concat((addedFirst ? "," : ""),tag.Type, ":", tag.Name));
  793. addedFirst = true;
  794. }
  795. return builder.ToString();
  796. }
  797. }
  798. #endregion
  799. #region ProcessingTag
  800. /// <summary>
  801. /// Enhancements to ADX autogenerated class <seealso cref="ProcessingTag"/>
  802. /// </summary>
  803. public partial class ProcessingTag
  804. {
  805. /// <summary>
  806. /// Checks if the tag equals this name and type
  807. /// </summary>
  808. /// <param name="name">The tag name.</param>
  809. /// <param name="type">The tag type.</param>
  810. /// <returns>True if they are equal; otherwise false</returns>
  811. public Boolean Equals(String name, String type)
  812. {
  813. if (String.IsNullOrEmpty(name) && String.IsNullOrEmpty(type) && String.IsNullOrEmpty(this.Name) && String.IsNullOrEmpty(this.Type))
  814. return true;
  815. if (!String.IsNullOrEmpty(name) && String.IsNullOrEmpty(type) && String.Equals(name,this.Name) && String.IsNullOrEmpty(this.Type))
  816. return true;
  817. if (String.IsNullOrEmpty(name) && !String.IsNullOrEmpty(type) && String.IsNullOrEmpty(this.Name) && String.Equals(type, this.Type))
  818. return true;
  819. if (!String.IsNullOrEmpty(name) && !String.IsNullOrEmpty(type) && String.Equals(name, this.Name) && String.Equals(type, this.Type))
  820. return true;
  821. return false;
  822. }
  823. }
  824. #endregion
  825. #region AnalysisProcedure
  826. /// <summary>
  827. /// Enhancements to ADX autogenerated class <seealso cref="AnalysisProcedure"/>
  828. /// </summary>
  829. public partial class AnalysisProcedure
  830. {
  831. public override string ToString()
  832. {
  833. String assayType = "?";
  834. if (String.Equals(this.Property, Enum.GetName(typeof(PropertyTypeStrict), PropertyTypeStrict.Unspecified)) && this.Code != null && String.Equals(this.UOM, Enum.GetName(typeof(PropertyTypeStrict), UOMStrict.Unspecified)))
  835. assayType = String.Format("{0}_{1}_{2}", this.Property, this.Code, this.UOM);
  836. else if (String.Equals(this.Property, Enum.GetName(typeof(PropertyTypeStrict), PropertyTypeStrict.Unspecified)) && String.Equals(this.UOM, Enum.GetName(typeof(PropertyTypeStrict), UOMStrict.Unspecified)))
  837. assayType = String.Format("{0}_{1}", this.Property, this.UOM);
  838. else if (String.Equals(this.Property, Enum.GetName(typeof(PropertyTypeStrict), PropertyTypeStrict.Unspecified)) && this.Code != null)
  839. assayType = String.Format("{0}_{1}", this.Property, this.Code);
  840. else if (String.Equals(this.Property, Enum.GetName(typeof(PropertyTypeStrict), PropertyTypeStrict.Unspecified)))
  841. assayType = String.Format("{0}", this.Property);
  842. return assayType;
  843. }
  844. }
  845. #endregion
  846. }