コード例 #1
0
            public bool TryGetTranslator <T>(out IEntityTranslator <T, TSchema> translator)
                where T : TSchema
            {
                translator = _translator as IEntityTranslator <T, TSchema>;

                return(translator != null);
            }
コード例 #2
0
ファイル: ExpressionBreaker.cs プロジェクト: stalinvr007/VoDB
        private static IEnumerable<IExpressionPiece> BreakExpression(IEntityTranslator translator, LambdaExpression expression)
        {
            var current = GetFirstMember(expression);

            while (current != null)
            {
                var part = new ExpressionPiece
                {
                    PropertyName = current.Member.Name,
                    EntityType = current.Member.DeclaringType
                };

                // Gets the table for this entity type.
                part.EntityTable = translator.Translate(part.EntityType);

                // Gets the field used in this expression part.
                part.Field = part.EntityTable
                    .Fields
                    .FirstOrDefault(f => f.Info.Name == part.PropertyName);

                Debug.Assert(part.Field != null, "The property [" + part.PropertyName + "] used in the expression doesn't belong to the Entity table representation.");

                yield return part;

                current = current.Expression as MemberExpression;
            }
        }
コード例 #3
0
        private readonly ReaderWriterLockSlim _sync; // I chose this over a simple lock because the popular use case for this
                                                     // class is Get() so using this will result in even better retrieval times

        public Cache(IRepositoryProvider fileReadDataProvider, IEntityTranslator <T> personEntityTranslator, InitType initType = InitType.Eager)
        {
            _initType           = initType;
            _repositoryProvider = fileReadDataProvider;
            _entityTranslator   = personEntityTranslator;
            _entityCache        = new Dictionary <int, T>();
            _sync = new ReaderWriterLockSlim();
        }
コード例 #4
0
ファイル: IEntityFactory.cs プロジェクト: stalinvr007/VoDB
 public Object Make(Type type, IInternalSession session, IEntityTranslator translator)
 {
     return type.Namespace.Equals("Castle.Proxies")
                    ? Make(type.BaseType, session, null)
                    : proxyGenerator.CreateClassProxy(type,
                                                      new Interceptor(
                                                          session));
 }
コード例 #5
0
 public TranslateEntityValuePropertyTranslator(Type implementationType, PropertyInfo entityPropertyInfo, PropertyInfo inputPropertyInfo,
                                               IEntityTranslator <TEntity, TSchema> entityTranslator)
 {
     _entityTranslator = entityTranslator;
     _propertyName     = entityPropertyInfo.Name;
     _property         = new WriteProperty <TResult, Value <TEntity> >(implementationType, _propertyName);
     _inputProperty    = new ReadOnlyProperty <TInput, Value <TEntity> >(inputPropertyInfo);
 }
コード例 #6
0
        public override void Apply(IEntityTranslatorBuilder <TResult, TInput, TSchema> builder)
        {
            IEntityTranslator <TEntity, TSchema> entityTranslator = builder.GetEntityTranslator <TEntity, TEntity, TTranslation>();

            var translator = new TranslateEntityValuePropertyTranslator <TResult, TEntity, TInput, TSchema>(builder.ImplementationType, ResultPropertyInfo, InputPropertyInfo,
                                                                                                            entityTranslator);

            builder.Add(ResultPropertyInfo.Name, translator);
        }
コード例 #7
0
        public void RegisterEntityTranslator(IEntityTranslator translator)
        {
            if (translator == null)
            {
                throw new ArgumentNullException("translator");
            }

            _translators.Add(translator);
        }
コード例 #8
0
        private IEntityTranslator FindTranslator(Type targetType, Type sourceType)
        {
            IEntityTranslator translator = _translators.Find(delegate(IEntityTranslator test)
            {
                return(test.CanTranslate(targetType, sourceType));
            });

            return(translator);
        }
コード例 #9
0
        public void RemoveEntityTranslator(IEntityTranslator translator)
        {
            if (translator == null)
            {
                throw new ArgumentNullException("translator");
            }

            _translators.Remove(translator);
        }
コード例 #10
0
        public static Task <TranslateResult <TSchema> > Translate <TInput, TSchema>(this IEntityTranslator <TInput, TSchema> translator, EntityResult <TSchema> result,
                                                                                    Result <Cursor <TSchema>, TInput> input)
            where TSchema : Entity
            where TInput : TSchema
        {
            var context = new EntityTranslateContext <TInput, TSchema>(result, input);

            return(translator.Translate(context));
        }
