ConfigurationSetExtensions.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Wayne.ForecourtControl.Fusion.ReadDeviceStatus;
  5. using Wayne.Lib;
  6. namespace Wayne.ForecourtControl.Fusion
  7. {
  8. public static class ConfigurationSetExtensions
  9. {
  10. /// <summary>
  11. /// Returns a list of pump numbers from the given configuration set
  12. /// </summary>
  13. /// <param name="configurationSet"></param>
  14. /// <returns></returns>
  15. public static int[] PumpNumbers(this ConfigurationSet configurationSet)
  16. {
  17. return configurationSet.DspConfiguration.FDCdata.
  18. WhereNotNull()
  19. .SelectMany(x => x.DeviceClass.WhereNotNull())
  20. .Select(x => Strings.ParseInt(x.DeviceID))
  21. .Where(x => x.HasValue)
  22. .Select(x => x.Value)
  23. .ToArray();
  24. }
  25. /// <summary>
  26. /// Returns an array of strings the denormalized nozzle information
  27. /// containing pumpnumber|nozzlenumber|productnumber|Tank1|Tank2 from the given configurationset.
  28. /// </summary>
  29. /// <param name="configurationSet"></param>
  30. /// <returns></returns>
  31. public static IEnumerable<string> NozzleSetup(this ConfigurationSet configurationSet)
  32. {
  33. foreach (var deviceClassDsp in configurationSet.DspConfiguration.FDCdata
  34. .WhereNotNull()
  35. .SelectMany(x => x.DeviceClass.WhereNotNull()))
  36. {
  37. foreach (var deviceClassFp in deviceClassDsp.DeviceClass.WhereNotNull())
  38. {
  39. foreach (var nozzle in deviceClassFp.FPNozzle.WhereNotNull())
  40. {
  41. foreach (var product in nozzle.FPProductId)
  42. {
  43. yield return string.Join("|",
  44. new []{deviceClassDsp.DeviceID,
  45. nozzle.FPNozzleNo,
  46. product.PIFPProductNo,
  47. product.PIFPTankNo1,
  48. product.PIFPTankNo2});
  49. }
  50. }
  51. }
  52. }
  53. }
  54. /// <summary>
  55. /// Returns an enumerable of the product numbers in the supplied configuration set.
  56. /// </summary>
  57. /// <param name="configurationSet"></param>
  58. /// <returns></returns>
  59. public static IEnumerable<int> ProductNumbers(this ConfigurationSet configurationSet)
  60. {
  61. return configurationSet.ProductTable.FDCdata
  62. .WhereNotNull()
  63. .SelectMany(x => x.FuelProducts.WhereNotNull())
  64. .SelectMany(x => x.Product.WhereNotNull())
  65. .Select(x => Strings.ParseInt(x.ProductNo))
  66. .Where(x => x.HasValue)
  67. .Select(x => x.Value)
  68. .ToArray();
  69. }
  70. }
  71. }