private void SetValues(NetworkPackage networkPackage, List <NetworkPackageValue> values, byte[] bytes) { foreach (NetworkPackageValue value in values) { dynamic converter = GetConverter(value.Type); if (converter != null) { if (value.ByteCount <= 1) { networkPackage[value.Name] = ConvertToByte(converter, bytes[value.RowNumber - 1]); } else { SetByteArrayValues(value, bytes, converter); } } } }
public NetworkPackage Generate(byte[] bytes) { PackageHelpers packageHelpers = new PackageHelpers(); NetworkPackage networkPackage = NetworkPackages.FirstOrDefault(); if (networkPackage != null) { int rowIndex = networkPackage.Type.RowNumber - 1; if (bytes.Count() >= rowIndex) { byte type = bytes[rowIndex]; networkPackage = NetworkPackages.Where(x => x.Type.Value == type).FirstOrDefault(); List <NetworkPackageValue> values = packageHelpers.GetNetworkPackageValues(networkPackage); SetValues(networkPackage, values, bytes); } } return(networkPackage); }
public void AddPackage(NetworkPackage networkPackage) { // yeni eklenen tipin özellikleri öncekiler ile farklı ise hata ver NetworkPackages.Add(networkPackage); }