public SiusDataMessage Parse(RawMessage rawMessage) { if (!rawMessage.IsResponsible(Identifier, ValueCount)) return null; string[] valueList = rawMessage.Values.ToArray(); SuccessHelper allOverSuccess = new SuccessHelper(); int laneId = ValueAccessHelper.GetInt(valueList, LaneId, allOverSuccess); int laneNumber = ValueAccessHelper.GetInt(valueList, LaneNumber, allOverSuccess); int shooterId = ValueAccessHelper.GetInt(valueList, ShooterId, allOverSuccess); DateTime timstamp = ValueAccessHelper.GetDateTime(valueList, DateTime, allOverSuccess); int shotType = ValueAccessHelper.GetInt(valueList, ShotType, allOverSuccess); decimal primaryScore = ValueAccessHelper.GetDecimal(valueList, PrimaryScore, allOverSuccess); decimal secondaryScore = ValueAccessHelper.GetDecimal(valueList, SecondaryScore, allOverSuccess); int shotNbr = ValueAccessHelper.GetInt(valueList, ShotNbr, allOverSuccess); //float x = ValueAccessHelper.GetFloat(valueList, X, allOverSuccess); //float y = ValueAccessHelper.GetFloat(valueList, Y, allOverSuccess); int programNumber = ValueAccessHelper.GetInt(valueList, ProgramNumber, allOverSuccess); if (!allOverSuccess.Success) return null; SiusDataMessage message = null; switch (shotType) { case 2: message = _messageFactory.MakeBestShotMessage(shooterId, laneId, laneNumber, timstamp, primaryScore, secondaryScore, shotNbr, programNumber); break; case 3: message = _messageFactory.MakeShotMessage(shooterId, laneId, laneNumber, timstamp, primaryScore, secondaryScore, shotNbr, programNumber); break; } return message; }
public List<SiusDataMessage> Parse(string source) { List<SiusDataMessage> messages = new List<SiusDataMessage>(); string[] stringList = source.Split(new[] { "\r\n" }, StringSplitOptions.None); if (stringList.Length > 0) { foreach (string s in stringList) { string[] values = s.Split(new[] { ';' }, StringSplitOptions.None); if (values.Length > 1) { string key = values[0]; List<string> valueList = Enumerable.Range(1, values.Length - 1).Select(_ => values[_]).ToList(); RawMessage rawMessage = new RawMessage {Identifier = key, Values = valueList}; foreach (IMessageParser parser in _messageParser) { SiusDataMessage message = parser.Parse(rawMessage); if (message != null) messages.Add(message); } } } } return messages; }
public SiusDataMessage Parse(RawMessage rawMessage) { if (!rawMessage.IsResponsible(Identifier, ValueCount)) return null; string[] valueList = rawMessage.Values.ToArray(); SuccessHelper allOverSuccess = new SuccessHelper(); int shooterNumber = ValueAccessHelper.GetInt(valueList, ShooterNumber, allOverSuccess); int laneId = ValueAccessHelper.GetInt(valueList, LaneId, allOverSuccess); int laneNumber = ValueAccessHelper.GetInt(valueList, LaneNumber, allOverSuccess); DateTime timestamp = ValueAccessHelper.GetDateTime(valueList, Timestamp, allOverSuccess); if (!allOverSuccess.Success) return null; return _messageFactory.MakePrchMessage(shooterNumber, laneId, laneNumber, timestamp); }
public SiusDataMessage Parse(RawMessage rawMessage) { if (!rawMessage.IsResponsible(Identifier, ValueCount)) return null; string[] valueList = rawMessage.Values.ToArray(); SuccessHelper allOverSuccess = new SuccessHelper(); int laneId = ValueAccessHelper.GetInt(valueList, LaneId, allOverSuccess); int laneNbr = ValueAccessHelper.GetInt(valueList, LaneNbr, allOverSuccess); int shooterId = ValueAccessHelper.GetInt(valueList, ShooterId, allOverSuccess); int primaryScore = ValueAccessHelper.GetInt(valueList, PrimaryScore, allOverSuccess); int secondaryScore = ValueAccessHelper.GetInt(valueList, SecondaryScore, allOverSuccess); DateTime timestamp = ValueAccessHelper.GetDateTime(valueList, Timestamp, allOverSuccess); if (!allOverSuccess.Success) return null; return _messageFactory.MakeTotalMessage(shooterId, laneId, timestamp, primaryScore, secondaryScore); }
public static bool IsResponsible(this RawMessage rawMessage, string identifier, int valueCount) { return(rawMessage.Identifier == identifier && (rawMessage.Values.Count() == valueCount || valueCount == -1)); }