コード例 #11
0
        public void Add <T>(IEntityTranslator <T, TSchema> translator)
            where T : TSchema
        {
            if (!_translators.TryGetValue(typeof(T), out var translatorList))
            {
                translatorList          = new EntityTranslatorList <T, TSchema>();
                _translators[typeof(T)] = translatorList;
            }

            translatorList.Add(translator);
        }
コード例 #12
0
        public void Add <T>(IEntityTranslator <T, TSchema> translator)
            where T : TSchema
        {
            var entityTranslator = translator as IEntityTranslator <TInput, TSchema>;

            if (entityTranslator == null)
            {
                throw new ArgumentException($"The translator entity type was invalid: {TypeCache<T>.ShortName} (expected: {TypeCache<TInput>.ShortName}");
            }

            _translators.Add(entityTranslator);
        }
コード例 #13
0
ファイル: ProxyCreator.cs プロジェクト: stalinvr007/VoDB
        public object Make(Type type, IInternalSession session, IEntityTranslator translator)
        {
            if (type.GetInterfaces().Contains(typeof(IProxyTargetAccessor)))
            {
                return Make(type.BaseType, session, translator);
            }

            return proxyGenerator.CreateClassProxy(type,
                new ProxyGenerationOptions {
                    Selector = new InterceptorSelector(
                        new NonCollectionInterceptor(session),
                        new CollectionPropertyInterceptor(session, translator)
                    )
                });
        }
コード例 #14
0
        public TTarget Translate <TTarget>(object source, object param)
        {
            Type targetType = typeof(TTarget);
            Type sourceType = source.GetType();

            if (targetType == null)
            {
                throw new ArgumentNullException("targetType");
            }

            if (sourceType == null)
            {
                throw new ArgumentNullException("sourceType");
            }

            if (source == null)
            {
                if (targetType.IsArray)
                {
                    return(default(TTarget));
                }
                else
                {
                    throw new ArgumentNullException("source");
                }
            }

            if (IsArrayConversionPossible(targetType, sourceType))
            {
                return((TTarget)TranslateArray(targetType, source));
            }
            else
            {
                IEntityTranslator translator = FindTranslator(targetType, sourceType);
                if (translator == null)
                {
                    translator = FindTranslator(targetType, sourceType.BaseType);
                }
                if (translator != null)
                {
                    return((TTarget)translator.Translate(this, targetType, source, param));
                }
            }

            throw new EntityTranslatorException(string.Format("No translator is available to map from {0} to {1}.", sourceType.GetTypeString(), targetType.GetTypeString()));
        }
コード例 #15
0
        public object Translate(Type targetType, object source)
        {
            if (targetType == null)
            {
                throw new ArgumentNullException("targetType");
            }

            if (source == null)
            {
                if (targetType.IsArray)
                {
                    return(null);
                }
                else
                {
                    throw new ArgumentNullException("source");
                }
            }

            Type sourceType = source.GetType();


            ///----- Added By Ericsson
            ///---temoprary solution for fixing the dynamic proxy
            if (sourceType.BaseType != null && sourceType.Namespace == "System.Data.Entity.DynamicProxies")
            {
                sourceType = sourceType.BaseType;
            }


            if (IsArrayConversionPossible(targetType, sourceType))
            {
                return(TranslateArray(targetType, source));
            }
            else
            {
                IEntityTranslator translator = FindTranslator(targetType, sourceType);
                if (translator != null)
                {
                    return(translator.Translate(this, targetType, source));
                }
            }

            throw new EntityTranslatorException("No translator is available to perform the operation.");
        }
コード例 #16
0
        public object Translate(Type targetType, Type sourceType, object source)
        {
            if (targetType == null)
            {
                throw new ArgumentNullException("targetType");
            }

            if (sourceType == null)
            {
                throw new ArgumentNullException("sourceType");
            }

            if (source == null)
            {
                if (targetType.IsArray)
                {
                    return(null);
                }
                else
                {
                    throw new ArgumentNullException("source");
                }
            }

            if (IsArrayConversionPossible(targetType, sourceType))
            {
                return(TranslateArray(targetType, source));
            }
            else
            {
                IEntityTranslator translator = FindTranslator(targetType, sourceType);
                if (translator == null)
                {
                    translator = FindTranslator(targetType, sourceType.BaseType);
                }
                if (translator != null)
                {
                    return(translator.Translate(this, targetType, source));
                }
            }

            throw new EntityTranslatorException(string.Format("No translator is available to map from {0} to {1}.", sourceType.GetTypeString(), targetType.GetTypeString()));
        }
