/// <summary> /// Loads structured data for the specified entity. /// </summary> /// <param name="entityId">The entity to load.</param> /// <param name="request">The description of fields and related entities to load.</param> /// <returns>The requested data. Or null if the entity does not exist.</returns> /// <exception cref="PlatformSecurityException"> /// The user lacks read access to the given entity. /// </exception> public EntityData GetEntityData(EntityRef entityId, EntityMemberRequest request) { try { // Validate input if (entityId == null) { throw new ArgumentNullException("entityId"); } try { long id = entityId.Id; // ensure we can resolve any alias } catch (ArgumentException) { return(null); // alias does not exist .. return null } request = ValidateRequest(request); // Place request var resultList = GetEntitiesData(entityId.ToEnumerable(), request, SecurityOption.DemandAll); var result = resultList.FirstOrDefault(); return(result); } catch (Exception ex) { EventLog.Application.WriteError("Failed GetEntityData. Entity: #{0}\nRequest details:\n{1}\n\nException:\n{2}", entityId, request == null ? "null" : request.Debug(), ex); throw; } }
/// <summary> /// Convenient constructor. /// </summary> public EntityRequest(EntityRef entity, string requestString, QueryType queryType, string hint = null) { Entities = entity.ToEnumerable(); RequestString = requestString; QueryType = queryType; Hint = hint; }
IEnumerable <EntityData> IEntityInfoRead.GetEntitiesByType(EntityRef entityType, bool includeDerivedTypes, EntityMemberRequest request) { if (string.IsNullOrEmpty(request.RequestString)) { Assert.Ignore("GetEntitiesByType not supported by BulkRequestRunner without request string"); } else { var entityRequest = new EntityRequest { QueryType = includeDerivedTypes ? QueryType.Instances : QueryType.ExactInstances, IgnoreResultCache = true, Entities = entityType.ToEnumerable(), RequestString = request.RequestString }; // preferred path .. but still need to get away from passing EntityMemberRequest IEnumerable <EntityData> res = BulkRequestRunner.GetEntitiesByType(entityRequest); return(res); } return(null); }
public bool OnBeforeSave(IEnumerable <IEntity> entities, IDictionary <string, object> state) { foreach (var entity in entities) { var task = entity.As <BaseUserTask>(); if (task.HasChanges(changesWeAreInterestedIn)) { var justCompleted = task.HasChanges(taskStatusRef.ToEnumerable()) && task.TaskStatus_Enum == TaskStatusEnum_Enumeration.TaskStatusCompleted; if (justCompleted) { task.UserTaskIsComplete = true; task.UserTaskCompletedOn = DateTime.UtcNow; task.PercentageCompleted = 100; } else if (task.HasChanges(changesWeAreInterestedIn)) { if (task.TaskStatus_Enum != TaskStatusEnum_Enumeration.TaskStatusCompleted) { if (task.UserTaskIsComplete ?? false) { task.UserTaskIsComplete = false; } if (task.UserTaskCompletedOn != null) { task.UserTaskCompletedOn = null; } // ignore percentage complete } else // we are already complete { if (!(task.UserTaskIsComplete ?? false)) { task.UserTaskIsComplete = true; } if (task.PercentageCompleted != 100) { task.PercentageCompleted = 100; } // Ignore the completed date } } } } return(false); }
public EntityData GetEntityData(EntityRef id, EntityMemberRequest request) { if (string.IsNullOrEmpty(request.RequestString)) { // obsolete path var results = GetEntitiesData(id.ToEnumerable(), request); EntityData res = results.FirstOrDefault(); return(res); } else { // preferred path .. but still need to get away from passing EntityMemberRequest EntityData res = BulkRequestRunner.GetEntityData(id, request.RequestString); return(res); } }
/// <summary> /// Runs a request. Caches it. Secures it. /// </summary> /// <param name="entityRef">The entity to load.</param> /// <param name="request">The entity member request string.</param> /// <param name="hintText">A hint about what this query is doing. Use for logging/diagnostics only.</param> /// <returns>The entity data for the requested entity, or null if it was not found.</returns> public static EntityData GetEntityData(EntityRef entityRef, string request, string hintText = null) { if (entityRef == null) { throw new ArgumentNullException("entityRef"); } if (request == null) { throw new ArgumentNullException("request"); } // Run query var results = GetEntitiesData(entityRef.ToEnumerable(), request, hintText); EntityData result = results.FirstOrDefault(); return(result); }
/// <summary> /// Gets the identity providers for the specified tenant. /// </summary> /// <returns>TenantIdentityProviderResponse.</returns> public TenantIdentityProviderResponse GetIdentityProviders(string tenant) { if (string.IsNullOrWhiteSpace(tenant)) { throw new ArgumentNullException(nameof(tenant)); } var response = new TenantIdentityProviderResponse { IdentityProviders = new List <IdentityProviderResponse>() }; using (new SecurityBypassContext()) { TenantAdministratorContext tenantAdminContext; try { tenantAdminContext = new TenantAdministratorContext(tenant); } catch (EntityNotFoundException) { return(response); } try { var idProviderId = new EntityRef("core:identityProvider"); var isOfTypeId = new EntityRef("core:isOfType"); var nameId = new EntityRef("core:name"); var aliasId = new EntityRef("core:alias"); var isEnabledId = new EntityRef("core:isProviderEnabled"); var ordinalId = new EntityRef("core:providerOrdinal"); // Get the identity providers for the given tenant var entityRequest = new EntityRequest { Entities = idProviderId.ToEnumerable(), RequestString = "name, isProviderEnabled, providerOrdinal, isOfType.alias", Hint = "tenant ip providers", QueryType = QueryType.Instances }; // Run the query var instances = BulkRequestRunner.GetEntitiesByType(entityRequest); if (instances == null) { return(response); } foreach (var instance in instances) { var isEnabled = false; string name = null; var ordinal = 0; var id = instance.Id.Id; foreach (var fieldData in instance.Fields) { if (fieldData.FieldId == null || fieldData.Value?.Type == null) { continue; } if (fieldData.FieldId.Id == nameId.Id) { name = fieldData.Value.ValueString; } else if (fieldData.FieldId.Id == ordinalId.Id && fieldData.Value.Type.GetRunTimeType() == typeof(int) && fieldData.Value.Value != null) { ordinal = (int)fieldData.Value.Value; } else if (fieldData.FieldId.Id == isEnabledId.Id && fieldData.Value.Type.GetRunTimeType() == typeof(bool) && fieldData.Value.Value != null) { isEnabled = (bool)fieldData.Value.Value; } } if (!isEnabled || string.IsNullOrWhiteSpace(name)) { continue; } var singleOrDefault = instance.Relationships.SingleOrDefault(r => r.RelationshipTypeId.Id == isOfTypeId.Id); if (singleOrDefault == null) { continue; } var isOfTypeEntityData = singleOrDefault.Entities; var identityProvider = new IdentityProviderResponse { Id = id, Name = name, Ordinal = ordinal }; if (isOfTypeEntityData != null) { var typeEntity = isOfTypeEntityData.FirstOrDefault(); if (typeEntity == null) { continue; } var typeAliasData = typeEntity.Fields.SingleOrDefault(f => f.FieldId.Id == aliasId.Id); if (typeAliasData?.Value != null) { identityProvider.TypeAlias = typeAliasData.Value.ValueString; } } response.IdentityProviders.Add(identityProvider); } } finally { tenantAdminContext.Dispose(); } } return(response); }