public bool TryGetTranslator <T>(out IEntityTranslator <T, TSchema> translator) where T : TSchema { translator = _translator as IEntityTranslator <T, TSchema>; return(translator != null); }
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; } }
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(); }
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)); }
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); }
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); }
public void RegisterEntityTranslator(IEntityTranslator translator) { if (translator == null) { throw new ArgumentNullException("translator"); } _translators.Add(translator); }
private IEntityTranslator FindTranslator(Type targetType, Type sourceType) { IEntityTranslator translator = _translators.Find(delegate(IEntityTranslator test) { return(test.CanTranslate(targetType, sourceType)); }); return(translator); }
public void RemoveEntityTranslator(IEntityTranslator translator) { if (translator == null) { throw new ArgumentNullException("translator"); } _translators.Remove(translator); }
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)); }
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); }
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); }
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) ) }); }
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())); }
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."); }
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())); }
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())); }
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."); }
public EmpresaController(IEmpresaManager empresaManager, IMapper mapper, IEntityTranslator translator) { _empresaManager = empresaManager; _mapper = mapper; _translator = translator; }
public CachingTranslator(IEntityTranslator translator) { _Translator = translator; }
public void Enlist(IEntityAdapter adapter, IEntityTranslator translator) { exchange_list.Add(adapter, translator); }
public CachedTranslator(IEntityTranslator <TInput, TSchema> translator) { _translator = translator; }
public static IEnumerable<ITable> ToTables(this IEnumerable<Type> type, IEntityTranslator translator) { return TestModels .Select(t => translator.Translate(t)); }
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; }
public void RegisterEntityTranslator(IEntityTranslator translator) { RegisteredTranslators.Add(translator); }
public void RemoveEntityTranslator(IEntityTranslator translator) { }
public ExpressionBreaker(IEntityTranslator translator) { _Translator = translator; }
public TranslateEntityTranslatePropertyProvider(ITranslatePropertyProvider <Entity <TEntity>, TInput, TSchema> provider, IEntityTranslator <TEntity, TSchema> translator) { _provider = provider; _translator = translator; }