private IServiceConfiguration LoadConfiguration(ICDSExecutionContext executionContext, bool disableCache) { var settings = SettingsFactory.Create(executionContext); if (!disableCache && executionContext.Cache.Exists(CACHE_KEY)) { return(executionContext.Cache.Get <IServiceConfiguration>(CACHE_KEY)); } IServiceConfiguration config = new ServiceConfiguration(); //get all XML data configuration files located in the virtual configuration path. var qry = new QueryExpression { EntityName = "webresource", ColumnSet = new ColumnSet("name"), Criteria = new FilterExpression { Conditions = { new ConditionExpression { AttributeName = "name", Operator = ConditionOperator.BeginsWith, Values = { settings.ConfigurationDataPath } } } } }; var xmlDataResources = executionContext.OrganizationService.RetrieveMultiple(qry).Entities; executionContext.Trace(string.Format("Retrieved {0} XML Data resource records.", xmlDataResources.Count)); // Process each named XML configuration resource to build out the field level configuration service configuration. foreach (var resource in xmlDataResources) { var name = resource.GetAttributeValue <string>("name"); try { var xmlConfigData = executionContext.XmlConfigurationResources.Get(name, false); config.AddConfiguration(xmlConfigData); } catch (Exception ex) { executionContext.Trace(Core.eSeverityLevel.Error, "Error processing entity file {0} - {1}", name, ex.Message); } } if (!disableCache && executionContext.Cache != null && settings.CacheTimeout != null) { executionContext.Cache.Add <IServiceConfiguration>(CACHE_KEY, config, settings.CacheTimeout.Value); } return(config); }
public Guid[] GetLinkedIds(ICDSExecutionContext executionContext, string searchTerm, bool useElevatedAccess) { var processName = $"{nameof(QuickFindQueryExpressionBuilder<TTarget>)}.{nameof(GetLinkedIds)}"; executionContext.Trace($"Entered {processName}"); var qry = QueryExpressionBuilder .WithSearchValue(searchTerm) .Build(); // execute the query and return a list of target ids found. var orgService = useElevatedAccess ? executionContext.ElevatedOrganizationService : executionContext.OrganizationService; var ids = orgService.RetrieveMultiple(qry).Entities.Select(e => e.Id).ToArray(); executionContext.Trace($"Exiting {processName} - Returning {ids.Length} record ids."); return(ids); }
public IQuickFindQueryBuilder <TEntity> SearchParent <TParent>(string fromAttribute, Action <IQuickFindParentEntity <TEntity, TParent> > expression) where TParent : Entity, new() { var processName = $"{nameof(QuickFindQueryBuilder<TEntity>)}.{nameof(SearchParent)}"; executionContext.Trace($"Entered {processName}"); var linkedParent = new QuickFindParentEntity <TEntity, TParent>(fromAttribute); expression(linkedParent); linkedEntities.Add(linkedParent); executionContext.Trace($"Exiting {processName} - Completed."); return(this); }
public Guid[] GetLinkedIds(ICDSExecutionContext executionContext, string searchTerm, bool useElevatedAccess) { var processName = $"{nameof(QuickFindParentEntity<TTarget, TParent>)}.{nameof(GetLinkedIds)}"; executionContext.Trace($"Entered {processName}"); if (linkingAttribute.Length == 0 || searchFields.Count == 0) { executionContext.Trace($"Exiting {processName} - No search fields or linking attribute."); return(Array.Empty <Guid>()); } var targetLogicalName = new TTarget().LogicalName; var targetIdField = targetLogicalName + "id"; var parentLogicalName = new TParent().LogicalName; var parentIdField = parentLogicalName + "id"; // create a query that returns ids for the target entity that are joined to // the parent entity via the identified linking attribute where the parent entity // matches any of the search fields. var qry = new QueryExpression { EntityName = targetLogicalName, ColumnSet = new ColumnSet(targetIdField), Distinct = true, NoLock = true, TopCount = topCount, LinkEntities = { new LinkEntity { JoinOperator = JoinOperator.Inner, LinkFromEntityName = targetLogicalName, LinkFromAttributeName = linkingAttribute, LinkToEntityName = parentLogicalName, LinkToAttributeName = parentIdField, LinkCriteria = new FilterExpression { FilterOperator = LogicalOperator.And, Conditions = { }, Filters = { new FilterExpression { FilterOperator = LogicalOperator.Or, Conditions = { } } } } } } }; // unless inactive parents are excluded then add a condition to the linked entity criteria to only // join active records. if (!includeInactiveRecords) { executionContext.Trace($"{processName}: Filtering on active records."); qry.LinkEntities[0].LinkCriteria.Conditions.Add(new ConditionExpression("statecode", ConditionOperator.Equal, 0)); } // add one condition for each search field to the linked entity search filter. foreach (var field in searchFields) { qry.LinkEntities[0].LinkCriteria.Filters[0].Conditions.Add(new ConditionExpression(field, ConditionOperator.Like, searchTerm + "%")); } // execute the query and return a list of target ids found. var orgService = useElevatedAccess ? executionContext.ElevatedOrganizationService : executionContext.OrganizationService; var ids = orgService.RetrieveMultiple(qry).Entities.Select(e => e.Id).ToArray(); executionContext.Trace($"Exiting {processName} - Returning {ids.Length} record ids."); return(ids); }