private void ImportDataMap() { if (string.IsNullOrWhiteSpace(this.FilePath)) { this.Log.LogError("Required parameter missing: FilePath"); return; } if (!File.Exists(this.FilePath)) { this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "Could not find Data Map file {0}", this.FilePath)); return; } Log.LogMessage(MessageImportance.Normal, string.Format(CultureInfo.CurrentCulture, "Connecting to Organization {0}.", this.OrganizationUrl)); string connectionString = string.Format(CultureInfo.CurrentCulture, "Server={0};Timeout={1}", this.OrganizationUrl, this.ConnectionTimeout); var connection = CrmConnection.Parse(connectionString); var mapText = File.ReadAllText(this.FilePath); using (var serviceContext = new CrmOrganizationServiceContext(connection)) { try { var request = new ImportMappingsImportMapRequest { MappingsXml = mapText, ReplaceIds = true }; if (this.overwrite) { DeleteDataMap(serviceContext, this.Name); } Log.LogMessage(MessageImportance.Normal, string.Format(CultureInfo.CurrentCulture, "Importing Data Map {0}", this.Name)); serviceContext.Execute(request); Log.LogMessage(MessageImportance.Normal, string.Format(CultureInfo.CurrentCulture, "Successfully imported Data Map {0} to organization with Url {1}.", this.Name, this.OrganizationUrl)); } catch (Exception exception) { Log.LogError(string.Format( CultureInfo.CurrentCulture, "An error occurred while importing Data Map {0} to Organization with Url {1}. [{2}]", this.Name, this.OrganizationUrl, exception.Message)); } } }
/// <summary> /// Create a mapping from Xml /// </summary> private void ImportMappingsByXml() { if (string.IsNullOrWhiteSpace(_mappingXml)) { return; } //<snippetImportMappingsImportMap> // Create the import mapping from the XML var request = new ImportMappingsImportMapRequest { MappingsXml = _mappingXml, ReplaceIds = true, }; Console.WriteLine(String.Concat("\nCreating mapping based on XML:\n", _mappingXml)); var response = (ImportMappingsImportMapResponse) _serviceProxy.Execute(request); _newImportMapId = response.ImportMapId; Console.WriteLine(String.Concat("\nNew import mapping created: ", _newImportMapId.Value)); //</snippetImportMappingsImportMap> //<snippetExportMappingsImportMap> // Retrieve the value for validation var exportRequest = new ExportMappingsImportMapRequest { ImportMapId = _newImportMapId.Value, ExportIds = true, }; var exportResponse = (ExportMappingsImportMapResponse)_serviceProxy .Execute(exportRequest); var mappingXml = exportResponse.MappingsXml; Console.WriteLine(String.Concat("\nValidating mapping xml for : ", _newImportMapId.Value, ",\nMappingsXml:\n", mappingXml)); //</snippetExportMappingsImportMap> }
private void ImportDataMap() { if (string.IsNullOrWhiteSpace(this.FilePath)) { this.Log.LogError("Required parameter missing: FilePath"); return; } if (!File.Exists(this.FilePath)) { this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "Could not find Data Map file {0}", this.FilePath)); return; } Log.LogMessage(MessageImportance.Normal, string.Format(CultureInfo.CurrentCulture, "Connecting to Organization {0}.", this.OrganizationUrl)); string connectionString = string.Format(CultureInfo.CurrentCulture, "Server={0};Timeout={1}", this.OrganizationUrl, this.ConnectionTimeout); var connection = CrmConnection.Parse(connectionString); var mapText = File.ReadAllText(this.FilePath); using (var serviceContext = new CrmOrganizationServiceContext(connection)) { try { var request = new ImportMappingsImportMapRequest { MappingsXml = mapText, ReplaceIds = true }; if (this.overwrite) { DeleteDataMap(serviceContext, this.Name); } Log.LogMessage(MessageImportance.Normal, string.Format(CultureInfo.CurrentCulture, "Importing Data Map {0}", this.Name)); serviceContext.Execute(request); Log.LogMessage(MessageImportance.Normal, string.Format(CultureInfo.CurrentCulture, "Successfully imported Data Map {0} to organization with Url {1}.", this.Name, this.OrganizationUrl)); } catch (Exception exception) { Log.LogError(string.Format( CultureInfo.CurrentCulture, "An error occurred while importing Data Map {0} to Organization with Url {1}. [{2}]", this.Name, this.OrganizationUrl, exception.Message)); } } }
/// <summary> /// Create a mapping from Xml /// </summary> private void ImportMappingsByXml() { if (string.IsNullOrWhiteSpace(_mappingXml)) return; //<snippetImportMappingsImportMap> // Create the import mapping from the XML var request = new ImportMappingsImportMapRequest { MappingsXml = _mappingXml, ReplaceIds = true, }; Console.WriteLine(String.Concat("\nCreating mapping based on XML:\n", _mappingXml)); var response = (ImportMappingsImportMapResponse) _serviceProxy.Execute(request); _newImportMapId = response.ImportMapId; Console.WriteLine(String.Concat("\nNew import mapping created: ", _newImportMapId.Value)); //</snippetImportMappingsImportMap> //<snippetExportMappingsImportMap> // Retrieve the value for validation var exportRequest = new ExportMappingsImportMapRequest { ImportMapId = _newImportMapId.Value, ExportIds = true, }; var exportResponse = (ExportMappingsImportMapResponse)_serviceProxy .Execute(exportRequest); var mappingXml = exportResponse.MappingsXml; Console.WriteLine(String.Concat("\nValidating mapping xml for : ", _newImportMapId.Value, ",\nMappingsXml:\n", mappingXml)); //</snippetExportMappingsImportMap> }