public object Clone() { var newTree = new FactorTree(); foreach (FactorData o in Factors) { newTree.Factors.Add(o); } foreach (FactorDataset data in Data) { newTree.Data.Add(data); } if (DatasetMapping != null) { newTree.DatasetMapping = new long[DatasetMapping.Length]; DatasetMapping.CopyTo(newTree.DatasetMapping, 0); } return(newTree); }
private string TranslateSourceValueForElement(DatasetMapping mapping, string sourceValue) { var formattedValue = sourceValue.Trim(); switch (mapping.MappingType) { case MappingType.FirstClassToElement: case MappingType.AttributeToElement: // Length restriction for alpha numerics if (mapping.DestinationElement.DatasetElement.Field.FieldType.Description == "AlphaNumericTextbox") { var len = mapping.DestinationElement.DatasetElement.Field.MaxLength != null?Convert.ToInt32(mapping.DestinationElement.DatasetElement.Field.MaxLength) : 0; formattedValue = len > 0 ? formattedValue.Length > len?formattedValue.Substring(0, len - 1) : formattedValue : formattedValue; } if (mapping.DestinationElement.DatasetElement.Field.FieldType.Description == "Date") { DateTime tempdt; if (DateTime.TryParse(formattedValue, out tempdt)) { if (!String.IsNullOrWhiteSpace(mapping.MappingOption)) { formattedValue = Convert.ToDateTime(formattedValue) == DateTime.MinValue ? "" : Convert.ToDateTime(formattedValue).ToString(mapping.MappingOption); } } else { formattedValue = ""; } } if (mapping.DestinationElement.DatasetElement.Field.FieldType.Description == "NumericTextbox" && mapping.DestinationElement.DatasetElement.Field.Decimals == 0) { Int32 tempi; formattedValue = Int32.TryParse(formattedValue, out tempi) ? Convert.ToInt32(formattedValue).ToString() : ""; } if (mapping.DestinationElement.DatasetElement.Field.FieldType.Description == "NumericTextbox" && mapping.DestinationElement.DatasetElement.Field.Decimals > 0) { Decimal tempd; formattedValue = Decimal.TryParse(formattedValue, out tempd) ? Convert.ToDecimal(formattedValue).ToString() : ""; } break; case MappingType.ValueToValue: case MappingType.AttributeToValue: case MappingType.FirstClassToValue: // Map value to value var mappedValue = mapping.DatasetMappingValues.SingleOrDefault(mv => mv.SourceValue == sourceValue && mv.Active == true); if (mappedValue != null) { formattedValue = mappedValue.DestinationValue; } else { formattedValue = string.Empty; // didnt find a mapping } break; case MappingType.ElementToElement: // Length restriction for alpha numerics if (mapping.DestinationElement.DatasetElement.Field.FieldType.Description == "AlphaNumericTextbox") { var len = mapping.DestinationElement.DatasetElement.Field.MaxLength != null?Convert.ToInt32(mapping.DestinationElement.DatasetElement.Field.MaxLength) : 0; formattedValue = len > 0 ? formattedValue.Length > len?formattedValue.Substring(0, len - 1) : formattedValue : formattedValue; } if (mapping.DestinationElement.DatasetElement.Field.FieldType.Description == "Date") { DateTime tempdt; if (DateTime.TryParse(formattedValue, out tempdt)) { if (!String.IsNullOrWhiteSpace(mapping.MappingOption)) { formattedValue = Convert.ToDateTime(formattedValue).ToString(mapping.MappingOption); } } else { formattedValue = ""; } } if (mapping.DestinationElement.DatasetElement.Field.FieldType.Description == "NumericTextbox" && mapping.DestinationElement.DatasetElement.Field.Decimals == 0) { Int32 tempi; formattedValue = Int32.TryParse(formattedValue, out tempi) ? Convert.ToInt32(formattedValue).ToString() : ""; } if (mapping.DestinationElement.DatasetElement.Field.FieldType.Description == "NumericTextbox" && mapping.DestinationElement.DatasetElement.Field.Decimals > 0) { Decimal tempd; formattedValue = Decimal.TryParse(formattedValue, out tempd) ? Convert.ToDecimal(formattedValue).ToString() : ""; } break; default: break; } return(formattedValue); }