Ejemplo n.º 1
0
        public static IEntity Create(this IEntityFactory entityFactory, IEntityDefinition definition)
        {
            entityFactory.NotNull(nameof(entityFactory));
            definition.NotNull(nameof(definition));

            return(entityFactory.Create(definition, CancellationToken.None).GetAwaiter().GetResult());
        }
Ejemplo n.º 2
0
        public Task <bool> Delete(IEntityDefinition entityDefinition, object id, CancellationToken ct)
        {
            entityDefinition.NotNull(nameof(entityDefinition));
            id.NotNull(nameof(id));

            return(entityDefinition.DeleteHandler.Execute(new DeleteExecution(entityDefinition, id), ct));
        }
Ejemplo n.º 3
0
        public static IEntity Hydrate(this IEntityFactory entityFactory, IEntityDefinition definition, PropertyBag values)
        {
            entityFactory.NotNull(nameof(entityFactory));
            definition.NotNull(nameof(definition));

            return(entityFactory.Hydrate(definition, values, CancellationToken.None).GetAwaiter().GetResult());
        }
Ejemplo n.º 4
0
        public IQuery CreateQuery(IEntityDefinition entityDefinition)
        {
            entityDefinition.NotNull(nameof(entityDefinition));

            //TODO: Might allow security/audit interception capability later...
            return(_entityRepository.CreateQuery(entityDefinition));
        }
Ejemplo n.º 5
0
        public static IPropertyDefinition Create(
            IEntityDefinition entityDefinition,
            IDataType dataType      = null,
            PropertyBag propertyBag = null)
        {
            entityDefinition.NotNull(nameof(entityDefinition));

            var result = new PropertyDefinition
            {
                EntityDefinition = entityDefinition,
                PropertyType     = dataType,
                PropertyBag      = propertyBag,
                Name             = propertyBag?["name"] as string,
                Description      = propertyBag?["description"] as string,
                DefaultValue     = propertyBag?["default"]
            };

            var validatorsData = propertyBag?["validators"] as PropertyBag[];

            if (validatorsData != null)
            {
                result.ValidatorDefinitions = CreateValidatorDefinitions(result, validatorsData);
            }

            return(result);
        }
Ejemplo n.º 6
0
 protected Query(IEntityDefinition entityDefinition)
 {
     EntityDefinition = entityDefinition.NotNull(nameof(entityDefinition));
     Criterions       = new List <ICriterion>();
     Orders           = new List <Order>();
     SubQueries       = new Dictionary <string, IQuery>(StringComparer.OrdinalIgnoreCase);
     Includes         = new HashSet <IPropertyDefinition>();
 }
Ejemplo n.º 7
0
        public static Task <IEntity> GetById(this IEntityService entityService, IEntityDefinition entityDefinition, object id, CancellationToken ct)
        {
            entityService.NotNull(nameof(entityService));
            entityDefinition.NotNull(nameof(entityDefinition));
            id.NotNull(nameof(id));

            return(entityService.CreateQuery(entityDefinition).Add(Criterion.IdEq(id)).UniqueResult <IEntity>(ct));
        }
Ejemplo n.º 8
0
        public async Task <IEntity> Create(IEntityDefinition definition, PropertyBag initialValues, CancellationToken ct)
        {
            definition.NotNull(nameof(definition));
            var entity = Hydrate(definition, initialValues);

            await Init(entity, ct);

            return(entity);
        }
Ejemplo n.º 9
0
        public async Task <bool> Delete(IEntityDefinition entityDefinition, object id, CancellationToken ct)
        {
            entityDefinition.NotNull(nameof(entityDefinition));
            id.NotNull(nameof(id));

            try
            {
                await Telemetry.TrackAsyncDependency(
                    ct,
                    _ => Client.DeleteDocumentAsync(GetDocumentUri(entityDefinition, id)),
                    DependencyKind.HTTP,
                    DependencyName
                    );
            }
            catch (DocumentClientException ex)
            {
                if (ex.StatusCode == HttpStatusCode.NotFound)
                {
                    return(false);
                }
                throw;
            }
            return(true);
        }
Ejemplo n.º 10
0
 public Entity(IEntityDefinition definition)
 {
     Definition = definition.NotNull(nameof(definition));
 }
Ejemplo n.º 11
0
 public Task <IEntity> Hydrate(IEntityDefinition definition, PropertyBag initialValues, CancellationToken ct)
 {
     definition.NotNull(nameof(definition));
     return(Task.FromResult(Hydrate(definition, initialValues)));
 }
Ejemplo n.º 12
0
        public IQuery CreateQuery(IEntityDefinition entityDefinition)
        {
            entityDefinition.NotNull(nameof(entityDefinition));

            return(new DocumentDbQuery(this, entityDefinition));
        }