private void GenerateFieldMappings(CancellationToken cancel, IProgress <ExecutionProgress> progress) { progress?.Report(new ExecutionProgress(NotificationType.Information, Properties.Resources.Dynamics365FieldOperationGenerateMappingsReadingDataSourceFields)); List <DataTableField> sourceFields = DataTableField.GetDataTableFields(DataSource?.GetDataColumns()); cancel.ThrowIfCancellationRequested(); progress?.Report(new ExecutionProgress(NotificationType.Information, Properties.Resources.Dynamics365FieldOperationGenerateMappingsReadingEntityFields)); List <Field> destinationFields = Entity.GetFields(Connection).Where(field => ((Dynamics365Field)field).CanUpdate || ((Dynamics365Field)field).CanCreate).ToList(); cancel.ThrowIfCancellationRequested(); values?.Clear(); foreach (DataTableField sourceField in sourceFields) { // Formats to match: // fieldLogicalName // entityLogicalName.fieldLogicalName // entityLogicalName.fieldLogicalName.Identifier // entityLogicalName.fieldLogicalName.Code // FieldDisplayName // FieldDisplayName (<other text>) // FieldDisplayName (Identifier) // FieldDisplayName (Code) string strippedColumnName = sourceField.ColumnName; if (strippedColumnName.EndsWith(".Identifier") || strippedColumnName.EndsWith(".Code")) { strippedColumnName = strippedColumnName.Substring(0, strippedColumnName.LastIndexOf(".")); } else if (strippedColumnName.EndsWith(" (Identifier)") || strippedColumnName.EndsWith(" (Code)")) { strippedColumnName = strippedColumnName.Substring(0, strippedColumnName.LastIndexOf(" ")); } // todo - also add option set support if just name is supplied Dynamics365Field destinationField = (Dynamics365Field)destinationFields.Find(field => strippedColumnName == ((Dynamics365Field)field).LogicalName || strippedColumnName == string.Concat(((Dynamics365Field)field).EntityLogicalName, ".", ((Dynamics365Field)field).LogicalName) || strippedColumnName == ((Dynamics365Field)field).DisplayName); if (destinationField != default(Dynamics365Field)) { // todo - use other fields ('name', 'entity') to correct set target and possibly create lookup data field values.Add(new Dynamics365DataSourceValue(this) { DestinationField = destinationField, SourceField = sourceField }); } cancel.ThrowIfCancellationRequested(); } progress?.Report(new ExecutionProgress(NotificationType.Information, string.Format(Properties.Resources.Dynamics365FieldOperationGenerateMappingsSuccessful, values.Count))); }
public virtual List <DataTableField> GetDataSourceFields() { List <DataTableField> fields = new List <DataTableField>(); try { fields.AddRange(DataTableField.GetDataTableFields(DataSource?.GetDataColumns())); } catch { } return(fields); }
/// <summary> /// /// </summary> /// <returns></returns> public List <DataTableField> GetDataSourceFields() { return(DataTableField.GetDataTableFields(DataSource?.GetDataColumns())); }