private List <Entity> RetrieveRecords(Record recordsConfig, Guid?recordId)
        {
            log.Log($"Injecting ID field in FetchXML ...");
            recordsConfig.FetchXml = InjectIdFieldInFetchXml(recordsConfig.FetchXml, recordsConfig.LogicalName);
            log.Log($"Finished injecting ID field in FetchXML.");

            log.Log($"Cloning query ...");
            var query = service.CloneQuery(new FetchExpression(recordsConfig.FetchXml));

            log.Log($"Finished cloning query.");

            // replace recordId placeholders with the record ID if given
            if (recordId != null)
            {
                foreach (var values in query.LinkEntities
                         .SelectMany(l => l.LinkCriteria.Conditions
                                     .Where(c => c.Values.Any(v => v is Guid vs && vs == Guid.Empty)))
                         .Select(c => c.Values))
                {
                    // ToArray: can't modify collection inside loop
                    foreach (var value in values.Where(v => v is Guid vs && vs == Guid.Empty).ToArray())
                    {
                        values.Remove(value);
                        values.Add(recordId);
                    }
                }
            }

            log.Log($"Retrieving records using FetchXML for '{recordsConfig.LogicalName}' ...");
            var records = service.RetrieveMultiple <Entity>(query).Distinct(new EntityComparer()).ToList();

            log.Log($"Finished retrieving records using FetchXML for '{recordsConfig.LogicalName}'. Found {records.Count}.");

            return(records);
        }
Exemplo n.º 2
0
 private List <Entity> RetrieveRecords(string fetchXml)
 {
     retrieveCache.TryGetValue(fetchXml, out var existingRecords);
     retrieveCache[fetchXml] = existingRecords = existingRecords
                                                 ?? service.RetrieveMultiple <Entity>(service.CloneQuery(new FetchExpression(fetchXml)))
                                                 .Distinct(new EntityComparer()).ToList();
     return(existingRecords);
 }
Exemplo n.º 3
0
        private static string RetrieveSolutionVersion(string solutionName, IEnhancedOrgService service)
        {
            solutionName.RequireNotEmpty(nameof(solutionName));
            service.Require(nameof(service));

            var query =
                new QueryExpression
            {
                EntityName = Solution.EntityLogicalName,
                ColumnSet  = new ColumnSet(Solution.Fields.Version),
                Criteria   = new FilterExpression()
            };

            query.Criteria.AddCondition(Solution.Fields.Name, ConditionOperator.Equal, solutionName);

            log.Log($"Retrieving solution version for solution '{solutionName}'...");
            var solution = service.RetrieveMultiple(query).Entities.FirstOrDefault()?.ToEntity <Solution>();

            log.Log($"Version: {solution?.Version}.");

            return(solution?.Version);
        }