internal static List <Guid> executeAttachmentsCopyBasedMasterEntity(CrmServiceClient crmSource, CrmServiceClient crmTarget, string datafilePath, bool includeNotes, string logPath, out int webFilesCount) { List <Guid> result = new List <Guid>(); webFilesCount = 0; DataEntities entities = IOHelper.DeserializeXmlFromFile <DataEntities>(datafilePath); //web files foreach (DataEntity de in entities.entities) { webFilesCount += de.RecordsCollection.Count; //get attachment per entity record, files only, get lates foreach (Record rec in de.RecordsCollection) { Entity latestAttacnment = CrmHelper.getLattestAttachmentByEntity(crmSource, new Guid(rec.id), de.name, includeNotes); if (ReferenceEquals(latestAttacnment, null)) { continue; } //check is target has same entity Entity targetMaster = crmTarget.Retrieve(de.name, new Guid(rec.id), new ColumnSet()); if (ReferenceEquals(targetMaster, null)) { continue; } //copy to target try { Guid?newNote = CrmHelper.cloneAnnotation(crmTarget, latestAttacnment); if (newNote.HasValue) { result.Add(newNote.Value); } } catch (Exception ex) { IOHelper.appendLogFile(logPath, ex.Message); continue; } } } return(result); }