Ejemplo n.º 1
0
        public async Task <TranslateResult <TSchema> > Translate(TranslateContext <TSchema> context, TSchema entity)
        {
            if (entity is TEntity)
            {
                var input = (TEntity)entity;

                var entityContext = context.CreateContext(input);

                if (_observers.Count > 0)
                {
                    await _observers.PreTranslateEntity(input, entityContext).ConfigureAwait(false);
                }

                TranslateResult <TSchema> translateResult;
                if (_filter != null)
                {
                    translateResult = await GetFilteredResult(entityContext, input).ConfigureAwait(false);
                }
                else
                {
                    translateResult = context.Empty <TEntity>();
                }

                if (_observers.Count > 0)
                {
                    await _observers.PostTranslateEntity(translateResult, entityContext);
                }

                return(translateResult);
            }

            return(context.NotTranslated <TEntity>());
        }
Ejemplo n.º 2
0
        public async Task <TranslateResult <TSchema> > Translate(TranslateContext <TInput, TSchema> context)
        {
            var entity = _entityFactory.Create();

            if (_observers.Count > 0)
            {
                await _observers.PreTranslateEntity(entity, context).ConfigureAwait(false);
            }

            await Task.WhenAll(_propertyTranslaters.Select(x => x.Apply(entity, context))).ConfigureAwait(false);

            var translateResult = context.Result(entity);

            if (_observers.Count > 0)
            {
                await _observers.PostTranslateEntity(translateResult, context).ConfigureAwait(false);
            }

            return(translateResult);
        }