1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- namespace VeederRoot_ATG_Console.MessageEntity.Incoming
- {
- /// <summary>
- /// i|I602
- /// </summary>
- public class QueryOrSetTankProductLabelResponse : IncomingMessageBase
- {
- public DateTime? CurrentDateAndTime
- {
- get
- {
- if (base.FunctionCode.Item1 == MessageFormat.Display)
- return null;
- return DateTime.ParseExact(
- Encoding.ASCII.GetString(base.DataFieldAndOptionalCheckSumAndETX.Take(10).ToArray()),
- "yyMMddHHmm", CultureInfo.InvariantCulture);
- }
- }
- public int? TankNumberInFunctionCode
- {
- get
- {
- if (base.FunctionCode.Item1 == MessageFormat.Display)
- return null;
- var r = int.Parse(base.FunctionCode.Item3);
- return r;
- }
- }
- /// <summary>
- /// Get pairs of TankNumber:ProductLabel
- /// </summary>
- public IEnumerable<Tuple<int, string>> ProductLabels
- {
- get
- {
- if (base.FunctionCode.Item1 == MessageFormat.Display)
- return null;
- var result = new List<Tuple<int, string>>();
- int elapsed = 10;
- while (true)
- {
- if (base.DataFieldAndOptionalCheckSumAndETX.Skip(elapsed).Count() < 22) break;
- var target = base.DataFieldAndOptionalCheckSumAndETX.Skip(elapsed).Take(22).ToArray();
- var tankNumber = int.Parse(Encoding.ASCII.GetString(target.Take(2).ToArray()));
- var label = Encoding.ASCII.GetString(target.Skip(2).Take(20).ToArray());
- elapsed += 22;
- result.Add(new Tuple<int, string>(tankNumber, label));
- }
- return result;
- }
- }
- public override string ToLogString()
- {
- if (base.FunctionCode.Item1 == MessageFormat.Display)
- return Encoding.ASCII.GetString(base.DataFieldAndOptionalCheckSumAndETX.ToArray());
- return "Current DateTime: " + this.CurrentDateAndTime.Value.ToString("yyyy-MM-dd HH:mm")
- + ", TankNumberInFunctionCode: " + this.TankNumberInFunctionCode.Value
- + " with ProductLabel list(tankNumber:ProductLabel)-> "
- + (this.ProductLabels != null && this.ProductLabels.Any() ?
- this.ProductLabels.Select(p => p.Item1 + ":" + p.Item2).Aggregate((acc, n) => acc + ", " + n)
- : "");
- }
- }
- }
|