public SourcesViewModel(ISourceManager sourceManager) : base("sources") { DisplayName = "Sources"; Metadata = MappingCollection.Create(sourceManager.Metadata, source => new MetadataSourceViewModel(source)); Content = MappingCollection.Create(sourceManager.Content, source => new ContentSourceViewModel(source)); }
public void ClassWithProtectedProperties_ProtectedAccessorsShouldNotBeAvailable() { // Arrange: // const string altogetherProtectedProperty = "ImAltogetherProtected"; // Not expected to be available either as a source or destination property. const string propertyWithProtectedGetter = "MyGetterIsProtected"; var propertyWithProtectedSetter = MemberExpressions.GetMemberInfo <ClassWithProtectedProperties>(c => c.MySetterIsProtected).Name; var altogetherAccessibleProperty = MemberExpressions.GetMemberInfo <ClassWithProtectedProperties>(c => c.ImAltogetherAccessible).Name; var expectedSourcePropertyNames = new[] { propertyWithProtectedSetter, altogetherAccessibleProperty }; var expectedDestinationProperyNames = new[] { propertyWithProtectedGetter, altogetherAccessibleProperty }; // Act: var mappingCollection = new MappingCollection <ClassWithProtectedProperties, ClassWithProtectedProperties, object>(null); var availableSourcePropertyNames = mappingCollection.Unmapped.Source.Select(sourceMember => sourceMember.Name).ToArray(); var availableDestinationPropertyNames = mappingCollection.Unmapped.Destination.Select(destMember => destMember.Name).ToArray(); // Assert: Array.Sort(expectedSourcePropertyNames); Array.Sort(availableSourcePropertyNames); Assert.AreEqual(expectedSourcePropertyNames, availableSourcePropertyNames); Array.Sort(expectedDestinationProperyNames); Array.Sort(availableDestinationPropertyNames); Assert.AreEqual(expectedDestinationProperyNames, availableDestinationPropertyNames); }
public MappingCollection <T> GetRange(int index, int count) { if (index < 0) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } if (count < 0) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } if (_size - index < count) { ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); } Contract.Ensures(Contract.Result <MappingCollection <T> >() != null); Contract.EndContractBlock(); MappingCollection <T> list = new MappingCollection <T>(count); Array.Copy(_items, index, list._items, 0, count); list._size = count; return(list); }
public virtual MappingCollection <TOutput> ConvertAll <TOutput>(Converter <T, TOutput> converter) { if (converter == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.converter); } Contract.EndContractBlock(); Type OutputType = GetType().GetGenericTypeDefinition().MakeGenericType(typeof(TOutput)); MappingCollection <TOutput> output = (MappingCollection <TOutput>)Activator.CreateInstance(OutputType); if (output._items.Length < _size) { TOutput[] newItems = new TOutput[_size]; if (output._items.Length > 0) { Array.Copy(output._items, newItems, output._items.Length); } output._items = newItems; } for (int i = 0; i < _size; i++) { output._items[i] = converter(_items[i]); } output._size = _size; return(output); }
public SearchResult <TEntityType> DoSearch <TEntityType>( IQueryable <TEntityType> query, FilterSet filter, MappingCollection <TEntityType> mappings ) where TEntityType : class { if (filter.PageNumber < 1) { filter.PageNumber = 1; } if (filter.HasFilters()) { query = query.AsExpandable().Where( SearchHelper.CreateSearchPredicate(filter, mappings) ); } query = ApplySort(query, filter, mappings); var resIdx = (filter.PageSize * filter.PageNumber) - filter.PageSize; return(new SearchResult <TEntityType> { TotalResults = query.Count(), Results = query.Skip(resIdx) .Take(filter.PageSize) .ToList() }); }
/// <summary> /// Constructor /// </summary> public AutoMapperImpl(MappingCollection typeMap) : base(typeMap) { var profile = new AutoMapperProfile(typeMap); var mapperConfiguration = new AutoMapper.MapperConfiguration(cfg => cfg.AddProfile(profile)); this.Mapper = mapperConfiguration.CreateMapper(); }
internal Enumerator(MappingCollection <T> list) { this.list = list; index = 0; version = list._version; current = default(T); }
/// <summary> /// Searches the type and child types for a field that matches the given column name. /// </summary> /// <param name="type">The type to search.</param> /// <param name="columnName">The column to search for.</param> /// <param name="mappingCollection">The mapping collection containing the configuration for this context.</param> /// <returns>The name of the field or null if there is no match.</returns> internal static string SearchForMatchingField(Type type, string columnName, MappingCollection mappingCollection) { var queue = new Queue <Tuple <Type, string> >(); queue.Enqueue(Tuple.Create(type, String.Empty)); var searched = new HashSet <Type>(); while (queue.Any()) { var tuple = queue.Dequeue(); var t = tuple.Item1; var prefix = tuple.Item2; searched.Add(t); var prop = GetMemberByColumnName(t, columnName); if (prop != null) { return(prefix + prop.Name); } if (mappingCollection.CanBindChild(t)) { foreach (var p in ClassPropInfo.GetMembersForType(t).Where(m => !TypeHelper.IsAtomicType(m.MemberType))) { if (!searched.Contains(p.MemberType)) { queue.Enqueue(Tuple.Create(p.MemberType, prefix + p.Name + MemberSeparator)); } } } } return(null); }
public void Overlay_Root_To_Expression() { var collection = new MappingCollection <ResourceClassNested, DomainClassSimple, CloneableTestContext>(_mapper.Object); collection.Overlay(to => to, from => from.Child); Assert.AreEqual(1, collection.Setters.Count()); }
public void Overlay_Expression_To_Expression() { var collection = new MappingCollection <MultiSrc, MultiNestedDest, CloneableTestContext>(_mapper.Object); collection.Overlay(to => to.Dest, from => from.Src1); Assert.AreEqual(new[] { "Dest", "Dest.Property1" }, ToDestinationStrings(collection.Setters)); }
public void Overlay_Root_To_Expression_MultipleSources() { var collection = new MappingCollection <MultiSrc, MultiDest, CloneableTestContext>(_mapper.Object); collection.Overlay(to => to, from => from.Src1); collection.Overlay(to => to, from => from.Src2); Assert.AreEqual(new[] { "Property1", "Property2" }, ToDestinationStrings(collection.Setters)); }
public AutoMapperProfile(MappingCollection typeMap) { foreach (var typePair in typeMap.Mappings) { var sourceType = typePair.Key; var destinationType = typePair.Value; this.CreateMap(sourceType, destinationType); } }
/// <summary> /// Constructor /// </summary> /// <param name="typeMap"></param> public TinyMapperImpl(MappingCollection typeMap) : base(typeMap) { foreach (var typePair in typeMap.Mappings) { var sourceType = typePair.Key; var destinationType = typePair.Value; TinyMapper.Bind(sourceType, destinationType); } }
public SearchResult <TEntityType> DoSearch <TEntityType>( IQueryable <TEntityType> query, FilterSet filter, List <IMapAFilter <TEntityType> > mappings ) where TEntityType : class { var mappingDef = new MappingCollection <TEntityType>(mappings); return(DoSearch(query, filter, mappingDef)); }
private static Expression <Func <T, bool> > GetExpression <T>( MappingCollection <T> mappings, FilterGroup filterGroup ) where T : class { var predicate = PredicateBuilder.New <T>(filterGroup.Operator == FilterOperator.And); var filterApplied = false; foreach (var filter in filterGroup.Filters.Where(f => !string.IsNullOrWhiteSpace(f.Value))) { var mapping = mappings.GetMapping(filter.Field); var expression = mapping.GetFilterLambda(filter.Value, filter.Action); if (expression == null) { continue; } filterApplied = true; if (filterGroup.Operator == FilterOperator.And) { predicate = predicate.And(expression); } else { predicate = predicate.Or(expression); } } // if an or filter doesnt actually do any filtering, we return true. // this allows us to ignore empty predicates if (!filterApplied && filterGroup.Operator == FilterOperator.Or) { predicate = PredicateBuilder.New <T>(true); } if (filterGroup.FilterGroups != null) { foreach (var group in filterGroup.FilterGroups) { if (filterGroup.Operator == FilterOperator.And) { predicate = predicate.And(GetExpression <T>(mappings, group)); } else { predicate = predicate.Or(GetExpression <T>(mappings, group)); } } } return(predicate); }
public void OverrideChildContext_ValueType_ReturnsNewValue() { var collection = new MappingCollection <object, object, bool>(null); collection.SetChildContext((from, to, context) => { Assert.IsTrue(context); return(false); }); Assert.IsFalse(collection.ContextUpdater(null, null, true)); }
public bool MoveNext() { MappingCollection <T> localList = list; if (version == localList._version && ((uint)index < (uint)localList._size)) { current = localList._items[index]; index++; return(true); } return(MoveNextRare()); }
public void SetUp() { _builder = new Builder(); _mapper = new Mock <IResourceMapper <CloneableTestContext> >(); _mapper.Setup(m => m.MemberConsumers).Returns(new PriorityList <IMemberConsumer> { new DefaultMemberConsumer() }); _mapper.Setup(m => m.MemberResolvers).Returns(new PriorityList <IMemberResolver> { new IgnoreCaseNameMatcher() }); _collection = new MappingCollection <ClassWithSeveralPropertiesSrcNullable, ClassWithSeveralPropertiesDest, CloneableTestContext>(_mapper.Object); }
private Type FindType(string url) { url = ResolveUrl(url); if (!string.IsNullOrEmpty(url)) { Type result; MappingCollection mappings = this.Mappings; if (mappings.TryGetValue(url, out result)) { return(result); } } return(null); }
public void SetItemTest() { PrivateObject param0 = CreateIniElement(); MappingCollection_Accessor target = new MappingCollection_Accessor(param0); // TODO: Initialize to an appropriate value int index = 0; Mapping item = target.CreateMapping(); item.Assembly = "or.dll"; target.SetItem(index, item); MappingCollection tar = (MappingCollection)target.Target; Assert.AreEqual("or.dll", tar[index].Assembly); }
public void CreateMappingTest() { XNamespace name = "urn:nhibernate-configuration-2.2"; XElement sessionFactoryEelement = new XElement(name + "sessionFactory", new XElement(name + "property", new XAttribute("name", "name"), new XText("values")), new XElement(name + "mapping", new XAttribute("assembly", "name"), new XText("orname.core.dll")) ); MappingCollection target = new MappingCollection(sessionFactoryEelement); var actual = target.CreateMapping(); Assert.AreEqual(name, actual.Element.Name.Namespace); }
public void ClearItemsTest() { PrivateObject param0 = CreateIniElement(); MappingCollection_Accessor target = new MappingCollection_Accessor(param0); MappingCollection tar = (MappingCollection)target.Target; tar.Clear(); IEnumerable <XElement> elements = from mappingNode in target.sessionFactoryEelement.Elements(xNamespace + "mapping") select mappingNode; XElement[] mappings = elements.ToArray <XElement>(); Assert.AreEqual(0, mappings.Length); Assert.AreEqual(0, tar.Count); }
public void Initialize() { if (!Initialized) { var mappingCollection = new MappingCollection <TFrom, TTo, TContext>(_mapper); foreach (var @override in _override) { @override(mappingCollection); } _override.Clear(); mappingCollection.DoAutomapping(); mappingCollection.VerifyMap(); _mapStatement = _mapper.Builder.BuildAction(mappingCollection); Initialized = true; } }
private IQueryable <TEntityType> ApplySort <TEntityType>( IQueryable <TEntityType> query, FilterSet filter, MappingCollection <TEntityType> mappings ) where TEntityType : class { if (!string.IsNullOrWhiteSpace(filter.SortBy)) { var mapping = mappings.GetMapping(filter.SortBy); return(mapping.ApplySort(query, filter.SortDir ?? mappings.DefaultSort.SortOrder)); } var defaultSort = mappings.DefaultSort; return(defaultSort.Mapping.ApplySort(query, filter.SortDir ?? mappings.DefaultSort.SortOrder)); }
public void RemoveItemTest() { PrivateObject param0 = CreateIniElement(); MappingCollection_Accessor target = new MappingCollection_Accessor(param0); // TODO: Initialize to an appropriate value int index = 0; target.RemoveItem(index); IEnumerable <XElement> elements = from mappingNode in target.sessionFactoryEelement.Elements(xNamespace + "mapping") select mappingNode; XElement[] mappings = elements.ToArray <XElement>(); Assert.AreEqual(0, mappings.Length); MappingCollection tar = (MappingCollection)target.Target; Assert.AreEqual(0, tar.Count); }
public virtual void Add(string url, Type type) { url = ResolveUrl(url); if (!string.IsNullOrEmpty(url) && type != null) { MappingCollection mappings = this.Mappings; if (mappings != null) { Type newType = null; mappings.TryGetValue(url, out newType); if (newType != type) { lock (mappings) { mappings[url] = type; } } } } }
private IQueryable <TEntityType> ApplySort <TEntityType>( IQueryable <TEntityType> query, FilterSet filter, MappingCollection <TEntityType> mappings ) where TEntityType : class { var isDescending = filter.SortDir == "desc"; var isAscending = filter.SortDir == "asc"; bool?selectedSort = isDescending ? true : (isAscending ? false : (bool?)null); if (!string.IsNullOrWhiteSpace(filter.SortBy)) { var mapping = mappings.GetMapping(filter.SortBy); return(mapping.ApplySort(query, selectedSort ?? mappings.DefaultSort.Descending)); } var defaultSort = mappings.DefaultSort; return(defaultSort.Mapping.ApplySort(query, selectedSort ?? mappings.DefaultSort.Descending)); }
public void InsertItemTest_index0() { PrivateObject param0 = CreateIniElement(); MappingCollection_Accessor target = new MappingCollection_Accessor(param0); //Insert 第一位 int index = 0; Mapping item = target.CreateMapping(); item.Assembly = "ol.dll"; target.InsertItem(index, item); MappingCollection tar = (MappingCollection)target.Target; Assert.AreEqual <Int32>(2, tar.Count); Assert.AreEqual("ol.dll", tar[0].Assembly); //Insert 最后一位 item = target.CreateMapping(); item.Assembly = "ol1.dll"; index = tar.Count; target.InsertItem(index, item); Assert.AreEqual("ol1.dll", tar[2].Assembly); //insert 中间位置 index = 1; item = target.CreateMapping(); item.Assembly = "middle.dll"; target.InsertItem(index, item); Assert.AreEqual("middle.dll", tar[index].Assembly); }
private static void EnsureManagedProperties(SPSite site, IEnumerable <ManagedPropertyDefinition> definitions) { SearchServiceApplication searchApplication = GetSearchServiceApplication(site); if (searchApplication != null) { Schema schema = new Schema(searchApplication); IEnumerable <CrawledProperty> allCrawledProperties = schema.AllCategories["SharePoint"].GetAllCrawledProperties().OfType <CrawledProperty>(); foreach (ManagedPropertyDefinition definition in definitions) { int variantType = VariantTypeDictionary[definition.DataType]; CrawledProperty rawProperty = allCrawledProperties.FirstOrDefault(v => v.Name == definition.CrawledPropertyName); if (rawProperty == null || rawProperty.GetMappedManagedProperties().GetEnumerator().MoveNext()) { continue; } ManagedProperty property; try { property = schema.AllManagedProperties[definition.MappedPropertyName]; } catch (KeyNotFoundException) { property = schema.AllManagedProperties.Create(definition.MappedPropertyName, definition.DataType); } MappingCollection mappings = property.GetMappings(); Mapping mapping = new Mapping(); mapping.CrawledPropset = rawProperty.Propset; mapping.CrawledPropertyName = rawProperty.Name; mapping.ManagedPid = property.PID; mappings.Add(mapping); property.SetMappings(mappings); property.Update(); } FlushCache(site); } }
public EFContact() { Emails = new MappingCollection<IEmail, EFEmail>(); Phones = new MappingCollection<IPhone, EFPhone>(); Addresses = new MappingCollection<IAddress, EFAddress>(); }
CreateSearchPredicate <T>(FilterSet filterSet, MappingCollection <T> mappings ) where T : class { return(GetExpression <T>(mappings, filterSet.Filter)); }