Exemple #1
0
        public EntityMetadata RetrieveEntities(string logicalName, IOrganizationService orgService, IExceptionService dataMigratorExceptionHelper)
        {
            orgService.ThrowArgumentNullExceptionIfNull(nameof(orgService));

            try
            {
                lock (EntityMetadataCache)
                {
                    if (EntityMetadataCache.ContainsKey(logicalName))
                    {
                        return(EntityMetadataCache[logicalName]);
                    }

                    var request = new RetrieveEntityRequest
                    {
                        LogicalName   = logicalName,
                        EntityFilters = EntityFilters.Attributes | EntityFilters.Relationships
                    };

                    var response = (RetrieveEntityResponse)orgService.Execute(request);

                    EntityMetadataCache.Add(logicalName, response.EntityMetadata);
                    return(response.EntityMetadata);
                }
            }
            catch (Exception error)
            {
                string errorMessage = dataMigratorExceptionHelper.GetErrorMessage(error, false);
                throw new OrganizationalServiceException($"Error while retrieving entity: {errorMessage}");
            }
        }