public virtual char GetMappedLetter(char letter, MappingDirection dir = MappingDirection.RightToLeft) { if (dir == MappingDirection.RightToLeft) return Mapping[letter - 'A']; return (char) (Mapping.IndexOf(letter) + 'A'); }
internal static string[] MapColumnNames(DataColumnMappingCollection mappingCollection, string[] names, MappingDirection direction) { if ((mappingCollection == null) || (names == null)) { return new string[0]; } ArrayList list = new ArrayList(); foreach (string str2 in names) { string sourceColumn; try { if (direction == MappingDirection.DataSetToSource) { sourceColumn = mappingCollection.GetByDataSetColumn(str2).SourceColumn; } else { DataColumnMapping mapping = mappingCollection[str2]; sourceColumn = mapping.DataSetColumn; } } catch (IndexOutOfRangeException) { sourceColumn = str2; } list.Add(sourceColumn); } return (string[]) list.ToArray(typeof(string)); }
public Item(MappingInstructionType instructionType,MappingDirection direction, Object source, Type sourceType, Object target, Type targetType, PropertyMapCollection propertyMapList) { this.InstructionType = instructionType; this.Direction = direction; this.Source = source; this.SourceType = sourceType; this.Target = target; this.TargetType = targetType; this.PropertyMapList = propertyMapList; }
/** * Creates a MappingsContext instance to handle a set of mappings operations using * the same parameters * @param m The mappings instance to use * @param direction The mappings direction * @param version The version of SIF to use for evaluating rule filters on field mappings * @param elementDef The ElementDef representing the object type being mapped * @return A new MappingsContext, initialized to map using the specified parameters */ public static MappingsContext Create(Mappings m, MappingDirection direction, SifVersion version, IElementDef elementDef) { // Get the rules associated with the element type MappingsContext mc = new MappingsContext(m, direction, version, elementDef); ObjectMapping om = m.GetRules(elementDef.Name, true); mc.AddRules(om); return(mc); }
/** * @param mappings * @param direction * @param version * @param elementType */ private MappingsContext( Mappings mappings, MappingDirection direction, SifVersion version, IElementDef elementType) { fMappings = mappings; fDirection = direction; fSIFVersion = version; fElementDef = elementType; }
public override char GetMappedLetter(char letter, MappingDirection dir = MappingDirection.RightToLeft) { if (dir == MappingDirection.RightToLeft) { char innerMapping = Mapping[letter.AddOffset(-_offset) - 'A']; return innerMapping.AddOffset(_offset); } char innerInput = letter.AddOffset(-_offset); return (char)(((Mapping.IndexOf(innerInput) + _offset) % AlphabetLength) + 'A'); }
public override char GetMappedLetter(char letter, MappingDirection dir = MappingDirection.RightToLeft) { if (dir == MappingDirection.RightToLeft) { char innerMapping = Mapping[letter.AddOffset(-_offset) - 'A']; return(innerMapping.AddOffset(_offset)); } char innerInput = letter.AddOffset(-_offset); return((char)(((Mapping.IndexOf(innerInput) + _offset) % AlphabetLength) + 'A')); }
internal MappingContext(QueryBase query, Mapping <T> mapping, MappingDirection dir) : base(mapping.EntitySpace) { this.ResultSetName = mapping.ResultSetName; this.MappingFunction = mapping.MappingFunction; this.Property = mapping.Property; foreach (IMapping sub in mapping.SubMappings) { this.SubMappings.Add(sub.CreateContext(this.Query, dir)); } }
public MappingInstruction(MappingInstruction parent,PropertyMap parentCollectionPropertyMap, DataMap dataMap, MappingDirection changeDirection, Object source,Object target) { this.Parent = parent; this.ParentCollectionPropertyMap = parentCollectionPropertyMap; this.DataMap = dataMap; this.ChangeDirection = changeDirection; this.Source = source; this.Target = target; this.Children = new MappingInstructionList(); this.SetCommandType(); }
public SubqueryTemplate ParamFromInput(string paramName, string inputName, MappingDirection direction = MappingDirection.Outbound, Func <object, object> convertOut = null, Func <object, object> convertIn = null, PersistenceParameterOptions options = null) { // Define it this.Param(paramName, null, direction, options); BeforeExecute(sq => { QueryInput p = sq.GetQueryInput(inputName); sq.Param(paramName, convertOut == null ? p.Value : convertOut(p.Value)); }); return(this); }
private async Task <IMapper> GetMapperAsync(Type entityType, Type dtoType, MappingDirection direction) { var cacheKey = GetCacheKey(entityType, dtoType); var itemFactory = new Func <MapperItem>(() => { var autoMapper = direction == MappingDirection.Entity2Dto ? GetMapper(entityType, dtoType) : GetMapper(dtoType, entityType); var cacheItem = new MapperItem(dtoType, direction, autoMapper); return(cacheItem); }); IMapper mapper = null; var mappers = await InternalCache.GetAsync(cacheKey, () => { var cacheItem = itemFactory(); mapper = cacheItem.Mapper; return(Task.FromResult(new List <MapperItem>() { cacheItem })); }); // if the mapper was created during the cache creation - return it without search if (mapper != null) { return(mapper); } // if mapper already cached - return from cache var cacheItem = mappers.FirstOrDefault(m => m.Direction == direction && m.DtoType == dtoType); if (cacheItem != null) { return(cacheItem.Mapper); } // cache exists but it doesn't contain mapper for specified DTO - create it and update cache cacheItem = itemFactory(); mappers.Add(itemFactory()); await InternalCache.SetAsync(cacheKey, mappers); return(cacheItem.Mapper); }
private MappingInstruction BuildCommand(MappingInstruction parent, DataMap dataMap, PropertyMap parentCollectionPropertyMap, MappingDirection direction, Object source, Object target) { //create a new command. This will figure out based on the direction and the source and target objects //whether we are doing an add, update, delete or nothing. MappingInstruction dataMapCommand = new MappingInstruction( parent, parentCollectionPropertyMap, dataMap, direction, source, target); //find all the collection properties. var collectionProperties = dataMap.DataMapCollectionList.Select(a=>a.PropertyMap).ToList(); //loop through the collection properties foreach (var collectionProperty in collectionProperties) { var sourceList = collectionProperty.SourcePropertyInfo.TryExtractIDataMapperList(source); var targetList = collectionProperty.TargetPropertyInfo.TryExtractIDataMapperList(target); var dataMapForCollection = dataMap.FindDataMapForCollectionProperty(collectionProperty); var sourceKeyAndObjectList = this.BuildKeyAndObjectPairList(sourceList, dataMapForCollection, true); var targetKeyAndObjectList = this.BuildKeyAndObjectPairList(targetList, dataMapForCollection, false); //do the full outer join var sourceToTargetFullOuterJoin = sourceKeyAndObjectList.FullOuterJoin( targetKeyAndObjectList, x => x.Key, x => x.Key, (x1, x2) => new Tuple<KeyAndObjectPair<CompositeKey>, KeyAndObjectPair<CompositeKey>>(x1, x2)) .ToList(); //at this point, we have all the things put together for us foreach (var item in sourceToTargetFullOuterJoin) { //yummy recursion dataMapCommand.Children.Add( this.BuildCommand( dataMapCommand, dataMapForCollection, collectionProperty, direction, item.Item1 == null ? null : item.Item1.Value, item.Item2 == null ? null : item.Item2.Value)); } } return dataMapCommand; }
public SubqueryTemplate Param(string paramName, object defaultValue = null, MappingDirection direction = MappingDirection.Outbound, PersistenceParameterOptions options = null) { this.PersistenceAction.Parameters[paramName] = new PersistenceParameter(paramName, defaultValue, direction, options); return(this); }
/// <summary> Evaluates the Message Direction filter against a direction flag.</summary> /// <param name="flag">Any <code>Mappings.DIRECTION_</code> constant /// </param> /// <returns> true If the message direction filter is undefined or /// matches the specified flag <code>flag</code> /// </returns> public bool EvalDirection(MappingDirection flag) { return(fDirection == MappingDirection.Unspecified || fDirection == flag); }
private static IEnumerable <PropertyMap> GetMappings <TSource, TDestination>() { var direction = new MappingDirection(typeof(TSource), typeof(TDestination)); if (!_mappingTables.TryGetValue(direction, out PropertyMap[] mappings))
public MappingContext <T> CreateContext(QueryBase query, MappingDirection dir) { return(new MappingContext <T>(query, this, dir)); }
internal static string[] MapColumnNames(DataColumnMappingCollection mappingCollection, string[] names, MappingDirection direction) { if ((mappingCollection == null) || (names == null)) { return(new string[0]); } ArrayList list = new ArrayList(); foreach (string str2 in names) { string sourceColumn; try { if (direction == MappingDirection.DataSetToSource) { sourceColumn = mappingCollection.GetByDataSetColumn(str2).SourceColumn; } else { DataColumnMapping mapping = mappingCollection[str2]; sourceColumn = mapping.DataSetColumn; } } catch (IndexOutOfRangeException) { sourceColumn = str2; } list.Add(sourceColumn); } return((string[])list.ToArray(typeof(string))); }
public SqlParameterAdapter(SqlPersistenceAction action, MappingDirection mappingDirection) : base(action, mappingDirection) { }
internal MappingContext(PersistenceAdapter adapter, Subquery subquery, IMapping mapping, MappingDirection direction, MappingContext parentContext = null) { this.Adapter = adapter; this.Direction = direction; this.ParentContext = parentContext; this.CurrentSubquery = subquery; this.CurrentMapping = mapping; this.Reset(); }
/** * Selects an appropriate MappingsContext object to use for <code>map</code> * operations. Call this method on the root Mappings object to obtain a * MappingsContext instance, then call its <code>map</code> method to perform a * mapping operation. * * @param direction The MappingsDirection that this mapping will use * @param elementDef The ElementDef of the Element being mapped to * @param version The SIFVersion to use when evaluating mappings XPaths. * @param zoneId The ID of the zone that this mappings operation is being performed on * @param sourceId The Source ID of the destination agent that this mappings is being performed for * @return a MappingsContext that can be used for evaluating mappings * @throws ADKMappingException */ private MappingsContext SelectContext( MappingDirection direction, IElementDef elementDef, SifVersion version, String zoneId, String sourceId) { // Select the mappings instance Mappings m = Select(zoneId, sourceId, version); // Create a mappings context, that retains the filters and metadata associated // with this mappings operation MappingsContext mc = MappingsContext.Create(m, direction, version, elementDef); return mc; }
MappingContext IMapping.CreateContext(PersistenceAdapter adapter, Subquery subquery, MappingDirection direction) { return(new MappingContext <T>(adapter, subquery, this, direction)); }
public MappingInstruction Build(DataMap dataMap, MappingDirection direction, Object source, Object target) { this.ValidateTypes(source, target, dataMap); return this.BuildCommand(null, dataMap, null, direction, source, target); }
IMappingContext IMapping.CreateContext(QueryBase query, MappingDirection dir) { return(this.CreateContext(query, dir)); }
public MapperItem(Type dtoType, MappingDirection direction, IMapper mapper) { DtoType = dtoType; Direction = direction; Mapper = mapper; }
protected HttpMappedValueAttribute(MappingDirection direction, string name) { Direction = direction; Name = name; }
public PersistenceAdapter(PersistenceAction action, MappingDirection mappingDirection) { this.Action = action; this.MappingDirection = mappingDirection; }
/** * Creates a MappingsContext instance to handle a set of mappings operations using * the same parameters * @param m The mappings instance to use * @param direction The mappings direction * @param version The version of SIF to use for evaluating rule filters on field mappings * @param elementDef The ElementDef representing the object type being mapped * @return A new MappingsContext, initialized to map using the specified parameters */ public static MappingsContext Create(Mappings m, MappingDirection direction, SifVersion version, IElementDef elementDef) { // Get the rules associated with the element type MappingsContext mc = new MappingsContext(m, direction, version, elementDef); ObjectMapping om = m.GetRules(elementDef.Name, true); mc.AddRules(om); return mc; }
private IList<FieldMapping> GetRulesList(ObjectMapping om, SifVersion version, MappingDirection direction) { IList<FieldMapping> list = om.GetRulesList(true); // Remove any items that should be filtered out for (int a = list.Count - 1; a > -1; a--) { MappingsFilter filt = list[a].Filter; // Filter out this rule? if (filt != null) { if (!filt.EvalDirection(direction) || !filt.EvalVersion(version)) { list.RemoveAt(a); } } } return list; }
/// <summary> Evaluates the Message Direction filter against a direction flag.</summary> /// <param name="flag">Any <code>Mappings.DIRECTION_</code> constant /// </param> /// <returns> true If the message direction filter is undefined or /// matches the specified flag <code>flag</code> /// </returns> public bool EvalDirection(MappingDirection flag) { return fDirection == MappingDirection.Unspecified || fDirection == flag; }
protected HttpHeaderAttribute(MappingDirection direction, string header) : base(direction, header) { Value = null; }
protected HttpHeaderAttribute(MappingDirection direction, string header, string value) : base(direction, header) { Value = value; }
public override PersistenceAdapter GetAdapter(PersistenceAdapterPurpose purpose, MappingDirection mappingDirection) { /* * this.Command.Connection = this.Connection.DbConnection; * * if (adapterType == PersistenceAdapterType.ResultSet) * return new SqlDataReaderAdapter(this, this.Command.ExecuteReader()); * else if (adapterType == PersistenceAdapterType.Parameters) * return new SqlParameterAdapter(this); * else */ throw new NotImplementedException(); }
/// <summary> /// /// </summary> public abstract PersistenceAdapter GetAdapter(PersistenceAdapterPurpose purpose, MappingDirection mappingDirection);
public static void MapEntityModels(object viewModel, object dataModel, MappingDirection direction = MappingDirection.DataEntitytoView, MappingOperation operation = MappingOperation.AddInsert) { var viewmodelType = viewModel.GetType(); var props = viewmodelType.GetProperties(BindingFlags.Public | BindingFlags.Instance).ToList(); if(props != null && props.Count > 0) { foreach(var prop in props) { var att = prop.GetCustomAttribute(typeof(TargetEntityMap), false) as TargetEntityMap; var mapType = operation == MappingOperation.Update ? MappingType.Update : MappingType.Insert; if(att != null && (att.MapType.HasFlag(mapType) | att.MapType.HasFlag(MappingType.All)) && !string.IsNullOrEmpty(att.TargetProperty)) { var targetType = dataModel.GetType(); var targetProp = targetType.GetProperties(BindingFlags.Public | BindingFlags.Instance).ToList() .Where(t => t.Name.ToLower() == prop.Name.ToLower()).FirstOrDefault(); if(targetProp != null) { try { //set the value if (prop.PropertyType == targetProp.PropertyType) { if (direction == MappingDirection.ViewToDataEntity) { targetProp.SetValue(dataModel, prop.GetValue(viewModel)); } else { prop.SetValue(viewModel, targetProp.GetValue(dataModel)); } } else { if (direction == MappingDirection.ViewToDataEntity) { var objnewValue = ConvertValue(prop.GetValue(viewModel), targetProp.PropertyType, att.Format); if (objnewValue != null) { targetProp.SetValue(dataModel, objnewValue); } } else { var objnewValue = ConvertValue(targetProp.GetValue(dataModel), prop.PropertyType, att.Format); if (objnewValue != null) { prop.SetValue(dataModel, objnewValue); } } } } catch { throw new Exception( string.Format("Unable to set value for {0}", targetProp.Name)); } } } } } }