コード例 #17
0
ファイル: ExchangeSession.cs プロジェクト: zhichkin/sss
 private void Exchange(IEntityAdapter adapter, IEntityTranslator translator)
 {
     using (IComWrapper cursor = adapter.GetCursor())
     {
         if (cursor != null)
         {
             while ((bool)cursor.Call("Следующий"))
             {
                 using (SqlCommand command = connection.CreateCommand())
                 {
                     translator.Translate(cursor, command);
                     AddParameter(command, "id_sea", SqlDbType.Int, ParameterDirection.Input, session_id);
                     command.ExecuteNonQuery();
                 }
             }
         }
     }
     log.Write(string.Format("ok : {0}", adapter.ToString()));
 }
コード例 #18
0
        public object Translate(Type targetType, object source)
        {
            if (targetType == null)
            {
                throw new ArgumentNullException("targetType");
            }

            if (source == null)
            {
                if (targetType.IsArray)
                {
                    return(null);
                }
                else
                {
                    throw new ArgumentNullException("source");
                }
            }

            Type sourceType = source.GetType();

            if (IsArrayConversionPossible(targetType, sourceType))
            {
                return(TranslateArray(targetType, source));
            }
            else
            {
                IEntityTranslator translator = FindTranslator(targetType, sourceType);
                if (translator != null)
                {
                    return(translator.Translate(this, targetType, source));
                }
            }

            throw new EntityTranslatorException("No translator is available to perform the operation.");
        }
コード例 #19
0
 public EmpresaController(IEmpresaManager empresaManager, IMapper mapper, IEntityTranslator translator)
 {
     _empresaManager = empresaManager;
     _mapper         = mapper;
     _translator     = translator;
 }
コード例 #20
0
ファイル: CachingTranslator.cs プロジェクト: stalinvr007/VoDB
 public CachingTranslator(IEntityTranslator translator)
 {
     _Translator = translator;
 }
コード例 #21
0
ファイル: ExchangeSession.cs プロジェクト: zhichkin/sss
 public void Enlist(IEntityAdapter adapter, IEntityTranslator translator)
 {
     exchange_list.Add(adapter, translator);
 }
コード例 #22
0
 public CachedTranslator(IEntityTranslator <TInput, TSchema> translator)
 {
     _translator = translator;
 }
コード例 #23
0
ファイル: Utils.cs プロジェクト: stalinvr007/VoDB
 public static IEnumerable<ITable> ToTables(this IEnumerable<Type> type, IEntityTranslator translator)
 {
     return TestModels
         .Select(t => translator.Translate(t));
 }
コード例 #24
0
ファイル: EntityTranslator.cs プロジェクト: stalinvr007/VoDB
        private static IField SetFieldBindMember(IEntityTranslator translator, PropertyInfo item, Field field)
        {
            var bind = item.Attribute<DbBindAttribute>();
            String bindFieldName = null;

            MethodInfo getMethod = item.GetGetMethod();

            if (bind != null)
            {
                if (!getMethod.IsVirtual)
                {
                    throw new InvalidMappingException("The field [{0}] is marked with DbBind but is not Virtual.", field.Name);
                }

                bindFieldName = bind.FieldName;
            }

            if (getMethod.IsVirtual && !getMethod.ReturnType.Assembly.FullName.StartsWith("mscorlib, "))
            {
                bindFieldName = bindFieldName ?? field.Name;

                var table = item.PropertyType != field.EntityType ?
                    translator.Translate(item.PropertyType) :
                    field.Table;

                field.BindToField = table.Fields
                    .FirstOrDefault(f => f.Name.Equals(bindFieldName, StringComparison.InvariantCultureIgnoreCase));

                if (field.BindToField == null)
                {
                    throw new InvalidMappingException("The field [{0}] is a reference to the table [{1}] but no match was found.", field.Name, table.Name);
                }

                return new BindedField(field);
            }

            return field;
        }
コード例 #25
0
 public void RegisterEntityTranslator(IEntityTranslator translator)
 {
     RegisteredTranslators.Add(translator);
 }
コード例 #26
0
 public void RemoveEntityTranslator(IEntityTranslator translator)
 {
 }
コード例 #27
0
ファイル: ExpressionBreaker.cs プロジェクト: stalinvr007/VoDB
 public ExpressionBreaker(IEntityTranslator translator)
 {
     _Translator = translator;
 }
コード例 #28
0
 public TranslateEntityTranslatePropertyProvider(ITranslatePropertyProvider <Entity <TEntity>, TInput, TSchema> provider, IEntityTranslator <TEntity, TSchema> translator)
 {
     _provider   = provider;
     _translator = translator;
 }