public void LoadTargetSecurityReferenceData() { var targetDataLoader = new DataLoader(OrganizationService); // load metadata for all Logger?.Invoke(this, "\r\nLoading Metadata, Business Units and Teams from target systems..."); EntityCollection targetSystemUsers = null; EntityCollection targetOrgInstanceInfo = null; EntityCollection targetBUInfo = null; // load all the system reference data from target Parallel.Invoke( () => TargetEntitiesMetaData = targetDataLoader.GetAllEntitiesMetaData(EntityFilters.Entity), () => targetOrgInstanceInfo = targetDataLoader.GetAllEntity(Constant.Organization.EntityLogicalName, new[] { Constant.Organization.Name }), () => targetBUInfo = targetDataLoader.GetAllEntity(Constant.BusinessUnit.EntityLogicalName, new[] { Constant.BusinessUnit.Name }, LogicalOperator.And, new[] { new ConditionExpression(Constant.BusinessUnit.ParentBusinessUnitId, ConditionOperator.Null) }), () => targetSystemUsers = targetDataLoader.GetAllEntity(Constant.User.EntityLogicalName, new[] { Constant.User.DomainName }, LogicalOperator.And, new[] { new ConditionExpression(Constant.User.DomainName, ConditionOperator.Equal, CrmParameter.UserName) }) ); Logger?.Invoke(this, "\r\nPreparing data replacement for Target Organization Info..."); _transformData.SetOrganizationId(targetOrgInstanceInfo); // replace BU constant _transformData.ReplaceBUConstant(targetBUInfo); // root BU must be mapped before import can proceed _transformData.SetSourceAndTargetRootBusinessUnitMapping(); Logger?.Invoke(this, "\r\nPreparing data replacement for System Administrator..."); // Important note: if the SysAdmin is already set for Team.AdministratorId using the transform config then // this method will NOT override the value set by the Transforms _transformData.SetSystemAdministrator(targetSystemUsers, CrmParameter.UserName); Logger?.Invoke(this, "\r\nPreparing FetchXML replacements for Target Organization..."); _transformData.ReplaceFetchXMLEntries(targetDataLoader); }
private bool AddTransformsForEntity(EntityCollection fetchXmlQueryData) { var targetDataLoader = new DataLoader(OrganizationService); var entityName = fetchXmlQueryData.Entities[0].LogicalName; switch (entityName) { case Constant.BusinessUnit.EntityLogicalName: Logger?.Invoke(this, "\r\nPreparing data replacement for Business Units..."); var targetBusinessUnits = targetDataLoader.GetAllEntity(Constant.BusinessUnit.EntityLogicalName, new[] { Constant.BusinessUnit.Name, Constant.BusinessUnit.ParentBusinessUnitId }); _transformData.PopulateBusinessUnitTransforms(fetchXmlQueryData, targetBusinessUnits); break; case Constant.Role.EntityLogicalName: // Note: Alternate key for Security role is "Business Unit Name + Security Role Name" Logger?.Invoke(this, "\r\nPreparing data replacement for Security Roles..."); var targetSecurityRoles = targetDataLoader.GetAllEntity(Constant.Role.EntityLogicalName, new[] { Constant.Role.Name, Constant.Role.BusinessUnitId }); _transformData.PopulateSecurityRoleTransforms(fetchXmlQueryData, targetSecurityRoles); return(false); //security role is imported using D365 solution case Constant.Team.EntityLogicalName: // there can more than 1 teams with same name but different business unit - this is similar to security role!!!!! // Note: Alternate key for Security role is "Business Unit Name + Security Role Name" Logger?.Invoke(this, "\r\nPreparing data replacement for Team..."); var targetTeams = targetDataLoader.GetAllEntity(Constant.Team.EntityLogicalName, new[] { Constant.Team.Name, Constant.Team.BusinessUnitId, Constant.Team.IsDefault }, LogicalOperator.And, new[] { new ConditionExpression(Constant.Team.TeamType, ConditionOperator.Equal, 0) }); _transformData.PopulateTeamTransforms(fetchXmlQueryData, targetTeams); break; case Constant.FieldSecurityProfile.EntityLogicalName: // Note: Alternate key for Security role is "Business Unit Name + Security Role Name" Logger?.Invoke(this, "\r\nPreparing data replacement for Field Security Profile..."); var targetFieldSecurityProfiles = targetDataLoader.GetAllEntity(Constant.FieldSecurityProfile.EntityLogicalName, new[] { Constant.FieldSecurityProfile.Name }); _transformData.PopulateFieldSecurityProfileTransforms(fetchXmlQueryData, targetFieldSecurityProfiles); return(false); //security role is imported using D365 solution case Constant.TransactionCurrency.EntityLogicalName: Logger?.Invoke(this, "\r\nPreparing data replacement for Currencies..."); var targetCurrencies = targetDataLoader.GetAllEntity(Constant.TransactionCurrency.EntityLogicalName, new[] { Constant.TransactionCurrency.CurrencyName, Constant.TransactionCurrency.IsoCurrencyCode }); _transformData.PopulateCurrencyTransforms(fetchXmlQueryData, targetCurrencies); break; case Constant.Queue.EntityLogicalName: Logger?.Invoke(this, "\r\nPreparing data replacement for Queues..."); var targetQueues = targetDataLoader.GetAllEntity(Constant.Queue.EntityLogicalName, new[] { Constant.Queue.Name, Constant.Queue.TransactionCurrencyId }, LogicalOperator.And, new[] { new ConditionExpression(Constant.Queue.Name, ConditionOperator.DoesNotBeginWith, "<") }); _transformData.PopulateQueueTransforms(fetchXmlQueryData, targetQueues); break; } return(true); }