protected virtual void AddPackageImageJoin(FetchEntity fetchEntity) { fetchEntity.Links.Add(new Link { Alias = "image", Name = "adx_packageimage", FromAttribute = "adx_packageid", ToAttribute = "adx_packageid", Type = JoinOperator.LeftOuter, Attributes = new[] { new FetchAttribute("adx_packageimageid"), new FetchAttribute("adx_name"), new FetchAttribute("adx_description"), }, Filters = new[] { new Filter { Conditions = new[] { new Condition("statecode", ConditionOperator.Equal, 0) } } } }); }
protected virtual void AddPackageVersionJoin(FetchEntity fetchEntity) { fetchEntity.Links.Add(new Link { Alias = "version", Name = "adx_packageversion", FromAttribute = "adx_packageid", ToAttribute = "adx_packageid", Type = JoinOperator.LeftOuter, Attributes = new[] { new FetchAttribute("adx_packageversionid"), new FetchAttribute("adx_description"), new FetchAttribute("adx_name"), new FetchAttribute("adx_packageid"), new FetchAttribute("adx_releasedate"), new FetchAttribute("adx_requiredinstallerversion"), new FetchAttribute("adx_version"), new FetchAttribute("adx_configuration") }, Filters = new[] { new Filter { Conditions = new[] { new Condition("statecode", ConditionOperator.Equal, 0) } } } }); }
protected virtual void AddPackageDependencyJoin(FetchEntity fetchEntity) { fetchEntity.Links.Add(new Link { Alias = "dependency", Name = "adx_packagedependency", FromAttribute = "adx_packageid", ToAttribute = "adx_packageid", Type = JoinOperator.LeftOuter, Attributes = new[] { new FetchAttribute("adx_packagedependencyid"), new FetchAttribute("adx_name"), new FetchAttribute("adx_packageid"), new FetchAttribute("adx_dependencypackageid"), new FetchAttribute("adx_dependencypackageuri"), new FetchAttribute("adx_version"), new FetchAttribute("adx_order"), new FetchAttribute("createdon"), }, Links = new[] { new Link { Alias = "dependencypackage", Name = "adx_package", FromAttribute = "adx_packageid", ToAttribute = "adx_dependencypackageid", Type = JoinOperator.LeftOuter, Attributes = new[] { new FetchAttribute("adx_packageid"), new FetchAttribute("adx_name"), new FetchAttribute("adx_uniquename"), new FetchAttribute("adx_packagerepositoryid") }, Filters = new[] { new Filter { Conditions = new[] { new Condition("statecode", ConditionOperator.Equal, 0) } } } } }, Filters = new[] { new Filter { Conditions = new[] { new Condition("statecode", ConditionOperator.Equal, 0) } } } }); }
protected void AddSearchFilterToFetchEntity(FetchEntity fetchEntity, EntityListSettings settings, string search, IEnumerable <string> searchableAttributes) { if (!settings.SearchEnabled || string.IsNullOrWhiteSpace(search)) { return; } var serviceContext = Dependencies.GetServiceContext(); var response = (RetrieveEntityResponse)serviceContext.Execute(new RetrieveEntityRequest { LogicalName = fetchEntity.Name, EntityFilters = EntityFilters.Attributes, }); var entityMetadata = response.EntityMetadata; var query = search.Trim().Replace("*", "%"); var conditions = searchableAttributes .Select(attribute => GetSearchFilterConditionForAttribute(attribute, query, entityMetadata)) .Where(condition => condition != null) .ToList(); if (!conditions.Any()) { return; } fetchEntity.Filters.Add(new Filter { Type = LogicalOperator.Or, Conditions = conditions }); }
protected void AddWebsiteFilterToFetchEntity(FetchEntity fetchEntity, EntityListSettings settings) { if (string.IsNullOrWhiteSpace(settings.FilterWebsiteFieldName)) { return; } var website = Dependencies.GetWebsite(); foreach (var condition in GetConditions(fetchEntity).Where(condition => condition.UiType == "adx_website")) { condition.Value = website == null ? Guid.Empty : website.Id; } if (website == null) { return; } fetchEntity.Filters.Add(new Filter { Type = LogicalOperator.And, Conditions = new List <Condition> { new Condition(settings.FilterWebsiteFieldName, ConditionOperator.Equal, website.Id), } }); }
async Task PurgeFrequenciesIfExistingOf(FetchEntity fetchEntity) { if (fetchEntity.Frequencies != null && fetchEntity.Frequencies.Any()) { _context.Frequencies.RemoveRange(fetchEntity.Frequencies); await _context.SaveChangesAsync(); } }
protected static void AddEntityReferenceFilterToFetchEntity(FetchEntity fetchEntity, string attribute, EntityReference entity) { fetchEntity.Filters.Add(new Filter { Type = LogicalOperator.And, Conditions = new List <Condition> { new Condition(attribute, ConditionOperator.Equal, entity == null ? Guid.Empty : entity.Id) } }); }
/// <summary> /// Adds Content Access Level and Product Filtering to fetch /// </summary> /// <param name="annotation">Annotation</param> /// <param name="context">Context</param> /// <param name="contentAccessLevelProvider">content Access Level Provider</param> /// <param name="productAccessProvider">product Access Provider</param> private bool AssertKnowledgeArticleCalAndProductFiltering(Entity annotation, OrganizationServiceContext context, ContentAccessLevelProvider contentAccessLevelProvider, ProductAccessProvider productAccessProvider) { if (!contentAccessLevelProvider.IsEnabled() & !productAccessProvider.IsEnabled()) { // If CAL and Product Filtering is not enabled then we must not restrict access to the article. This will also eliminate an unnecessary knowledge article query. return(true); } var entityReference = annotation.GetAttributeValue <EntityReference>("objectid"); var fetch = new Fetch(); var knowledgeArticleFetch = new FetchEntity("knowledgearticle") { Filters = new List <Filter> { new Filter { Type = LogicalOperator.And, Conditions = new List <Condition> { new Condition("knowledgearticleid", ConditionOperator.Equal, entityReference.Id) } } }, Links = new List <Link>() }; fetch.Entity = knowledgeArticleFetch; // Apply Content Access Level filtering. If it is not enabled the fetch will not be modified contentAccessLevelProvider.TryApplyRecordLevelFiltersToFetch(CrmEntityPermissionRight.Read, fetch); // Apply Product filtering. If it is not enabled the fetch will not be modified. productAccessProvider.TryApplyRecordLevelFiltersToFetch(CrmEntityPermissionRight.Read, fetch); var kaResponse = (RetrieveMultipleResponse)context.Execute(fetch.ToRetrieveMultipleRequest()); var isValid = kaResponse.EntityCollection.Entities.Any(); if (isValid) { if (FeatureCheckHelper.IsFeatureEnabled(FeatureNames.TelemetryFeatureUsage)) { PortalFeatureTrace.TraceInstance.LogFeatureUsage(FeatureTraceCategory.Note, HttpContext.Current, "TryCreateHandler CAL/PF passed", 1, annotation.ToEntityReference(), "read"); } return(true); } if (FeatureCheckHelper.IsFeatureEnabled(FeatureNames.TelemetryFeatureUsage)) { PortalFeatureTrace.TraceInstance.LogFeatureUsage(FeatureTraceCategory.Note, HttpContext.Current, "TryCreateHandler CAL/PF failed", 1, annotation.ToEntityReference(), "read"); } return(false); }
protected static void AddAttributesToFetchEntity(FetchEntity fetchEntity, EntityListSettings settings) { foreach (var attribute in settings.DefinedAttributes) { if (fetchEntity.Attributes.Any(a => a.Name == attribute)) { continue; } fetchEntity.Attributes.Add(new FetchAttribute(attribute)); } }
private static void AddDateRangeFilterToFetchEntity(FetchEntity fetchEntity, EntityListSettings settings, DateTime from, DateTime to) { fetchEntity.Filters.Add(new Filter { Type = LogicalOperator.And, Conditions = new List <Condition> { new Condition(settings.StartDateFieldName, ConditionOperator.OnOrAfter, from), new Condition(settings.StartDateFieldName, ConditionOperator.OnOrBefore, to) } }); }
public static void AddAttributes(this FetchEntity fetchEntity, params string[] attributes) { foreach (var attribute in attributes) { if (fetchEntity.Attributes.Any(a => string.Equals(a.Name, attribute, StringComparison.InvariantCulture))) { continue; } fetchEntity.Attributes.Add(new FetchAttribute(attribute)); } }
async Task PersistFrequenciesAsync(Fetch fetch, FetchEntity fetchEntity, int n) { if (fetch.Frequencies != null && fetch.Frequencies.Any()) { foreach (var frequency in fetch.Frequencies.Take(n)) { var frequencyEntity = _frequencyAdapter.ToFrequencyEntity(frequency); frequencyEntity.Fetch = fetchEntity; _context.Frequencies.Add(frequencyEntity); } await _context.SaveChangesAsync(); } }
async Task <FetchEntity> PersistFetchAsync(Fetch fetch) { var entity = _context.Fetches.SingleOrDefault(f => f.Source == fetch.Source); if (entity == null) { entity = new FetchEntity(); entity.Source = fetch.Source; entity.CreatedAt = DateTime.UtcNow; _context.Fetches.Add(entity); await _context.SaveChangesAsync(); } return(entity); }
protected virtual void AddPackagePublisherJoin(FetchEntity fetchEntity) { fetchEntity.Links.Add(new Link { Alias = "publisher", Name = "adx_packagepublisher", FromAttribute = "adx_packagepublisherid", ToAttribute = "adx_publisherid", Type = JoinOperator.LeftOuter, Attributes = new[] { new FetchAttribute("adx_name"), new FetchAttribute("adx_uniquename"), } }); }
protected static IEnumerable <Condition> GetConditions(FetchEntity fetchEntity) { if (fetchEntity == null) { yield break; } if (fetchEntity.Filters != null) { foreach (var condition in fetchEntity.Filters.SelectMany(GetConditions)) { yield return(condition); } } if (fetchEntity.Links != null) { foreach (var condition in fetchEntity.Links.SelectMany(GetConditions)) { yield return(condition); } } }
protected virtual void AddPackageCategoryFilter(FetchEntity fetchEntity, string category) { if (string.IsNullOrWhiteSpace(category)) { return; } fetchEntity.Links.Add(new Link { Name = "adx_package_packagecategory", FromAttribute = "adx_packageid", ToAttribute = "adx_packageid", Type = JoinOperator.Inner, Links = new[] { new Link { Name = "adx_packagecategory", FromAttribute = "adx_packagecategoryid", ToAttribute = "adx_packagecategoryid", Type = JoinOperator.Inner, Filters = new[] { new Filter { Type = LogicalOperator.And, Conditions = new[] { new Condition("adx_name", ConditionOperator.Equal, category), new Condition("statecode", ConditionOperator.Equal, 0) } } } } } }); }
protected void AddSelectableFilterToFetchEntity(FetchEntity fetchEntity, EntityListSettings settings, string filter) { var user = Dependencies.GetPortalUser(); foreach (var condition in GetConditions(fetchEntity).Where(condition => condition.UiType == "contact")) { condition.Value = user == null ? Guid.Empty : user.Id; } var userAccount = GetPortalUserAccount(user); foreach (var condition in GetConditions(fetchEntity).Where(condition => condition.UiType == "account")) { condition.Value = userAccount == null ? Guid.Empty : userAccount.Id; } // Build dictionary of available selectable filters. var filters = new Dictionary <string, Action>(StringComparer.InvariantCultureIgnoreCase); if (!string.IsNullOrWhiteSpace(settings.FilterPortalUserFieldName)) { filters["user"] = () => AddEntityReferenceFilterToFetchEntity(fetchEntity, settings.FilterPortalUserFieldName, user); } if (!string.IsNullOrWhiteSpace(settings.FilterAccountFieldName)) { filters["account"] = () => AddEntityReferenceFilterToFetchEntity(fetchEntity, settings.FilterAccountFieldName, userAccount); } // If there are no filters, apply nothing. if (filters.Count < 1) { return; } // If there is only one filter defined, apply it automatically. if (filters.Count == 1) { filters.Single().Value(); return; } Action applyFilter; // Try look up the specified filter in the filter dictionary. Apply it if found. if (filter != null && filters.TryGetValue(filter, out applyFilter)) { applyFilter(); return; } // If the specified filter is not found, try apply the user filter. if (filters.TryGetValue("user", out applyFilter)) { applyFilter(); return; } // If the user filter is not found, try apply the account filter. if (filters.TryGetValue("account", out applyFilter)) { applyFilter(); return; } }