public override void ExecuteExtention(MigrateRecordsRequest request, MigrateRecordsResponse response,
                                              ServiceRequestController controller)
        {
            var exportService = new ExportXmlService(new XrmRecordService(request.SourceConnection));

            var exportedEntities = new List <Entity>();

            exportService.ProcessExport(request.RecordTypesToMigrate, request.IncludeNotes, request.IncludeNNRelationshipsBetweenEntities, controller.Controller
                                        , (entity) => exportedEntities.Add(entity)
                                        , (entity) => exportedEntities.Add(entity));

            var removeDuplicates = new List <Entity>();

            foreach (var entity in exportedEntities)
            {
                if (!removeDuplicates.Any(e => e.Id == entity.Id && e.LogicalName == entity.LogicalName))
                {
                    removeDuplicates.Add(entity);
                }
            }

            var importService      = new DataImportService(new XrmRecordService(request.TargetConnection));
            var matchOption        = request.MatchByName ? DataImportService.MatchOption.PrimaryKeyThenName : DataImportService.MatchOption.PrimaryKeyOnly;
            var dataImportResponse = importService.DoImport(removeDuplicates, controller, request.MaskEmails, matchOption: matchOption, includeOwner: request.IncludeOwner);

            response.ConnectionMigratedInto = request.TargetConnection;
            response.LoadDataImport(dataImportResponse);
            response.Message = "The Record Migration Has Completed";
        }
        public void ImportXml(string folder, ServiceRequestController controller,
                              ImportXmlResponse response, bool maskEmails = false, bool includeOwner = false, bool matchByName = true)
        {
            controller.UpdateProgress(0, 1, "Loading XML Files");
            var entities       = LoadEntitiesFromXmlFiles(folder, controller.Controller);
            var matchOption    = matchByName ? DataImportService.MatchOption.PrimaryKeyThenName : DataImportService.MatchOption.PrimaryKeyOnly;
            var importResponse = DataImportService.DoImport(entities, controller, maskEmails, matchOption: matchOption, includeOwner: includeOwner);

            response.LoadDataImport(importResponse);
        }
Exemple #3
0
        public void ImportXml(IImportXmlRequest request, ServiceRequestController controller,
                              ImportXmlResponse response, bool maskEmails = false, bool includeOwner = false, bool matchByName = true, int?executeMultipleSetSize = null, int?targetCacheLimit = null)
        {
            controller.UpdateProgress(0, 1, "Loading XML Files");
            var entities       = request.GetOrLoadEntitiesForImport(controller.Controller).Values.ToArray();
            var matchOption    = matchByName ? MatchOption.PrimaryKeyThenName : MatchOption.PrimaryKeyOnly;
            var importResponse = DataImportService.DoImport(entities, controller, maskEmails, matchOption: matchOption, includeOwner: includeOwner, executeMultipleSetSize: executeMultipleSetSize, targetCacheLimit: targetCacheLimit);

            response.Connection = XrmRecordService.XrmRecordConfiguration;
            response.LoadDataImport(importResponse);
            response.Message = "The Import Process Has Completed";
        }
Exemple #4
0
        public SpreadsheetImportResponse DoImport(Dictionary <IMapSpreadsheetImport, IEnumerable <IRecord> > mappings, bool maskEmails, bool matchByName, bool updateOnly, ServiceRequestController controller, int?executeMultipleSetSize = null, bool useAmericanDates = false, int?targetCacheLimit = null)
        {
            var response      = new SpreadsheetImportResponse();
            var parseResponse = ParseIntoEntities(mappings, useAmericanDates: useAmericanDates);

            response.LoadParseResponse(parseResponse);
            var dataImportService  = new DataImportService(XrmRecordService);
            var matchKeyDictionary = new Dictionary <string, IEnumerable <string> >();

            foreach (var map in mappings.Keys)
            {
                if (map.AltMatchKeys != null && map.AltMatchKeys.Any())
                {
                    if (matchKeyDictionary.ContainsKey(map.TargetType))
                    {
                        throw new NotSupportedException($"Error Type {map.TargetType} Is Defined With Multiple Match Keys");
                    }
                    matchKeyDictionary.Add(map.TargetType, map.AltMatchKeys.Select(mk => mk.TargetField).ToArray());
                }
            }
            response.LoadDataImport(dataImportService.DoImport(parseResponse.GetParsedEntities(), controller, maskEmails, matchOption: matchByName ? MatchOption.PrimaryKeyThenName : MatchOption.PrimaryKeyOnly, loadExistingErrorsIntoSummary: response.ResponseItems, altMatchKeyDictionary: matchKeyDictionary, updateOnly: updateOnly, includeOwner: true, containsExportedConfigFields: false, executeMultipleSetSize: executeMultipleSetSize, targetCacheLimit: targetCacheLimit));
            return(response);
        }