123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Xml;
- using Wayne.ForecourtControl;
- using Wayne.Lib.IO;
- namespace LSForecourtSimulatorImpl
- {
- /// <summary>
- /// Hardcoded temporary solution!
- /// </summary>
- public class FuelModeAndPriceModeConfig : IForecourtConfiguration
- {
- private readonly IFileSupport fileSupport;
- private XmlDocument xmlDocument;
- public FuelModeAndPriceModeConfig(IFileSupport fileSupport)
- {
- this.fileSupport = fileSupport;
- ReadConfig(@"c:\Wayne\Config\FuelModeConfig\FuelModeConfig.xml");
- }
- public FuelModeAndPriceModeConfig(string configFilePath, IFileSupport fileSupport)
- {
- this.fileSupport = fileSupport;
- ReadConfig(configFilePath);
- }
- private void ReadConfig(string filePath)
- {
- xmlDocument = new XmlDocument();
- fileSupport.LoadXml(xmlDocument, filePath, Encoding.UTF8);
- }
- #region Implementation of IForecourtConfiguration
- public IEnumerable<IPumpConfiguration> Pumps { get; private set; }
- public IEnumerable<ITankConfiguration> Tanks { get; private set; }
- public IEnumerable<ITankSuctionConfiguration> TankSuctions { get; private set; }
- public IEnumerable<IFuelProductConfiguration> Products { get; private set; }
- public IEnumerable<IFuelGradeConfiguration> Grades { get; private set; }
- public IEnumerable<IFuelGradeConfiguration> GetPumpGrades(IDeviceIndex pump)
- {
- throw new NotImplementedException();
- }
- public IEnumerable<ITankMonitorConfiguration> TankMonitors { get; private set; }
- public IEnumerable<IPricePoleConfiguration> PricePoles { get; private set; }
- public IEnumerable<IFuelPrice> Prices { get; private set; }
- /// <summary>
- /// Gets a fuel mode, given the fuelling type and the price group
- /// </summary>
- /// <param name="fuellingType">The fuelling type</param>
- /// <param name="priceGroup">The price group</param>
- public int GetFuelMode(FuellingType fuellingType, PriceGroup priceGroup)
- {
- try
- {
- var configNode =
- xmlDocument.SelectSingleNode(
- string.Concat("/FuelModeConfig/FuellingType_PriceGroup_FuelMode_Mapping/FuellingType[@t='",
- (int)fuellingType, "']/PriceGroup[@g='", (int)priceGroup) + "']");
- var fm = XmlConvert.ToInt32(configNode.InnerText);
- return fm;
- }
- catch (Exception)
- {
- return 1;
- }
- }
- /// <summary>
- /// Gets a post-paid fuel mode, given the price group and the authorized in advance flag
- /// </summary>
- /// <param name="priceGroup">The price group</param>
- /// <param name="authInAdvance">Authorized in advance flag</param>
- public int GetFuelMode(PriceGroup priceGroup, bool authInAdvance)
- {
- try
- {
- var authType = authInAdvance ? "AuthInAdvance" : "NormalAuth";
- var configNode =
- xmlDocument.SelectSingleNode(
- string.Concat("/FuelModeConfig/FuelMode_For_PreAuthorize/" + authType + "/PriceGroup_",
- (int)priceGroup));
- var fm = Convert.ToInt32(configNode.InnerText);
- return fm;
- }
- catch (Exception)
- {
- return 1;
- }
- }
- /// <summary>
- /// Gets a fuel mode, given the fuelling type
- /// </summary>
- /// <param name="fuellingType">The fuelling type</param>
- public int GetFuelMode(FuellingType fuellingType)
- {
- try
- {
- var configNode =
- xmlDocument.SelectSingleNode(
- string.Concat("/FuelModeConfig/FuellingType_PriceGroup_FuelMode_Mapping/FuellingType[@t='",
- (int)fuellingType) + "']/PriceGroup");
- var fm = Convert.ToInt32(configNode.InnerText);
- return fm;
- }
- catch (Exception)
- {
- return 1;
- }
- }
- /// <summary>
- /// Gets the default fuel mode for the given price group
- /// </summary>
- /// <param name="priceGroup">The price group</param>
- public int GetDefaultFuelMode(PriceGroup priceGroup)
- {
- try
- {
- var configNode =
- xmlDocument.SelectSingleNode(string.Concat("/FuelModeConfig/DefaultFuelModeTable/PriceGroup_",
- (int)priceGroup));
- var fm = Convert.ToInt32(configNode.InnerText);
- return fm;
- }
- catch (Exception)
- {
- return 1;
- }
- }
- /// <summary>
- /// Gets a collection of fuel modes, given the price group
- /// </summary>
- /// <param name="priceGroup">The price group</param>
- public IEnumerable<int> GetFuelModes(PriceGroup priceGroup)
- {
- try
- {
- var configNodeList =
- xmlDocument.SelectNodes(
- string.Concat(
- "/FuelModeConfig/FuellingType_PriceGroup_FuelMode_Mapping/FuellingType/PriceGroup[@g='",
- (int)priceGroup) + "']");
- var fmList = new List<int>();
- foreach (XmlNode xn in configNodeList)
- {
- fmList.Add(Convert.ToInt32(xn.InnerText));
- }
- return (fmList);
- }
- catch (Exception)
- {
- return new List<int>();
- }
- }
- /// <summary>
- /// Gets the price group related with the given fuel mode
- /// </summary>
- /// <param name="fuelMode">The fuel mode</param>
- public PriceGroup GetPriceGroup(int fuelMode, FuellingType fuellingType)
- {
- try
- {
- var configNodeList =
- xmlDocument.SelectNodes(
- string.Concat("/FuelModeConfig/FuellingType_PriceGroup_FuelMode_Mapping/FuellingType[@t='", (int)fuellingType, "']/PriceGroup"));
- foreach (XmlNode xn in configNodeList)
- {
- var fm = Convert.ToInt32(xn.InnerText);
- if (fm == fuelMode)
- {
- var pgv = Convert.ToInt32(xn.Attributes["g"].Value);
- var pg = (PriceGroup)pgv;
- return pg; // found first matching fuel mode
- }
- }
- return PriceGroup.Unknown;
- }
- catch (Exception)
- {
- return PriceGroup.Unknown;
- }
- return PriceGroup.Unknown;
- }
- /// <summary>
- /// Gets the price groups related with the given fuel mode
- /// </summary>
- /// <param name="fuelMode">The fuel mode</param>
- public IEnumerable<int> GetPriceGroups(int fuelMode)
- {
- try
- {
- XmlNodeList configNodeList =
- xmlDocument.SelectNodes(
- "/FuelModeConfig/FuellingType_PriceGroup_FuelMode_Mapping/FuellingType/PriceGroup");
- IList<int> pgList = new List<int>();
- foreach (XmlNode xn in configNodeList)
- {
- int fm = Convert.ToInt32(xn.InnerText);
- if (fm == fuelMode)
- {
- var pg = Convert.ToInt32(xn.Attributes["g"].Value);
- pgList.Add(pg);
- }
- }
- return pgList;
- }
- catch (Exception)
- {
- return new List<int>();
- }
- }
- /// <summary>
- /// Gets the fuelling type related with the given fuel mode and price group
- /// </summary>
- /// <param name="fuelMode">fuel mode</param>
- /// <param name="priceGroup">price group</param>
- public FuellingType GetFuellingType(int fuelMode, PriceGroup priceGroup)
- {
- try
- {
- var configNodeList =
- xmlDocument.SelectNodes("/FuelModeConfig/FuellingType_PriceGroup_FuelMode_Mapping/FuellingType");
- foreach (XmlNode xn in configNodeList)
- {
- foreach (XmlElement cn in xn.ChildNodes)
- {
- int fm = Convert.ToInt32(cn.InnerText);
- var pg = Convert.ToInt32(cn.Attributes["g"].Value);
- if (fm == fuelMode && pg == (int)priceGroup)
- {
- var ft = (FuellingType)Convert.ToInt32(xn.Attributes["t"].Value);
- return ft;
- }
- }
- }
- return FuellingType.Unknown;
- }
- catch (Exception)
- {
- return FuellingType.Unknown;
- }
- }
- public bool WriteFuelPrice(int productId, int fuelMode, decimal newPrice)
- {
- return false;
- }
- public event AsyncCompletedEventHandler OnConfigurationChange;
- #endregion
- }
- }
|