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));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
    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);
    }
Esempio n. 4
0
    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);
    }
Esempio n. 5
0
        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()
            });
        }
Esempio n. 6
0
        /// <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();
        }
Esempio n. 7
0
 internal Enumerator(MappingCollection <T> list)
 {
     this.list = list;
     index     = 0;
     version   = list._version;
     current   = default(T);
 }
Esempio n. 8
0
        /// <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);
        }
Esempio n. 9
0
        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());
        }
Esempio n. 10
0
        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));
        }
Esempio n. 11
0
        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));
        }
Esempio n. 12
0
 public AutoMapperProfile(MappingCollection typeMap)
 {
     foreach (var typePair in typeMap.Mappings)
     {
         var sourceType      = typePair.Key;
         var destinationType = typePair.Value;
         this.CreateMap(sourceType, destinationType);
     }
 }
Esempio n. 13
0
 /// <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);
     }
 }
Esempio n. 14
0
        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);
        }
Esempio n. 16
0
        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));
        }
Esempio n. 17
0
        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());
        }
Esempio n. 18
0
 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);
 }
Esempio n. 19
0
 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);
 }
Esempio n. 20
0
        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);
        }
Esempio n. 21
0
        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);
        }
Esempio n. 22
0
        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);
        }
Esempio n. 23
0
 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;
     }
 }
Esempio n. 24
0
        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));
        }
Esempio n. 25
0
        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);
        }
Esempio n. 26
0
        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;
                        }
                    }
                }
            }
        }
Esempio n. 27
0
        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));
        }
Esempio n. 28
0
        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);
        }
Esempio n. 29
0
        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);
            }
        }
Esempio n. 30
0
 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));
 }
        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);
        }