/// <summary> /// Transforms to target object. /// </summary> /// <param name="itemId">The item</param> /// <returns></returns> private IMatchDuplicateProvider GetDuplicateProvider(string itemId) { IImportHistoryItem item = Sage.Platform.EntityFactory.GetById <IImportHistoryItem>(itemId); IImportHistory importHistory = Sage.Platform.EntityFactory.GetById <IImportHistory>(item.ImportHistoryId); ImportTemplateManager templateManager = new ImportTemplateManager(importHistory.Data, Type.GetType(importHistory.EntityType)); ImportCSVOptions csvOptions = new ImportCSVOptions(); templateManager.LoadImportSourceOptions(csvOptions); StringBuilder sb = new StringBuilder(); if (csvOptions.FirstRowColHeader) { string colheader = string.Empty; int lastColIndex = templateManager.SourceProperties.Count; int index = 0; foreach (ImportSourceProperty sp in templateManager.SourceProperties) { index++; colheader = colheader + Convert.ToString(csvOptions.Qualifier) + sp.FieldName + Convert.ToString(csvOptions.Qualifier); if (lastColIndex != index) { colheader = colheader + Convert.ToString(csvOptions.Delimiter); } } sb.AppendLine(colheader); } sb.AppendLine(item.Data); ImportCSVReader sourceReader = GetCSVReader(sb.ToString()); sourceReader.Options = csvOptions; ImportTransformationManager transformationManager = new ImportTransformationManager(templateManager.EntityManager.EntityType, templateManager.ImportMaps, templateManager.TargetPropertyDefaults); //Calculated properties? transformationManager.TransformationProvider = new ImportTransformationProvider(); sourceReader.MoveToNext(); object targetEntityObj = Sage.Platform.EntityFactory.Create(templateManager.EntityManager.EntityType); transformationManager.FillEntity(sourceReader.CurrentRecord, targetEntityObj); //Need to make this more generic IMatchDuplicateProvider dupProvider = new LeadDuplicateProvider(); dupProvider.AdvancedOptions = templateManager.MatchAdvancedOptions; dupProvider.AdvancedOptions.AutoMerge = false; foreach (string filter in templateManager.MatchFilters) { dupProvider.SetActiveFilter(filter, true); } MatchEntitySource entitySource = new MatchEntitySource(templateManager.EntityManager.EntityType, targetEntityObj); dupProvider.EntitySource = entitySource; return(dupProvider); }
/// <summary> /// Loads the source snapshot. /// </summary> /// <param name="source">The source.</param> private void LoadSourceSnapshot(MatchEntitySource source) { if (source.EntityData != null && source.EntityType == typeof(IContact)) { IContact contact = source.EntityData as IContact; if (!String.IsNullOrEmpty(contact.LastName)) { lblContact.Text = String.Format("{0}, {1}", contact.LastName, contact.FirstName); } else { lblContact.Text = contact.FirstName; } lblValueAccount.Text = contact.Account.AccountName; if (contact.Address != null) { lblAddress.Text = contact.Address.FormatFullAddress(); } lblValueEmail.Text = contact.Email; lblValueTitle.Text = contact.Title; phnWorkPhone.Text = contact.WorkPhone; lblValueWeb.Text = contact.WebAddress; } }
/// <summary> /// Loads the source snapshot. /// </summary> /// <param name="source">The source.</param> private void LoadSourceSnapshot(MatchEntitySource source) { if (source.EntityData != null && source.EntityType == typeof(IContact)) { IContact contact = source.EntityData as IContact; if (!String.IsNullOrEmpty(contact.LastName)) { lblContact.Text = String.Format("{0}, {1}", contact.LastName, contact.FirstName); } else { lblContact.Text = contact.FirstName; } lblValueAccount.Text = contact.Account.AccountName; if (contact.Address != null) lblAddress.Text = contact.Address.FormatFullAddress(); lblValueEmail.Text = contact.Email; lblValueTitle.Text = contact.Title; phnWorkPhone.Text = contact.WorkPhone; lblValueWeb.Text = contact.WebAddress; } }
/// <summary> /// Transforms to target object. /// </summary> /// <param name="itemId">The item</param> /// <returns></returns> private IMatchDuplicateProvider GetDuplicateProvider(string itemId) { IImportHistoryItem item = Sage.Platform.EntityFactory.GetById<IImportHistoryItem>(itemId); IImportHistory importHistory = Sage.Platform.EntityFactory.GetById<IImportHistory>(item.ImportHistoryId); ImportTemplateManager templateManager = new ImportTemplateManager(importHistory.Data, Type.GetType(importHistory.EntityType)); ImportCSVOptions csvOptions = new ImportCSVOptions(); templateManager.LoadImportSourceOptions(csvOptions); StringBuilder sb = new StringBuilder(); if (csvOptions.FirstRowColHeader) { string colheader = string.Empty; int lastColIndex = templateManager.SourceProperties.Count; int index = 0; foreach (ImportSourceProperty sp in templateManager.SourceProperties) { index++; colheader = colheader + Convert.ToString(csvOptions.Qualifier) + sp.FieldName + Convert.ToString(csvOptions.Qualifier); if (lastColIndex != index) { colheader = colheader + Convert.ToString(csvOptions.Delimiter); } } sb.AppendLine(colheader); } sb.AppendLine(item.Data); ImportCSVReader sourceReader = GetCSVReader(sb.ToString()); sourceReader.Options = csvOptions; ImportTransformationManager transformationManager = new ImportTransformationManager(templateManager.EntityManager.EntityType, templateManager.ImportMaps, templateManager.TargetPropertyDefaults); //Calculated properties? transformationManager.TransformationProvider = new ImportTransformationProvider(); sourceReader.MoveToNext(); object targetEntityObj = Sage.Platform.EntityFactory.Create(templateManager.EntityManager.EntityType); transformationManager.FillEntity(sourceReader.CurrentRecord, targetEntityObj); //Need to make this more generic IMatchDuplicateProvider dupProvider = new LeadDuplicateProvider(); dupProvider.AdvancedOptions = templateManager.MatchAdvancedOptions; dupProvider.AdvancedOptions.AutoMerge = false; foreach (string filter in templateManager.MatchFilters) { dupProvider.SetActiveFilter(filter, true); } MatchEntitySource entitySource = new MatchEntitySource(templateManager.EntityManager.EntityType, targetEntityObj); dupProvider.EntitySource = entitySource; return dupProvider; }
/// <summary> /// Merges the record. /// </summary> /// <param name="targetId">The target id.</param> /// <param name="targetType">Type of the target.</param> private void MergeRecord(string targetId, string targetType) { Type tType = null; object tValue = null; if (targetType.Equals("Lead")) { tType = typeof(ILead); tValue = EntityFactory.GetById<ILead>(targetId); } if (targetType.Equals("Contact")) { tType = typeof(IContact); tValue = EntityFactory.GetById<IContact>(targetId); } MatchEntitySource target = new MatchEntitySource(tType, tValue); if (DuplicateProvider == null) return; MatchEntitySource source = DuplicateProvider.EntitySource; if (source.EntityType != typeof (ILead)) return; LeadMergeProvider mergeProvider = new LeadMergeProvider(target.EntityType) {Source = source, Target = target}; Page.Session["mergeProvider"] = mergeProvider; IList<MergeRecordView> mergeView = mergeProvider.GetMergeView(); grdMerge.DataSource = mergeView; grdMerge.DataBind(); }
protected void Page_Init(object sender, EventArgs e) { if (DialogService.DialogParameters.ContainsKey("selectionContextKey")) { if (!DialogService.DialogParameters.ContainsKey("MergeProvider")) { Type type = EntityService.EntityType; string key = DialogService.DialogParameters["selectionContextKey"].ToString(); ISelectionService srv = SelectionServiceRequest.GetSelectionService(); ISelectionContext selectionContext = srv.GetSelectionContext(key); IList<string> list = selectionContext.GetSelectedIds(); object source = GetEntity(type, list[0]); object target = GetEntity(type, list[1]); MergeProvider mergeProvider = new MergeProvider(type, type); MatchEntitySource targetEntity = new MatchEntitySource(type, target, list[1]); MatchEntitySource sourceEntity = new MatchEntitySource(type, source, list[0]); mergeProvider.Source = sourceEntity; mergeProvider.Target = targetEntity; //Verify the user has read write permissions for every property in the configuration mappings. ValidateUserSecurity(mergeProvider); SessionMergeProvider = mergeProvider; IList<MergeRecordView> mergeView = mergeProvider.GetMergeView(); grdMerge.DataSource = mergeView; grdMerge.DataBind(); DialogService.DialogParameters.Remove("MergeProvider"); DialogService.DialogParameters.Add("MergeProvider", mergeProvider); } else { SessionMergeProvider = DialogService.DialogParameters["MergeProvider"] as MergeProvider; } } }