public static void MapToSegment(A14FTSegment segment, RawSegment rawSegment) { var a14ftValue = rawSegment.SegmentString .Replace("A14FT-", string.Empty); if (a14ftValue.StartsWith("IdCliente-")) { segment.ClientId = a14ftValue.Replace("IdCliente-", string.Empty); } if (a14ftValue.StartsWith("IdUsuario-")) { segment.UserId = a14ftValue.Replace("IdUsuario-", string.Empty); } if (a14ftValue.StartsWith("FormaPago-")) { segment.InvoicePaymentMethod = a14ftValue.Replace("FormaPago-", string.Empty); } if (a14ftValue.StartsWith("MetodoPago-")) { segment.InvoicePaymentType = a14ftValue.Replace("MetodoPago-", string.Empty); } if (a14ftValue.StartsWith("TipoDocumento-")) { segment.InvoiceTypeId = a14ftValue.Replace("TipoDocumento-", string.Empty); } if (a14ftValue.StartsWith("UsoCFDI-")) { segment.InvoiceUseTypeId = a14ftValue.Replace("UsoCFDI-", string.Empty); } if (a14ftValue.StartsWith("TipoDocumento-")) { segment.InvoiceTypeId = a14ftValue.Replace("TipoDocumento-", string.Empty); } if (a14ftValue.StartsWith("CargoServicio-")) { var cargo = a14ftValue.Replace("CargoServicio-", string.Empty); segment.InvoiceServiceAmounts.Add(cargo); } if (a14ftValue.StartsWith("Concepto-")) { var concepto = a14ftValue.Replace("Concepto-", string.Empty); segment.InvoiceLines.Add(concepto); } if (a14ftValue.StartsWith("FtMarkup-")) { var ftMarkup = a14ftValue.Replace("FtMarkup-", string.Empty); segment.FtMarkups.Add(ftMarkup); } }
private static BaseSegment GenerateGeneralSegment(RawSegment rawStringSegment) { BaseSegment segmentInstance = null; Type segmentTypeDefinition = null; var rawSegment = rawStringSegment.SegmentString; switch (rawStringSegment.SegmentType) { case SegmentType.Header: segmentInstance = new HeaderSegment(); segmentTypeDefinition = typeof(HeaderFieldDefinition); break; case SegmentType.CustomerRemarks: segmentInstance = new CustomerRemarkSegment(); segmentTypeDefinition = typeof(CustomerRemarkFieldDefinition); break; case SegmentType.Passenger: segmentInstance = new PassengerSegment(); segmentTypeDefinition = typeof(PassengerFieldDefinition); break; case SegmentType.FareValue: segmentInstance = new FareValueSegment(); segmentTypeDefinition = typeof(FareValueFieldDefinition); break; case SegmentType.A16Hotel: segmentInstance = new A16HotelSegment(); segmentTypeDefinition = typeof(HotelFieldDefinition); break; case SegmentType.A16Car: segmentInstance = new A16CarSegment(); segmentTypeDefinition = typeof(CarFieldDefinition); break; default: return(null); } var previousSegmentPropIsNotPresent = false; var rawSegmentLastPosition = 0; var segmentProperties = PropertiesService.GetDynamicProperties(segmentInstance); var segmentDMLPropertyValues = PropertiesService.GetDynamicPropertyValues(segmentTypeDefinition); foreach (var segmentProperty in segmentProperties) { if (previousSegmentPropIsNotPresent) { previousSegmentPropIsNotPresent = false; continue; } var parentSegmentPropName = segmentProperty.Name.Contains("_") ? segmentProperty.Name.Split("_").First() : segmentProperty.Name; var childSegmentPropName = segmentProperty.Name.Contains("_") ? segmentProperty.Name.Split("_").Last() : string.Empty; var dmlPropValue = segmentDMLPropertyValues.FirstOrDefault(pv => pv.Name.StartsWith(parentSegmentPropName)); if (dmlPropValue != null) { var segmentPropValue = ""; var fieldDefinition = dmlPropValue.Value as FieldDefinition; if (fieldDefinition.HasNestedFields && !string.IsNullOrEmpty(childSegmentPropName)) { var childFieldDefinition = fieldDefinition.NestedFields.FirstOrDefault(_ => _.Name == childSegmentPropName); if (childFieldDefinition != null) { fieldDefinition = childFieldDefinition; } else { continue; } } if (fieldDefinition.IsComplexField && fieldDefinition.HasCodeId) { var segmentChunks = rawSegment.Split("|"); var complexField = string.Empty; if (fieldDefinition.IsOptionalContained) { complexField = segmentChunks .FirstOrDefault(_ => _ .StartsWith(fieldDefinition.CodeId) ); if (!complexField.IsNullOrEmpty()) { segmentPropValue = complexField .Replace(fieldDefinition.CodeId, string.Empty) .Substring(fieldDefinition.SegmentPosition); } } else { foreach (var chunk in segmentChunks) { var optionalDelimitedChunks = chunk.Split(fieldDefinition.Delimitator); complexField = optionalDelimitedChunks .FirstOrDefault(_ => _ .Contains(fieldDefinition.CodeId) ); if (!complexField.IsNullOrEmpty()) { complexField = complexField .Replace(fieldDefinition.CodeId, string.Empty); if (fieldDefinition.IsNestedDelimitatorDriven) { complexField = complexField.Split(fieldDefinition.NestedDelimitator).First(); complexField = complexField.Substring(0, complexField.Length - fieldDefinition.CropIndex); } segmentPropValue = complexField; break; } } } } else { var rawSegmentStartPosition = GetRawSegmentStartPosition(fieldDefinition, rawSegmentLastPosition); rawSegmentLastPosition = rawSegmentStartPosition + fieldDefinition.Length; if (rawSegment.Length >= rawSegmentLastPosition) { var propValue = rawSegment.Substring(rawSegmentStartPosition, fieldDefinition.Length); if (fieldDefinition.IsOptionalField) { if (fieldDefinition.HasCodeId) { if (string.IsNullOrEmpty(fieldDefinition.CodeId) || propValue != fieldDefinition.CodeId) { rawSegmentLastPosition = rawSegmentStartPosition; previousSegmentPropIsNotPresent = true; continue; } } } segmentPropValue = propValue; } } SetPropertyValue(segmentInstance, segmentProperty, segmentPropValue); } } return(segmentInstance); }